use of org.apache.samza.job.ApplicationStatus in project samza by apache.
the class RemoteApplicationRunner method status.
@Override
public ApplicationStatus status(StreamApplication app) {
try {
boolean hasNewJobs = false;
boolean hasRunningJobs = false;
ApplicationStatus unsuccessfulFinishStatus = null;
ExecutionPlan plan = getExecutionPlan(app);
for (JobConfig jobConfig : plan.getJobConfigs()) {
JobRunner runner = new JobRunner(jobConfig);
ApplicationStatus status = runner.status();
log.debug("Status is {} for job {}", new Object[] { status, jobConfig.getName() });
switch(status.getStatusCode()) {
case New:
hasNewJobs = true;
break;
case Running:
hasRunningJobs = true;
break;
case UnsuccessfulFinish:
unsuccessfulFinishStatus = status;
break;
case SuccessfulFinish:
break;
default:
}
}
if (hasNewJobs) {
// There are jobs not started, report as New
return ApplicationStatus.New;
} else if (hasRunningJobs) {
// All jobs are started, some are running
return ApplicationStatus.Running;
} else if (unsuccessfulFinishStatus != null) {
// All jobs are finished, some are not successful
return unsuccessfulFinishStatus;
} else {
// All jobs are finished successfully
return ApplicationStatus.SuccessfulFinish;
}
} catch (Throwable t) {
throw new SamzaException("Failed to get status for application", t);
}
}
use of org.apache.samza.job.ApplicationStatus in project samza by apache.
the class RemoteApplicationRunner method getApplicationStatus.
/* package private */
ApplicationStatus getApplicationStatus(JobConfig jobConfig) {
JobRunner runner = new JobRunner(jobConfig);
ApplicationStatus status = runner.status();
LOG.debug("Status is {} for job {}", new Object[] { status, jobConfig.getName() });
return status;
}
use of org.apache.samza.job.ApplicationStatus in project samza by apache.
the class TestRunner method run.
/**
* Run the application with the specified timeout
*
* @param timeout time to wait for the application to finish. This timeout does not include
* input stream initialization time or the assertion time over output streams. This timeout just accounts
* for time that samza job takes run. Timeout must be greater than 0.
* @throws SamzaException if Samza job fails with exception and returns UnsuccessfulFinish as the statuscode
*/
public void run(Duration timeout) {
Preconditions.checkNotNull(app);
Preconditions.checkState(!timeout.isZero() || !timeout.isNegative(), "Timeouts should be positive");
// Cleaning store directories to ensure current run does not pick up state from previous run
deleteStoreDirectories();
Config config = new MapConfig(JobPlanner.generateSingleJobConfig(configs));
final LocalApplicationRunner runner = new LocalApplicationRunner(app, config, new InMemoryMetadataStoreFactory());
runner.run(externalContext);
if (!runner.waitForFinish(timeout)) {
throw new SamzaException("Timed out waiting for application to finish");
}
ApplicationStatus status = runner.status();
deleteStoreDirectories();
if (status.getStatusCode() == ApplicationStatus.StatusCode.UnsuccessfulFinish) {
throw new SamzaException("Application could not finish successfully", status.getThrowable());
}
}
use of org.apache.samza.job.ApplicationStatus in project samza by apache.
the class RemoteApplicationRunner method waitForFinish.
@Override
public boolean waitForFinish(Duration timeout) {
JobConfig jobConfig = new JobConfig(JobPlanner.generateSingleJobConfig(config));
boolean finished = true;
long timeoutInMs = timeout.toMillis();
long startTimeInMs = System.currentTimeMillis();
long timeElapsed = 0L;
long sleepDurationInMs = timeoutInMs < 1 ? DEFAULT_SLEEP_DURATION_MS : Math.min(timeoutInMs, DEFAULT_SLEEP_DURATION_MS);
ApplicationStatus status;
try {
while (timeoutInMs < 1 || timeElapsed <= timeoutInMs) {
status = getApplicationStatus(jobConfig);
if (status == SuccessfulFinish || status == UnsuccessfulFinish) {
LOG.info("Application finished with status {}", status);
break;
}
Thread.sleep(sleepDurationInMs);
timeElapsed = System.currentTimeMillis() - startTimeInMs;
}
if (timeElapsed > timeoutInMs) {
LOG.warn("Timed out waiting for application to finish.");
finished = false;
}
} catch (Exception e) {
LOG.error("Error waiting for application to finish", e);
throw new SamzaException(e);
}
return finished;
}
Aggregations