Search in sources :

Example 11 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class LocalContainerRunner method startContainerHeartbeatMonitor.

private void startContainerHeartbeatMonitor() {
    String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
    String executionEnvContainerId = System.getenv(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID());
    if (executionEnvContainerId != null) {
        log.info("Got execution environment container id: {}", executionEnvContainerId);
        containerHeartbeatMonitor = new ContainerHeartbeatMonitor(() -> {
            container.shutdown();
            containerRunnerException = new SamzaException("Container shutdown due to expired heartbeat");
        }, new ContainerHeartbeatClient(coordinatorUrl, executionEnvContainerId));
        containerHeartbeatMonitor.start();
    } else {
        containerHeartbeatMonitor = null;
        log.warn("executionEnvContainerId not set. Container heartbeat monitor will not be started");
    }
}
Also used : ContainerHeartbeatClient(org.apache.samza.container.ContainerHeartbeatClient) ContainerHeartbeatMonitor(org.apache.samza.container.ContainerHeartbeatMonitor) SamzaException(org.apache.samza.SamzaException)

Example 12 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class PassthroughJobCoordinator method getJobModel.

@Override
public JobModel getJobModel() {
    JavaSystemConfig systemConfig = new JavaSystemConfig(this.config);
    Map<String, SystemAdmin> systemAdmins = new HashMap<>();
    for (String systemName : systemConfig.getSystemNames()) {
        String systemFactoryClassName = systemConfig.getSystemFactory(systemName);
        if (systemFactoryClassName == null) {
            LOGGER.error(String.format("A stream uses system %s, which is missing from the configuration.", systemName));
            throw new SamzaException(String.format("A stream uses system %s, which is missing from the configuration.", systemName));
        }
        SystemFactory systemFactory = Util.<SystemFactory>getObj(systemFactoryClassName);
        systemAdmins.put(systemName, systemFactory.getAdmin(systemName, this.config));
    }
    StreamMetadataCache streamMetadataCache = new StreamMetadataCache(Util.<String, SystemAdmin>javaMapAsScalaMap(systemAdmins), 5000, SystemClock.instance());
    /** TODO:
     Locality Manager seems to be required in JC for reading locality info and grouping tasks intelligently and also,
     in SamzaContainer for writing locality info to the coordinator stream. This closely couples together
     TaskNameGrouper with the LocalityManager! Hence, groupers should be a property of the jobcoordinator
     (job.coordinator.task.grouper, instead of task.systemstreampartition.grouper)
     */
    return JobModelManager.readJobModel(this.config, Collections.emptyMap(), null, streamMetadataCache, null);
}
Also used : StreamMetadataCache(org.apache.samza.system.StreamMetadataCache) JavaSystemConfig(org.apache.samza.config.JavaSystemConfig) SystemFactory(org.apache.samza.system.SystemFactory) HashMap(java.util.HashMap) SystemAdmin(org.apache.samza.system.SystemAdmin) SamzaException(org.apache.samza.SamzaException)

Example 13 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class YarnClusterResourceManager method start.

/**
   * Starts the YarnContainerManager and initialize all its sub-systems.
   * Attempting to start an already started container manager will return immediately.
   */
@Override
public void start() {
    if (!started.compareAndSet(false, true)) {
        log.info("Attempting to start an already started ContainerManager");
        return;
    }
    metrics.start();
    service.onInit();
    log.info("Starting YarnContainerManager.");
    amClient.init(hConfig);
    amClient.start();
    lifecycle.onInit();
    if (lifecycle.shouldShutdown()) {
        clusterManagerCallback.onError(new SamzaException("Invalid resource request."));
    }
    log.info("Finished starting YarnContainerManager");
}
Also used : SamzaException(org.apache.samza.SamzaException)

Example 14 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class YarnJobValidationTool method validateContainerCount.

public int validateContainerCount(ApplicationAttemptId attemptId) throws Exception {
    int runningContainerCount = 0;
    for (ContainerReport containerReport : this.client.getContainers(attemptId)) {
        if (containerReport.getContainerState() == ContainerState.RUNNING) {
            ++runningContainerCount;
        }
    }
    // expected containers to be the configured job containers plus the AppMaster container
    int containerExpected = this.config.getContainerCount() + 1;
    if (runningContainerCount == containerExpected) {
        log.info("Container count matches. " + runningContainerCount + " containers are running.");
        return runningContainerCount;
    } else {
        throw new SamzaException("Container count does not match. " + runningContainerCount + " containers are running, while " + containerExpected + " is expected.");
    }
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) SamzaException(org.apache.samza.SamzaException)

Example 15 with SamzaException

use of org.apache.samza.SamzaException in project samza by apache.

the class YarnJobValidationTool method validateRunningAttemptId.

public ApplicationAttemptId validateRunningAttemptId(ApplicationId appId) throws Exception {
    ApplicationAttemptId attemptId = this.client.getApplicationReport(appId).getCurrentApplicationAttemptId();
    ApplicationAttemptReport attemptReport = this.client.getApplicationAttemptReport(attemptId);
    if (attemptReport.getYarnApplicationAttemptState() == YarnApplicationAttemptState.RUNNING) {
        log.info("Job is running. AttempId " + attemptId.toString());
        return attemptId;
    } else {
        throw new SamzaException("Job not running " + this.jobName);
    }
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) SamzaException(org.apache.samza.SamzaException)

Aggregations

SamzaException (org.apache.samza.SamzaException)58 IOException (java.io.IOException)15 HashMap (java.util.HashMap)9 Config (org.apache.samza.config.Config)6 Test (org.junit.Test)6 Partition (org.apache.samza.Partition)5 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)5 HashSet (java.util.HashSet)4 JobConfig (org.apache.samza.config.JobConfig)4 MapConfig (org.apache.samza.config.MapConfig)4 Map (java.util.Map)3 ExecutionPlan (org.apache.samza.execution.ExecutionPlan)3 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)3 SystemFactory (org.apache.samza.system.SystemFactory)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)2 Path (org.apache.hadoop.fs.Path)2