Search in sources :

Example 46 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMNodeClient method init.

@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
    HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
    RMRestClient restApiClient = new RMRestClient(connectionInfo.getUrl(), new ApacheHttpClient4Engine(client));
    this.rm = restApiClient.getRm();
    this.connectionInfo = connectionInfo;
    try {
        String sid = rm.rmConnect(connectionInfo.getLogin(), connectionInfo.getPassword());
        setSession(sid);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RMRestClient(org.ow2.proactive_grid_cloud_portal.rm.client.RMRestClient) HttpClient(org.apache.http.client.HttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) IOException(java.io.IOException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) RMNodeException(org.ow2.proactive.resourcemanager.exception.RMNodeException)

Example 47 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class NodeSource method acquireNode.

/**
 * Acquires the existing node with specific url. The node have to be up and running.
 *
 * @param nodeUrl the url of the node
 * @param provider
 */
public BooleanWrapper acquireNode(String nodeUrl, Client provider) {
    if (toShutdown) {
        throw new AddingNodesException("[" + name + "] node " + nodeUrl + " adding request discarded because node source is shutting down");
    }
    // checking that client has a right to change this node source
    // if the provider is the administrator of the node source it always has this permission
    provider.checkPermission(providerPermission, provider + " is not authorized to add node " + nodeUrl + " to " + name, new RMCoreAllPermission(), new NSAdminPermission());
    // lookup for a new Node
    int lookUpTimeout = PAResourceManagerProperties.RM_NODELOOKUP_TIMEOUT.getValueAsInt();
    Node nodeToAdd = null;
    try {
        logger.info("Looking up the node " + nodeUrl + " with " + lookUpTimeout + " ms timeout");
        nodeToAdd = lookupNode(nodeUrl, lookUpTimeout);
        logger.info("The node " + nodeUrl + " has been successfully looked up");
    } catch (Exception e) {
        logger.warn("Cannot look up the node " + nodeUrl + " within " + lookUpTimeout + " ms due to " + e.getMessage(), e);
        throw new AddingNodesException(e);
    }
    // node should be not null at this point...
    if (nodeToAdd == null) {
        throw new AddingNodesException("Cannot lookup node for unknown reason : " + nodeUrl);
    }
    // now checking if this node has been registered before in the node source
    if (downNodes.containsKey(nodeUrl)) {
        // it was registered but detected as down node,
        // so basically the node was restarted.
        // adding a new node and removing old one from the down list
        logger.debug("Removing existing node from down nodes list");
        BooleanWrapper result = rmcore.removeNodeFromCore(nodeUrl);
        if (result.getBooleanValue()) {
            if (logger.isDebugEnabled())
                logger.debug("[" + name + "] successfully removed node " + nodeUrl + " from the core");
            // just removing it from down nodes list
            removeNode(nodeUrl, provider);
        }
    } else if (nodes.containsKey(nodeUrl)) {
        // adding a node which exists in node source
        Node existingNode = nodes.get(nodeUrl);
        if (nodeToAdd.equals(existingNode)) {
            // don't do anything
            if (logger.isDebugEnabled())
                logger.debug("An attempt to add the same node twice " + nodeUrl + " - ignoring");
            return new BooleanWrapper(false);
        } else {
            // adding another node with the same url
            // replacing the old node by the new one
            logger.debug("Removing existing node from the RM without request propagation to the infrastructure manager");
            BooleanWrapper result = rmcore.removeNodeFromCore(nodeUrl);
            if (result.getBooleanValue()) {
                if (logger.isDebugEnabled())
                    logger.debug("[" + name + "] successfully removed node " + nodeUrl + " from the core");
                // removing it from the nodes list but don't propagate
                // the request the the infrastructure because the restarted node will be killed
                nodes.remove(nodeUrl);
            }
        }
    }
    // if any exception occurs in internalAddNode(node) do not add the node to the core
    RMDeployingNode deployingNode;
    try {
        deployingNode = internalAddNode(nodeToAdd);
    } catch (RMException e) {
        throw new AddingNodesException(e);
    }
    // we build the rmnode
    RMNode rmNode = buildRMNode(nodeToAdd, provider);
    if (deployingNode != null) {
        // inherit locking status from associated deploying node created before
        ((AbstractRMNode) rmNode).copyLockStatusFrom(deployingNode);
    }
    BooleanWrapper nodeAdded = rmcore.registerAvailableNode(rmNode);
    rmcore.internalRegisterConfiguringNode(rmNode);
    return nodeAdded;
}
Also used : RMCoreAllPermission(org.ow2.proactive.permissions.RMCoreAllPermission) NSAdminPermission(org.ow2.proactive.permissions.NSAdminPermission) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) AbstractRMNode(org.ow2.proactive.resourcemanager.rmnode.AbstractRMNode) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) Node(org.objectweb.proactive.core.node.Node) AbstractRMNode(org.ow2.proactive.resourcemanager.rmnode.AbstractRMNode) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) RMException(org.ow2.proactive.resourcemanager.exception.RMException) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) RMException(org.ow2.proactive.resourcemanager.exception.RMException) AbstractRMNode(org.ow2.proactive.resourcemanager.rmnode.AbstractRMNode)

Example 48 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMCore method configureDeployedNodeSource.

private void configureDeployedNodeSource(String nodeSourceName, NodeSourceDescriptor nodeSourceDescriptor, NodeSource nodeSourceStub, NodeSourcePolicy nodeSourcePolicyStub) {
    // Adding access to the core for node source and policy.
    // In order to do it node source and policy active objects are added to the clients list.
    // They will be removed from this list when node source is unregistered.
    UniqueID nsId = Client.getId(nodeSourceStub);
    UniqueID policyId = Client.getId(nodeSourcePolicyStub);
    if (nsId == null || policyId == null) {
        throw new IllegalStateException("Cannot register the node source");
    }
    BooleanWrapper result = nodeSourceStub.activate();
    if (!result.getBooleanValue()) {
        logger.error(NODE_SOURCE_STRING + nodeSourceName + " cannot be activated");
    }
    Client provider = nodeSourceDescriptor.getProvider();
    Client nsService = new Client(provider.getSubject(), false);
    Client policyService = new Client(provider.getSubject(), false);
    nsService.setId(nsId);
    policyService.setId(policyId);
    RMCore.clients.put(nsId, nsService);
    RMCore.clients.put(policyId, policyService);
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 49 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMCore method checkMethodCallPermission.

/**
 * Checks if the caller thread has permissions to call particular method name
 *
 * @return client object corresponding to the caller thread
 */
private Client checkMethodCallPermission(final String methodName, UniqueID clientId) {
    Client client = RMCore.clients.get(clientId);
    if (client == null) {
        // Check if the client id is a local body or half body
        LocalBodyStore lbs = LocalBodyStore.getInstance();
        if (lbs.getLocalBody(clientId) != null || lbs.getLocalHalfBody(clientId) != null) {
            return RMCore.localClient;
        }
        throw new NotConnectedException("Client " + clientId.shortString() + " is not connected to the resource manager");
    }
    final String fullMethodName = RMCore.class.getName() + "." + methodName;
    final MethodCallPermission methodCallPermission = new MethodCallPermission(fullMethodName);
    client.checkPermission(methodCallPermission, client + " is not authorized to call " + fullMethodName, new RMCoreAllPermission());
    return client;
}
Also used : RMCoreAllPermission(org.ow2.proactive.permissions.RMCoreAllPermission) LocalBodyStore(org.objectweb.proactive.core.body.LocalBodyStore) MethodCallPermission(org.ow2.proactive.permissions.MethodCallPermission) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 50 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMCore method checkNodeAdminOrProviderPermission.

/**
 * Checks if the client is the node admin or provider.
 *
 * @param rmnode is a node to be checked
 * @param client is a client to be checked
 * @return true if the client is an admin or provider, SecurityException otherwise
 */
private boolean checkNodeAdminOrProviderPermission(RMNode rmnode, Client client) {
    if (client == localClient) {
        return true;
    }
    NodeSource nodeSource = rmnode.getNodeSource();
    String errorMessage = client.getName() + " is not authorized to manage node " + rmnode.getNodeURL() + " from " + rmnode.getNodeSourceName();
    // a node provider
    try {
        // checking if the caller is an administrator
        client.checkPermission(nodeSource.getAdminPermission(), errorMessage, new RMCoreAllPermission(), new NSAdminPermission());
    } catch (SecurityException ex) {
        // the caller is not an administrator, so checking if it is a node source provider
        client.checkPermission(nodeSource.getProviderPermission(), errorMessage, new RMCoreAllPermission(), new NSAdminPermission());
    }
    return true;
}
Also used : NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) RMCoreAllPermission(org.ow2.proactive.permissions.RMCoreAllPermission) NSAdminPermission(org.ow2.proactive.permissions.NSAdminPermission)

Aggregations

Test (org.junit.Test)69 ISchedulerClient (org.ow2.proactive.scheduler.rest.ISchedulerClient)36 Client (org.ow2.proactive.resourcemanager.authentication.Client)31 JobId (org.ow2.proactive.scheduler.common.job.JobId)30 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)28 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)25 SimpleJob (functionaltests.jobs.SimpleJob)25 Job (org.ow2.proactive.scheduler.common.job.Job)25 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)18 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)18 ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)18 File (java.io.File)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)11 Node (org.objectweb.proactive.core.node.Node)9 IOException (java.io.IOException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)8 NodeSet (org.ow2.proactive.utils.NodeSet)7