@Test public void testSystemMetadata() { MetadataEntity entity = NamespaceId.DEFAULT.app("appX").workflow("wtf").toMetadataEntity(); store.replaceMetadata(MetadataScope.SYSTEM, new MetadataDataset.Record( entity, ImmutableMap.of("a", "b", "x", "y"), ImmutableSet.of("tag1", "tag2")), ImmutableSet.of("a"), ImmutableSet.of("x")); MetadataSearchResponse response = store.search( new SearchRequest(null, "tag1", Collections.emptySet(), SortInfo.DEFAULT, 0, Integer.MAX_VALUE, 0, null, false, EnumSet.allOf(EntityScope.class))); Set<MetadataSearchResultRecord> results = response.getResults(); Assert.assertEquals(1, results.size()); store.replaceMetadata(MetadataScope.SYSTEM, new MetadataDataset.Record( entity, ImmutableMap.of("a", "b", "x", "y"), ImmutableSet.of("tag1", "tag2")), ImmutableSet.of("a"), ImmutableSet.of("x")); response = store.search( new SearchRequest(null, "tag1", Collections.emptySet(), SortInfo.DEFAULT, 0, Integer.MAX_VALUE, 0, null, false, EnumSet.allOf(EntityScope.class))); results = response.getResults(); Assert.assertEquals(1, results.size()); }
@Test public void testSearchOnTagsUpdate() { MetadataEntity entity = NamespaceId.DEFAULT.app("appX").workflow("wtf").toMetadataEntity(); store.addTags(MetadataScope.SYSTEM, entity, ImmutableSet.of("tag1", "tag2")); Assert.assertEquals(ImmutableSet.of("tag1", "tag2"), store.getTags(MetadataScope.SYSTEM, entity)); MetadataSearchResponse response = store.search( new SearchRequest(null, "tag1", Collections.emptySet(), SortInfo.DEFAULT, 0, Integer.MAX_VALUE, 0, null, false, EnumSet.allOf(EntityScope.class))); Set<MetadataSearchResultRecord> results = response.getResults(); Assert.assertEquals(1, results.size()); // add an more tags store.addTags(MetadataScope.SYSTEM, entity, ImmutableSet.of("tag3", "tag4")); ImmutableSet<String> expectedTags = ImmutableSet.of("tag1", "tag2", "tag3", "tag4"); Assert.assertEquals(expectedTags, store.getTags(MetadataScope.SYSTEM, entity)); for (String expectedTag : expectedTags) { response = store.search( new SearchRequest(null, expectedTag, Collections.emptySet(), SortInfo.DEFAULT, 0, Integer.MAX_VALUE, 0, null, false, EnumSet.allOf(EntityScope.class))); results = response.getResults(); Assert.assertEquals(1, results.size()); } // add an empty set of tags. This should have no effect on retrieval or search of tags store.addTags(MetadataScope.SYSTEM, entity, ImmutableSet.of()); Assert.assertEquals(expectedTags, store.getTags(MetadataScope.SYSTEM, entity)); response = store.search( new SearchRequest(null, "tag1", Collections.emptySet(), SortInfo.DEFAULT, 0, Integer.MAX_VALUE, 0, null, false, EnumSet.allOf(EntityScope.class))); results = response.getResults(); Assert.assertEquals(1, results.size()); }
@Test public void testWorkflowTags() throws Exception { String appName = WorkflowAppWithFork.class.getSimpleName(); ApplicationId appId = NamespaceId.DEFAULT.app(appName); String workflowName = WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName(); ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0"); ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName); WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName); SystemMetadataWriterStage systemMetadataWriterStage = new SystemMetadataWriterStage(metadataPublisher); StageContext stageContext = new StageContext(Object.class); systemMetadataWriterStage.process(stageContext); systemMetadataWriterStage.process(appWithPrograms); // verify that the workflow is not tagged with the fork node name. First wait for tags to show up Tasks.waitFor(false, () -> metadataStore.getTags( MetadataScope.SYSTEM, appId.workflow(workflowName).toMetadataEntity()).isEmpty(), 5, TimeUnit.SECONDS); Set<String> workflowSystemTags = metadataStore.getTags(MetadataScope.SYSTEM, appId.workflow(workflowName).toMetadataEntity()); Sets.SetView<String> intersection = Sets.intersection(workflowSystemTags, getWorkflowForkNodes(workflowSpec)); Assert.assertTrue("Workflows should not be tagged with fork node names, but found the following fork nodes " + "in the workflow's system tags: " + intersection, intersection.isEmpty()); // verify that metadata was added for the workflow's schedule. First wait for the metadata to show up Tasks.waitFor(false, () -> metadataStore.getProperties( MetadataScope.SYSTEM, appId.toMetadataEntity()).isEmpty(), 5, TimeUnit.SECONDS); Map<String, String> metadataProperties = metadataStore.getMetadata(MetadataScope.SYSTEM, appId.toMetadataEntity()).getProperties(); Assert.assertEquals(WorkflowAppWithFork.SCHED_NAME + ":testDescription", metadataProperties.get("schedule:" + WorkflowAppWithFork.SCHED_NAME)); }
@Test public void testSearchOnTagsUpdate() throws IOException { MetadataStorage mds = getMetadataStorage(); MetadataEntity entity = NamespaceId.DEFAULT.app("appX").workflow("wtf").toMetadataEntity(); Metadata meta = new Metadata(SYSTEM, tags("tag1", "tag2")); mds.apply(new Update(entity, meta)); Assert.assertEquals(meta.getTags(SYSTEM), mds.read(new Read(entity, SYSTEM)).getTags(SYSTEM)); assertResults(mds, SearchRequest.of("tag1").build(), new MetadataRecord(entity, meta)); // add an more tags mds.apply(new Update(entity, new Metadata(SYSTEM, tags("tag3", "tag4")))); Set<String> newTags = tags("tag1", "tag2", "tag3", "tag4"); Metadata newMeta = new Metadata(SYSTEM, newTags); Assert.assertEquals(newTags, mds.read(new Read(entity, SYSTEM)).getTags(SYSTEM)); for (String expectedTag : newTags) { assertResults(mds, SearchRequest.of(expectedTag).build(), new MetadataRecord(entity, newMeta)); } // add an empty set of tags. This should have no effect on retrieval or search of tags mds.apply(new Update(entity, new Metadata(SYSTEM, tags()))); Assert.assertEquals(newTags, mds.read(new Read(entity, SYSTEM)).getTags(SYSTEM)); for (String expectedTag : newTags) { assertResults(mds, SearchRequest.of(expectedTag).build(), new MetadataRecord(entity, newMeta)); } // clean up mds.apply(new Drop(entity)); }