Search in sources :

Example 11 with Drop

use of io.cdap.cdap.spi.metadata.MetadataMutation.Drop in project cdap by caskdata.

the class MetadataStorageTest method testSearchOnValue.

@Test
public void testSearchOnValue() throws Exception {
    MetadataStorage mds = getMetadataStorage();
    MetadataEntity program = ofWorker(ofApp("ns1", "app1"), "wk1");
    MetadataEntity dataset = ofDataset("ns1", "ds2");
    // Add some metadata
    final String multiWordValue = "aV1 av2 ,  -  ,  av3 - av4_av5 av6";
    MetadataRecord programRecord = new MetadataRecord(program, new Metadata(USER, props("key1", "value1", "key2", "value2", "multiword", multiWordValue)));
    mds.apply(new Update(program, programRecord.getMetadata()), MutationOptions.DEFAULT);
    // Search for it based on value
    assertResults(mds, SearchRequest.of("value1").build(), programRecord);
    assertResults(mds, SearchRequest.of("  aV1   ").addType(TYPE_PROGRAM).build(), programRecord);
    assertEmpty(mds, SearchRequest.of("  aV1   ").addType(TYPE_ARTIFACT).build());
    // Search for it based split patterns to make sure nothing is matched
    assertEmpty(mds, SearchRequest.of("-").build());
    assertEmpty(mds, SearchRequest.of(",").build());
    assertEmpty(mds, SearchRequest.of("_").build());
    assertEmpty(mds, SearchRequest.of(", ,").build());
    assertEmpty(mds, SearchRequest.of(", - ,").build());
    // Search for it based on a word in value
    assertResults(mds, SearchRequest.of("av5").addType(TYPE_PROGRAM).build(), programRecord);
    // Case insensitive
    assertResults(mds, SearchRequest.of("ValUe1").addType(TYPE_PROGRAM).build(), programRecord);
    // add a property for the program
    mds.apply(new Update(program, new Metadata(SYSTEM, props("key3", "value1"))), MutationOptions.DEFAULT);
    programRecord = new MetadataRecord(program, new Metadata(ImmutableSet.of(), ImmutableMap.of(new ScopedName(USER, "key1"), "value1", new ScopedName(USER, "key2"), "value2", new ScopedName(USER, "multiword"), multiWordValue, new ScopedName(SYSTEM, "key3"), "value1")));
    // search by value
    assertResults(mds, SearchRequest.of("value1").addType(TYPE_PROGRAM).build(), programRecord);
    // add a property for the dataset
    MetadataRecord datasetRecord = new MetadataRecord(dataset, new Metadata(USER, props("key21", "value21")));
    mds.apply(new Update(dataset, datasetRecord.getMetadata()), MutationOptions.DEFAULT);
    // Search based on value prefix
    assertResults(mds, SearchRequest.of("value2*").build(), programRecord, datasetRecord);
    // Search based on value prefix in the wrong namespace
    assertEmpty(mds, SearchRequest.of("value2*").addNamespace("ns12").build());
    // clean up
    mds.batch(batch(new Drop(program), new Drop(dataset)), MutationOptions.DEFAULT);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Example 12 with Drop

use of io.cdap.cdap.spi.metadata.MetadataMutation.Drop in project cdap by caskdata.

the class MetadataStorageTest method testUpdateRemove.

@Test
public void testUpdateRemove() throws IOException {
    MetadataStorage mds = getMetadataStorage();
    MetadataEntity entity = ofDataset(DEFAULT_NAMESPACE, "entity");
    // get metadata for non-existing entity
    verifyMetadata(mds, entity, Metadata.EMPTY);
    // add some metadata for the entity
    Metadata metadata = new Metadata(ImmutableSet.of(new ScopedName(SYSTEM, "sysTag"), new ScopedName(USER, "userTag")), ImmutableMap.of(new ScopedName(SYSTEM, "sysProp"), "sysVal", new ScopedName(USER, "userProp"), "userVal"));
    MetadataChange change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, Metadata.EMPTY, metadata), change);
    verifyMetadata(mds, entity, metadata);
    // remove everything
    change = mds.apply(new Remove(entity), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, metadata, Metadata.EMPTY), change);
    verifyMetadata(mds, entity, Metadata.EMPTY);
    // add back all metadata, then remove everything in user scope
    change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, Metadata.EMPTY, metadata), change);
    verifyMetadata(mds, entity, metadata);
    change = mds.apply(new Remove(entity, USER), MutationOptions.DEFAULT);
    Metadata newMetadata = filterBy(metadata, SYSTEM, null);
    Assert.assertEquals(new MetadataChange(entity, metadata, newMetadata), change);
    verifyMetadata(mds, entity, newMetadata);
    // add back all metadata, then remove everything in system scope
    change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, newMetadata, metadata), change);
    verifyMetadata(mds, entity, metadata);
    change = mds.apply(new Remove(entity, SYSTEM), MutationOptions.DEFAULT);
    newMetadata = filterBy(metadata, USER, null);
    Assert.assertEquals(new MetadataChange(entity, metadata, newMetadata), change);
    verifyMetadata(mds, entity, newMetadata);
    // add back all metadata, then remove all tags
    change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, newMetadata, metadata), change);
    verifyMetadata(mds, entity, metadata);
    change = mds.apply(new Remove(entity, TAG), MutationOptions.DEFAULT);
    newMetadata = filterBy(metadata, null, PROPERTY);
    Assert.assertEquals(new MetadataChange(entity, metadata, newMetadata), change);
    verifyMetadata(mds, entity, newMetadata);
    // add back all metadata, then remove all properties
    change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, newMetadata, metadata), change);
    verifyMetadata(mds, entity, metadata);
    change = mds.apply(new Remove(entity, PROPERTY), MutationOptions.DEFAULT);
    newMetadata = filterBy(metadata, null, TAG);
    Assert.assertEquals(new MetadataChange(entity, metadata, newMetadata), change);
    verifyMetadata(mds, entity, newMetadata);
    // add back all metadata, then remove all properties in system scope
    change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, newMetadata, metadata), change);
    verifyMetadata(mds, entity, metadata);
    change = mds.apply(new Remove(entity, SYSTEM, PROPERTY), MutationOptions.DEFAULT);
    newMetadata = union(filterBy(metadata, SYSTEM, TAG), filterBy(metadata, USER, null));
    Assert.assertEquals(new MetadataChange(entity, metadata, newMetadata), change);
    verifyMetadata(mds, entity, newMetadata);
    // add back all metadata, then remove all tags in user scope
    change = mds.apply(new Update(entity, metadata), MutationOptions.DEFAULT);
    Assert.assertEquals(new MetadataChange(entity, newMetadata, metadata), change);
    verifyMetadata(mds, entity, metadata);
    change = mds.apply(new Remove(entity, USER, TAG), MutationOptions.DEFAULT);
    newMetadata = union(filterBy(metadata, USER, PROPERTY), filterBy(metadata, SYSTEM, null));
    Assert.assertEquals(new MetadataChange(entity, metadata, newMetadata), change);
    verifyMetadata(mds, entity, newMetadata);
    // clean up
    mds.apply(new Drop(entity), MutationOptions.DEFAULT);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Example 13 with Drop

use of io.cdap.cdap.spi.metadata.MetadataMutation.Drop in project cdap by caskdata.

the class MetadataStorageTest method testSearchWithInvalidSchema.

@Test
public void testSearchWithInvalidSchema() throws IOException {
    String invalidSchema = "an invalid schema";
    MetadataEntity entity = MetadataEntity.ofDataset("myDs");
    Metadata meta = new Metadata(SYSTEM, props(MetadataConstants.ENTITY_NAME_KEY, "myDs", MetadataConstants.SCHEMA_KEY, invalidSchema));
    MetadataRecord record = new MetadataRecord(entity, meta);
    MetadataStorage mds = getMetadataStorage();
    mds.apply(new Update(entity, meta), MutationOptions.DEFAULT);
    assertResults(mds, SearchRequest.of("myds").build(), record);
    assertResults(mds, SearchRequest.of("schema:*").build(), record);
    assertResults(mds, SearchRequest.of("properties:schema").build(), record);
    assertResults(mds, SearchRequest.of("schema:inval*").build(), record);
    // clean up
    mds.apply(new Drop(entity), MutationOptions.DEFAULT);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Example 14 with Drop

use of io.cdap.cdap.spi.metadata.MetadataMutation.Drop in project cdap by caskdata.

the class MetadataStorageTest method testUpdateSearch.

@Test
public void testUpdateSearch() throws IOException {
    MetadataStorage mds = getMetadataStorage();
    String ns = "ns";
    MetadataEntity program = ofWorker(ofApp(ns, "app1"), "wk1");
    Metadata meta = new Metadata(USER, tags("tag1", "tag2"), props("key1", "value1", "key2", "value2"));
    MetadataRecord programRecord = new MetadataRecord(program, meta);
    mds.apply(new Update(program, meta), MutationOptions.DEFAULT);
    assertResults(mds, SearchRequest.of("value1").addNamespace(ns).build(), programRecord);
    assertResults(mds, SearchRequest.of("value2").addNamespace(ns).build(), programRecord);
    assertResults(mds, SearchRequest.of("tag2").addNamespace(ns).build(), programRecord);
    mds.apply(new Update(program, new Metadata(USER, props("key1", "value3"))), MutationOptions.DEFAULT);
    mds.apply(new Remove(program, ImmutableSet.of(new ScopedNameOfKind(PROPERTY, USER, "key2"), new ScopedNameOfKind(TAG, USER, "tag2"))), MutationOptions.DEFAULT);
    programRecord = new MetadataRecord(program, new Metadata(USER, tags("tag1"), props("key1", "value3")));
    // Searching for value1 should be empty
    assertEmpty(mds, SearchRequest.of("value1").addNamespace(ns).build());
    // Instead key1 has value value3 now
    assertResults(mds, SearchRequest.of("value3").addNamespace(ns).build(), programRecord);
    // key2 and tag2 were deleted
    assertEmpty(mds, SearchRequest.of("value2").addNamespace(ns).build());
    assertEmpty(mds, SearchRequest.of("tag2").addNamespace(ns).build());
    // tag1 is still here
    assertResults(mds, SearchRequest.of("tag1").addNamespace(ns).build(), programRecord);
    // clean up
    mds.apply(new Drop(program), MutationOptions.DEFAULT);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Example 15 with Drop

use of io.cdap.cdap.spi.metadata.MetadataMutation.Drop in project cdap by caskdata.

the class MetadataStorageTest method testSearchDifferentNamespaces.

@Test
public void testSearchDifferentNamespaces() throws IOException {
    MetadataStorage mds = getMetadataStorage();
    String ns1 = "ns1";
    MetadataEntity artifact = ofArtifact(ns1, "artifact", "1.0");
    MetadataEntity sysArtifact = ofArtifact(SYSTEM_NAMESPACE, "artifact", "1.0");
    String multiWordKey = "multiword";
    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.batch(batch(new Update(artifact, meta), new Update(sysArtifact, meta)), MutationOptions.DEFAULT);
    // 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(batch(new Drop(artifact), new Drop(sysArtifact)), MutationOptions.DEFAULT);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Aggregations

Drop (io.cdap.cdap.spi.metadata.MetadataMutation.Drop)32 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)31 Update (io.cdap.cdap.spi.metadata.MetadataMutation.Update)31 Test (org.junit.Test)31 Remove (io.cdap.cdap.spi.metadata.MetadataMutation.Remove)14 Create (io.cdap.cdap.spi.metadata.MetadataMutation.Create)12 IOException (java.io.IOException)10 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 Collections (java.util.Collections)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Assert (org.junit.Assert)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Schema (io.cdap.cdap.api.data.schema.Schema)7 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)7 SYSTEM (io.cdap.cdap.api.metadata.MetadataScope.SYSTEM)7 USER (io.cdap.cdap.api.metadata.MetadataScope.USER)7 PROPERTY (io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY)7 TAG (io.cdap.cdap.spi.metadata.MetadataKind.TAG)7