Search in sources :

Example 36 with NotConnectedException

use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.

the class SchedulerClient method submit.

@Override
public JobId submit(URL job, Map<String, String> variables, Map<String, String> requestHeaderParams) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
    JobIdData jobIdData = null;
    try {
        URLConnection urlConnection = job.openConnection();
        for (Map.Entry<String, String> requestHeaderEntry : requestHeaderParams.entrySet()) {
            urlConnection.addRequestProperty(requestHeaderEntry.getKey(), requestHeaderEntry.getValue());
        }
        InputStream is = urlConnection.getInputStream();
        jobIdData = restApiClient().submitXml(sid, is, variables);
    } catch (Exception e) {
        throwNCEOrPEOrSCEOrJCE(e);
    }
    return jobId(jobIdData);
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Map(java.util.Map) AbstractMap(java.util.AbstractMap) URLConnection(java.net.URLConnection) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)

Example 37 with NotConnectedException

use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.

the class SchedulerClient method submitFromCatalog.

@Override
public JobId submitFromCatalog(String catalogRestURL, String bucketName, String workflowName, Map<String, String> variables) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
    JobIdData jobIdData = null;
    HttpGet httpGet = new HttpGet(catalogRestURL + "/buckets/" + bucketName + "/resources/" + workflowName + "/raw");
    httpGet.addHeader("sessionid", sid);
    try (CloseableHttpClient httpclient = HttpClients.createDefault();
        CloseableHttpResponse response = httpclient.execute(httpGet)) {
        jobIdData = restApiClient().submitXml(sid, response.getEntity().getContent(), variables);
    } catch (Exception e) {
        throwNCEOrPEOrSCEOrJCE(e);
    }
    return jobId(jobIdData);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)

Example 38 with NotConnectedException

use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.

the class DataSpaceClient method list.

@Override
public ListFile list(IRemoteSource source) throws NotConnectedException, PermissionException {
    StringBuffer uriTmpl = (new StringBuffer()).append(restDataspaceUrl).append(source.getDataspace().value());
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).build();
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(source.getPath()).queryParam("comp", "list");
    List<String> includes = source.getIncludes();
    if (includes != null && !includes.isEmpty()) {
        target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
    }
    List<String> excludes = source.getExcludes();
    if (excludes != null && !excludes.isEmpty()) {
        target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
    }
    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 NotConnectedException("User not authenticated or session timeout.");
            } else {
                throw new RuntimeException(String.format("Cannot list the specified location: %s", source.getPath()));
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)

Example 39 with NotConnectedException

use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.

the class DataSpaceClient method upload.

@Override
public boolean upload(final ILocalSource source, final IRemoteDestination destination) throws NotConnectedException, PermissionException {
    if (log.isDebugEnabled()) {
        log.debug("Uploading from " + source + " to " + destination);
    }
    StringBuffer uriTmpl = (new StringBuffer()).append(restDataspaceUrl).append(destination.getDataspace().value());
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).build();
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(destination.getPath());
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).put(Entity.entity(new StreamingOutput() {

            @Override
            public void write(OutputStream outputStream) throws IOException, WebApplicationException {
                source.writeTo(outputStream);
            }
        }, new Variant(MediaType.APPLICATION_OCTET_STREAM_TYPE, (Locale) null, source.getEncoding())));
        if (response.getStatus() != HttpURLConnection.HTTP_CREATED) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedException("User not authenticated or session timeout.");
            } else {
                throw new RuntimeException("File upload failed. Status code:" + response.getStatus());
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Upload from " + source + " to " + destination + " performed with success");
        }
        return true;
    } catch (IOException ioe) {
        throw Throwables.propagate(ioe);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Locale(java.util.Locale) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) WebApplicationException(javax.ws.rs.WebApplicationException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)

Example 40 with NotConnectedException

use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.

the class RMRest method rmDisconnect.

/**
 * Disconnects from resource manager and releases all the nodes taken by
 * user for computations.
 *
 * @param sessionId
 *            a valid session id
 * @throws NotConnectedException
 */
@Override
@POST
@Path("disconnect")
@Produces("application/json")
public void rmDisconnect(@HeaderParam("sessionid") String sessionId) throws NotConnectedException {
    RMProxyUserInterface rm = checkAccess(sessionId);
    rm.disconnect();
    sessionStore.terminate(sessionId);
}
Also used : RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)68 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)64 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)51 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)48 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)46 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)40 Path (javax.ws.rs.Path)39 Produces (javax.ws.rs.Produces)37 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)36 GET (javax.ws.rs.GET)28 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)27 JobState (org.ow2.proactive.scheduler.common.job.JobState)21 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)19 GZIP (org.jboss.resteasy.annotations.GZIP)18 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)18 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)17 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)16 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)16