use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class ArtifactStore method getArtifacts.
/**
* Get information about all artifacts in the given namespace. If there are no artifacts in the namespace,
* this will return an empty list. Note that existence of the namespace is not checked.
*
* @param namespace the namespace to get artifact information about
* @return unmodifiable list of artifact info about every artifact in the given namespace
* @throws IOException if there was an exception reading the artifact information from the metastore
*/
public List<ArtifactDetail> getArtifacts(final NamespaceId namespace) throws IOException {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = getTable(context, StoreDefinition.ArtifactStore.ARTIFACT_DATA_TABLE);
List<ArtifactDetail> artifacts = Lists.newArrayList();
Range scanRange = createArtifactScanRange(namespace);
// TODO: CDAP-14636 add scan method without limit
try (CloseableIterator<StructuredRow> iterator = table.scan(scanRange, Integer.MAX_VALUE)) {
getArtifacts(iterator, Integer.MAX_VALUE, null, () -> artifacts);
}
return Collections.unmodifiableList(artifacts);
}, IOException.class);
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class ArtifactStore method clear.
/**
* Clear all data in the given namespace. Used only in unit tests.
*
* @param namespace the namespace to delete data in
* @throws IOException if there was some problem deleting the data
*/
@VisibleForTesting
void clear(final NamespaceId namespace) throws IOException {
final Id.Namespace namespaceId = Id.Namespace.fromEntityId(namespace);
namespacePathLocator.get(namespace).append(ARTIFACTS_PATH).delete(true);
TransactionRunners.run(transactionRunner, context -> {
// delete all rows about artifacts in the namespace
StructuredTable artifactDataTable = getTable(context, StoreDefinition.ArtifactStore.ARTIFACT_DATA_TABLE);
Range artifactScanRange = createArtifactScanRange(namespace);
deleteRangeFromTable(artifactDataTable, artifactScanRange);
// delete all rows about artifacts in the namespace and the plugins they have access to
StructuredTable pluginDataTable = getTable(context, StoreDefinition.ArtifactStore.PLUGIN_DATA_TABLE);
Collection<Field<?>> pluginKey = Collections.singleton(Fields.stringField(StoreDefinition.ArtifactStore.PARENT_NAMESPACE_FIELD, namespace.getNamespace()));
deleteRangeFromTable(pluginDataTable, Range.singleton(pluginKey));
// delete all rows about universal plugins
StructuredTable univPluginsDataTable = getTable(context, StoreDefinition.ArtifactStore.UNIV_PLUGIN_DATA_TABLE);
deleteRangeFromTable(univPluginsDataTable, createUniversalPluginScanRange(namespace.getNamespace(), null));
// delete app classes in this namespace
StructuredTable appClassTable = getTable(context, StoreDefinition.ArtifactStore.APP_DATA_TABLE);
deleteRangeFromTable(appClassTable, createAppClassRange(namespace));
// delete plugins in this namespace from system artifacts
// for example, if there was an artifact in this namespace that extends a system artifact
Collection<Field<?>> systemPluginKey = Collections.singleton(Fields.stringField(StoreDefinition.ArtifactStore.PARENT_NAMESPACE_FIELD, Id.Namespace.SYSTEM.getId()));
try (CloseableIterator<StructuredRow> iterator = pluginDataTable.scan(Range.singleton(systemPluginKey), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
// if the plugin artifact is in the namespace we're deleting, delete this column.
if (namespaceId.getId().equals(row.getString(StoreDefinition.ArtifactStore.ARTIFACT_NAMESPACE_FIELD))) {
pluginDataTable.delete(concatFields(PluginKeyPrefix.fromRow(row), ArtifactCell.fromRow(row)));
}
}
}
}, IOException.class);
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by cdapio.
the class ArtifactStore method addPluginsInRangeToMap.
private void addPluginsInRangeToMap(final NamespaceId namespace, List<Id.Artifact> parentArtifacts, Iterator<StructuredRow> iterator, SortedMap<ArtifactDescriptor, PluginClass> plugins, @Nullable Predicate<io.cdap.cdap.proto.id.ArtifactId> range, int limit) {
// if predicate is null,
// filter out plugins whose artifacts are not in the system namespace and not in this namespace
range = range != null ? range : input -> NamespaceId.SYSTEM.equals(input.getParent()) || input.getParent().equals(namespace);
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
ImmutablePair<ArtifactDescriptor, PluginData> pluginPair = getPlugin(row, range);
if (pluginPair == null) {
continue;
}
PluginData pluginData = pluginPair.getSecond();
// filter out plugins that don't extend this version of the parent artifact
for (Id.Artifact parentArtifactId : parentArtifacts) {
if (pluginData.isUsableBy(parentArtifactId.toEntityId()) && isAllowed(pluginData.pluginClass)) {
plugins.put(pluginPair.getFirst(), pluginData.pluginClass);
break;
}
}
if (limit < plugins.size()) {
plugins.remove(plugins.lastKey());
}
}
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by caskdata.
the class ProgramScheduleStoreDataset method deleteSchedules.
/**
* Removes all schedules for a specific application from the store.
*
* @param appId the application id for which to delete the schedules
* @return the IDs of the schedules that were deleted
*/
// TODO: fix the bug that this method will return fake schedule id https://issues.cask.co/browse/CDAP-13626
public List<ScheduleId> deleteSchedules(ApplicationId appId, long deleteTime) throws IOException {
List<ScheduleId> deleted = new ArrayList<>();
Collection<Field<?>> scanKeys = getScheduleKeysForApplicationScan(appId);
Range range = Range.singleton(scanKeys);
// First collect all the schedules that are going to be deleted
try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(range, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
if (row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE) != null) {
markScheduleAsDeleted(row, deleteTime);
deleted.add(rowToScheduleId(row));
}
}
}
// Then delete all triggers for the app
triggerStore.deleteAll(range);
return deleted;
}
use of io.cdap.cdap.spi.data.table.field.Range in project cdap by caskdata.
the class ProgramScheduleStoreDataset method deleteSchedules.
/**
* Removes all schedules for a specific program from the store.
*
* @param programId the program id for which to delete the schedules
* @return the IDs of the schedules that were deleted
*/
// TODO: fix the bug that this method will return fake schedule id https://issues.cask.co/browse/CDAP-13626
public List<ScheduleId> deleteSchedules(ProgramId programId, long deleteTime) throws IOException {
List<ScheduleId> deleted = new ArrayList<>();
Collection<Field<?>> scanKeys = getScheduleKeysForApplicationScan(programId.getParent());
Range range = Range.singleton(scanKeys);
// First collect all the schedules that are going to be deleted
try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(range, Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
String serializedSchedule = row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE);
if (serializedSchedule != null) {
ProgramSchedule schedule = GSON.fromJson(serializedSchedule, ProgramSchedule.class);
if (programId.equals(schedule.getProgramId())) {
markScheduleAsDeleted(row, deleteTime);
Collection<Field<?>> deleteKeys = getScheduleKeys(row);
triggerStore.deleteAll(Range.singleton(deleteKeys));
deleted.add(rowToScheduleId(row));
}
}
}
}
return deleted;
}
Aggregations