Search in sources :

Example 1 with RMNodeImpl

use of org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl in project scheduling by ow2-proactive.

the class NodeSource method buildRMNodeAfterRecovery.

/**
 * Rebuild a RMNode from a node that could be looked up again after a
 * recovery of the RM. This builder configures nothing for the node
 * because it is configured already as it suppoesed to be recovered from
 * the database.
 * @return the expected RMNode
 */
private RMNode buildRMNodeAfterRecovery(Node node, RMNodeData rmNodeData) {
    RMNodeImpl rmNode = new RMNodeImpl(node, stub, rmNodeData.getName(), rmNodeData.getNodeUrl(), rmNodeData.getProvider(), rmNodeData.getHostname(), rmNodeData.getJmxUrls(), rmNodeData.getJvmName(), rmNodeData.getUserPermission(), rmNodeData.getState());
    if (rmNodeData.getState().equals(NodeState.BUSY)) {
        logger.info("Node " + rmNodeData.getName() + " was found busy after scheduler recovery with owner " + rmNodeData.getOwner());
        rmNode.setBusy(rmNodeData.getOwner());
    }
    return rmNode;
}
Also used : RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)

Example 2 with RMNodeImpl

use of org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl in project scheduling by ow2-proactive.

the class NodeSource method buildRMNode.

/**
 * Builds a RMNode from a raw Node
 * @param node the node object
 * @param provider the client of the request
 * @return the expected RMNode
 */
private RMNode buildRMNode(Node node, Client provider) {
    // creating a node access permission
    // it could be either PROVIDER/PROVIDER_GROUPS and in this case
    // the provider principals will be taken or
    // ME/MY_GROUPS (ns creator/ns creator groups) and in this case
    // creator's principals will be used
    Client permissionOwner = administrator;
    if (nodeUserAccessType.equals(AccessType.PROVIDER) || nodeUserAccessType.equals(AccessType.PROVIDER_GROUPS)) {
        permissionOwner = provider;
    }
    // now selecting the type (user or group) and construct the permission
    Set<IdentityPrincipal> principals = (Set<IdentityPrincipal>) nodeUserAccessType.getIdentityPrincipals(permissionOwner);
    boolean tokenInNode = false;
    boolean tokenInNodeSource = nodeUserAccessType.getTokens() != null && nodeUserAccessType.getTokens().length > 0;
    try {
        String nodeAccessToken = node.getProperty(RMNodeStarter.NODE_ACCESS_TOKEN);
        tokenInNode = nodeAccessToken != null && nodeAccessToken.length() > 0;
        if (tokenInNode) {
            logger.debug("Node " + node.getNodeInformation().getURL() + " is protected by access token " + nodeAccessToken);
            // it overrides all other principals
            principals.clear();
            principals.add(new TokenPrincipal(nodeAccessToken));
        }
    } catch (Exception e) {
        throw new AddingNodesException(e);
    }
    PrincipalPermission nodeAccessPermission = new PrincipalPermission(node.getNodeInformation().getURL(), principals);
    RMNodeImpl rmnode = new RMNodeImpl(node, stub, provider, nodeAccessPermission);
    rmnode.setProtectedByToken(tokenInNode || tokenInNodeSource);
    return rmnode;
}
Also used : Set(java.util.Set) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) TokenPrincipal(org.ow2.proactive.authentication.principals.TokenPrincipal) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) Client(org.ow2.proactive.resourcemanager.authentication.Client) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 3 with RMNodeImpl

use of org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl in project scheduling by ow2-proactive.

the class NodesLockRestorationManagerTest method testHandleNotInitialized.

@Test
public void testHandleNotInitialized() {
    // creates a node that matches an entry in the table specifying the nodes to lock
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns1", "n1", "h1", "nurl1", "parurl1").getLeft();
    assertThat(rmNode.isLocked()).isFalse();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Example 4 with RMNodeImpl

use of org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl in project scheduling by ow2-proactive.

the class NodesLockRestorationManagerTest method testHandleNodeAlreadyLocked.

@Test
public void testHandleNodeAlreadyLocked() {
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns1", "n1", "h1", "nurl1", "parurl1").getLeft();
    rmNode.lock(null);
    assertThat(rmNode.isLocked()).isTrue();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    nodesLockRestorationManager.initialize();
    assertThat(nodesLockRestorationManager.isInitialized()).isTrue();
    verify(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Example 5 with RMNodeImpl

use of org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl in project scheduling by ow2-proactive.

the class NodeSourceTest method testSetNodeAvailableKnownNode.

@Test
public void testSetNodeAvailableKnownNode() throws RMException {
    Node node = createNode(PROACTIVE_PROGRAMMING_NODE_URL);
    RMNode rmNode = new RMNodeImpl(node, nodeSource, client, mock(Permission.class));
    nodeSource.internalAddNode(node);
    nodeSource.detectedPingedDownNode(node.getNodeInformation().getName(), node.getNodeInformation().getURL());
    assertThat(nodeSource.getDownNodes()).hasSize(1);
    boolean result = nodeSource.setNodeAvailable(rmNode);
    assertThat(result).isTrue();
    assertThat(nodeSource.getDownNodes()).hasSize(0);
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) Permission(java.security.Permission) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Aggregations

RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)10 Test (org.junit.Test)7 MutableInteger (org.objectweb.proactive.core.util.MutableInteger)5 Permission (java.security.Permission)3 Client (org.ow2.proactive.resourcemanager.authentication.Client)3 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)3 Node (org.objectweb.proactive.core.node.Node)2 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)2 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)2 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Subject (javax.security.auth.Subject)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IdentityPrincipal (org.ow2.proactive.authentication.principals.IdentityPrincipal)1 TokenPrincipal (org.ow2.proactive.authentication.principals.TokenPrincipal)1 UserNamePrincipal (org.ow2.proactive.authentication.principals.UserNamePrincipal)1 PrincipalPermission (org.ow2.proactive.permissions.PrincipalPermission)1