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"));
}
}
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);
}
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);
}
}
Aggregations