Search in sources :

Example 6 with RMInitialState

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;
}
Also used : RMStateDelta(org.ow2.proactive.resourcemanager.common.event.dto.RMStateDelta)

Example 7 with RMInitialState

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;
}
Also used : Arrays(java.util.Arrays) NodeSet(org.ow2.proactive.utils.NodeSet) ScriptResult(org.ow2.proactive.scripting.ScriptResult) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMAuthenticationImpl(org.ow2.proactive.resourcemanager.authentication.RMAuthenticationImpl) Matcher(java.util.regex.Matcher) Body(org.objectweb.proactive.Body) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) DefaultInfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.DefaultInfrastructureManager) ImmediateService(org.objectweb.proactive.annotation.ImmediateService) Map(java.util.Map) Script(org.ow2.proactive.scripting.Script) RMInitialState(org.ow2.proactive.resourcemanager.common.event.RMInitialState) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent) RMJMXHelper(org.ow2.proactive.resourcemanager.core.jmx.RMJMXHelper) NodeSourceStatus(org.ow2.proactive.resourcemanager.nodesource.NodeSourceStatus) RMState(org.ow2.proactive.resourcemanager.common.RMState) Set(java.util.Set) InitActive(org.objectweb.proactive.InitActive) NodeState(org.ow2.proactive.resourcemanager.common.NodeState) Serializable(java.io.Serializable) RMMonitoringImpl(org.ow2.proactive.resourcemanager.frontend.RMMonitoringImpl) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleScript(org.ow2.proactive.scripting.SimpleScript) NodeException(org.objectweb.proactive.core.node.NodeException) Permission(java.security.Permission) Predicate(com.google.common.base.Predicate) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) ScriptException(org.ow2.proactive.scripting.ScriptException) RMEvent(org.ow2.proactive.resourcemanager.common.event.RMEvent) Service(org.objectweb.proactive.Service) StaticPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy) UserData(org.ow2.proactive.authentication.UserData) ArrayList(java.util.ArrayList) NodeSourceDescriptor(org.ow2.proactive.resourcemanager.nodesource.NodeSourceDescriptor) RMNodeConfigurator(org.ow2.proactive.resourcemanager.nodesource.RMNodeConfigurator) Client(org.ow2.proactive.resourcemanager.authentication.Client) TopologyException(org.ow2.proactive.resourcemanager.frontend.topology.TopologyException) RMEventType(org.ow2.proactive.resourcemanager.common.event.RMEventType) Criteria(org.ow2.proactive.utils.Criteria) Node(org.objectweb.proactive.core.node.Node) StubObject(org.objectweb.proactive.core.mop.StubObject) InfrastructureManagerFactory(org.ow2.proactive.resourcemanager.nodesource.infrastructure.InfrastructureManagerFactory) TopologyManager(org.ow2.proactive.resourcemanager.selection.topology.TopologyManager) StringWrapper(org.objectweb.proactive.core.util.wrapper.StringWrapper) PluginDescriptor(org.ow2.proactive.resourcemanager.nodesource.common.PluginDescriptor) RunActive(org.objectweb.proactive.RunActive) InfrastructureManager(org.ow2.proactive.resourcemanager.nodesource.infrastructure.InfrastructureManager) RMNodeData(org.ow2.proactive.resourcemanager.db.RMNodeData) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) PAFuture(org.objectweb.proactive.api.PAFuture) URISyntaxException(java.net.URISyntaxException) ClientPinger(org.ow2.proactive.resourcemanager.utils.ClientPinger) LocalBodyStore(org.objectweb.proactive.core.body.LocalBodyStore) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) ProbablisticSelectionManager(org.ow2.proactive.resourcemanager.selection.statistics.ProbablisticSelectionManager) MethodCallPermission(org.ow2.proactive.permissions.MethodCallPermission) Logger(org.apache.log4j.Logger) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor) RMStateNodeUrls(org.ow2.proactive.resourcemanager.common.RMStateNodeUrls) SelectionManager(org.ow2.proactive.resourcemanager.selection.SelectionManager) URI(java.net.URI) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Topology(org.ow2.proactive.resourcemanager.frontend.topology.Topology) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Request(org.objectweb.proactive.core.body.request.Request) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) List(java.util.List) ActiveObject(org.objectweb.proactive.extensions.annotation.ActiveObject) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) RMDBManager(org.ow2.proactive.resourcemanager.db.RMDBManager) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) RMMonitoring(org.ow2.proactive.resourcemanager.frontend.RMMonitoring) UniqueID(org.objectweb.proactive.core.UniqueID) UserNamePrincipal(org.ow2.proactive.authentication.principals.UserNamePrincipal) TargetType(org.ow2.proactive.resourcemanager.utils.TargetType) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) NodeSourcePolicy(org.ow2.proactive.resourcemanager.nodesource.policy.NodeSourcePolicy) HashMap(java.util.HashMap) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) NodeSourceData(org.ow2.proactive.resourcemanager.db.NodeSourceData) HashSet(java.util.HashSet) UserHistory(org.ow2.proactive.resourcemanager.core.history.UserHistory) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) LinkedList(java.util.LinkedList) RMAccountsManager(org.ow2.proactive.resourcemanager.core.account.RMAccountsManager) RMConstants(org.ow2.proactive.resourcemanager.common.RMConstants) IntWrapper(org.objectweb.proactive.core.util.wrapper.IntWrapper) ProActiveException(org.objectweb.proactive.core.ProActiveException) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) RMNodeHelper(org.ow2.proactive.resourcemanager.utils.RMNodeHelper) ClientsPolicy(org.ow2.proactive.policy.ClientsPolicy) NodeSourcePolicyFactory(org.ow2.proactive.resourcemanager.nodesource.policy.NodeSourcePolicyFactory) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) NodesCleaner(org.ow2.proactive.resourcemanager.cleaning.NodesCleaner) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) RMNodeSourceEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent) RMInitialState(org.ow2.proactive.resourcemanager.common.event.RMInitialState) ArrayList(java.util.ArrayList) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) RMNodeEvent(org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)

Example 8 with 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;
    }
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 9 with 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());
}
Also used : RMStateDelta(org.ow2.proactive.resourcemanager.common.event.dto.RMStateDelta) Test(org.junit.Test)

Example 10 with RMInitialState

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());
}
Also used : RMStateDelta(org.ow2.proactive.resourcemanager.common.event.dto.RMStateDelta) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 RMInitialState (org.ow2.proactive.resourcemanager.common.event.RMInitialState)5 RMStateDelta (org.ow2.proactive.resourcemanager.common.event.dto.RMStateDelta)4 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)3 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)2 HashSet (java.util.HashSet)2 PAActiveObject (org.objectweb.proactive.api.PAActiveObject)2 UniqueID (org.objectweb.proactive.core.UniqueID)2 Client (org.ow2.proactive.resourcemanager.authentication.Client)2 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)2 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Serializable (java.io.Serializable)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Permission (java.security.Permission)1 ArrayList (java.util.ArrayList)1