Search in sources :

Example 1 with ApplicationMeta

use of io.cdap.cdap.internal.app.store.ApplicationMeta 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 ApplicationMeta

use of io.cdap.cdap.internal.app.store.ApplicationMeta in project cdap by caskdata.

the class MetadataSubscriberService method getPluginCounts.

private void getPluginCounts(String namespace, List<ApplicationMeta> apps) throws IOException {
    List<MetadataMutation> updates = new ArrayList<>();
    for (ApplicationMeta app : apps) {
        this.collectPluginMetadata(namespace, app.getSpec(), updates);
    }
    metadataStorage.batch(updates, MutationOptions.DEFAULT);
}
Also used : MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) ArrayList(java.util.ArrayList) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta)

Example 3 with ApplicationMeta

use of io.cdap.cdap.internal.app.store.ApplicationMeta in project cdap by caskdata.

the class ProfileMetadataMessageProcessor method collectProfileMetadata.

private void collectProfileMetadata(EntityId entityId, MetadataMessage message, List<MetadataMutation> updates) throws IOException {
    switch(entityId.getEntityType()) {
        case INSTANCE:
            for (NamespaceMeta meta : namespaceTable.list()) {
                collectProfileMetadata(meta.getNamespaceId(), message, updates);
            }
            break;
        case NAMESPACE:
            NamespaceId namespaceId = (NamespaceId) entityId;
            // make sure namespace exists before updating
            if (namespaceTable.get(namespaceId) == null) {
                LOG.debug("Namespace {} is not found, so the profile metadata of programs or schedules in it will not get " + "updated. Ignoring the message {}", namespaceId, message);
                return;
            }
            ProfileId namespaceProfile = getResolvedProfileId(namespaceId);
            List<ApplicationMeta> applicationMetas = appMetadataStore.getAllApplications(namespaceId.getNamespace());
            for (ApplicationMeta meta : applicationMetas) {
                collectAppProfileMetadata(namespaceId.app(meta.getId()), meta.getSpec(), namespaceProfile, updates);
            }
            break;
        case APPLICATION:
            ApplicationId appId = (ApplicationId) entityId;
            // make sure app exists before updating
            ApplicationMeta meta = appMetadataStore.getApplication(appId);
            if (meta == null) {
                LOG.debug("Application {} is not found, so the profile metadata of its programs/schedules will not get " + "updated. Ignoring the message {}", appId, message);
                return;
            }
            collectAppProfileMetadata(appId, meta.getSpec(), null, updates);
            collectPluginMetadata(appId, meta.getSpec(), updates);
            break;
        case PROGRAM:
            ProgramId programId = (ProgramId) entityId;
            // make sure the app of the program exists before updating
            meta = appMetadataStore.getApplication(programId.getParent());
            if (meta == null) {
                LOG.debug("Application {} is not found, so the profile metadata of program {} will not get updated. " + "Ignoring the message {}", programId.getParent(), programId, message);
                return;
            }
            if (PROFILE_ALLOWED_PROGRAM_TYPES.contains(programId.getType())) {
                collectProgramProfileMetadata(programId, null, updates);
            }
            break;
        case SCHEDULE:
            ScheduleId scheduleId = (ScheduleId) entityId;
            // make sure the schedule exists before updating
            try {
                ProgramSchedule schedule = scheduleDataset.getSchedule(scheduleId);
                collectScheduleProfileMetadata(schedule, getResolvedProfileId(schedule.getProgramId()), updates);
            } catch (NotFoundException e) {
                LOG.debug("Schedule {} is not found, so its profile metadata will not get updated. " + "Ignoring the message {}", scheduleId, message);
                return;
            }
            break;
        default:
            // this should not happen
            LOG.warn("Type of the entity id {} cannot be used to update profile metadata. " + "Ignoring the message {}", entityId, message);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NotFoundException(io.cdap.cdap.common.NotFoundException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta)

Aggregations

ApplicationMeta (io.cdap.cdap.internal.app.store.ApplicationMeta)3 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)2 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)2 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 MetadataMutation (io.cdap.cdap.spi.metadata.MetadataMutation)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)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 NotFoundException (io.cdap.cdap.common.NotFoundException)1