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());
}
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);
}
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);
}
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();
});
}
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());
}
Aggregations