use of org.ow2.proactive.resourcemanager.core.RMCore in project scheduling by ow2-proactive.
the class RMCoreTest method testLockNodeState.
private void testLockNodeState(NodeState nodeState) {
RMNodeImpl rmNode = spy(RMNodeHelper.basicWithMockedInternals().getLeft());
rmNode.setState(nodeState);
HashMap<String, RMNode> allNodes = new HashMap<>();
allNodes.put(rmNode.getNodeURL(), rmNode);
ArrayList<RMNode> freeNodes = Lists.newArrayList((RMNode) rmNode);
RMCore rmCore = new RMCore(new HashMap<String, NodeSource>(), allNodes, Mockito.mock(Client.class), Mockito.mock(RMMonitoringImpl.class), Mockito.mock(SelectionManager.class), freeNodes, Mockito.mock(RMDBManager.class));
rmCore.signalRMCoreIsInitialized();
BooleanWrapper lockResult = rmCore.lockNodes(ImmutableSet.of(rmNode.getNodeURL()));
assertThat(lockResult.getBooleanValue()).isTrue();
assertThat(rmNode.getState()).isEqualTo(nodeState);
assertThat(rmNode.isLocked()).isTrue();
assertThat(freeNodes).isEmpty();
}
use of org.ow2.proactive.resourcemanager.core.RMCore in project scheduling by ow2-proactive.
the class RMCore method getRMInitialState.
/**
* Builds and returns a snapshot of RMCore's current state. Initial state
* must be understood as a new Monitor point of view. A new monitor start to
* receive RMCore events, so must be informed of the current state of the
* Core at the beginning of monitoring. The monitor is built in three parts
* first with all the nodes knows by the RMCore, then with all deploying
* nodes known by the deployed node sources and then with all the defined
* node sources.
*
* @return RMInitialState containing nodes and nodeSources of the RMCore.
*/
public RMInitialState getRMInitialState() {
final Map<String, RMNodeEvent> nodeEvents = this.allNodes.values().stream().map(RMNode::createNodeEvent).collect(Collectors.toMap(RMNodeEvent::getNodeUrl, event -> event));
for (NodeSource source : this.deployedNodeSources.values()) {
for (RMDeployingNode node : source.getDeployingAndLostNodes()) {
final RMNodeEvent nodeEvent = node.createNodeEvent();
nodeEvents.put(nodeEvent.getNodeUrl(), nodeEvent);
}
}
final List<RMNodeSourceEvent> nodeSourceEvents = new ArrayList<>(this.definedNodeSources.values().stream().map(NodeSource::createNodeSourceEvent).collect(Collectors.toList()));
long eventCounter = 0;
for (RMNodeSourceEvent nodeSourceEvent : nodeSourceEvents) {
nodeSourceEvent.setCounter(eventCounter++);
}
for (RMNodeEvent nodeEvent : nodeEvents.values()) {
nodeEvent.setCounter(eventCounter++);
}
final RMInitialState rmInitialState = new RMInitialState();
rmInitialState.addAll(nodeEvents.values());
rmInitialState.addAll(nodeSourceEvents);
return rmInitialState;
}
use of org.ow2.proactive.resourcemanager.core.RMCore in project scheduling by ow2-proactive.
the class RMCore method undeployNodeSource.
/**
* {@inheritDoc}
*/
public BooleanWrapper undeployNodeSource(String nodeSourceName, boolean preempt) {
if (!this.definedNodeSources.containsKey(nodeSourceName)) {
throw new IllegalArgumentException("Unknown node source " + nodeSourceName);
}
if (this.deployedNodeSources.containsKey(nodeSourceName)) {
NodeSource nodeSourceToRemove = this.deployedNodeSources.get(nodeSourceName);
this.caller.checkPermission(nodeSourceToRemove.getAdminPermission(), this.caller + " is not authorized to remove " + nodeSourceName);
logger.info("Undeploy node source " + nodeSourceName + " with preempt=" + preempt + REQUESTED_BY_STRING + this.caller.getName());
nodeSourceToRemove.setStatus(NodeSourceStatus.NODES_UNDEPLOYED);
this.removeAllNodes(nodeSourceName, preempt);
// delegate the removal process to the node source that will
// eventually call back the RMCore to unregister the deployed node
// source
nodeSourceToRemove.shutdown(this.caller);
this.updateNodeSourceDescriptorWithStatusAndPersist(this.definedNodeSources.get(nodeSourceName).getDescriptor(), NodeSourceStatus.NODES_UNDEPLOYED);
logger.info(NODE_SOURCE_STRING + nodeSourceName + " has been successfully undeployed");
}
return new BooleanWrapper(true);
}
use of org.ow2.proactive.resourcemanager.core.RMCore in project scheduling by ow2-proactive.
the class RMCore method shutdown.
/**
* Shutdown the resource manager
*/
public BooleanWrapper shutdown(boolean preempt) {
// this method could be called twice from shutdown hook and user action
if (toShutDown)
return new BooleanWrapper(false);
logger.info("RMCore shutdown request");
this.monitoring.rmEvent(new RMEvent(RMEventType.SHUTTING_DOWN));
this.toShutDown = true;
if (PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean() || this.deployedNodeSources.size() == 0) {
finalizeShutdown();
} else {
for (Entry<String, NodeSource> entry : this.deployedNodeSources.entrySet()) {
removeAllNodes(entry.getKey(), preempt, true);
entry.getValue().shutdown(caller);
}
}
return new BooleanWrapper(true);
}
use of org.ow2.proactive.resourcemanager.core.RMCore in project scheduling by ow2-proactive.
the class RMCore method createNodeSourceInstance.
private NodeSource createNodeSourceInstance(NodeSourceDescriptor nodeSourceDescriptor) {
InfrastructureManager infrastructureManager = InfrastructureManagerFactory.create(nodeSourceDescriptor);
NodeSourcePolicy notActivePolicy = NodeSourcePolicyFactory.create(nodeSourceDescriptor.getPolicyType());
return new NodeSource(this.getUrl(), nodeSourceDescriptor.getName(), infrastructureManager, notActivePolicy, (RMCore) PAActiveObject.getStubOnThis(), this.monitoring, nodeSourceDescriptor);
}
Aggregations