public String dumpNodeInfo(NodeType node) { return node.getNodeIdentifier() + " (" + node.getHostname() + ")"; }
private List<PrismObject<NodeType>> getMatchingNodes(List<PrismObject<NodeType>> knownNodes, String remoteName, String remoteAddress, String operation) { List<PrismObject<NodeType>> matchingNodes = new ArrayList<>(); for (PrismObject<NodeType> node : knownNodes) { NodeType actualNode = node.asObjectable(); if (remoteName != null && remoteName.equalsIgnoreCase(actualNode.getHostname())) { LOGGER.trace("The node {} was recognized as a known node (remote host name {} matched). Attempting to execute the requested operation: {} ", actualNode.getName(), actualNode.getHostname(), operation); matchingNodes.add(node); continue; } if (actualNode.getIpAddress().contains(remoteAddress)) { LOGGER.trace("The node {} was recognized as a known node (remote host address {} matched). Attempting to execute the requested operation: {} ", actualNode.getName(), remoteAddress, operation); matchingNodes.add(node); continue; } } return matchingNodes; }
public boolean authenticate(String remoteName, String remoteAddress, String operation) { LOGGER.debug("Checking if {} ({}) is a known node", remoteName, remoteAddress); OperationResult result = new OperationResult(OPERATION_SEARCH_NODE); ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_REST_URI); try { List<PrismObject<NodeType>> allNodes = repositoryService.searchObjects(NodeType.class, null, null, result); List<PrismObject<NodeType>> matchingNodes = getMatchingNodes(allNodes, remoteName, remoteAddress, operation); if (matchingNodes.size() == 1 || matchingNodes.size() >= 1 && taskManager.isLocalNodeClusteringEnabled()) { PrismObject<NodeType> actualNode = allNodes.iterator().next(); LOGGER.trace( "Matching result: The node {} was recognized as a known node (remote host name {} or IP address {} matched). Attempting to execute the requested operation: {}", actualNode.asObjectable().getName(), actualNode.asObjectable().getHostname(), remoteAddress, operation); NodeAuthenticationToken authNtoken = new NodeAuthenticationToken(actualNode, remoteAddress, Collections.emptyList()); SecurityContextHolder.getContext().setAuthentication(authNtoken); securityHelper.auditLoginSuccess(actualNode.asObjectable(), connEnv); return true; } } catch (RuntimeException | SchemaException e) { LOGGER.error("Unhandled exception when listing nodes"); LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing nodes", e); } securityHelper.auditLoginFailure(remoteName != null ? remoteName : remoteAddress, null, connEnv, "Failed to authenticate node."); return false; }
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; } }
String address = node.getHostname() + ":" + node.getJmxPort();
String address = node.getHostname() + ":" + node.getJmxPort();
private void addNodeAndTaskInformation(ClusterStatusInformation info, PrismObject<NodeType> node, OperationResult parentResult) { OperationResult result = parentResult.createSubresult(ExecutionManager.class.getName() + ".addNodeAndTaskInformation"); result.addParam("node", node); if (isCurrentNode(node)) { LOGGER.trace("Getting node and task info from the current node ({})", node.asObjectable().getNodeIdentifier()); List<ClusterStatusInformation.TaskInfo> taskInfoList = new ArrayList<>(); Set<Task> tasks = localNodeManager.getLocallyRunningTasks(result); for (Task task : tasks) { taskInfoList.add(new ClusterStatusInformation.TaskInfo(task.getOid())); } node.asObjectable().setExecutionStatus(localNodeManager.getLocalNodeExecutionStatus()); node.asObjectable().setErrorStatus(taskManager.getLocalNodeErrorStatus()); info.addNodeAndTaskInfo(node.asObjectable(), taskInfoList); } else { // if remote LOGGER.debug("Getting running task info from remote node ({}, {})", node.asObjectable().getNodeIdentifier(), node.asObjectable().getHostname()); remoteNodesManager.addNodeStatusFromRemoteNode(info, node, result); } result.recordSuccessIfUnknown(); }
String nodeOid = nodeRef.getOid(); NodeType node = modelService.getObject(NodeType.class, nodeOid, null, null, parentResult).asObjectable(); String hostName = node.getHostname(); SystemConfigurationType systemConfig = modelService .getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, task,
String nodeOid = nodeRef.getOid(); NodeType node = modelService.getObject(NodeType.class, nodeOid, null, null, parentResult).asObjectable(); String hostName = node.getHostname(); SystemConfigurationType systemConfig = modelService .getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, task,
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); } }
continue; baseUrl = httpUrlPattern.replace("$host", nodeType.getHostname());
String address = nodeInfo.getHostname() + ":" + nodeInfo.getJmxPort();
LOGGER.info("Registering this node in the repository as " + nodeToBe.getNodeIdentifier() + " at " + nodeToBe.getHostname() + ":" + nodeToBe.getJmxPort());