Search in sources :

Example 21 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class NodeSourcesTest method testAddNodeSourceWithEmptyInfrastructureVariables.

@Test
public void testAddNodeSourceWithEmptyInfrastructureVariables() {
    NodeSourceData nodeSourceData = createNodeSource();
    nodeSourceData.setInfrastructureVariables(new HashMap<String, Serializable>());
    dbManager.addNodeSource(nodeSourceData);
    Collection<NodeSourceData> nodeSources = dbManager.getNodeSources();
    assertThat(nodeSources).hasSize(1);
    NodeSourceData nodeSource = nodeSources.iterator().next();
    assertThat(nodeSource.getInfrastructureVariables()).hasSize(0);
}
Also used : Serializable(java.io.Serializable) NodeSourceData(org.ow2.proactive.resourcemanager.db.NodeSourceData) Test(org.junit.Test) ProActiveTest(org.ow2.tests.ProActiveTest)

Example 22 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class NodeSourcesTest method testAddNodeSourceWithVariousObjectsInInfrastructureVariables.

@Test
public void testAddNodeSourceWithVariousObjectsInInfrastructureVariables() {
    NodeSourceData nodeSourceData = createNodeSource();
    Map<String, Serializable> infrastructureVariables = new HashMap<>();
    Integer integer = new Integer(42);
    AtomicBoolean atomicBoolean = new AtomicBoolean(true);
    char c = 'z';
    infrastructureVariables.put("anInteger", integer);
    infrastructureVariables.put("aBoolean", atomicBoolean);
    infrastructureVariables.put("aChar", c);
    nodeSourceData.setInfrastructureVariables(infrastructureVariables);
    dbManager.addNodeSource(nodeSourceData);
    Collection<NodeSourceData> nodeSources = dbManager.getNodeSources();
    assertThat(nodeSources).hasSize(1);
    NodeSourceData nodeSource = nodeSources.iterator().next();
    Map<String, Serializable> retrievedInfravariables = nodeSource.getInfrastructureVariables();
    assertThat(retrievedInfravariables).hasSize(3);
    assertThat(retrievedInfravariables.get("anInteger")).isEqualTo(integer);
    // works with autoboxing
    assertThat(retrievedInfravariables.get("anInteger")).isEqualTo(42);
    assertThat(((AtomicBoolean) retrievedInfravariables.get("aBoolean")).get()).isEqualTo(atomicBoolean.get());
    assertThat(retrievedInfravariables.get("aChar")).isEqualTo(c);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Serializable(java.io.Serializable) NodeSourceData(org.ow2.proactive.resourcemanager.db.NodeSourceData) Test(org.junit.Test) ProActiveTest(org.ow2.tests.ProActiveTest)

Example 23 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class TestExecRemote method scriptOnNodeSource.

private void scriptOnNodeSource(String nsName, HashSet<String> nodesUrls) throws Exception {
    RMTHelper.log("Test 6 - Execute script on a specified nodesource name");
    SimpleScript script = new SimpleScript(TestExecRemote.simpleScriptContent, "javascript");
    HashSet<String> targets = new HashSet<>(1);
    targets.add(nsName);
    List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODESOURCE_NAME.toString(), targets);
    assertEquals("The size of result list must equal to size of nodesource", nodesUrls.size(), results.size());
    for (ScriptResult<Object> res : results) {
        Throwable exception = res.getException();
        if (exception != null) {
            RMTHelper.log("An exception occured while executing the script remotely:");
            exception.printStackTrace(System.out);
        }
        assertNull("No exception must occur", exception);
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) HashSet(java.util.HashSet)

Example 24 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class RMCoreTest method configureNodeSource.

private void configureNodeSource(NodeSource nodeSource, String nodeSourceName) {
    when(nodeSource.getName()).thenReturn(nodeSourceName);
    when(nodeSource.acquireNode(any(String.class), any(Client.class))).thenReturn(new BooleanWrapper(true));
    when(nodeSource.acquireNode(any(String.class), any(Client.class))).thenReturn(new BooleanWrapper(true));
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) Matchers.anyString(org.mockito.Matchers.anyString) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 25 with NodeSource

use of org.ow2.proactive.resourcemanager.nodesource.NodeSource in project scheduling by ow2-proactive.

the class RMCoreTest method populateRMCore.

/**
 * 6 nodes (same nodesource).
 */
private void populateRMCore() {
    when(mockedCaller.checkPermission(any(Permission.class), any(String.class))).thenReturn(true);
    when(mockedSelectionManager.selectNodes(any(Criteria.class), any(Client.class))).thenReturn(new NodeSet());
    nodeSources = new HashMap<String, NodeSource>(1);
    configureNodeSource(mockedNodeSource, "NODESOURCE-test");
    nodeSources.put(mockedNodeSource.getName(), mockedNodeSource);
    // MockedRMNodeParameters(String url, boolean isFree, boolean isDown, boolean isLocked, NodeSource nodeSource, RMNode rmNode)
    configureRMNode(new MockedRMNodeParameters("mockedRemovableNode", true, true, false, mockedNodeSource, "NODESOURCE-test", mockedRemovableNode));
    configureRMNode(new MockedRMNodeParameters("mockedUnremovableNode", false, true, false, mockedNodeSource, "NODESOURCE-test", mockedUnremovableNode));
    configureRMNode(new MockedRMNodeParameters(RMDeployingNode.PROTOCOL_ID + "://removableNode", true, true, false, mockedNodeSource, "NODESOURCE-test", mockedRemovableNodeInDeploy));
    configureRMNode(new MockedRMNodeParameters(RMDeployingNode.PROTOCOL_ID + "://unRemovableNode", false, false, false, mockedNodeSource, "NODESOURCE-test", mockedUnremovableNodeInDeploy));
    configureRMNode(new MockedRMNodeParameters("mockedBusyNode", false, false, true, mockedNodeSource, "NODESOURCE-test", mockedBusyNode));
    configureRMNode(new MockedRMNodeParameters("mockedFreeButLockedNode", true, false, true, mockedNodeSource, "NODESOURCE-test", mockedFreeButLockedNode));
    HashMap<String, RMNode> nodes = new HashMap<>(6);
    nodes.put(mockedRemovableNodeInDeploy.getNodeName(), mockedRemovableNodeInDeploy);
    nodes.put(mockedUnremovableNodeInDeploy.getNodeName(), mockedUnremovableNodeInDeploy);
    nodes.put(mockedRemovableNode.getNodeName(), mockedRemovableNode);
    nodes.put(mockedUnremovableNode.getNodeName(), mockedUnremovableNode);
    nodes.put(mockedBusyNode.getNodeName(), mockedBusyNode);
    nodes.put(mockedFreeButLockedNode.getNodeName(), mockedFreeButLockedNode);
    ArrayList<RMNode> freeNodes = new ArrayList<>(3);
    freeNodes.add(mockedRemovableNodeInDeploy);
    freeNodes.add(mockedRemovableNode);
    freeNodes.add(mockedFreeButLockedNode);
    rmCore = new RMCore(nodeSources, nodes, mockedCaller, mockedMonitoring, mockedSelectionManager, freeNodes, dbManager);
    rmCore.signalRMCoreIsInitialized();
    rmCore = spy(rmCore);
    nodesLockRestorationManager = new NodesLockRestorationManager(rmCore);
    nodesLockRestorationManager = spy(nodesLockRestorationManager);
    doReturn(new Function<RMCore, NodesRecoveryManager>() {

        @Override
        public NodesRecoveryManager apply(RMCore rmCore) {
            nodesRecoveryManager = new NodesRecoveryManager(rmCore);
            nodesRecoveryManager = spy(nodesRecoveryManager);
            return nodesRecoveryManager;
        }
    }).when(rmCore).getNodesRecoveryManagerBuilder();
    rmCore.initiateRecoveryIfRequired();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Criteria(org.ow2.proactive.utils.Criteria) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Permission(java.security.Permission) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Aggregations

NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)21 Test (org.junit.Test)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)11 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)11 Client (org.ow2.proactive.resourcemanager.authentication.Client)9 Node (org.objectweb.proactive.core.node.Node)8 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)7 ArrayList (java.util.ArrayList)6 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)6 Permission (java.security.Permission)5 NodeSourceData (org.ow2.proactive.resourcemanager.db.NodeSourceData)5 RMException (org.ow2.proactive.resourcemanager.exception.RMException)5 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Matchers.anyString (org.mockito.Matchers.anyString)4