Search in sources :

Example 1 with WorkerSpecification

use of co.cask.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DefaultAppConfigurer method addWorker.

@Override
public void addWorker(Worker worker) {
    Preconditions.checkArgument(worker != null, "Worker cannot be null.");
    DefaultWorkerConfigurer configurer = new DefaultWorkerConfigurer(worker, deployNamespace, artifactId, artifactRepository, pluginInstantiator);
    worker.configure(configurer);
    addDatasetsAndPlugins(configurer);
    WorkerSpecification spec = configurer.createSpecification();
    workers.put(spec.getName(), spec);
}
Also used : WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) DefaultWorkerConfigurer(co.cask.cdap.internal.app.worker.DefaultWorkerConfigurer)

Example 2 with WorkerSpecification

use of co.cask.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DistributedWorkerProgramRunner method validateOptions.

@Override
protected void validateOptions(Program program, ProgramOptions options) {
    super.validateOptions(program, options);
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    Preconditions.checkNotNull(appSpec, "Missing application specification.");
    ProgramType processorType = program.getType();
    Preconditions.checkNotNull(processorType, "Missing processor type.");
    Preconditions.checkArgument(processorType == ProgramType.WORKER, "Only WORKER process type is supported.");
    WorkerSpecification workerSpec = appSpec.getWorkers().get(program.getName());
    Preconditions.checkNotNull(workerSpec, "Missing WorkerSpecification for %s", program.getName());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) ProgramType(co.cask.cdap.proto.ProgramType)

Example 3 with WorkerSpecification

use of co.cask.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DistributedWorkerProgramRunner method setupLaunchConfig.

@Override
protected void setupLaunchConfig(LaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) throws IOException {
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    WorkerSpecification workerSpec = appSpec.getWorkers().get(program.getName());
    String instances = options.getArguments().getOption(ProgramOptionConstants.INSTANCES, String.valueOf(workerSpec.getInstances()));
    Resources resources = SystemArguments.getResources(options.getUserArguments(), workerSpec.getResources());
    launchConfig.addRunnable(workerSpec.getName(), new WorkerTwillRunnable(workerSpec.getName()), resources, Integer.parseInt(instances));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) Resources(co.cask.cdap.api.Resources)

Example 4 with WorkerSpecification

use of co.cask.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DefaultStore method setWorkerInstances.

@Override
public void setWorkerInstances(final ProgramId id, final int instances) {
    Preconditions.checkArgument(instances > 0, "Cannot change number of worker instances to %s", instances);
    Transactions.executeUnchecked(transactional, new TxRunnable() {

        @Override
        public void run(DatasetContext context) throws Exception {
            AppMetadataStore metaStore = getAppMetadataStore(context);
            ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
            WorkerSpecification workerSpec = getWorkerSpecOrFail(id, appSpec);
            WorkerSpecification newSpecification = new WorkerSpecification(workerSpec.getClassName(), workerSpec.getName(), workerSpec.getDescription(), workerSpec.getProperties(), workerSpec.getDatasets(), workerSpec.getResources(), instances);
            ApplicationSpecification newAppSpec = replaceWorkerInAppSpec(appSpec, id, newSpecification);
            metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
        }
    });
    LOG.trace("Setting program instances: namespace: {}, application: {}, worker: {}, new instances count: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), instances);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ForwardingApplicationSpecification(co.cask.cdap.internal.app.ForwardingApplicationSpecification) TxRunnable(co.cask.cdap.api.TxRunnable) WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) DatasetContext(co.cask.cdap.api.data.DatasetContext) TransactionFailureException(org.apache.tephra.TransactionFailureException) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) TransactionNotInProgressException(org.apache.tephra.TransactionNotInProgressException) TransactionConflictException(org.apache.tephra.TransactionConflictException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Example 5 with WorkerSpecification

use of co.cask.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class ApplicationSpecificationCodec method deserialize.

@Override
public ApplicationSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();
    String appVersion = ApplicationId.DEFAULT_VERSION;
    if (jsonObj.has("appVersion")) {
        appVersion = jsonObj.get("appVersion").getAsString();
    }
    String description = jsonObj.get("description").getAsString();
    String configuration = null;
    if (jsonObj.has("configuration")) {
        configuration = jsonObj.get("configuration").getAsString();
    }
    ArtifactId artifactId = context.deserialize(jsonObj.get("artifactId"), ArtifactId.class);
    Map<String, StreamSpecification> streams = deserializeMap(jsonObj.get("streams"), context, StreamSpecification.class);
    Map<String, String> datasetModules = deserializeMap(jsonObj.get("datasetModules"), context, String.class);
    Map<String, DatasetCreationSpec> datasetInstances = deserializeMap(jsonObj.get("datasetInstances"), context, DatasetCreationSpec.class);
    Map<String, FlowSpecification> flows = deserializeMap(jsonObj.get("flows"), context, FlowSpecification.class);
    Map<String, MapReduceSpecification> mapReduces = deserializeMap(jsonObj.get("mapReduces"), context, MapReduceSpecification.class);
    Map<String, SparkSpecification> sparks = deserializeMap(jsonObj.get("sparks"), context, SparkSpecification.class);
    Map<String, WorkflowSpecification> workflows = deserializeMap(jsonObj.get("workflows"), context, WorkflowSpecification.class);
    Map<String, ServiceSpecification> services = deserializeMap(jsonObj.get("services"), context, ServiceSpecification.class);
    Map<String, ScheduleSpecification> schedules = deserializeMap(jsonObj.get("schedules"), context, ScheduleSpecification.class);
    Map<String, ScheduleCreationSpec> programSchedules = deserializeMap(jsonObj.get("programSchedules"), context, ScheduleCreationSpec.class);
    Map<String, WorkerSpecification> workers = deserializeMap(jsonObj.get("workers"), context, WorkerSpecification.class);
    Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);
    return new DefaultApplicationSpecification(name, appVersion, description, configuration, artifactId, streams, datasetModules, datasetInstances, flows, mapReduces, sparks, workflows, services, schedules, programSchedules, workers, plugins);
}
Also used : ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) JsonObject(com.google.gson.JsonObject) SparkSpecification(co.cask.cdap.api.spark.SparkSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) MapReduceSpecification(co.cask.cdap.api.mapreduce.MapReduceSpecification) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Plugin(co.cask.cdap.api.plugin.Plugin)

Aggregations

WorkerSpecification (co.cask.cdap.api.worker.WorkerSpecification)8 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)5 ProgramType (co.cask.cdap.proto.ProgramType)3 Resources (co.cask.cdap.api.Resources)2 JsonObject (com.google.gson.JsonObject)2 RunId (org.apache.twill.api.RunId)2 TxRunnable (co.cask.cdap.api.TxRunnable)1 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)1 DatasetContext (co.cask.cdap.api.data.DatasetContext)1 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)1 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)1 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 Plugin (co.cask.cdap.api.plugin.Plugin)1 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)1 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)1 SparkSpecification (co.cask.cdap.api.spark.SparkSpecification)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1 ProgramController (co.cask.cdap.app.runtime.ProgramController)1