use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class AbstractNamespaceQueryClient method list.
@Override
public List<NamespaceMeta> list() throws Exception {
HttpRequest request = HttpRequest.get(resolve("namespaces")).build();
HttpResponse response = execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, new TypeToken<List<NamespaceMeta>>() {
}).getResponseObject();
}
throw new IOException(String.format("Cannot list namespaces. Reason: %s", response.getResponseBodyAsString()));
}
use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class DefaultNamespaceStore method update.
@Override
public void update(final NamespaceMeta metadata) {
Preconditions.checkArgument(metadata != null, "Namespace metadata cannot be null.");
TransactionRunners.run(transactionRunner, context -> {
NamespaceTable mds = getNamespaceTable(context);
NamespaceMeta existing = mds.get(metadata.getNamespaceId());
if (existing != null) {
mds.create(metadata);
}
});
}
use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class DefaultNamespaceStore method delete.
@Override
@Nullable
public NamespaceMeta delete(final NamespaceId id) {
Preconditions.checkArgument(id != null, "Namespace id cannot be null.");
return TransactionRunners.run(transactionRunner, context -> {
NamespaceTable mds = getNamespaceTable(context);
NamespaceMeta existing = mds.get(id);
if (existing != null) {
mds.delete(id);
}
return existing;
});
}
use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class LocalDatasetDeleterRunnable method run.
@Override
public void run() {
try {
List<NamespaceMeta> list = namespaceAdmin.list();
for (NamespaceMeta namespaceMeta : list) {
Collection<DatasetSpecificationSummary> specs = datasetFramework.getInstances(namespaceMeta.getNamespaceId(), PROPERTIES);
if (specs.isEmpty()) {
// avoid fetching run records
continue;
}
Set<String> activeRuns = getActiveRuns(namespaceMeta.getNamespaceId());
for (DatasetSpecificationSummary spec : specs) {
deleteLocalDataset(namespaceMeta.getName(), spec.getName(), activeRuns, spec.getProperties());
}
}
} catch (Throwable t) {
LOG.warn("Failed to delete the local datasets.", t);
}
}
use of io.cdap.cdap.proto.NamespaceMeta 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"));
}
}
Aggregations