Search in sources :

Example 1 with SchedulerRestClient

use of org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient 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)

Example 2 with SchedulerRestClient

use of org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient in project scheduling by ow2-proactive.

the class RestClientExceptionHandlerTest method client_handles_jetty_errors_500.

@Test
public void client_handles_jetty_errors_500() throws Exception {
    try {
        SchedulerRMProxyFactory schedulerFactory = mock(SchedulerRMProxyFactory.class);
        when(schedulerFactory.connectToScheduler(Matchers.<CredData>any())).thenThrow(new LoginException());
        SharedSessionStore.getInstance().setSchedulerRMProxyFactory(schedulerFactory);
        SchedulerRestClient client = new SchedulerRestClient("http://localhost:" + port + "/");
        client.getScheduler().login("demo", "demo");
        fail("Should have throw an exception");
    } catch (WebApplicationException e) {
        assertTrue(e instanceof InternalServerErrorException);
        assertEquals(500, e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) LoginException(javax.security.auth.login.LoginException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) SchedulerRMProxyFactory(org.ow2.proactive_grid_cloud_portal.common.SchedulerRMProxyFactory) Test(org.junit.Test)

Example 3 with SchedulerRestClient

use of org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient in project scheduling by ow2-proactive.

the class SchedulerClient method init.

@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
    HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
    SchedulerRestClient restApiClient = new SchedulerRestClient(connectionInfo.getUrl(), new ApacheHttpClient4Engine(client));
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.register(new WildCardTypeReader());
    factory.register(new OctetStreamReader());
    factory.register(new TaskResultReader());
    SchedulerRestClient.registerGzipEncoding(factory);
    setApiClient(restApiClient);
    this.connectionInfo = connectionInfo;
    this.initialized = true;
    renewSession();
}
Also used : WildCardTypeReader(org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader) TaskResultReader(org.ow2.proactive.scheduler.rest.readers.TaskResultReader) OctetStreamReader(org.ow2.proactive.scheduler.rest.readers.OctetStreamReader) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) SchedulerRestClient(org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 4 with SchedulerRestClient

use of org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient 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)

Aggregations

SchedulerRestInterface (org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LoginException (javax.security.auth.login.LoginException)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 HttpClient (org.apache.http.client.HttpClient)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)1 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)1 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1 Test (org.junit.Test)1 HttpClientBuilder (org.ow2.proactive.http.HttpClientBuilder)1 OctetStreamReader (org.ow2.proactive.scheduler.rest.readers.OctetStreamReader)1 TaskResultReader (org.ow2.proactive.scheduler.rest.readers.TaskResultReader)1 WildCardTypeReader (org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader)1 SchedulerRMProxyFactory (org.ow2.proactive_grid_cloud_portal.common.SchedulerRMProxyFactory)1