Search in sources :

Example 1 with LocalLocationModule

use of io.cdap.cdap.common.guice.LocalLocationModule in project cdap by caskdata.

the class SqlAppMetadataStoreTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException, TableAlreadyExistsException {
    CConfiguration cConf = CConfiguration.create();
    pg = PostgresInstantiator.createAndStart(cConf, TEMP_FOLDER.newFolder());
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new LocalLocationModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new StorageModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
        }
    });
    transactionRunner = injector.getInstance(TransactionRunner.class);
    StoreDefinition.AppMetadataStore.create(injector.getInstance(StructuredTableAdmin.class));
}
Also used : StorageModule(io.cdap.cdap.data.runtime.StorageModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) BeforeClass(org.junit.BeforeClass)

Example 2 with LocalLocationModule

use of io.cdap.cdap.common.guice.LocalLocationModule in project cdap by caskdata.

the class TaskWorkerTwillRunnable method createInjector.

@VisibleForTesting
static Injector createInjector(CConfiguration cConf, Configuration hConf) {
    List<Module> modules = new ArrayList<>();
    CoreSecurityModule coreSecurityModule = CoreSecurityRuntimeModule.getDistributedModule(cConf);
    modules.add(new ConfigModule(cConf, hConf));
    modules.add(RemoteAuthenticatorModules.getDefaultModule());
    modules.add(new LocalLocationModule());
    modules.add(new IOModule());
    modules.add(new AuthenticationContextModules().getMasterWorkerModule());
    modules.add(coreSecurityModule);
    modules.add(new MessagingClientModule());
    modules.add(new SystemAppModule());
    modules.add(new MetricsClientRuntimeModule().getDistributedModules());
    // If MasterEnvironment is not available, assuming it is the old hadoop stack with ZK, Kafka
    MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
    if (masterEnv == null) {
        modules.add(new ZKClientModule());
        modules.add(new ZKDiscoveryModule());
        modules.add(new KafkaClientModule());
        modules.add(new KafkaLogAppenderModule());
    } else {
        modules.add(new AbstractModule() {

            @Override
            protected void configure() {
                bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
                bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
            }
        });
        modules.add(new RemoteLogAppenderModule());
        if (coreSecurityModule.requiresZKClient()) {
            modules.add(new ZKClientModule());
        }
    }
    return Guice.createInjector(modules);
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) RemoteLogAppenderModule(io.cdap.cdap.logging.guice.RemoteLogAppenderModule) ArrayList(java.util.ArrayList) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) KafkaLogAppenderModule(io.cdap.cdap.logging.guice.KafkaLogAppenderModule) AbstractModule(com.google.inject.AbstractModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) SupplierProviderBridge(io.cdap.cdap.common.guice.SupplierProviderBridge) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) CoreSecurityModule(io.cdap.cdap.security.guice.CoreSecurityModule) KafkaLogAppenderModule(io.cdap.cdap.logging.guice.KafkaLogAppenderModule) MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) RemoteLogAppenderModule(io.cdap.cdap.logging.guice.RemoteLogAppenderModule) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) IOModule(io.cdap.cdap.common.guice.IOModule) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) AbstractModule(com.google.inject.AbstractModule) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with LocalLocationModule

use of io.cdap.cdap.common.guice.LocalLocationModule in project cdap by caskdata.

the class ConfiguratorTask method run.

@Override
public void run(RunnableTaskContext context) throws Exception {
    AppDeploymentInfo deploymentInfo = GSON.fromJson(context.getParam(), AppDeploymentInfo.class);
    Injector injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getDefaultModule(), new LocalLocationModule(), new ConfiguratorTaskModule(), new AuthenticationContextModules().getMasterWorkerModule());
    ConfigResponse result = injector.getInstance(ConfiguratorTaskRunner.class).configure(deploymentInfo);
    AppSpecInfo appSpecInfo = result.getAppSpecInfo();
    // If configuration succeeded and if only system artifacts are involved, no need to restart the task
    if (result.getExitCode() == 0 && appSpecInfo != null && NamespaceId.SYSTEM.equals(deploymentInfo.getArtifactId().getNamespaceId())) {
        boolean hasUserPlugins = appSpecInfo.getAppSpec().getPlugins().values().stream().map(Plugin::getArtifactId).map(ArtifactId::getScope).anyMatch(ArtifactScope.USER::equals);
        context.setTerminateOnComplete(hasUserPlugins);
    }
    context.writeResult(GSON.toJson(result).getBytes(StandardCharsets.UTF_8));
}
Also used : AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 4 with LocalLocationModule

use of io.cdap.cdap.common.guice.LocalLocationModule in project cdap by caskdata.

the class RuntimeClientServiceTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.RuntimeMonitor.TOPICS_CONFIGS, TOPIC_CONFIGS_VALUE);
    topicConfigs = RuntimeMonitors.createTopicConfigs(cConf);
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    // Injector for the server side
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new LocalLocationModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new RuntimeServerModule() {

        @Override
        protected void bindRequestValidator() {
            bind(RuntimeRequestValidator.class).toInstance((programRunId, request) -> new ProgramRunInfo(ProgramRunStatus.COMPLETED, null));
        }

        @Override
        protected void bindLogProcessor() {
            bind(RemoteExecutionLogProcessor.class).toInstance(payloads -> {
            });
        }
    }, new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(DiscoveryService.class).toInstance(discoveryService);
            bind(DiscoveryServiceClient.class).toInstance(discoveryService);
        }
    });
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    runtimeServer = injector.getInstance(RuntimeServer.class);
    runtimeServer.startAndWait();
    // Injector for the client side
    clientCConf = CConfiguration.create();
    clientCConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    clientCConf.set(Constants.RuntimeMonitor.TOPICS_CONFIGS, TOPIC_CONFIGS_VALUE);
    // Shorten the poll delay and grace period to speed up testing of program terminate state handling
    clientCConf.setLong(Constants.RuntimeMonitor.POLL_TIME_MS, 200);
    clientCConf.setLong(Constants.RuntimeMonitor.GRACEFUL_SHUTDOWN_MS, 3000);
    // Use smaller batch size so that fetches is broken into multiple fetches
    clientCConf.setInt(Constants.RuntimeMonitor.BATCH_SIZE, 1);
    injector = Guice.createInjector(new ConfigModule(clientCConf), RemoteAuthenticatorModules.getNoOpModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(DiscoveryService.class).toInstance(discoveryService);
            bind(DiscoveryServiceClient.class).toInstance(discoveryService);
            bind(ProgramRunId.class).toInstance(PROGRAM_RUN_ID);
        }
    });
    clientMessagingService = injector.getInstance(MessagingService.class);
    if (clientMessagingService instanceof Service) {
        ((Service) clientMessagingService).startAndWait();
    }
    runtimeClientService = injector.getInstance(RuntimeClientService.class);
    runtimeClientService.startAndWait();
}
Also used : MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) Arrays(java.util.Arrays) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Notification(io.cdap.cdap.proto.Notification) Spliterators(java.util.Spliterators) TimeoutException(java.util.concurrent.TimeoutException) MessageFetcher(io.cdap.cdap.api.messaging.MessageFetcher) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) Gson(com.google.gson.Gson) RuntimeServerModule(io.cdap.cdap.app.guice.RuntimeServerModule) After(org.junit.After) Map(java.util.Map) ClassRule(org.junit.ClassRule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) Tasks(io.cdap.cdap.common.utils.Tasks) MessagingService(io.cdap.cdap.messaging.MessagingService) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) MultiThreadMessagingContext(io.cdap.cdap.messaging.context.MultiThreadMessagingContext) Constants(io.cdap.cdap.common.conf.Constants) MessagingContext(io.cdap.cdap.api.messaging.MessagingContext) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) RemoteAuthenticatorModules(io.cdap.cdap.common.guice.RemoteAuthenticatorModules) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) StreamSupport(java.util.stream.StreamSupport) Nullable(javax.annotation.Nullable) Before(org.junit.Before) DiscoveryService(org.apache.twill.discovery.DiscoveryService) Message(io.cdap.cdap.api.messaging.Message) RunIds(io.cdap.cdap.common.app.RunIds) Test(org.junit.Test) IOException(java.io.IOException) CloseableIterator(io.cdap.cdap.api.dataset.lib.CloseableIterator) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) MessagePublisher(io.cdap.cdap.api.messaging.MessagePublisher) Guice(com.google.inject.Guice) Assert(org.junit.Assert) Collections(java.util.Collections) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MessagingService(io.cdap.cdap.messaging.MessagingService) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) 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) MessagingService(io.cdap.cdap.messaging.MessagingService) RuntimeServerModule(io.cdap.cdap.app.guice.RuntimeServerModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) Before(org.junit.Before)

Example 5 with LocalLocationModule

use of io.cdap.cdap.common.guice.LocalLocationModule in project cdap by caskdata.

the class SqlProgramScheduleStoreDatasetTest method setup.

@BeforeClass
public static void setup() throws IOException, TableAlreadyExistsException {
    CConfiguration cConf = CConfiguration.create();
    // any plugin which requires transaction will be excluded
    cConf.set(Constants.REQUIREMENTS_DATASET_TYPE_EXCLUDE, Joiner.on(",").join(Table.TYPE, KeyValueTable.TYPE));
    pg = PostgresInstantiator.createAndStart(cConf, TEMP_FOLDER.newFolder());
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new LocalLocationModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new StorageModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
        }
    });
    transactionRunner = injector.getInstance(TransactionRunner.class);
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
}
Also used : StorageModule(io.cdap.cdap.data.runtime.StorageModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) BeforeClass(org.junit.BeforeClass)

Aggregations

ConfigModule (io.cdap.cdap.common.guice.ConfigModule)27 LocalLocationModule (io.cdap.cdap.common.guice.LocalLocationModule)27 AbstractModule (com.google.inject.AbstractModule)24 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)20 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)20 Injector (com.google.inject.Injector)19 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)19 StorageModule (io.cdap.cdap.data.runtime.StorageModule)16 BeforeClass (org.junit.BeforeClass)16 SystemDatasetRuntimeModule (io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule)15 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)13 StructuredTableAdmin (io.cdap.cdap.spi.data.StructuredTableAdmin)13 TransactionRunner (io.cdap.cdap.spi.data.transaction.TransactionRunner)11 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)8 MessagingServerRuntimeModule (io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule)8 Service (com.google.common.util.concurrent.Service)6 MessagingService (io.cdap.cdap.messaging.MessagingService)6 AuthorizationEnforcementModule (io.cdap.cdap.security.authorization.AuthorizationEnforcementModule)6 KafkaClientModule (io.cdap.cdap.common.guice.KafkaClientModule)5 ZKClientModule (io.cdap.cdap.common.guice.ZKClientModule)5