use of org.ow2.proactive.resourcemanager.common.event.RMInitialState in project scheduling by ow2-proactive.
the class RMInitialState method cloneAndFilter.
/**
* Clones current state events, but keep only those events which has counter bigger than provided 'filter'
* Event counter can take values [0, +).
* So if filter is '-1' then all events will returned.
* @param filter
* @return rmInitialState where all the events bigger than 'filter'
*/
public RMStateDelta cloneAndFilter(long filter) {
long actualFilter = computeActualFilter(filter);
final List<RMEvent> responseEvents = events.getSortedItems().tailSet(// because tailSet returns event which is equal or greater
new RMEvent(actualFilter + 1)).stream().limit(PAResourceManagerProperties.RM_REST_MONITORING_MAXIMUM_CHUNK_SIZE.getValueAsInt()).collect(Collectors.toList());
RMStateDelta response = new RMStateDelta();
response.setNodeSource(getNodeSourceEvents(responseEvents));
response.setNodesEvents(getNodeEvents(responseEvents));
response.setLatestCounter(Math.max(actualFilter, findLargestCounter(responseEvents)));
return response;
}
use of org.ow2.proactive.resourcemanager.common.event.RMInitialState 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.common.event.RMInitialState in project scheduling by ow2-proactive.
the class RMMonitoringImpl method addRMEventListener.
/**
* Register a new Resource manager listener.
* Way to a monitor object to ask at RMMonitoring to throw
* RM events to it.
* @param stub a listener object which implements {@link RMEventListener}
* interface.
* @param events list of wanted events that must be received.
* @return RMInitialState snapshot of RM's current state : nodes and node sources.
*/
public RMInitialState addRMEventListener(RMEventListener stub, RMEventType... events) {
UniqueID id = PAActiveObject.getContext().getCurrentRequest().getSourceBodyID();
logger.debug("Adding the RM listener for " + id.shortString());
synchronized (dispatchers) {
Client client = null;
synchronized (RMCore.clients) {
client = RMCore.clients.get(id);
}
if (client == null) {
throw new IllegalArgumentException("Unknown client " + id.shortString());
}
EventDispatcher eventDispatcher = null;
if (stub instanceof RMGroupEventListener) {
eventDispatcher = new GroupEventDispatcher(client, stub, events);
} else {
eventDispatcher = new EventDispatcher(client, stub, events);
}
this.dispatchers.put(id, eventDispatcher);
RMInitialState rmInitialState = rmcore.getRMInitialState();
eventDispatcher.setCounter(rmInitialState.getLatestCounter());
return rmInitialState;
}
}
use of org.ow2.proactive.resourcemanager.common.event.RMInitialState in project scheduling by ow2-proactive.
the class RMInitialStateTest method testCloneAndFilter2.
@Test
public void testCloneAndFilter2() {
final RMStateDelta rmInitialState = this.rmInitialState.cloneAndFilter(20);
assertEquals(5, rmInitialState.getNodesEvents().size());
assertEquals(2, rmInitialState.getNodeSource().size());
}
use of org.ow2.proactive.resourcemanager.common.event.RMInitialState in project scheduling by ow2-proactive.
the class RMInitialStateTest method testCloneAndFilter1.
@Test
public void testCloneAndFilter1() {
final RMStateDelta rmInitialState = this.rmInitialState.cloneAndFilter(RMInitialState.EMPTY_STATE);
assertEquals(5, rmInitialState.getNodesEvents().size());
assertEquals(2, rmInitialState.getNodeSource().size());
}
Aggregations