Search in sources :

Example 1 with JobExecutionData

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

the class OperationQueueBase method createExecution.

protected JobExecutionData createExecution(JobData jobData) throws OpsException {
    Date startedAt = new Date();
    String executionId;
    try {
        executionId = jobRepository.insertExecution(jobData.key, startedAt);
    } catch (RepositoryException e) {
        throw new OpsException("Error inserting job execution into repository", e);
    }
    JobExecutionData execution = new JobExecutionData();
    execution.job = jobData;
    execution.jobKey = jobData.getJobKey();
    execution.startedAt = startedAt;
    execution.executionId = executionId;
    execution.state = JobState.PRESTART;
    return execution;
}
Also used : OpsException(org.platformlayer.ops.OpsException) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) RepositoryException(org.platformlayer.RepositoryException) Date(java.util.Date)

Example 2 with JobExecutionData

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

the class PersistentJobRegistry method getJobLog.

// @Override
// JobRecord startJob(JobRecord jobRecord) {
// PlatformLayerKey jobKey = jobRecord.getJobKey();
// 
// if (jobKey != null) {
// synchronized (activeJobs) {
// activeJobs.put(jobKey, jobRecord);
// }
// }
// 
// return jobRecord;
// }
// public JobData getJob(PlatformLayerKey jobKey, boolean fetchLog) {
// JobData jobData = null;
// synchronized (activeJobs) {
// jobRecord = activeJobs.get(jobKey);
// }
// 
// if (jobData == null) {
// synchronized (recentJobs) {
// for (JobData recentJob : recentJobs) {
// if (recentJob.getJobKey().equals(jobKey)) {
// jobData = recentJob;
// break;
// }
// }
// }
// }
// 
// if (jobData == null) {
// throw new UnsupportedOperationException();
// 
// // jobRecord = repository.getJob(jobId, fetchLog);
// }
// 
// return jobData;
// }
@Override
public JobLog getJobLog(PlatformLayerKey jobKey, String executionId, int logSkip) throws OpsException {
    JobExecutionData execution = findExecution(jobKey, executionId);
    Date startedAt = execution.getStartedAt();
    if (execution.getEndedAt() == null) {
        JobLog log = operationQueue.getActiveJobLog(jobKey, executionId);
        if (log != null) {
            JobLog ret = new JobLog();
            ret.lines = Lists.newArrayList(Iterables.skip(log.lines, logSkip));
            ret.execution = log.execution;
            return ret;
        }
    }
    try {
        String cookie = execution.logCookie;
        JobLog log = jobLogStore.getJobLog(startedAt, jobKey, executionId, cookie, logSkip);
        if (log != null) {
            log.execution = execution;
        }
        return log;
    } catch (IOException e) {
        throw new OpsException("Error reading job log", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobLog(org.platformlayer.jobs.model.JobLog) IOException(java.io.IOException) Date(java.util.Date)

Example 3 with JobExecutionData

use of org.platformlayer.jobs.model.JobExecutionData 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 4 with JobExecutionData

use of org.platformlayer.jobs.model.JobExecutionData 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 JobExecutionData

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

the class JobResource method getRuns.

@GET
@Path("runs")
@Produces({ XML, JSON })
public JobExecutionList getRuns() throws OpsException {
    List<JobExecutionData> jobList = jobRegistry.listExecutions(job.getJobKey());
    JobExecutionList runs = JobExecutionList.create(jobList);
    return runs;
}
Also used : JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JobExecutionData (org.platformlayer.jobs.model.JobExecutionData)12 JobExecutionList (org.platformlayer.jobs.model.JobExecutionList)5 JobLog (org.platformlayer.jobs.model.JobLog)3 OpsException (org.platformlayer.ops.OpsException)3 IOException (java.io.IOException)2 Date (java.util.Date)2 PlatformLayerClient (org.platformlayer.PlatformLayerClient)2 RepositoryException (org.platformlayer.RepositoryException)2 JobData (org.platformlayer.jobs.model.JobData)2 JobLogLine (org.platformlayer.jobs.model.JobLogLine)2 JobState (org.platformlayer.jobs.model.JobState)2 CliException (com.fathomdb.cli.CliException)1 Ansi (com.fathomdb.cli.commands.Ansi)1 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)1 PrintWriter (java.io.PrintWriter)1 SQLException (java.sql.SQLException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 PlatformLayerClientNotFoundException (org.platformlayer.PlatformLayerClientNotFoundException)1