Search in sources :

Example 1 with ApplicationStatus

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);
    }
}
Also used : JobRunner(org.apache.samza.job.JobRunner) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) ApplicationStatus(org.apache.samza.job.ApplicationStatus) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig)

Example 2 with ApplicationStatus

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;
}
Also used : JobRunner(org.apache.samza.job.JobRunner) ApplicationStatus(org.apache.samza.job.ApplicationStatus)

Example 3 with ApplicationStatus

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());
    }
}
Also used : MapConfig(org.apache.samza.config.MapConfig) InMemorySystemConfig(org.apache.samza.config.InMemorySystemConfig) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) ClusterManagerConfig(org.apache.samza.config.ClusterManagerConfig) StreamConfig(org.apache.samza.config.StreamConfig) ApplicationConfig(org.apache.samza.config.ApplicationConfig) TaskConfig(org.apache.samza.config.TaskConfig) ApplicationStatus(org.apache.samza.job.ApplicationStatus) InMemoryMetadataStoreFactory(org.apache.samza.metadatastore.InMemoryMetadataStoreFactory) MapConfig(org.apache.samza.config.MapConfig) SamzaException(org.apache.samza.SamzaException) LocalApplicationRunner(org.apache.samza.runtime.LocalApplicationRunner)

Example 4 with ApplicationStatus

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;
}
Also used : ApplicationStatus(org.apache.samza.job.ApplicationStatus) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig) SamzaException(org.apache.samza.SamzaException)

Aggregations

ApplicationStatus (org.apache.samza.job.ApplicationStatus)4 SamzaException (org.apache.samza.SamzaException)3 JobConfig (org.apache.samza.config.JobConfig)3 JobRunner (org.apache.samza.job.JobRunner)2 ApplicationConfig (org.apache.samza.config.ApplicationConfig)1 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)1 Config (org.apache.samza.config.Config)1 InMemorySystemConfig (org.apache.samza.config.InMemorySystemConfig)1 JobCoordinatorConfig (org.apache.samza.config.JobCoordinatorConfig)1 MapConfig (org.apache.samza.config.MapConfig)1 StreamConfig (org.apache.samza.config.StreamConfig)1 TaskConfig (org.apache.samza.config.TaskConfig)1 ExecutionPlan (org.apache.samza.execution.ExecutionPlan)1 InMemoryMetadataStoreFactory (org.apache.samza.metadatastore.InMemoryMetadataStoreFactory)1 LocalApplicationRunner (org.apache.samza.runtime.LocalApplicationRunner)1