use of io.cdap.cdap.common.guice.ConfigModule 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));
}
use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class CheckRunnerTest method setupTests.
@BeforeClass
public static void setupTests() {
CConfiguration cConf = CConfiguration.create();
cConf.set(AlwaysFailCheck.FAILURE_MESSAGE_KEY, FAILURE_MESSAGE);
injector = Guice.createInjector(new ConfigModule(cConf));
}
use of io.cdap.cdap.common.guice.ConfigModule 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();
}
use of io.cdap.cdap.common.guice.ConfigModule 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));
}
use of io.cdap.cdap.common.guice.ConfigModule in project cdap by caskdata.
the class ScheduleTaskRunnerTest method testRuntimeArgumentResolution.
@Test
public void testRuntimeArgumentResolution() throws Exception {
Injector injector = Guice.createInjector(new ConfigModule(), binder -> {
binder.bind(OwnerAdmin.class).to(NoOpOwnerAdmin.class);
binder.bind(NamespaceAdmin.class).to(InMemoryNamespaceAdmin.class);
binder.bind(NamespaceQueryAdmin.class).to(InMemoryNamespaceAdmin.class);
binder.bind(PreferencesFetcher.class).toInstance(new FakePreferencesFetcher(Collections.singletonMap("key", "should-be-overridden")));
});
PropertiesResolver propertiesResolver = injector.getInstance(PropertiesResolver.class);
ApplicationId appId = NamespaceId.DEFAULT.app("app");
ProgramSchedule programSchedule = new ProgramSchedule("schedule", "desc", appId.workflow("wf2"), Collections.singletonMap("key", "val"), new ProgramStatusTrigger(appId.workflow("wf1")), Collections.emptyList());
Map<String, String> userArgs = ScheduleTaskRunner.getUserArgs(programSchedule, propertiesResolver);
Assert.assertEquals("val", userArgs.get("key"));
}
Aggregations