use of io.cdap.cdap.runtime.spi.provisioner.Provisioner in project cdap by caskdata.
the class TetheringProvisionerTest method testGuiceInjector.
@Test
public void testGuiceInjector() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
Injector injector = Guice.createInjector(new ConfigModule(cConf), new LocalLocationModule(), new InMemoryDiscoveryModule(), new StorageModule(), new ProvisionerModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
bind(SecureStore.class).toInstance(FakeSecureStore.builder().build());
bind(ProgramStateWriter.class).to(NoOpProgramStateWriter.class);
}
});
ProvisionerProvider provisionerProvider = injector.getInstance(ProvisionerProvider.class);
Map<String, Provisioner> provisioners = provisionerProvider.loadProvisioners();
Assert.assertNotNull(provisioners.get(TetheringProvisioner.TETHERING_NAME));
ProvisionerConfigProvider configProvider = injector.getInstance(ProvisionerConfigProvider.class);
Map<String, ProvisionerConfig> configs = configProvider.loadProvisionerConfigs(provisioners.values());
Assert.assertNotNull(configs.get(TetheringProvisioner.TETHERING_NAME));
}
use of io.cdap.cdap.runtime.spi.provisioner.Provisioner in project cdap by caskdata.
the class ProvisioningService method deprovision.
// This is visible for testing, where we may not want to delete the task information after it completes
@VisibleForTesting
Runnable deprovision(ProgramRunId programRunId, StructuredTableContext context, Consumer<ProgramRunId> taskCleanup) throws IOException {
// look up information for the corresponding provision operation
ProvisioningTaskInfo existing = provisionerStore.getTaskInfo(new ProvisioningTaskKey(programRunId, ProvisioningOp.Type.PROVISION));
if (existing == null) {
runWithProgramLogging(programRunId, Collections.emptyMap(), () -> LOG.error("No task state found while deprovisioning the cluster. " + "The cluster will be marked as orphaned."));
programStateWriter.error(programRunId, new IllegalStateException("No task state found while deprovisioning the cluster."));
provisionerNotifier.orphaned(programRunId);
return () -> {
};
}
// to deprovision, but task state still needs to be cleaned up.
if (existing.getCluster() == null) {
provisionerNotifier.deprovisioned(programRunId);
return () -> taskCleanup.accept(programRunId);
}
Provisioner provisioner = provisionerInfo.get().provisioners.get(existing.getProvisionerName());
if (provisioner == null) {
runWithProgramLogging(programRunId, existing.getProgramOptions().getArguments().asMap(), () -> LOG.error("Could not deprovision the cluster because provisioner {} does not exist. " + "The cluster will be marked as orphaned.", existing.getProvisionerName()));
programStateWriter.error(programRunId, new IllegalStateException("Provisioner not found while deprovisioning the cluster."));
provisionerNotifier.orphaned(programRunId);
return () -> taskCleanup.accept(existing.getProgramRunId());
}
ProvisioningOp provisioningOp = new ProvisioningOp(ProvisioningOp.Type.DEPROVISION, ProvisioningOp.Status.REQUESTING_DELETE);
ProvisioningTaskInfo provisioningTaskInfo = new ProvisioningTaskInfo(existing, provisioningOp, existing.getCluster());
ProvisionerTable provisionerTable = new ProvisionerTable(context);
provisionerTable.putTaskInfo(provisioningTaskInfo);
return createDeprovisionTask(provisioningTaskInfo, provisioner, taskCleanup);
}
use of io.cdap.cdap.runtime.spi.provisioner.Provisioner in project cdap by caskdata.
the class ProvisioningService method getTotalProcessingCpusLabel.
/**
* Generates the label to display for total no of CPUs available for processing for the specified provisioner.
*
* @param provisionerName the name of the provisioner to validate
* @param properties properties for the specified provisioner
*/
public String getTotalProcessingCpusLabel(String provisionerName, Map<String, String> properties) throws NotFoundException {
Provisioner provisioner = provisionerInfo.get().provisioners.get(provisionerName);
if (provisioner == null) {
throw new NotFoundException(String.format("Provisioner '%s' does not exist", provisionerName));
}
Optional<String> label = provisioner.getTotalProcessingCpusLabel(properties);
return label.filter(s -> !s.isEmpty()).orElse(io.cdap.cdap.proto.provisioner.ProvisionerInfo.DEFAULT_PROCESSING_CPUS_LABEL);
}
use of io.cdap.cdap.runtime.spi.provisioner.Provisioner in project cdap by caskdata.
the class ProvisioningService method resumeTasks.
/**
* Scans the ProvisionerStore for any tasks that should be in progress but are not being executed and consumes
* them.
*/
@VisibleForTesting
void resumeTasks(Consumer<ProgramRunId> taskCleanup) throws IOException {
// TODO: CDAP-13462 read tasks in chunks to avoid tx timeout
List<ProvisioningTaskInfo> clusterTaskInfos = getInProgressTasks();
for (ProvisioningTaskInfo provisioningTaskInfo : clusterTaskInfos) {
State serviceState = state();
// normally this is only called when the service is starting, but it can be running in unit test
if (serviceState != State.STARTING && serviceState != State.RUNNING) {
return;
}
ProvisioningTaskKey taskKey = provisioningTaskInfo.getTaskKey();
Optional<Future<Void>> taskFuture = taskExecutor.getFuture(taskKey);
if (taskFuture.isPresent()) {
// this should only happen if a program run is started before we scanned for tasks
continue;
}
ProgramRunId programRunId = provisioningTaskInfo.getProgramRunId();
ProvisioningOp provisioningOp = provisioningTaskInfo.getProvisioningOp();
String provisionerName = provisioningTaskInfo.getProvisionerName();
Provisioner provisioner = provisionerInfo.get().provisioners.get(provisionerName);
if (provisioner == null) {
// can happen if CDAP is shut down in the middle of a task, and a provisioner is removed
LOG.error("Could not provision cluster for program run {} because provisioner {} no longer exists.", programRunId, provisionerName);
provisionerNotifier.orphaned(programRunId);
provisionerStore.deleteTaskInfo(provisioningTaskInfo.getProgramRunId());
continue;
}
Runnable task;
switch(provisioningOp.getType()) {
case PROVISION:
task = createProvisionTask(provisioningTaskInfo, provisioner);
break;
case DEPROVISION:
task = createDeprovisionTask(provisioningTaskInfo, provisioner, taskCleanup);
break;
default:
LOG.error("Skipping unknown provisioning task type {}", provisioningOp.getType());
continue;
}
// message about resuming a task that is in cancelled state or resuming a task that is completed
if (provisioningOp.getStatus() != ProvisioningOp.Status.CANCELLED && provisioningOp.getStatus() != ProvisioningOp.Status.CREATED) {
LOG.info("Resuming provisioning task for run {} of type {} in state {}.", provisioningTaskInfo.getProgramRunId(), provisioningTaskInfo.getProvisioningOp().getType(), provisioningTaskInfo.getProvisioningOp().getStatus());
}
task.run();
}
}
Aggregations