Search in sources :

Example 1 with NamespaceStore

use of io.cdap.cdap.store.NamespaceStore in project cdap by caskdata.

the class MetadataSubscriberService method preProcess.

@Override
protected void preProcess() {
    if (didBackfill) {
        return;
    }
    if (backfillAttempts > 10) {
        LOG.info("Skipping attempt to back-fill plugin metadata after 10 failures.");
        return;
    }
    // Backfill plugin metadata
    backfillAttempts++;
    LOG.info("Starting back-fill process(attempt {}) for plugin metadata", backfillAttempts);
    boolean updateFailed = false;
    NamespaceStore namespaceStore = new DefaultNamespaceStore(this.transactionRunner);
    List<String> namespaces = namespaceStore.list().stream().map(NamespaceMeta::getName).collect(Collectors.toList());
    LOG.debug("Back-filling plugin metadata for {} namespaces", namespaces.size());
    for (String namespace : namespaces) {
        List<ApplicationMeta> apps = TransactionRunners.run(this.transactionRunner, context -> {
            AppMetadataStore appMetadataStore = AppMetadataStore.create(context);
            return appMetadataStore.getAllApplications(namespace);
        });
        LOG.debug("Back-filling plugin metadata for namespace '{}' with {} applications", namespace, apps.size());
        try {
            this.getPluginCounts(namespace, apps);
        } catch (IOException e) {
            updateFailed = true;
            LOG.warn("Failed to write plugin metadata updates for namespace '{}': {}", namespace, e);
        }
    }
    if (!updateFailed) {
        LOG.info("Successfully back-filled plugin metadata for {} namespaces.", namespaces.size());
        didBackfill = true;
        TransactionRunners.run(transactionRunner, (TxRunnable) context -> AppMetadataStore.create(context).persistSubscriberState(getTopicId().getTopic(), BACKFILL_SUBSCRIBER_NAME, "true"));
    }
}
Also used : ImmutablePair(io.cdap.cdap.common.utils.ImmutablePair) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) RetryStrategies(io.cdap.cdap.common.service.RetryStrategies) UsageTable(io.cdap.cdap.data2.registry.UsageTable) GsonBuilder(com.google.gson.GsonBuilder) PluginId(io.cdap.cdap.proto.id.PluginId) DataAccessLineage(io.cdap.cdap.data2.metadata.writer.DataAccessLineage) EndPointField(io.cdap.cdap.data2.metadata.lineage.field.EndPointField) MetadataOperationTypeAdapter(io.cdap.cdap.data2.metadata.writer.MetadataOperationTypeAdapter) Gson(com.google.gson.Gson) InvalidMetadataException(io.cdap.cdap.common.InvalidMetadataException) Metadata(io.cdap.cdap.spi.metadata.Metadata) Map(java.util.Map) EntityType(io.cdap.cdap.proto.element.EntityType) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) BasicWorkflowToken(io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) ImmutableMap(com.google.common.collect.ImmutableMap) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) MessagingService(io.cdap.cdap.messaging.MessagingService) Set(java.util.Set) StructuredTableContext(io.cdap.cdap.spi.data.StructuredTableContext) Collectors(java.util.stream.Collectors) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) MultiThreadMessagingContext(io.cdap.cdap.messaging.context.MultiThreadMessagingContext) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) MetadataOperation(io.cdap.cdap.data2.metadata.writer.MetadataOperation) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) MessagingContext(io.cdap.cdap.api.messaging.MessagingContext) TxCallable(io.cdap.cdap.spi.data.transaction.TxCallable) HashMap(java.util.HashMap) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta) EntityId(io.cdap.cdap.proto.id.EntityId) Function(java.util.function.Function) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NamespaceStore(io.cdap.cdap.store.NamespaceStore) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) DatasetUsage(io.cdap.cdap.data2.registry.DatasetUsage) EntityIdTypeAdapter(io.cdap.cdap.proto.codec.EntityIdTypeAdapter) LineageTable(io.cdap.cdap.data2.metadata.lineage.LineageTable) ScopedNameOfKind(io.cdap.cdap.spi.metadata.ScopedNameOfKind) Operation(io.cdap.cdap.api.lineage.field.Operation) Nullable(javax.annotation.Nullable) WorkflowNodeStateDetail(io.cdap.cdap.proto.WorkflowNodeStateDetail) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) ProfileMetadataMessageProcessor(io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor) FieldLineageTable(io.cdap.cdap.data2.metadata.lineage.field.FieldLineageTable) Logger(org.slf4j.Logger) Message(io.cdap.cdap.api.messaging.Message) Iterator(java.util.Iterator) ProgramId(io.cdap.cdap.proto.id.ProgramId) TxRunnable(io.cdap.cdap.spi.data.transaction.TxRunnable) TxConstants(org.apache.tephra.TxConstants) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) EndpointFieldDeserializer(io.cdap.cdap.data2.metadata.lineage.field.EndpointFieldDeserializer) AbstractMessagingSubscriberService(io.cdap.cdap.messaging.subscriber.AbstractMessagingSubscriberService) MetadataKind(io.cdap.cdap.spi.metadata.MetadataKind) OperationTypeAdapter(io.cdap.cdap.proto.codec.OperationTypeAdapter) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) FieldLineageInfo(io.cdap.cdap.data2.metadata.lineage.field.FieldLineageInfo) MutationOptions(io.cdap.cdap.spi.metadata.MutationOptions) Collections(java.util.Collections) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) NamespaceStore(io.cdap.cdap.store.NamespaceStore) DefaultNamespaceStore(io.cdap.cdap.store.DefaultNamespaceStore) IOException(java.io.IOException) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta)

Example 2 with NamespaceStore

use of io.cdap.cdap.store.NamespaceStore in project cdap by caskdata.

the class EntityExistenceTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.INSTANCE_NAME, EXISTS);
    Injector injector = AppFabricTestHelper.getInjector(cConf);
    NamespaceStore nsStore = injector.getInstance(NamespaceStore.class);
    ArtifactRepository artifactRepository = injector.getInstance(ArtifactRepository.class);
    cConf = injector.getInstance(CConfiguration.class);
    nsStore.create(new NamespaceMeta.Builder().setName(EXISTS).build());
    existenceVerifier = injector.getInstance(Key.get(new TypeLiteral<EntityExistenceVerifier<EntityId>>() {
    }));
    LocalLocationFactory lf = new LocalLocationFactory(TEMPORARY_FOLDER.newFolder());
    File artifactFile = new File(AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class).toURI());
    artifactRepository.addArtifact(Id.Artifact.fromEntityId(ARTIFACT), artifactFile);
    AppFabricTestHelper.deployApplication(Id.Namespace.fromEntityId(NAMESPACE), AllProgramsApp.class, null, cConf);
}
Also used : EntityExistenceVerifier(io.cdap.cdap.common.entity.EntityExistenceVerifier) Injector(com.google.inject.Injector) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceStore(io.cdap.cdap.store.NamespaceStore) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 3 with NamespaceStore

use of io.cdap.cdap.store.NamespaceStore in project cdap by caskdata.

the class StorageProviderNamespaceAdminTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setBoolean(Constants.Explore.EXPLORE_ENABLED, true);
    Injector injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf)).with(new AbstractModule() {

        @Override
        protected void configure() {
            // use the DefaultNamespacePathLocator here to test proper namespace creation in storage handler and
            // not the NamespacedLocationFactoryTestClient
            bind(NamespacePathLocator.class).to(DefaultNamespacePathLocator.class);
        }
    }));
    namespacePathLocator = injector.getInstance(NamespacePathLocator.class);
    storageProviderNamespaceAdmin = injector.getInstance(StorageProviderNamespaceAdmin.class);
    // start the dataset service for namespace store to work
    transactionManager = injector.getInstance(TransactionManager.class);
    transactionManager.startAndWait();
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    // we don't use namespace admin here but the store because namespaceadmin will try to create the
    // home directory for namespace which we don't want. We just want to store the namespace meta in store
    // to look up during the delete.
    namespaceStore = injector.getInstance(NamespaceStore.class);
}
Also used : Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) NamespaceStore(io.cdap.cdap.store.NamespaceStore) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) DefaultNamespacePathLocator(io.cdap.cdap.common.namespace.DefaultNamespacePathLocator) NamespacePathLocator(io.cdap.cdap.common.namespace.NamespacePathLocator) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) BeforeClass(org.junit.BeforeClass)

Aggregations

CConfiguration (io.cdap.cdap.common.conf.CConfiguration)3 NamespaceStore (io.cdap.cdap.store.NamespaceStore)3 Injector (com.google.inject.Injector)2 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AbstractModule (com.google.inject.AbstractModule)1 Inject (com.google.inject.Inject)1 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)1 Operation (io.cdap.cdap.api.lineage.field.Operation)1 Message (io.cdap.cdap.api.messaging.Message)1 MessagingContext (io.cdap.cdap.api.messaging.MessagingContext)1 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)1 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 ConflictException (io.cdap.cdap.common.ConflictException)1 InvalidMetadataException (io.cdap.cdap.common.InvalidMetadataException)1 Constants (io.cdap.cdap.common.conf.Constants)1 EntityExistenceVerifier (io.cdap.cdap.common.entity.EntityExistenceVerifier)1