use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.
the class ClusterExecutionHelperImpl method createClient.
private WebClient createClient(NodeType node, ClusterExecutionOptions options, String context) throws SchemaException {
String baseUrl;
if (node.getUrl() != null) {
baseUrl = node.getUrl();
} else {
LOGGER.warn("Node URL is not known, skipping remote execution ({}) for node {}", context, node.getNodeIdentifier());
return null;
}
String url = baseUrl + "/ws/cluster";
LOGGER.debug("Going to execute '{}' on '{}'", context, url);
WebClient client = WebClient.create(url, Arrays.asList(xmlProvider, jsonProvider, yamlProvider));
if (!ClusterExecutionOptions.isSkipDefaultAccept(options)) {
client.accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml");
}
client.type(MediaType.APPLICATION_XML);
NodeType localNode = taskManager.getLocalNode();
ProtectedStringType protectedSecret = localNode != null ? localNode.getSecret() : null;
if (protectedSecret == null) {
throw new SchemaException("No secret is set for local node " + localNode);
}
String secret;
try {
secret = protector.decryptString(protectedSecret);
} catch (EncryptionException e) {
throw new SystemException("Couldn't decrypt local node secret: " + e.getMessage(), e);
}
client.header("Authorization", RestAuthenticationMethod.CLUSTER.getMethod() + " " + Base64Utility.encode(secret.getBytes()));
return client;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.
the class ClusterExecutionHelperImpl method executeWithFallback.
@Override
public PrismObject<NodeType> executeWithFallback(@Nullable String nodeOid, @NotNull ClientCode code, ClusterExecutionOptions options, String context, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(DOT_CLASS + "executeWithFallback");
try {
if (nodeOid != null) {
PrismObject<NodeType> node = null;
try {
node = repositoryService.getObject(NodeType.class, nodeOid, null, result);
} catch (Throwable t) {
LOGGER.info("Couldn't get node '{}' - will try other nodes to execute '{}', if they are available: {}", nodeOid, context, t.getMessage(), t);
}
if (node != null && tryExecute(node.asObjectable(), code, options, context, result)) {
result.recordStatus(OperationResultStatus.SUCCESS, "Succeeded on suggested node");
return node;
}
}
SearchResultList<PrismObject<NodeType>> otherClusterNodes = searchOtherClusterNodes(context, result);
if (otherClusterNodes != null) {
for (PrismObject<NodeType> otherNode : otherClusterNodes.getList()) {
if (nodeOid == null || !nodeOid.equals(otherNode.getOid())) {
if (tryExecute(otherNode.asObjectable(), code, options, context, result)) {
String identifier = otherNode.asObjectable().getNodeIdentifier();
LOGGER.info("Operation '{}' succeeded on node '{}'", context, identifier);
result.recordStatus(OperationResultStatus.SUCCESS, "Succeeded on " + identifier);
return otherNode;
}
}
}
}
return null;
} catch (Throwable t) {
// should not occur
result.recordFatalError(t);
throw t;
} finally {
// "UNKNOWN" should occur only if no node succeeds
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.
the class NodeIdComputer method getNodeIdFromExpression.
private String getNodeIdFromExpression(ConfigurationInterpolator parentInterpolator, String expression, OperationResult result) {
SequenceLookup sequenceLookup = new SequenceLookup();
InterpolatorSpecification sequenceProvidingInterpolatorSpec = new InterpolatorSpecification.Builder().withParentInterpolator(parentInterpolator).withPrefixLookup("sequence", sequenceLookup).create();
ConfigurationInterpolator interpolator = ConfigurationInterpolator.fromSpecification(sequenceProvidingInterpolatorSpec);
for (int attempt = 0; ; attempt++) {
Object interpolationResult = interpolator.interpolate(expression);
if (!(interpolationResult instanceof String)) {
LOGGER.warn("Node ID expression '{}' returned null or non-String value: {}", expression, interpolationResult);
return null;
}
String candidateNodeId = (String) interpolationResult;
if (candidateNodeId.contains("${")) {
// This is a bit of hack: it looks like the node was not resolved correctly.
throw new SystemException("Looks like we couldn't resolve the node ID expression. The (partial) result is: '" + candidateNodeId + "'");
}
if (sequenceLookup.iterationRequired) {
try {
// Let us try to create node with given name. If we fail we know we need to iterate.
// If we succeed, we will (later) replace the node with the correct content.
// Note that we set (fake) last check-in time here so this node will not be accidentally cleaned-up.
// TODO consider moving this addObject call to NodeRegistrar (requires cleanup of the mix of
// Spring injected and manually created objects)
NodeType node = new NodeType(prismContext).name(candidateNodeId).lastCheckInTime(XmlTypeConverter.createXMLGregorianCalendar());
repositoryService.addObject(node.asPrismObject(), null, result);
} catch (ObjectAlreadyExistsException e) {
// We have a conflict. But the node might be - in fact - dead. So let's try to reclaim it if possible.
String nodeIdNorm = prismContext.getDefaultPolyStringNormalizer().normalize(candidateNodeId);
SearchResultList<PrismObject<NodeType>> existingNodes;
try {
existingNodes = repositoryService.searchObjects(NodeType.class, prismContext.queryFor(NodeType.class).item(NodeType.F_NAME).eqPoly(candidateNodeId, nodeIdNorm).matchingNorm().build(), null, result);
} catch (SchemaException ex) {
throw new SystemException("Unexpected schema exception while looking for node '" + candidateNodeId + "': " + e.getMessage(), e);
}
if (existingNodes.isEmpty()) {
// Strange. The node should have gone in the meanwhile. To be safe, let's try another one.
LOGGER.warn("Node name '{}' seemed to be already reserved. But it cannot be found now. Iterating to the" + " next one (if possible).", candidateNodeId);
sequenceLookup.advance();
} else if (existingNodes.size() > 1) {
LOGGER.warn("Strange: More than one node with the name of '{}': {}. Trying next name in the sequence" + "(if possible).", candidateNodeId, existingNodes);
sequenceLookup.advance();
} else {
NodeType existingNode = existingNodes.get(0).asObjectable();
if (existingNode.getOperationalState() == NodeOperationalStateType.DOWN) {
LOGGER.info("Considering using the node name of '{}' that already exists but is marked as being down" + " (OID {}). So deleting the node and trying again.", candidateNodeId, existingNode.getOid());
try {
repositoryService.deleteObject(NodeType.class, existingNode.getOid(), result);
} catch (ObjectNotFoundException ex) {
LoggingUtils.logExceptionAsWarning(LOGGER, "Couldn't delete the node {}. Probably someone" + " else is faster than us.", ex, existingNode);
}
// no advance here
} else {
LOGGER.debug("Node name '{}' is already reserved. Iterating to next one (if possible).", candidateNodeId);
sequenceLookup.advance();
}
}
if (attempt > MAX_ATTEMPTS_SAFEGUARD) {
throw new SystemException("Maximum attempts safeguard value of " + MAX_ATTEMPTS_SAFEGUARD + " has been reached. " + "Something very strange must have happened.");
} else if (sequenceLookup.isOutOfNumbers()) {
throw new SystemException("Cannot acquire node name. The sequence upper border (" + sequenceLookup.end + ") has been reached.");
} else {
continue;
}
} catch (SchemaException e) {
throw new SystemException("Unexpected schema exception while creating temporary node: " + e.getMessage(), e);
}
}
return candidateNodeId;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.
the class PageAbout method initLayout.
private void initLayout() {
Label branch = new Label(ID_BRANCH, createStringResource("midpoint.system.branch"));
branch.setRenderBodyOnly(true);
add(branch);
Label revision = new Label(ID_BUILD, createStringResource("midpoint.system.build"));
revision.setRenderBodyOnly(true);
add(revision);
Label build = new Label(ID_BUILD_TIMESTAMP, createStringResource("midpoint.system.buildTimestamp"));
build.setRenderBodyOnly(true);
add(build);
ListView<SystemItem> listSystemItems = new ListView<SystemItem>(ID_LIST_SYSTEM_ITEMS, getItems()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<SystemItem> item) {
SystemItem systemItem = item.getModelObject();
Label property = new Label(ID_PROPERTY, systemItem.getProperty());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_VALUE, systemItem.getValue());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(listSystemItems);
addLabel(ID_IMPLEMENTATION_SHORT_NAME, "implementationShortName");
addLabel(ID_IMPLEMENTATION_DESCRIPTION, "implementationDescription");
addLabel(ID_IS_EMBEDDED, "isEmbedded");
addLabel(ID_DRIVER_SHORT_NAME, "driverShortName");
addLabel(ID_DRIVER_VERSION, "driverVersion");
addLabel(ID_REPOSITORY_URL, "repositoryUrl");
ListView<LabeledString> additionalDetails = new ListView<LabeledString>(ID_ADDITIONAL_DETAILS, new PropertyModel<>(repoDiagModel, "additionalDetails")) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<LabeledString> item) {
LabeledString labeledString = item.getModelObject();
Label property = new Label(ID_DETAIL_NAME, labeledString.getLabel());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_DETAIL_VALUE, labeledString.getData());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(additionalDetails);
ListView<LabeledString> provisioningAdditionalDetails = new ListView<LabeledString>(ID_PROVISIONING_ADDITIONAL_DETAILS, new PropertyModel<>(provisioningDiagModel, "additionalDetails")) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<LabeledString> item) {
LabeledString labeledString = item.getModelObject();
Label property = new Label(ID_PROVISIONING_DETAIL_NAME, labeledString.getLabel());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_PROVISIONING_DETAIL_VALUE, labeledString.getData());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(provisioningAdditionalDetails);
String nodeId = getTaskManager().getNodeId();
OperationResult result = new OperationResult(OPERATION_LOAD_NODE);
List<PrismObject<NodeType>> nodes = WebModelServiceUtils.searchObjects(NodeType.class, getPrismContext().queryFor(NodeType.class).item(NodeType.F_NODE_IDENTIFIER).eq(nodeId).build(), result, PageAbout.this);
if (nodes.isEmpty()) {
throw new IllegalArgumentException("Couldn't find NodeType with identifier '" + nodeId + "'");
}
if (nodes.size() > 1) {
throw new IllegalArgumentException("Found more as one NodeType with identifier '" + nodeId + "'");
}
PrismObject<NodeType> node = nodes.get(0);
if (node == null) {
throw new IllegalArgumentException("Found NodeType with identifier '" + nodeId + "' is null");
}
NodeType nodeType = node.asObjectable();
Label nodeName = new Label(ID_NODE_NAME, nodeType.getName() != null ? nodeType.getName() : "");
nodeName.setRenderBodyOnly(true);
add(nodeName);
Label nodeIdValue = new Label(ID_NODE_ID, nodeType.getNodeIdentifier());
nodeIdValue.setRenderBodyOnly(true);
add(nodeIdValue);
Label nodeUrl = new Label(ID_NODE_URL, nodeType.getUrl() != null ? nodeType.getUrl() : "");
nodeUrl.setRenderBodyOnly(true);
add(nodeUrl);
Label jvmProperties = new Label(ID_JVM_PROPERTIES, new LoadableModel<String>(false) {
private static final long serialVersionUID = 1L;
@Override
protected String load() {
try {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
return StringUtils.join(arguments, "<br/>");
} catch (Exception ex) {
return PageAbout.this.getString("PageAbout.message.couldntObtainJvmParams");
}
}
});
jvmProperties.setEscapeModelStrings(false);
add(jvmProperties);
initButtons();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.
the class RemoteNodesManager method stopRemoteScheduler.
public void stopRemoteScheduler(String nodeIdentifier, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(RemoteNodesManager.class.getName() + ".stopRemoteScheduler");
result.addParam("nodeIdentifier", nodeIdentifier);
NodeType node = getNode(nodeIdentifier, result);
if (node == null) {
return;
}
String nodeName = node.getNodeIdentifier();
String address = node.getHostname() + ":" + node.getJmxPort();
JMXConnector connector = null;
try {
MBeanServerConnection mbsc;
try {
connector = connectViaJmx(address);
mbsc = connector.getMBeanServerConnection();
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the remote node {} at {}", e, nodeName, address);
result.recordFatalError("Cannot connect to the remote node " + nodeName + " at " + address + ": " + e.getMessage(), e);
return;
}
try {
QuartzSchedulerMBean mbeanProxy = getMBeanProxy(nodeName, mbsc);
if (mbeanProxy != null) {
mbeanProxy.standby();
result.recordSuccess();
} else {
result.recordWarning("Cannot stop the scheduler on node " + nodeName + " at " + address + " because the JMX object for scheduler cannot be found on that node.");
}
return;
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot put remote scheduler into standby mode; remote node {} at {}", e, nodeName, address);
result.recordFatalError("Cannot put remote scheduler " + nodeName + " at " + address + " into standby mode: " + e.getMessage());
return;
}
} finally {
try {
if (connector != null) {
connector.close();
}
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot close JMX connection to {}", e, address);
}
}
}
Aggregations