use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.
the class PreviewRunnerModule method configure.
@Override
protected void configure() {
Boolean artifactLocalizerEnabled = cConf.getBoolean(Constants.Preview.ARTIFACT_LOCALIZER_ENABLED, false);
if (artifactLocalizerEnabled) {
// Use remote implementation to fetch artifact metadata from AppFab.
// Remote implementation internally uses artifact localizer to fetch and cache artifacts locally.
bind(ArtifactRepositoryReader.class).to(RemoteArtifactRepositoryReaderWithLocalization.class);
bind(ArtifactRepository.class).to(RemoteArtifactRepositoryWithLocalization.class);
expose(ArtifactRepository.class);
bind(ArtifactRepository.class).annotatedWith(Names.named(AppFabricServiceRuntimeModule.NOAUTH_ARTIFACT_REPO)).to(RemoteArtifactRepositoryWithLocalization.class).in(Scopes.SINGLETON);
expose(ArtifactRepository.class).annotatedWith(Names.named(AppFabricServiceRuntimeModule.NOAUTH_ARTIFACT_REPO));
// Use remote implementation to fetch plugin metadata from AppFab.
// Remote implementation internally uses artifact localizer to fetch and cache artifacts locally.
bind(PluginFinder.class).to(RemoteWorkerPluginFinder.class);
expose(PluginFinder.class);
// Use remote implementation to fetch preferences from AppFab.
bind(PreferencesFetcher.class).to(RemotePreferencesFetcherInternal.class);
expose(PreferencesFetcher.class);
} else {
bind(ArtifactRepositoryReader.class).toProvider(artifactRepositoryReaderProvider);
bind(ArtifactRepository.class).to(DefaultArtifactRepository.class);
expose(ArtifactRepository.class);
bind(ArtifactRepository.class).annotatedWith(Names.named(AppFabricServiceRuntimeModule.NOAUTH_ARTIFACT_REPO)).to(DefaultArtifactRepository.class).in(Scopes.SINGLETON);
expose(ArtifactRepository.class).annotatedWith(Names.named(AppFabricServiceRuntimeModule.NOAUTH_ARTIFACT_REPO));
bind(PluginFinder.class).toProvider(pluginFinderProvider);
expose(PluginFinder.class);
bind(PreferencesFetcher.class).toProvider(preferencesFetcherProvider);
expose(PreferencesFetcher.class);
}
bind(ArtifactStore.class).toInstance(artifactStore);
expose(ArtifactStore.class);
bind(MessagingService.class).annotatedWith(Names.named(PreviewConfigModule.GLOBAL_TMS)).toInstance(messagingService);
expose(MessagingService.class).annotatedWith(Names.named(PreviewConfigModule.GLOBAL_TMS));
bind(AccessEnforcer.class).toInstance(accessEnforcer);
expose(AccessEnforcer.class);
bind(ContextAccessEnforcer.class).toInstance(contextAccessEnforcer);
expose(ContextAccessEnforcer.class);
bind(AccessControllerInstantiator.class).toInstance(accessControllerInstantiator);
expose(AccessControllerInstantiator.class);
bind(PermissionManager.class).toInstance(permissionManager);
expose(PermissionManager.class);
bind(PreferencesService.class).toInstance(preferencesService);
// bind explore client to mock.
bind(ExploreClient.class).to(MockExploreClient.class);
expose(ExploreClient.class);
bind(ProgramRuntimeProviderLoader.class).toInstance(programRuntimeProviderLoader);
expose(ProgramRuntimeProviderLoader.class);
bind(StorageProviderNamespaceAdmin.class).to(LocalStorageProviderNamespaceAdmin.class);
bind(PipelineFactory.class).to(SynchronousPipelineFactory.class);
install(new FactoryModuleBuilder().implement(Configurator.class, InMemoryConfigurator.class).build(ConfiguratorFactory.class));
// expose this binding so program runner modules can use
expose(ConfiguratorFactory.class);
install(new FactoryModuleBuilder().implement(new TypeLiteral<Manager<AppDeploymentInfo, ApplicationWithPrograms>>() {
}, new TypeLiteral<PreviewApplicationManager<AppDeploymentInfo, ApplicationWithPrograms>>() {
}).build(new TypeLiteral<ManagerFactory<AppDeploymentInfo, ApplicationWithPrograms>>() {
}));
bind(Store.class).to(DefaultStore.class);
bind(SecretStore.class).to(DefaultSecretStore.class).in(Scopes.SINGLETON);
bind(UGIProvider.class).to(DefaultUGIProvider.class);
expose(UGIProvider.class);
bind(WorkflowStateWriter.class).to(BasicWorkflowStateWriter.class);
expose(WorkflowStateWriter.class);
// we don't delete namespaces in preview as we just delete preview directory when its done
bind(NamespaceResourceDeleter.class).to(NoopNamespaceResourceDeleter.class).in(Scopes.SINGLETON);
bind(NamespaceAdmin.class).to(DefaultNamespaceAdmin.class).in(Scopes.SINGLETON);
bind(NamespaceQueryAdmin.class).to(DefaultNamespaceAdmin.class).in(Scopes.SINGLETON);
expose(NamespaceAdmin.class);
expose(NamespaceQueryAdmin.class);
bind(MetadataAdmin.class).to(DefaultMetadataAdmin.class);
expose(MetadataAdmin.class);
bindPreviewRunner(binder());
expose(PreviewRunner.class);
bind(Scheduler.class).to(NoOpScheduler.class);
bind(DataTracerFactory.class).to(DefaultDataTracerFactory.class);
expose(DataTracerFactory.class);
bind(PreviewDataPublisher.class).to(MessagingPreviewDataPublisher.class);
bind(OwnerStore.class).to(DefaultOwnerStore.class);
expose(OwnerStore.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
expose(OwnerAdmin.class);
bind(CapabilityReader.class).to(CapabilityStatusStore.class);
}
use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.
the class TwillAppLifecycleEventHandler method initialize.
@Override
public void initialize(EventHandlerContext context) {
super.initialize(context);
this.runningPublished = new AtomicBoolean();
this.twillRunId = context.getRunId();
Map<String, String> configs = context.getSpecification().getConfigs();
this.programRunId = GSON.fromJson(configs.get("programRunId"), ProgramRunId.class);
this.clusterMode = ClusterMode.valueOf(configs.get("clusterMode"));
this.runtimeMonitorType = RuntimeMonitorType.valueOf(configs.get("monitorType"));
// Fetch cConf and hConf from resources jar
File cConfFile = new File("resources.jar/resources/" + CDAP_CONF_FILE_NAME);
File hConfFile = new File("resources.jar/resources/" + HADOOP_CONF_FILE_NAME);
if (!cConfFile.exists()) {
// This shouldn't happen, unless CDAP is misconfigured
throw new IllegalArgumentException("Missing cConf file " + cConfFile.getAbsolutePath());
}
try {
// Load the configuration from the XML files serialized from the cdap master.
CConfiguration cConf = CConfiguration.create();
cConf.clear();
cConf.addResource(cConfFile.toURI().toURL());
Configuration hConf = new Configuration();
if (hConfFile.exists()) {
hConf.clear();
hConf.addResource(hConfFile.toURI().toURL());
}
// Create the injector to create a program state writer
List<Module> modules = new ArrayList<>(Arrays.asList(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getDefaultModule(), new MessagingClientModule(), new AbstractModule() {
@Override
protected void configure() {
bind(ProgramStateWriter.class).to(MessagingProgramStateWriter.class);
}
}));
switch(clusterMode) {
case ON_PREMISE:
modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
modules.add(new ZKClientModule());
modules.add(new ZKDiscoveryModule());
modules.add(new KafkaClientModule());
break;
case ISOLATED:
modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
modules.add(new RemoteExecutionDiscoveryModule());
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(RuntimeMonitorType.class).toInstance(runtimeMonitorType);
}
});
break;
}
Injector injector = Guice.createInjector(modules);
if (clusterMode == ClusterMode.ON_PREMISE) {
zkClientService = injector.getInstance(ZKClientService.class);
zkClientService.startAndWait();
}
ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class);
MessagingService messagingService = injector.getInstance(MessagingService.class);
programStateWriterWithHeartBeat = new ProgramStateWriterWithHeartBeat(programRunId, programStateWriter, messagingService, cConf);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.
the class TetheringRuntimeJobManagerTest method setUp.
@BeforeClass
public static void setUp() throws IOException, TopicAlreadyExistsException {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.Tethering.TOPIC_PREFIX, "prefix-");
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
Injector injector = Guice.createInjector(new ConfigModule(cConf), new InMemoryDiscoveryModule(), new LocalLocationModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
}
});
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
TetheringConf conf = TetheringConf.fromProperties(PROPERTIES);
topicId = new TopicId(NamespaceId.SYSTEM.getNamespace(), cConf.get(Constants.Tethering.TOPIC_PREFIX) + TETHERED_INSTANCE_NAME);
messagingService.createTopic(new TopicMetadata(topicId, Collections.emptyMap()));
messageFetcher = new MultiThreadMessagingContext(messagingService).getMessageFetcher();
runtimeJobManager = new TetheringRuntimeJobManager(conf, cConf, messagingService);
}
use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.
the class ProvisioningServiceTest method setupClass.
@BeforeClass
public static void setupClass() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
Injector injector = Guice.createInjector(new AppFabricTestModule(cConf));
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
// Define all StructuredTable before starting any services that need StructuredTable
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
messagingService = injector.getInstance(MessagingService.class);
provisionerStore = injector.getInstance(ProvisionerStore.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
provisioningService = injector.getInstance(ProvisioningService.class);
provisioningService.startAndWait();
transactionRunner = injector.getInstance(TransactionRunner.class);
}
use of io.cdap.cdap.messaging.MessagingService in project cdap by caskdata.
the class MetadataSubscriberServiceTest method testAppDeletionMessage.
@Test
public void testAppDeletionMessage() throws Exception {
Injector injector = getInjector();
// get the alert publisher
CConfiguration cConf = injector.getInstance(CConfiguration.class);
MessagingService messagingService = injector.getInstance(MessagingService.class);
MultiThreadMessagingContext messagingContext = new MultiThreadMessagingContext(messagingService);
AdminEventPublisher publisher = new AdminEventPublisher(cConf, messagingContext);
// get the mds and put some workflow metadata in that, the publish of app deletion message should get the metadata
// deleted
MetadataStorage mds = injector.getInstance(MetadataStorage.class);
// use an app with all program types to get all specification tested
ApplicationId appId = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
ProgramId workflowId = appId.workflow(AllProgramsApp.NoOpWorkflow.NAME);
// generate an app spec from the application
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// need to put metadata on workflow since we currently only set or delete workflow metadata
mds.apply(new MetadataMutation.Update(workflowId.toMetadataEntity(), new Metadata(MetadataScope.SYSTEM, Collections.singletonMap("profile", ProfileId.NATIVE.getScopedName()))), MutationOptions.DEFAULT);
Assert.assertEquals(ProfileId.NATIVE.getScopedName(), getProfileProperty(mds, workflowId));
// publish app deletion message
publisher.publishAppDeletion(appId, appSpec);
// Verify the workflow profile metadata is removed because of the publish app deletion message
Tasks.waitFor(true, () -> mds.read(new Read(workflowId.toMetadataEntity())).isEmpty(), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
Aggregations