private Range createUniversalPluginScanRange(String namespace, @Nullable String type) { List<Field<?>> keys = new ArrayList<>(); keys.add(Fields.stringField(StoreDefinition.ArtifactStore.NAMESPACE_FIELD, namespace)); if (type != null) { keys.add(Fields.stringField(StoreDefinition.ArtifactStore.PLUGIN_TYPE_FIELD, type)); } return Range.singleton(keys); }
private Range createArtifactScanRange(NamespaceId namespace) { Field<String> stringField = Fields.stringField(StoreDefinition.ArtifactStore.ARTIFACT_NAMESPACE_FIELD, namespace.getNamespace()); return Range.singleton(Collections.singleton(stringField)); }
private Range createAppClassRange(NamespaceId namespace) { return Range.singleton(Collections.singleton(Fields.stringField(StoreDefinition.ArtifactStore.NAMESPACE_FIELD, namespace.getNamespace()))); }
private Range createPluginScanRange(Id.Artifact parentArtifactId, @Nullable String type) { List<Field<?>> keys = new ArrayList<>(); keys.add(Fields.stringField(StoreDefinition.ArtifactStore.PARENT_NAMESPACE_FIELD, parentArtifactId.getNamespace().getId())); keys.add(Fields.stringField(StoreDefinition.ArtifactStore.PARENT_NAME_FIELD, parentArtifactId.getName())); if (type != null) { keys.add(Fields.stringField(StoreDefinition.ArtifactStore.PLUGIN_TYPE_FIELD, type)); } return Range.singleton(keys); }
private List<ArtifactDetail> getArtifacts(StructuredTable artifactDataTable, ArtifactRange range, int limit, ArtifactSortOrder order) throws IOException { Collection<Field<?>> keys = Arrays.asList(Fields.stringField(StoreDefinition.ArtifactStore.ARTIFACT_NAMESPACE_FIELD, range.getNamespace()), Fields.stringField(StoreDefinition.ArtifactStore.ARTIFACT_NAME_FIELD, range.getName())); // here we have to query with Integer.MAX_VALUE since we want to sort the result try (CloseableIterator<StructuredRow> iterator = artifactDataTable.scan(Range.singleton(keys), Integer.MAX_VALUE)) { return getArtifacts(iterator, limit, order, range); } }
/** * Get all application classes that belong to the specified namespace. * Results are returned as a sorted map from artifact to application classes in that artifact. * Map entries are sorted by the artifact. * * @param namespace the namespace from which to get application classes * @return an unmodifiable map of artifact to a list of all application classes in that artifact. * The map will never be null. If there are no application classes, an empty map will be returned. */ public SortedMap<ArtifactDescriptor, List<ApplicationClass>> getApplicationClasses(NamespaceId namespace) { return TransactionRunners.run(transactionRunner, context -> { SortedMap<ArtifactDescriptor, List<ApplicationClass>> result = Maps.newTreeMap(); StructuredTable table = context.getTable(StoreDefinition.ArtifactStore.APP_DATA_TABLE); Collection<Field<?>> keys = Collections.singleton( Fields.stringField(StoreDefinition.ArtifactStore.NAMESPACE_FIELD, namespace.getNamespace())); try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(keys), Integer.MAX_VALUE)) { while (iterator.hasNext()) { StructuredRow row = iterator.next(); Map.Entry<ArtifactDescriptor, ApplicationClass> entry = extractApplicationClass(row); List<ApplicationClass> existingAppClasses = result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()); existingAppClasses.add(entry.getValue()); } } return Collections.unmodifiableSortedMap(result); }); }
/** * Get all application classes that belong to the specified namespace of the specified classname. * Results are returned as a sorted map from artifact to application classes in that artifact. * Map entries are sorted by the artifact. * * @param namespace the namespace from which to get application classes * @param className the classname of application classes to get * @return an unmodifiable map of artifact the application classes in that artifact. * The map will never be null. If there are no application classes, an empty map will be returned. */ public SortedMap<ArtifactDescriptor, ApplicationClass> getApplicationClasses(final NamespaceId namespace, final String className) { return TransactionRunners.run(transactionRunner, context -> { StructuredTable table = context.getTable(StoreDefinition.ArtifactStore.APP_DATA_TABLE); SortedMap<ArtifactDescriptor, ApplicationClass> result = Maps.newTreeMap(); Collection<Field<?>> keys = ImmutableList.of( Fields.stringField(StoreDefinition.ArtifactStore.NAMESPACE_FIELD, namespace.getNamespace()), Fields.stringField(StoreDefinition.ArtifactStore.CLASS_NAME_FIELD, className)); try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(keys), Integer.MAX_VALUE)) { while (iterator.hasNext()) { StructuredRow row = iterator.next(); Map.Entry<ArtifactDescriptor, ApplicationClass> entry = extractApplicationClass(row); result.put(entry.getKey(), entry.getValue()); } } return Collections.unmodifiableSortedMap(result); }); }
table.scan(Range.singleton(keys), Integer.MAX_VALUE)) { List<ArtifactDetail> artifacts = getArtifacts(iterator, limit, order, null); if (artifacts.isEmpty()) {
parentArtifactRange.getName(), type, name); try (CloseableIterator<StructuredRow> iterator = pluginTable.scan(Range.singleton(pluginKey.keys), Integer.MAX_VALUE)) { addPluginsInRangeToMap(namespace, parentArtifacts, iterator, plugins, pluginRange, limit); UniversalPluginKeyPrefix universalPluginKey = new UniversalPluginKeyPrefix(ns, type, name); try (CloseableIterator<StructuredRow> iterator = uniPluginTable.scan(Range.singleton(universalPluginKey.keys), Integer.MAX_VALUE)) { addPluginsInRangeToMap(namespace, parentArtifacts, iterator, plugins, pluginRange, limit);
@Test public void testSimpleScan() throws Exception { int max = 100; List<Collection<Field<?>>> expected = writeSimpleStructuredRows(max, ""); List<Collection<Field<?>>> actual = scanSimpleStructuredRows( Range.create(Collections.singleton(Fields.intField(KEY, 5)), Range.Bound.INCLUSIVE, Collections.singleton(Fields.intField(KEY, 15)), Range.Bound.EXCLUSIVE), max); Assert.assertEquals(expected.subList(5, 15), actual); actual = scanSimpleStructuredRows( Range.create(Collections.singleton(Fields.intField(KEY, 5)), Range.Bound.EXCLUSIVE, Collections.singleton(Fields.intField(KEY, 15)), Range.Bound.INCLUSIVE), max); Assert.assertEquals(expected.subList(6, 16), actual); actual = scanSimpleStructuredRows( Range.singleton(Collections.singleton(Fields.intField(KEY, 46))), max); Assert.assertEquals(expected.subList(46, 47), actual); // TODO: test invalid range // TODO: test begin only range // TODO: test end only range }
Collections.singleton(Fields.stringField(StoreDefinition.ArtifactStore.PARENT_NAMESPACE_FIELD, namespace.getNamespace())); deleteRangeFromTable(pluginDataTable, Range.singleton(pluginKey)); Id.Namespace.SYSTEM.getId())); try (CloseableIterator<StructuredRow> iterator = pluginDataTable.scan(Range.singleton(systemPluginKey), Integer.MAX_VALUE)) { while (iterator.hasNext()) { StructuredRow row = iterator.next();
for (ApplicationClass appClass : oldMeta.meta.getClasses().getApps()) { AppClassKey appClassKey = new AppClassKey(artifactId.getNamespace().toEntityId(), appClass.getClassName()); deleteRangeFromTable(appClassTable, Range.singleton(appClassKey.keys)); artifactRange.getName(), pluginClass.getType(), pluginClass.getName()); deleteRangeFromTable(pluginDataTable, Range.singleton(pluginKey.keys)); UniversalPluginKeyPrefix pluginKey = new UniversalPluginKeyPrefix(artifactId.getNamespace().getId(), pluginClass.getType(), pluginClass.getName()); deleteRangeFromTable(uniPluginTable, Range.singleton(pluginKey.keys));