public ArtifactSystemMetadataWriter(MetadataStore metadataStore, ArtifactId artifactId, ArtifactInfo artifactInfo) { super(metadataStore, artifactId); this.artifactInfo = artifactInfo; this.existing = !metadataStore.getProperties(MetadataScope.SYSTEM, artifactId.toMetadataEntity()).isEmpty(); }
@Override public void deleteArtifact(Id.Artifact artifactId) throws Exception { // delete the artifact first and then privileges. Not the other way to avoid orphan artifact // which does not have any privilege if the artifact delete from store fails. see CDAP-6648 artifactStore.delete(artifactId); metadataStore.removeMetadata(artifactId.toEntityId().toMetadataEntity()); }
@Override public void deleteArtifact(Id.Artifact artifactId) throws Exception { // delete the artifact first and then privileges. Not the other way to avoid orphan artifact // which does not have any privilege if the artifact delete from store fails. see CDAP-6648 artifactStore.delete(artifactId); metadataPublisher.publish(NamespaceId.SYSTEM, new MetadataOperation.Drop(artifactId.toEntityId().toMetadataEntity())); }
@Test public void testDeletingArtifact() throws Exception { Tasks.waitFor(false, () -> metadataStore.getMetadata(MetadataScope.SYSTEM, APP_ARTIFACT_ID.toEntityId().toMetadataEntity()) .getProperties().isEmpty(), 5, TimeUnit.SECONDS); artifactRepository.deleteArtifact(APP_ARTIFACT_ID); Tasks.waitFor(true, () -> metadataStore.getMetadata(MetadataScope.SYSTEM, APP_ARTIFACT_ID.toEntityId().toMetadataEntity()) .getProperties().isEmpty(), 5, TimeUnit.SECONDS); }
@Test public void testSearchIncludesSystemEntities() throws InterruptedException, TransactionFailureException { final MetadataEntity sysArtifact = NamespaceId.SYSTEM.artifact("artifact", "1.0").toMetadataEntity(); final MetadataEntity ns2Artifact = new ArtifactId("ns2", "artifact", "1.0").toMetadataEntity(); final String multiWordKey = "multiword"; final String multiWordValue = "aV1 av2 , - , av3 - av4_av5 av6";
@Test public void testSearchDifferentEntityScope() throws InterruptedException, TransactionFailureException { MetadataEntity sysArtifact = NamespaceId.SYSTEM.artifact("artifact", "1.0").toMetadataEntity(); MetadataEntity nsArtifact = new ArtifactId("ns1", "artifact", "1.0").toMetadataEntity(); String multiWordKey = "multiword"; String multiWordValue = "aV1 av2 , - , av3 - av4_av5 av6";
Assert.assertEquals(ImmutableMap.of(), getArtifactProperties(artifactId1)); Set<MetadataRecord> metadataRecords = metadataClient.getMetadata(artifactId1.toMetadataEntity(), MetadataScope.USER); Assert.assertEquals(1, metadataRecords.size()); Set<MetadataRecord> metadata = metadataClient.getMetadata(artifactId1.toMetadataEntity(), MetadataScope.USER);
@Test public void testSearchDifferentNamespaces() throws IOException { MetadataStorage mds = getMetadataStorage(); final String ns1 = "ns1"; final NamespaceId ns1Id = new NamespaceId(ns1); final MetadataEntity artifact = ns1Id.artifact("artifact", "1.0").toMetadataEntity(); final MetadataEntity sysArtifact = NamespaceId.SYSTEM.artifact("artifact", "1.0").toMetadataEntity(); final String multiWordKey = "multiword"; final String multiWordValue = "aV1 av2 , - , av3 - av4_av5 av6"; Metadata meta = new Metadata(SYSTEM, props(multiWordKey, multiWordValue)); MetadataRecord artifactRecord = new MetadataRecord(artifact, meta); MetadataRecord sysArtifactRecord = new MetadataRecord(sysArtifact, meta); mds.apply(new Update(artifact, meta)); mds.apply(new Update(sysArtifact, meta)); // searching only user namespace should not return system entity assertResults(mds, SearchRequest.of("aV5").addNamespace(ns1).build(), artifactRecord); // searching only user namespace and system should return only the system entity assertResults(mds, SearchRequest.of("aV5").addSystemNamespace().build(), sysArtifactRecord); // searching only user namespace and system should return both entities assertResults(mds, SearchRequest.of("aV5").addNamespace(ns1).addSystemNamespace().build(), artifactRecord, sysArtifactRecord); // clean up mds.batch(ImmutableList.of(new Drop(artifact), new Drop(sysArtifact))); }
final MetadataEntity program = appId.worker("wk1").toMetadataEntity(); final MetadataEntity artifact = ns2Id.artifact("artifact", "1.0").toMetadataEntity(); final MetadataEntity sysArtifact = NamespaceId.SYSTEM.artifact("artifact", "1.0").toMetadataEntity();