Search in sources :

Example 1 with CommandBuilder

use of org.apache.samza.job.CommandBuilder in project samza by apache.

the class AbstractContainerAllocator method getCommandBuilder.

/**
   * Returns a command builder with the build environment configured with the containerId.
   * @param samzaContainerId to configure the builder with.
   * @return the constructed builder object
   */
private CommandBuilder getCommandBuilder(String samzaContainerId) {
    String cmdBuilderClassName = taskConfig.getCommandClass(ShellCommandBuilder.class.getName());
    CommandBuilder cmdBuilder = (CommandBuilder) Util.getObj(cmdBuilderClassName);
    cmdBuilder.setConfig(config).setId(samzaContainerId).setUrl(state.jobModelManager.server().getUrl());
    return cmdBuilder;
}
Also used : ShellCommandBuilder(org.apache.samza.job.ShellCommandBuilder) CommandBuilder(org.apache.samza.job.CommandBuilder) ShellCommandBuilder(org.apache.samza.job.ShellCommandBuilder)

Example 2 with CommandBuilder

use of org.apache.samza.job.CommandBuilder in project samza by apache.

the class AbstractContainerAllocator method runStreamProcessor.

/**
   * Updates the request state and runs a container process on the specified host. Assumes a resource
   * is available on the preferred host, so the caller must verify that before invoking this method.
   *
   * @param request             the {@link SamzaResourceRequest} which is being handled.
   * @param preferredHost       the preferred host on which the StreamProcessor process should be run or
   *                            {@link ResourceRequestState#ANY_HOST} if there is no host preference.
   * @throws
   * SamzaException if there is no allocated resource in the specified host.
   */
protected void runStreamProcessor(SamzaResourceRequest request, String preferredHost) {
    CommandBuilder builder = getCommandBuilder(request.getContainerID());
    // Get the available resource
    SamzaResource resource = peekAllocatedResource(preferredHost);
    if (resource == null)
        throw new SamzaException("Expected resource was unavailable on host " + preferredHost);
    // Update state
    resourceRequestState.updateStateAfterAssignment(request, preferredHost, resource);
    String containerID = request.getContainerID();
    //run container on resource
    log.info("Found available resources on {}. Assigning request for container_id {} with " + "timestamp {} to resource {}", new Object[] { preferredHost, String.valueOf(containerID), request.getRequestTimestampMs(), resource.getResourceID() });
    try {
        //launches a StreamProcessor on the resource
        clusterResourceManager.launchStreamProcessor(resource, builder);
        if (state.neededContainers.decrementAndGet() == 0) {
            state.jobHealthy.set(true);
        }
        state.runningContainers.put(request.getContainerID(), resource);
    } catch (SamzaContainerLaunchException e) {
        log.warn(String.format("Got exception while starting resource %s. Requesting a new resource on any host", resource), e);
        resourceRequestState.releaseUnstartableContainer(resource);
        requestResource(containerID, ResourceRequestState.ANY_HOST);
    }
}
Also used : ShellCommandBuilder(org.apache.samza.job.ShellCommandBuilder) CommandBuilder(org.apache.samza.job.CommandBuilder) SamzaException(org.apache.samza.SamzaException)

Aggregations

CommandBuilder (org.apache.samza.job.CommandBuilder)2 ShellCommandBuilder (org.apache.samza.job.ShellCommandBuilder)2 SamzaException (org.apache.samza.SamzaException)1