Search in sources :

Example 6 with Client

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

the class SchedulerRestClient method upload.

public boolean upload(String sessionId, StreamingOutput output, String encoding, String dataspace, String path) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspace);
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(path);
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).put(Entity.entity(output, new Variant(MediaType.APPLICATION_OCTET_STREAM_TYPE, (Locale) null, encoding)));
        if (response.getStatus() != HttpURLConnection.HTTP_CREATED) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("File upload failed. Status code: %d" + response.getStatus()), response);
            }
        }
        return true;
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Locale(java.util.Locale) 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 7 with Client

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

the class SchedulerRestClient method pushFile.

public boolean pushFile(String sessionId, String space, String path, String fileName, InputStream fileContent) throws Exception {
    String uriTmpl = (new StringBuilder(restEndpointURL)).append(addSlashIfMissing(restEndpointURL)).append("scheduler/dataspace/").append(space).append(URLEncoder.encode(path, "UTF-8")).toString();
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl);
    MultipartFormDataOutput formData = new MultipartFormDataOutput();
    formData.addFormData("fileName", fileName, MediaType.TEXT_PLAIN_TYPE);
    formData.addFormData("fileContent", fileContent, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(formData) {
    };
    Response response = target.request().header("sessionid", sessionId).post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
    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("File upload failed. Status code: %d", response.getStatus()), response);
        }
    }
    return response.readEntity(Boolean.class);
}
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) MultipartFormDataOutput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)

Example 8 with Client

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

the class SchedulerRestClient method pullFile.

public void pullFile(String sessionId, String space, String path, String outputPath) throws Exception {
    String uriTmpl = (new StringBuilder(restEndpointURL)).append(addSlashIfMissing(restEndpointURL)).append("scheduler/dataspace/").append(space).append(URLEncoder.encode(path, "UTF-8")).toString();
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl);
    Response 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 retrieve the file. Status code: %s", response.getStatus()), response);
        }
    }
    try {
        File file = new File(outputPath);
        if (response.hasEntity()) {
            copyInputStreamToFile(response.readEntity(InputStream.class), file);
        } else {
            // creates an empty file
            file.createNewFile();
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (response != null) {
            response.close();
        }
        if (!client.isClosed()) {
            client.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) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ProcessingException(javax.ws.rs.ProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 9 with Client

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

the class SchedulerRestClient method reSubmit.

public JobIdData reSubmit(String sessionId, String jobId, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException {
    String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/jobs/" + jobId + "/resubmit";
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl);
    // Variables
    if (variables != null) {
        for (String key : variables.keySet()) {
            target = target.matrixParam(key, variables.get(key));
        }
    }
    // Generic infos
    if (genericInfos != null) {
        for (String key : genericInfos.keySet()) {
            target = target.queryParam(key, genericInfos.get(key));
        }
    }
    Response 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("Job submission failed status code: %d", response.getStatus()), response);
        }
    }
    return response.readEntity(JobIdData.class);
}
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 10 with Client

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

the class SchedulerClientExample method main.

public static void main(String[] args) throws Exception {
    // LOGIN IN
    SchedulerRestClient client = new SchedulerRestClient("http://localhost:8080/rest/");
    SchedulerRestInterface scheduler = client.getScheduler();
    String sessionId = scheduler.login("admin", "admin");
    // JOB SUBMISSION
    File xmlJobFile = new File("/path/to/some/existing/job/job_1.xml");
    JobIdData xmlJob;
    try (FileInputStream inputStream = new FileInputStream(xmlJobFile)) {
        xmlJob = client.submitXml(sessionId, inputStream);
    }
    System.out.println(xmlJob.getReadableName() + " " + xmlJob.getId());
    // FLAT JOB SUBMISSION
    JobIdData flatJob = scheduler.submitFlat(sessionId, "echo hello", "test-hello", null, null);
    System.out.println("Jobid=" + flatJob);
    String serverlog = scheduler.jobServerLog(sessionId, Long.toString(flatJob.getId()));
    System.out.println(serverlog);
    while (true) {
        JobStateData jobState2 = scheduler.listJobs(sessionId, Long.toString(flatJob.getId()));
        System.out.println(jobState2);
        if (jobState2.getJobInfo().getStatus().name().equals("FINISHED")) {
            break;
        }
        Thread.sleep(100);
    }
    JobResultData jobResultData = scheduler.jobResult(sessionId, Long.toString(flatJob.getId()));
    System.out.println(jobResultData);
    TaskResultData taskresult = scheduler.taskResult(sessionId, Long.toString(flatJob.getId()), "task_1");
    System.out.println(taskresult);
    List<TaskStateData> jobTaskStates = scheduler.getJobTaskStates(sessionId, Long.toString(flatJob.getId())).getList();
    System.out.println(jobTaskStates);
    TaskStateData task_1 = scheduler.jobTask(sessionId, Long.toString(flatJob.getId()), "task_1");
    System.out.println(task_1);
    // OTHER CALLS
    List<SchedulerUserData> users = scheduler.getUsers(sessionId);
    System.out.println(users);
    System.out.println(users.size());
    RestMapPage<Long, ArrayList<UserJobData>> page = scheduler.revisionAndJobsInfo(sessionId, 0, 50, true, true, true, true, true, null, null, null, null, null);
    Map<Long, ArrayList<UserJobData>> map = page.getMap();
    System.out.println(map);
    System.out.println(scheduler.getSchedulerStatus(sessionId));
    System.out.println(scheduler.getUsageOnMyAccount(sessionId, new Date(), new Date()));
    // FAILING CALL
    try {
        JobStateData jobState = scheduler.listJobs(sessionId, "601");
        System.out.println(jobState);
    } catch (UnknownJobRestException e) {
        System.err.println("exception! " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) JobResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobResultData) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) JobStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobStateData) SchedulerUserData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.SchedulerUserData) FileInputStream(java.io.FileInputStream) Date(java.util.Date) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) File(java.io.File)

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