Search in sources :

Example 1 with WorkerSpecification

use of io.cdap.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DistributedWorkerProgramRunner method setupLaunchConfig.

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

Example 2 with WorkerSpecification

use of io.cdap.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, pluginFinder, pluginInstantiator, runtimeInfo, getFeatureFlagsProvider());
    worker.configure(configurer);
    addDatasetsAndPlugins(configurer);
    WorkerSpecification spec = configurer.createSpecification();
    workers.put(spec.getName(), spec);
}
Also used : WorkerSpecification(io.cdap.cdap.api.worker.WorkerSpecification) DefaultWorkerConfigurer(io.cdap.cdap.internal.app.worker.DefaultWorkerConfigurer)

Example 3 with WorkerSpecification

use of io.cdap.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DefaultStore method setWorkerInstances.

@Override
public void setWorkerInstances(ProgramId id, int instances) {
    Preconditions.checkArgument(instances > 0, "Cannot change number of worker instances to %s", instances);
    TransactionRunners.run(transactionRunner, context -> {
        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, workerSpec.getPlugins());
        ApplicationSpecification newAppSpec = replaceWorkerInAppSpec(appSpec, id, newSpecification);
        metaStore.updateAppSpec(id.getParent(), newAppSpec);
    });
    LOG.trace("Setting program instances: namespace: {}, application: {}, worker: {}, new instances count: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), instances);
}
Also used : ForwardingApplicationSpecification(io.cdap.cdap.internal.app.ForwardingApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) WorkerSpecification(io.cdap.cdap.api.worker.WorkerSpecification)

Example 4 with WorkerSpecification

use of io.cdap.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class DefaultStore method getWorkerInstances.

@Override
public int getWorkerInstances(ProgramId id) {
    return TransactionRunners.run(transactionRunner, context -> {
        ApplicationSpecification appSpec = getAppSpecOrFail(getAppMetadataStore(context), id);
        WorkerSpecification workerSpec = getWorkerSpecOrFail(id, appSpec);
        return workerSpec.getInstances();
    });
}
Also used : ForwardingApplicationSpecification(io.cdap.cdap.internal.app.ForwardingApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) WorkerSpecification(io.cdap.cdap.api.worker.WorkerSpecification)

Example 5 with WorkerSpecification

use of io.cdap.cdap.api.worker.WorkerSpecification in project cdap by caskdata.

the class InMemoryWorkerRunner method run.

@Override
public ProgramController run(Program program, ProgramOptions options) {
    // Extract and verify parameters
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    Preconditions.checkNotNull(appSpec, "Missing application specification.");
    ProgramType type = program.getType();
    Preconditions.checkNotNull(type, "Missing processor type.");
    Preconditions.checkArgument(type == ProgramType.WORKER, "Only WORKER process type is supported.");
    WorkerSpecification workerSpec = appSpec.getWorkers().get(program.getName());
    Preconditions.checkNotNull(workerSpec, "Missing WorkerSpecification for %s", program.getName());
    String instances = options.getArguments().getOption(ProgramOptionConstants.INSTANCES, String.valueOf(workerSpec.getInstances()));
    WorkerSpecification newWorkerSpec = new WorkerSpecification(workerSpec.getClassName(), workerSpec.getName(), workerSpec.getDescription(), workerSpec.getProperties(), workerSpec.getDatasets(), workerSpec.getResources(), Integer.valueOf(instances), workerSpec.getPlugins());
    return startAll(program, options, newWorkerSpec.getInstances());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) WorkerSpecification(io.cdap.cdap.api.worker.WorkerSpecification) ProgramType(io.cdap.cdap.proto.ProgramType)

Aggregations

WorkerSpecification (io.cdap.cdap.api.worker.WorkerSpecification)9 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 ProgramType (io.cdap.cdap.proto.ProgramType)3 JsonObject (com.google.gson.JsonObject)2 Plugin (io.cdap.cdap.api.plugin.Plugin)2 ForwardingApplicationSpecification (io.cdap.cdap.internal.app.ForwardingApplicationSpecification)2 Resources (io.cdap.cdap.api.Resources)1 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)1 MapReduceSpecification (io.cdap.cdap.api.mapreduce.MapReduceSpecification)1 ServiceSpecification (io.cdap.cdap.api.service.ServiceSpecification)1 SparkSpecification (io.cdap.cdap.api.spark.SparkSpecification)1 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)1 ProgramController (io.cdap.cdap.app.runtime.ProgramController)1 ProgramContextAware (io.cdap.cdap.data.ProgramContextAware)1 BasicProgramContext (io.cdap.cdap.internal.app.runtime.BasicProgramContext)1 PluginInstantiator (io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator)1 DefaultWorkerConfigurer (io.cdap.cdap.internal.app.worker.DefaultWorkerConfigurer)1 DatasetCreationSpec (io.cdap.cdap.internal.dataset.DatasetCreationSpec)1 ScheduleCreationSpec (io.cdap.cdap.internal.schedule.ScheduleCreationSpec)1 ProgramId (io.cdap.cdap.proto.id.ProgramId)1