Search in sources :

Example 1 with JobData

use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.

the class FederatedPlatformLayerClient method deleteItem.

@Override
public JobData deleteItem(PlatformLayerKey key) throws PlatformLayerClientException {
    MappedPlatformLayerKey mapped = mapToChild(key);
    JobData jobData = mapped.child.client.deleteItem(key);
    return mapped.child.setHost(jobData);
}
Also used : JobData(org.platformlayer.jobs.model.JobData)

Example 2 with JobData

use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.

the class JdbcJobRepository method mapFromEntity.

private JobData mapFromEntity(JobEntity entity, PlatformLayerKey jobKey) throws RepositoryException {
    JobData data = new JobData();
    data.action = actionFromXml(entity.actionXml);
    data.key = jobKey;
    data.targetId = PlatformLayerKey.parse(entity.target);
    if (entity.lastrunId != null) {
        JobExecutionData execution = new JobExecutionData();
        execution.endedAt = entity.lastrunEndedAt;
        execution.executionId = entity.lastrunId;
        execution.state = entity.lastrunState;
        data.lastRun = execution;
    }
    return data;
}
Also used : JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobData(org.platformlayer.jobs.model.JobData)

Example 3 with JobData

use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.

the class ITSolrService method testCreateAndDeleteItem.

@Test
public void testCreateAndDeleteItem() throws Exception {
    String id = random.randomAlphanumericString(8);
    SolrCluster solr = new SolrCluster();
    solr.dnsName = id + ".test.platformlayer.org";
    solr = putItem(id, solr);
    solr = waitForHealthy(solr);
    InetSocketAddress socketAddress = getUniqueEndpoint(solr);
    Assert.assertFalse(isPortOpen(socketAddress));
    openFirewall(solr, SolrConstants.API_PORT);
    Assert.assertTrue(isPortOpen(socketAddress));
    // TODO: Make endpoint http://<ip>:<port>/<path>...
    String url = "http://" + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort() + "/solr";
    testSolr(url);
    String customFieldKey = "customfield1";
    SolrSchemaField field = new SolrSchemaField();
    field.name = customFieldKey;
    field.type = "text_general";
    field.getTags().add(Tag.buildParentTag(solr.getKey()));
    // TODO: Our scoping of keys is problematic now...
    // If two clusters both have the same key "customfield1", they can't have the same ID
    field = putItem(id + "-" + customFieldKey, field);
    waitForHealthy(field);
    // Currently, we need to do a manual configure operation...
    // TODO: trigger this automatically
    SolrServer server = getItem(id + "-0", SolrServer.class);
    JobData configureJob = getContext().doConfigure(server);
    waitForJobComplete(configureJob, TimeSpan.FIVE_MINUTES);
    testSolrCustomField(url, customFieldKey);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) JobData(org.platformlayer.jobs.model.JobData) SolrServer(org.platformlayer.service.solr.model.SolrServer) CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) SolrCluster(org.platformlayer.service.solr.model.SolrCluster) SolrSchemaField(org.platformlayer.service.solr.model.SolrSchemaField) Test(org.testng.annotations.Test) PlatformLayerApiTest(org.platformlayer.tests.PlatformLayerApiTest)

Example 4 with JobData

use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.

the class PlatformLayerTestContext method waitForJobComplete.

public JobData waitForJobComplete(JobData job, TimeSpan timeout) throws OpsException, IOException {
    TypedPlatformLayerClient client = getTypedClient();
    PlatformLayerKey jobKey = job.key;
    long startedAt = System.currentTimeMillis();
    while (true) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new IllegalStateException("Interrupted", e);
        }
        if (timeout != null && timeout.hasTimedOut(startedAt)) {
            throw new OpsException("Timeout waiting for job completion");
        }
        // TODO: We really need a "get job status" function
        JobData found = null;
        for (JobData candidate : client.listJobs().getJobs()) {
            if (jobKey.equals(candidate.getJobKey())) {
                found = candidate;
            }
        }
        if (found == null) {
            // Assume completed?
            throw new IllegalStateException("Job not found in job list");
        }
        JobExecutionList executions = client.listJobExecutions(job.getJobKey().getItemIdString());
        JobExecutionData foundExecution = null;
        for (JobExecutionData candidate : executions) {
            if (jobKey.equals(candidate.getJobKey())) {
                foundExecution = candidate;
            }
        }
        if (foundExecution == null) {
            throw new IllegalStateException("Execution not found in execution list");
        }
        JobState state = foundExecution.getState();
        switch(state) {
            case FAILED:
            case SUCCESS:
                System.out.println("Job completed; state=" + state);
                return found;
            case RUNNING:
                System.out.println("Continuing to wait for " + job.key + "; state=" + state);
                break;
            default:
                throw new IllegalStateException("Unexpected state: " + state + " for " + job.key);
        }
    }
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) OpsException(org.platformlayer.ops.OpsException) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobState(org.platformlayer.jobs.model.JobState) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) JobData(org.platformlayer.jobs.model.JobData) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList)

Example 5 with JobData

use of org.platformlayer.jobs.model.JobData in project platformlayer by platformlayer.

the class JobsCollectionResource method getJob.

@Path("{jobId}")
public JobResource getJob(@PathParam("jobId") String jobId) throws OpsException {
    PlatformLayerKey jobKey = JobData.buildKey(getProject(), new ManagedItemId(jobId));
    JobData record = jobRegistry.getJob(jobKey);
    if (record == null) {
        raiseNotFound();
    }
    JobResource jobResource = jobResourceProvider.get();
    jobResource.init(record);
    return jobResource;
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) JobData(org.platformlayer.jobs.model.JobData) ManagedItemId(org.platformlayer.ids.ManagedItemId) Path(javax.ws.rs.Path)

Aggregations

JobData (org.platformlayer.jobs.model.JobData)24 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)7 PlatformLayerClient (org.platformlayer.PlatformLayerClient)4 RepositoryException (org.platformlayer.RepositoryException)4 ManagedItemId (org.platformlayer.ids.ManagedItemId)4 OpsException (org.platformlayer.ops.OpsException)4 ItemBase (org.platformlayer.core.model.ItemBase)3 ProjectId (org.platformlayer.ids.ProjectId)3 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 JobDataList (org.platformlayer.jobs.model.JobDataList)2 JobExecutionData (org.platformlayer.jobs.model.JobExecutionData)2 OpsContext (org.platformlayer.ops.OpsContext)2 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)2 CliException (com.fathomdb.cli.CliException)1 Ansi (com.fathomdb.cli.commands.Ansi)1 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SQLException (java.sql.SQLException)1 List (java.util.List)1