Search in sources :

Example 6 with Provisioner

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));
}
Also used : NoOpProgramStateWriter(io.cdap.cdap.app.runtime.NoOpProgramStateWriter) ProvisionerProvider(io.cdap.cdap.internal.provision.ProvisionerProvider) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) ProvisionerConfigProvider(io.cdap.cdap.internal.provision.ProvisionerConfigProvider) StorageModule(io.cdap.cdap.data.runtime.StorageModule) ProvisionerModule(io.cdap.cdap.internal.provision.ProvisionerModule) ProvisionerConfig(io.cdap.cdap.internal.provision.ProvisionerConfig) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 7 with Provisioner

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);
}
Also used : Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with Provisioner

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);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) RetryStrategies(io.cdap.cdap.common.service.RetryStrategies) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) SparkCompatReader(io.cdap.cdap.internal.app.spark.SparkCompatReader) Future(java.util.concurrent.Future) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) Gson(com.google.gson.Gson) InvalidMacroException(io.cdap.cdap.api.macro.InvalidMacroException) Map(java.util.Map) MacroParserOptions(io.cdap.cdap.api.macro.MacroParserOptions) Cancellable(org.apache.twill.common.Cancellable) Capabilities(io.cdap.cdap.runtime.spi.provisioner.Capabilities) Threads(org.apache.twill.common.Threads) ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) Collection(java.util.Collection) Set(java.util.Set) KeyedExecutor(io.cdap.cdap.common.async.KeyedExecutor) LoggingContextAccessor(io.cdap.cdap.common.logging.LoggingContextAccessor) ProvisioningTask(io.cdap.cdap.internal.provision.task.ProvisioningTask) StructuredTableContext(io.cdap.cdap.spi.data.StructuredTableContext) SecureStore(io.cdap.cdap.api.security.store.SecureStore) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) List(java.util.List) SecurityRequestContext(io.cdap.cdap.security.spi.authentication.SecurityRequestContext) Type(java.lang.reflect.Type) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Optional(java.util.Optional) Constants(io.cdap.cdap.common.conf.Constants) ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) DeprovisionTask(io.cdap.cdap.internal.provision.task.DeprovisionTask) NotFoundException(io.cdap.cdap.common.NotFoundException) RuntimeJobManager(io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobManager) Retries(io.cdap.cdap.common.service.Retries) RuntimeMonitorType(io.cdap.cdap.runtime.spi.RuntimeMonitorType) Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) SSHKeyPair(io.cdap.cdap.runtime.spi.ssh.SSHKeyPair) Location(org.apache.twill.filesystem.Location) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ProvisionerContext(io.cdap.cdap.runtime.spi.provisioner.ProvisionerContext) Loggers(io.cdap.cdap.common.logging.Loggers) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ClusterStatus(io.cdap.cdap.runtime.spi.provisioner.ClusterStatus) SSHContext(io.cdap.cdap.runtime.spi.ssh.SSHContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) MacroParser(io.cdap.cdap.internal.app.runtime.plugin.MacroParser) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProvisionTask(io.cdap.cdap.internal.provision.task.ProvisionTask) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) PluginRequirement(io.cdap.cdap.internal.pipeline.PluginRequirement) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) VersionInfo(io.cdap.cdap.runtime.spi.VersionInfo) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) RetryableProvisionException(io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException) LoggingContextHelper(io.cdap.cdap.logging.context.LoggingContextHelper) Logger(org.slf4j.Logger) SparkCompat(io.cdap.cdap.runtime.spi.SparkCompat) Networks(io.cdap.cdap.common.utils.Networks) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) ProjectInfo(io.cdap.cdap.common.utils.ProjectInfo) ProvisionerSystemContext(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Requirements(io.cdap.cdap.api.plugin.Requirements) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LogSamplers(io.cdap.cdap.common.logging.LogSamplers) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) MacroEvaluator(io.cdap.cdap.api.macro.MacroEvaluator) Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 9 with Provisioner

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();
    }
}
Also used : Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) Future(java.util.concurrent.Future) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Provisioner (io.cdap.cdap.runtime.spi.provisioner.Provisioner)9 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)3 ProvisionerContext (io.cdap.cdap.runtime.spi.provisioner.ProvisionerContext)3 InvalidMacroException (io.cdap.cdap.api.macro.InvalidMacroException)2 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)2 NotFoundException (io.cdap.cdap.common.NotFoundException)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 ProvisionerDetail (io.cdap.cdap.proto.provisioner.ProvisionerDetail)2 ProvisionerSpecification (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification)2 ProvisionerSystemContext (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext)2 RetryableProvisionException (io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Future (java.util.concurrent.Future)2 Throwables (com.google.common.base.Throwables)1 Sets (com.google.common.collect.Sets)1 AbstractIdleService (com.google.common.util.concurrent.AbstractIdleService)1 Gson (com.google.gson.Gson)1