use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.
the class RecoverLocalInfrastructureTest method restartRmAndCheckFinalState.
private void restartRmAndCheckFinalState(boolean nodesShouldBeRecreated) throws Exception {
// restart RM
this.rmHelper = new RMTHelper();
this.startRmWithConfig(RESTART_CONFIG);
assertThat(PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean()).isFalse();
assertThat(this.rmHelper.isRMStarted()).isTrue();
// re-snapshot the RM state
RMMonitorEventReceiver resourceManagerMonitor = (RMMonitorEventReceiver) this.resourceManager;
List<RMNodeSourceEvent> nodeSourceEvent = resourceManagerMonitor.getInitialState().getNodeSourceEvents();
// the node source has been recovered on restart: we should have one node source with the same name
assertThat(nodeSourceEvent.size()).isEqualTo(1);
assertThat(nodeSourceEvent.get(0).getSourceName()).isEqualTo(NODE_SOURCE_NAME);
// wait for nodes to be recreated if needed
if (nodesShouldBeRecreated) {
this.rmHelper.waitForAnyMultipleNodeEvent(RMEventType.NODE_STATE_CHANGED, NODE_NUMBER);
}
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.
the class RMInitialStateChunksTest2 method clientKnowsNothing.
@Test
public void clientKnowsNothing() {
Map<String, RMNodeEvent> accumulatedNodeEvents = new HashMap<>();
Map<String, RMNodeSourceEvent> accumulatedNodeSourceEvents = new HashMap<>();
int numberOfRequests = 0;
long currentCounter = RMInitialState.EMPTY_STATE;
while (true) {
final RMStateDelta rmStateDelta = rmInitialState.cloneAndFilter(currentCounter);
++numberOfRequests;
rmStateDelta.getNodesEvents().forEach(rmNodeEvent -> {
accumulatedNodeEvents.put(rmNodeEvent.getNodeSource() + rmNodeEvent.getNodeUrl(), rmNodeEvent);
});
rmStateDelta.getNodeSource().forEach(rmNodeSourceEvent -> {
accumulatedNodeSourceEvents.put(rmNodeSourceEvent.getSourceName(), rmNodeSourceEvent);
});
if (rmStateDelta.getLatestCounter() == currentCounter) {
break;
} else {
currentCounter = rmStateDelta.getLatestCounter();
}
}
assertEquals(4, accumulatedNodeSourceEvents.size());
assertEquals(200, accumulatedNodeEvents.size());
assertEquals(6, numberOfRequests);
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.
the class RMGroupEventListener method notify.
public void notify(Collection<RMEvent> events) {
for (RMEvent event : events) {
if (event instanceof RMNodeEvent) {
RMNodeEvent nodeEvent = (RMNodeEvent) event;
nodeEvent(nodeEvent);
} else if (event instanceof RMNodeSourceEvent) {
RMNodeSourceEvent sourceEvent = (RMNodeSourceEvent) event;
nodeSourceEvent(sourceEvent);
} else {
rmEvent(event);
}
}
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.
the class RMRest method acquireNodes.
@Override
public Set<String> acquireNodes(String sessionId, String sourceName, int numberNodes, boolean synchronous, long timeout, String nodeConfigJson) throws NotConnectedException, RestException {
if (numberNodes <= 0) {
throw new IllegalArgumentException("Invalid number of nodes: " + numberNodes);
}
ResourceManager rm = checkAccess(sessionId);
if (sourceName == null) {
throw new IllegalArgumentException("Node source name should not be null.");
}
Optional<RMNodeSourceEvent> nodeSource = rm.getExistingNodeSourcesList().stream().filter(ns -> sourceName.equals(ns.getSourceName())).findAny();
if (!nodeSource.isPresent()) {
throw new IllegalArgumentException(String.format("Specified node source [%s] not exist.", sourceName));
}
if (!NODE_SOURCE_DEPLOYED_STATUS.equals(nodeSource.get().getNodeSourceStatus())) {
throw new IllegalArgumentException(String.format("Specified node source [%s] is not deployed.", sourceName));
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> nodeConfig;
try {
nodeConfig = mapper.readValue(nodeConfigJson, new TypeReference<Map<String, ?>>() {
});
} catch (Exception e) {
throw new IllegalArgumentException("Error during parsing the node configuration: " + nodeConfigJson, e);
}
if (synchronous) {
String acquireRequestId = "tmp:" + UUID.randomUUID().toString();
setRequestIdInNodeConfig(nodeConfig, acquireRequestId);
rm.acquireNodes(sourceName, numberNodes, timeout * 1000, nodeConfig);
waitUntil(timeout, "Nodes are not deployed within the specified timeout.", () -> rm.getNodesByTag(acquireRequestId).size() == numberNodes);
return orThrowRpe(rm.getNodesByTag(acquireRequestId));
} else {
rm.acquireNodes(sourceName, numberNodes, timeout * 1000, nodeConfig);
return new HashSet<>();
}
}
use of org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent in project scheduling by ow2-proactive.
the class RMCore method nodeSourceUnregister.
/**
* Unregisters node source from the resource manager core.
*/
public BooleanWrapper nodeSourceUnregister(String nodeSourceName, NodeSourceStatus nodeSourceStatus, RMNodeSourceEvent evt) {
NodeSource nodeSource = this.deployedNodeSources.remove(nodeSourceName);
if (nodeSource == null) {
logger.warn("Attempt to remove non-existing node source " + nodeSourceName);
return new BooleanWrapper(false);
}
logger.info(NODE_SOURCE_STRING + nodeSourceName + HAS_BEEN_SUCCESSFULLY + evt.getEventType().getDescription());
this.monitoring.nodeSourceEvent(evt);
this.emitRemovedEventIfNodeSourceWasNotUndeployed(nodeSource, nodeSourceStatus);
return new BooleanWrapper(true);
}
Aggregations