Search in sources :

Example 86 with Client

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

the class RMClientExample method main.

public static void main(String[] args) throws LoginException, KeyException, RMException {
    System.out.println("Hello from example.");
    RMRestClient client = new RMRestClient("http://localhost:8080/rest/", null);
    RMRestInterface rm = client.getRm();
    String sessionId = rm.rmConnect("admin", "admin");
    System.out.println(sessionId);
}
Also used : RMRestInterface(org.ow2.proactive_grid_cloud_portal.common.RMRestInterface)

Example 87 with Client

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

the class SchedulerRestClient method createRestProxy.

private static SchedulerRestInterface createRestProxy(ResteasyProviderFactory provider, String restEndpointURL, ClientHttpEngine httpEngine) {
    ResteasyClient client = buildResteasyClient(provider);
    ResteasyWebTarget target = client.target(restEndpointURL);
    SchedulerRestInterface schedulerRestClient = target.proxy(SchedulerRestInterface.class);
    return createExceptionProxy(schedulerRestClient);
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)

Example 88 with Client

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

the class SchedulerRestClient method list.

public ListFile list(String sessionId, String dataspacePath, String pathname) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(pathname).queryParam("comp", "list");
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot list the specified location: %s", pathname), response);
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 89 with Client

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

the class SubmitJob method begin.

public void begin() {
    // non blocking method to use futur management
    try {
        // connect the Scheduler
        // get the authentication interface using the SchedulerConnection
        SchedulerAuthenticationInterface auth = SchedulerConnection.waitAndJoin(SchedulerTHelper.getLocalUrl());
        // get the user interface using the retrieved SchedulerAuthenticationInterface
        user = auth.login(Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey()));
        // let the client be notified of its own 'job termination' -> job running to finished event
        user.addEventListener((SubmitJob) PAActiveObject.getStubOnThis(), true, SchedulerEvent.TASK_RUNNING_TO_FINISHED, SchedulerEvent.JOB_RUNNING_TO_FINISHED, SchedulerEvent.JOB_PENDING_TO_FINISHED);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)

Example 90 with Client

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

the class TerminateIfTaskHandler method terminateIfTask.

public boolean terminateIfTask(FlowAction action, InternalTask initiator, ChangedTasksInfo changesInfo, SchedulerStateUpdate frontend, InternalTask descriptor, TaskId taskId) {
    InternalTask[] targets = searchIfElseJoinTasks(action, initiator);
    // the targetIf from action getTarget is the selected branch
    // the IF condition has already been evaluated prior to being put in a
    // FlowAction
    // the targetElse from action getTargetElse is the branch that was NOT
    // selected
    InternalTask targetIf = targets[0];
    InternalTask targetElse = targets[1];
    InternalTask targetJoin = targets[2];
    LOGGER.info("Control Flow Action IF: " + targetIf.getId() + " join: " + ((targetJoin == null) ? "null" : targetJoin.getId()));
    // these 2 tasks delimit the Task Block formed by the IF branch
    InternalTask branchStart = targetIf;
    InternalTask branchEnd = null;
    String match = targetIf.getMatchingBlock();
    if (match != null) {
        for (InternalTask t : internalJob.getIHMTasks().values()) {
            if (match.equals(t.getName()) && !(t.getStatus().equals(TaskStatus.FINISHED) || t.getStatus().equals(TaskStatus.SKIPPED))) {
                branchEnd = t;
            }
        }
    }
    // no matching block: there is no block, the branch is a single task
    if (branchEnd == null) {
        branchEnd = targetIf;
    }
    // plug the branch
    branchStart.addDependence(initiator);
    changesInfo.taskUpdated(branchStart);
    if (targetJoin != null) {
        targetJoin.addDependence(branchEnd);
        changesInfo.taskUpdated(targetJoin);
    }
    // the other branch will not be executed
    // first, find the concerned tasks
    List<InternalTask> elseTasks = new ArrayList<>();
    // elseTasks.add(targetElse);
    for (InternalTask t : internalJob.getIHMTasks().values()) {
        if (t.dependsOn(targetElse)) {
            elseTasks.add(t);
        }
    }
    // even though the targetElse is not going to be executed, a
    // dependency on initiator still makes sense and would help
    // reconstruct the job graph on the client
    targetElse.addDependence(initiator);
    changesInfo.taskUpdated(targetElse);
    for (InternalTask it : elseTasks) {
        it.setFinishedTime(descriptor.getFinishedTime() + 1);
        it.setStatus(TaskStatus.SKIPPED);
        it.setExecutionDuration(0);
        changesInfo.taskSkipped(it);
        internalJob.setNumberOfPendingTasks(internalJob.getNumberOfPendingTasks() - 1);
        internalJob.setNumberOfFinishedTasks(internalJob.getNumberOfFinishedTasks() + 1);
        LOGGER.info("Task " + it.getId() + " will not be executed");
    }
    // plug the branch in the descriptor
    TaskId joinId = null;
    if (targetJoin != null) {
        joinId = targetJoin.getId();
    }
    internalJob.getJobDescriptor().doIf(initiator.getId(), branchStart.getId(), branchEnd.getId(), joinId, targetElse.getId(), elseTasks);
    ((JobInfoImpl) internalJob.getJobInfo()).setTasksChanges(changesInfo, internalJob);
    // notify frontend that tasks were modified
    if (frontend != null) {
        frontend.jobStateUpdated(internalJob.getOwner(), new NotificationData<>(SchedulerEvent.TASK_SKIPPED, internalJob.getJobInfo()));
        frontend.jobUpdatedFullData(internalJob);
    }
    ((JobInfoImpl) internalJob.getJobInfo()).clearTasksChanges();
    // no jump is performed ; now that the tasks have been plugged
    // the flow can continue its normal operation
    internalJob.getJobDescriptor().terminate(taskId);
    return true;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

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