private QuartzSchedulerMBean getMBeanProxy(String nodeName, MBeanServerConnection mbsc) throws MalformedObjectNameException { String mbeanNameAsString = "quartz:type=QuartzScheduler,name=midPointScheduler,instance=" + nodeName; ObjectName mbeanName = new ObjectName(mbeanNameAsString); try { if (mbsc.isRegistered(mbeanName)) { return JMX.newMBeanProxy(mbsc, mbeanName, QuartzSchedulerMBean.class, true); } else { LOGGER.trace("MBean " + mbeanNameAsString + " is not registered at " + nodeName); return null; } } catch (IOException e) { LoggingUtils.logUnexpectedException(LOGGER, "Cannot communicate with remote node via JMX", e); return null; } }
private QuartzSchedulerMBean getSchedulerBean(NodeType node, Holder<JMXConnector> connectorHolder, OperationResult result) { String nodeName = node.getNodeIdentifier(); String address = node.getHostname() + ":" + node.getJmxPort(); try { JMXConnector connector = connectViaJmx(address); connectorHolder.setValue(connector); MBeanServerConnection serverConnection = connector.getMBeanServerConnection(); QuartzSchedulerMBean bean = getMBeanProxy(nodeName, serverConnection); if (bean == null) { String message = "Cannot connect to the Quartz Scheduler bean at remote node " + nodeName + " at " + address + " because the JMX object for scheduler cannot be found on that node."; LOGGER.warn("{}", message); result.recordFatalError(message); } return bean; } catch (IOException|MalformedObjectNameException e) { LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the quartz scheduler bean at remote node {} at {}", e, nodeName, address); result.recordFatalError("Cannot connect to the quartz scheduler bean at remote node " + nodeName + " at " + address + ": " + e.getMessage(), e); return null; } }
public void redirectTaskToNode(@NotNull Task task, @NotNull NodeType node, @NotNull OperationResult result) { LOGGER.trace("Trying to schedule task {} on {}", task, node.getNodeIdentifier()); Holder<JMXConnector> connectorHolder = new Holder<>(); try { QuartzSchedulerMBean mbeanProxy = getSchedulerBean(node, connectorHolder, result); if (mbeanProxy != null) { try { createStarterJobIfNeeded(); mbeanProxy.triggerJob(STARTER_JOB_KEY.getName(), STARTER_JOB_KEY.getGroup(), Collections.singletonMap(JobStarter.TASK_OID, task.getOid())); LOGGER.debug("Successfully requested start of " + task + " at " + getClusterManager().dumpNodeInfo(node)); result.recordSuccessIfUnknown(); } catch (Exception e) { // necessary because of mbeanProxy String message = "Cannot schedule " + task + " at " + getClusterManager().dumpNodeInfo(node); LoggingUtils.logUnexpectedException(LOGGER, message, e); result.recordFatalError(message + ":" + e.getMessage(), e); } } else { LOGGER.warn("Couldn't obtain Quartz MBean so couldn't reschedule task {} on {}", task, node.getNodeIdentifier()); } } finally { closeJmxConnection(connectorHolder, getClusterManager().dumpNodeInfo(node)); } }
/** * QuartzSchedulerMBeanImpl * * @throws NotCompliantMBeanException */ protected QuartzSchedulerMBeanImpl(QuartzScheduler scheduler) throws NotCompliantMBeanException { super(QuartzSchedulerMBean.class); this.scheduler = scheduler; this.scheduler.addInternalJobListener(this); this.scheduler.addInternalSchedulerListener(this); this.sampledStatistics = NULL_SAMPLED_STATISTICS; this.sampledStatisticsEnabled = false; }
/** * QuartzSchedulerMBeanImpl * * @throws NotCompliantMBeanException */ protected QuartzSchedulerMBeanImpl(QuartzScheduler scheduler) throws NotCompliantMBeanException { super(QuartzSchedulerMBean.class); this.scheduler = scheduler; this.scheduler.addGlobalJobListener(this); this.scheduler.addSchedulerListener(this); this.sampledStatistics = NULL_SAMPLED_STATISTICS; this.sampledStatisticsEnabled = false; }
void stopRemoteTaskRun(String oid, NodeType node, OperationResult parentResult) { OperationResult result = parentResult.createSubresult(RemoteNodesManager.class.getName() + ".stopRemoteTaskRun"); result.addParam("oid", oid); result.addParam("node", node.toString()); LOGGER.debug("Interrupting task " + oid + " running at " + getClusterManager().dumpNodeInfo(node)); String nodeName = node.getNodeIdentifier(); String address = node.getHostname() + ":" + node.getJmxPort(); Holder<JMXConnector> connectorHolder = new Holder<>(); try { QuartzSchedulerMBean mbeanProxy = getSchedulerBean(node, connectorHolder, result); if (mbeanProxy != null) { try { mbeanProxy.interruptJob(oid, Scheduler.DEFAULT_GROUP); LOGGER.debug("Successfully signalled shutdown to task " + oid + " running at " + getClusterManager().dumpNodeInfo(node)); result.recordSuccessIfUnknown(); } catch (Exception e) { // necessary because of mbeanProxy String message = "Cannot signal task "+oid+" interruption to remote node "+nodeName+" at "+address; LoggingUtils.logUnexpectedException(LOGGER, message, e); result.recordFatalError(message + ":" + e.getMessage(), e); } } } finally { closeJmxConnection(connectorHolder, address); } }