public NodeType findNodeById(String nodeIdentifier) { for (NodeType node : tasks.keySet()) { if (node.getNodeIdentifier().equals(nodeIdentifier)) { return node; } } return null; }
public NodeType clone() { NodeType object = new NodeType(); PrismObject value = asPrismObject().clone(); object.setupContainer(value); return object; }
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 String dumpNodeInfo(NodeType node) { return node.getNodeIdentifier() + " (" + node.getHostname() + ")"; }
/** * Generates an identifier that is used to ensure that this Node object is not (by mistake) overwritten * by another node in cluster. ClusterManager thread periodically checks if this identifier has not been changed. */ private void generateInternalNodeIdentifier(NodeType node) { String id = node.getNodeIdentifier() + ":" + node.getJmxPort() + ":" + Math.round(Math.random() * 10000000000000.0); LOGGER.trace("internal node identifier generated: " + id); node.setInternalNodeIdentifier(id); }
LOGGER.info("Registering this node in the repository as " + nodeToBe.getNodeIdentifier() + " at " + nodeToBe.getHostname() + ":" + nodeToBe.getJmxPort()); nodesInRepo = findNodesWithGivenName(result, PolyString.getOrig(nodeToBe.getName())); } catch (SchemaException e) { throw new TaskManagerInitializationException("Node registration failed because of schema exception", e); PrismObject<NodeType> nodeInRepo = nodesInRepo.get(0); nodeToBe.setTaskExecutionLimitations(nodeInRepo.asObjectable().getTaskExecutionLimitations()); nodeToBe.setUrl(nodeInRepo.asObjectable().getUrl()); ObjectDelta<NodeType> nodeDelta = nodeInRepo.diff(nodeToBe.asPrismObject(), EquivalenceStrategy.LITERAL); LOGGER.debug("Applying delta to existing node object:\n{}", nodeDelta.debugDumpLazily()); try { getRepositoryService().modifyObject(NodeType.class, nodeInRepo.getOid(), nodeDelta.getModifications(), result); LOGGER.debug("Node was successfully updated in the repository."); nodeToBe.setOid(nodeInRepo.getOid()); setCachedLocalNodeObject(nodeToBe.asPrismObject()); return nodeToBe; } catch (ObjectNotFoundException|SchemaException|ObjectAlreadyExistsException e) { LOGGER.warn("More than one node with the name of {}: removing all of them.", nodeToBe.getName()); String oid = getRepositoryService().addObject(nodeToBe.asPrismObject(), null, result); nodeToBe.setOid(oid); setCachedLocalNodeObject(nodeToBe.asPrismObject()); } catch (ObjectAlreadyExistsException e) { taskManager.setNodeErrorStatus(NodeErrorStatusType.NODE_REGISTRATION_FAILED);
@NotNull private NodeType createLocalNodeObject(TaskManagerConfiguration configuration) { NodeType node = getPrismContext().createKnownObjectable(NodeType.class); String nodeId = configuration.getNodeId(); node.setNodeIdentifier(nodeId); node.setName(new PolyStringType(nodeId)); node.setHostname(getMyHostname()); node.getIpAddress().addAll(getMyIpAddresses()); node.setJmxPort(configuration.getJmxPort()); node.setClustered(configuration.isClustered()); node.setRunning(true); node.setLastCheckInTime(getCurrentTime()); node.setBuild(getBuildInformation()); node.setTaskExecutionLimitations( new TaskExecutionLimitationsType() .groupLimitation(new TaskGroupExecutionLimitationType().groupName("").limit(null)) .groupLimitation(new TaskGroupExecutionLimitationType().groupName(nodeId).limit(null)) .groupLimitation(new TaskGroupExecutionLimitationType().groupName(TaskConstants.LIMIT_FOR_OTHER_GROUPS).limit(0))); generateInternalNodeIdentifier(node); return node; }
NodeType returnedNode = nodeInRepositoryPrism.asObjectable(); NodeType nodeRuntimeInfo = clusterStatusInformation.findNodeById(returnedNode.getNodeIdentifier()); if (nodeRuntimeInfo != null) { returnedNode.setExecutionStatus(nodeRuntimeInfo.getExecutionStatus()); returnedNode.setErrorStatus(nodeRuntimeInfo.getErrorStatus()); returnedNode.setConnectionResult(nodeRuntimeInfo.getConnectionResult()); } else { returnedNode.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR); OperationResult r = new OperationResult("connect"); r.recordFatalError("Node not known at this moment"); returnedNode.setConnectionResult(r.createOperationResultType()); list.add(returnedNode.asPrismObject());
String nodeIdentifier = nodeInfo.getNodeIdentifier(); String address = nodeInfo.getHostname() + ":" + nodeInfo.getJmxPort(); nodeInfo.setExecutionStatus(NodeExecutionStatusType.DOWN); info.addNodeInfo(nodeInfo); result.recordStatus(OperationResultStatus.SUCCESS, "Node is down"); LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the remote node {} at {}", e, nodeIdentifier, address); result.recordWarning("Cannot connect to the remote node " + nodeIdentifier + " at " + address + ": " + e.getMessage(), e); nodeInfo.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR); nodeInfo.setConnectionResult(result.createOperationResultType()); info.addNodeInfo(nodeInfo); return; LoggingUtils.logUnexpectedException(LOGGER, message, e); result.recordWarning(message, e); nodeInfo.setConnectionResult(result.createOperationResultType()); nodeInfo.setConnectionResult(result.createOperationResultType()); nodeInfo.setExecutionStatus(NodeExecutionStatusType.ERROR); // this is a mark of error situation (we expect that during ordinary shutdown the node quickly goes down so there is little probability of getting this status on that occasion) } else if (running) { nodeInfo.setExecutionStatus(NodeExecutionStatusType.RUNNING); } else { nodeInfo.setExecutionStatus(NodeExecutionStatusType.PAUSED); result.recordStatus(OperationResultStatus.SUCCESS, "Node " + nodeIdentifier + ": status = " + nodeInfo.getExecutionStatus() + ", # of running tasks: " + taskInfoList.size()); LoggingUtils.logUnexpectedException(LOGGER, "Cannot get information from the remote node {} at {}", e, nodeIdentifier, address);
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; } }
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(); }
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); } }
if (nodeType.getUrl() != null) { baseUrl = nodeType.getUrl(); } else { String httpUrlPattern = systemConfig != null && systemConfig.getInfrastructure() != null if (StringUtils.isBlank(httpUrlPattern)) { LOGGER.warn("Node URL nor intra-cluster URL pattern specified, skipping cache clearing for node {}", nodeType.getNodeIdentifier()); continue; baseUrl = httpUrlPattern.replace("$host", nodeType.getHostname());
public static void copyFromJAXB(NodeType jaxb, RNode repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException { copyObjectInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult); repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName())); repo.setNodeIdentifier(jaxb.getNodeIdentifier()); } }
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 Collection<String> getNodeIdentifiers(WorkerTasksPerNodeConfigurationType perNodeConfig, OperationResult opResult) throws SchemaException { if (!perNodeConfig.getNodeIdentifier().isEmpty()) { return perNodeConfig.getNodeIdentifier(); } else { SearchResultList<PrismObject<NodeType>> nodes = taskManager.searchObjects(NodeType.class, null, null, opResult); return nodes.stream() .filter(n -> n.asObjectable().getExecutionStatus() == NodeExecutionStatusType.RUNNING) .map(n -> n.asObjectable().getNodeIdentifier()) .collect(Collectors.toSet()); } }
/** * There may be either exactly one non-clustered node (and no other nodes), or clustered nodes only. */ void checkNonClusteredNodes(OperationResult result) { LOGGER.trace("Checking non-clustered nodes."); List<String> clustered = new ArrayList<>(); List<String> nonClustered = new ArrayList<>(); List<PrismObject<NodeType>> allNodes = clusterManager.getAllNodes(result); for (PrismObject<NodeType> nodePrism : allNodes) { NodeType n = nodePrism.asObjectable(); if (isUp(n)) { if (n.isClustered()) { clustered.add(n.getNodeIdentifier()); } else { nonClustered.add(n.getNodeIdentifier()); } } } LOGGER.trace("Clustered nodes: " + clustered); LOGGER.trace("Non-clustered nodes: " + nonClustered); int all = clustered.size() + nonClustered.size(); if (!taskManager.getConfiguration().isClustered() && all > 1) { LOGGER.error("This node is a non-clustered one, mixed with other nodes. In this system, there are " + nonClustered.size() + " non-clustered nodes (" + nonClustered + ") and " + clustered.size() + " clustered ones (" + clustered + "). Stopping this node."); registerNodeError(NodeErrorStatusType.NON_CLUSTERED_NODE_WITH_OTHERS); } }
/** * Create an instance of {@link NodeType } * */ public NodeType createNodeType() { return new NodeType(); }
public List<String> createIpAddressList() { PrismForJAXBUtil.createProperty(asPrismContainerValue(), F_IP_ADDRESS); return getIpAddress(); }
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,