Search in sources :

Example 26 with Drop

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

the class MetadataStorageTest method testSearchOnTypes.

@Test
public void testSearchOnTypes() throws Exception {
    MetadataStorage mds = getMetadataStorage();
    MetadataEntity myDs = ofDataset(DEFAULT_NAMESPACE, "myDs");
    MetadataEntity myField1 = MetadataEntity.builder(myDs).appendAsType("field", "myField1").build();
    MetadataEntity myField2 = MetadataEntity.builder(myDs).appendAsType("field", "myField2").build();
    MetadataRecord record1 = new MetadataRecord(myField1, new Metadata(USER, props("testKey1", "testValue1")));
    MetadataRecord record2 = new MetadataRecord(myField2, new Metadata(USER, props("testKey2", "testValue2")));
    mds.batch(batch(new Update(myField1, record1.getMetadata()), new Update(myField2, record2.getMetadata())), MutationOptions.DEFAULT);
    // Search for it based on value
    assertResults(mds, SearchRequest.of("field:myField1").build(), record1);
    // should return both fields
    assertResults(mds, SearchRequest.of("field:myFie*").build(), record1, record2);
    assertResults(mds, SearchRequest.of("field*").build(), record1, record2);
    // searching an invalid type should return nothing
    assertEmpty(mds, SearchRequest.of("x*").addType("invalid").build());
    // clean up
    mds.batch(batch(new Drop(myField1), new Drop(myField2)), 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 27 with Drop

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

the class MetadataStorageTest method testSearchDescription.

@Test
public void testSearchDescription() throws IOException {
    MetadataStorage mds = getMetadataStorage();
    MetadataEntity app1 = ofApp("ns1", "app1");
    MetadataEntity app2 = ofApp("ns2", "app1");
    ScopedName descUser = new ScopedName(USER, "description");
    ScopedName descSystem = new ScopedName(SYSTEM, "description");
    MetadataRecord app1Record = new MetadataRecord(app1, new Metadata(tags(), props(descSystem, "this is the first application", descUser, "business description of app1")));
    MetadataRecord app2Record = new MetadataRecord(app2, new Metadata(tags(), props(descSystem, "this other app description")));
    // add some metadata with descriptions
    mds.batch(batch(new Update(app1, app1Record.getMetadata()), new Update(app2, app2Record.getMetadata())), MutationOptions.DEFAULT);
    // search with field description:
    assertEmpty(mds, SearchRequest.of("description:occursnot").setShowHidden(true).build());
    assertResults(mds, SearchRequest.of("description:first").build(), app1Record);
    assertResults(mds, SearchRequest.of("description:this").build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("description:app*").build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("description:description").build(), app1Record, app2Record);
    // search in SCOPE SYSTEM
    assertResults(mds, SearchRequest.of("description:first").setScope(SYSTEM).build(), app1Record);
    assertResults(mds, SearchRequest.of("description:this").setScope(SYSTEM).build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("description:app*").setScope(SYSTEM).build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("description:description").setScope(SYSTEM).build(), app2Record);
    // search in scope USER
    assertEmpty(mds, SearchRequest.of("description:first").setScope(USER).build());
    assertEmpty(mds, SearchRequest.of("description:this").setScope(USER).build());
    assertResults(mds, SearchRequest.of("description:app*").setScope(USER).build(), app1Record);
    assertResults(mds, SearchRequest.of("description:description").setScope(USER).build(), app1Record);
    // search plain text should match description text
    assertResults(mds, SearchRequest.of("first").build(), app1Record);
    assertResults(mds, SearchRequest.of("this").build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("app*").build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("description").build(), app1Record, app2Record);
    // search in SCOPE SYSTEM
    assertResults(mds, SearchRequest.of("first").setScope(SYSTEM).build(), app1Record);
    assertResults(mds, SearchRequest.of("this").setScope(SYSTEM).build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("app*").setScope(SYSTEM).build(), app1Record, app2Record);
    assertResults(mds, SearchRequest.of("description").setScope(SYSTEM).build(), app2Record);
    // search in scope USER
    assertEmpty(mds, SearchRequest.of("first").setScope(USER).build());
    assertEmpty(mds, SearchRequest.of("this").setScope(USER).build());
    assertResults(mds, SearchRequest.of("app*").setScope(USER).build(), app1Record);
    assertResults(mds, SearchRequest.of("description").setScope(USER).build(), app1Record);
    mds.batch(batch(new Drop(app1), new Drop(app2)), 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 28 with Drop

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

the class MetadataStorageTest method testCursorsOffsetsAndTotals.

@Test
public void testCursorsOffsetsAndTotals() throws IOException {
    MetadataStorage mds = getMetadataStorage();
    List<MetadataRecord> records = IntStream.range(0, 20).mapToObj(i -> new MetadataRecord(ofDataset(DEFAULT_NAMESPACE, "ds" + i), new Metadata(SYSTEM, props(ENTITY_NAME_KEY, "ds" + i)))).collect(Collectors.toList());
    mds.batch(records.stream().map(record -> new Update(record.getEntity(), record.getMetadata())).collect(Collectors.toList()), MutationOptions.DEFAULT);
    // no cursors
    validateCursorAndOffset(mds, 0, 10, null, false, 10, 0, 10, true, false);
    validateCursorAndOffset(mds, 5, 10, null, false, 10, 5, 10, true, false);
    validateCursorAndOffset(mds, 10, 10, null, false, 10, 10, 10, false, false);
    validateCursorAndOffset(mds, 15, 10, null, false, 5, 15, 10, false, false);
    validateCursorAndOffset(mds, 20, 10, null, false, 0, 20, 10, false, false);
    validateCursorAndOffset(mds, 25, 10, null, false, 0, 25, 10, false, false);
    // request cursors, but don't use them
    validateCursorAndOffset(mds, 0, 10, null, true, 10, 0, 10, true, true);
    validateCursorAndOffset(mds, 0, 20, null, true, 20, 0, 20, false, false);
    validateCursorAndOffset(mds, 0, 30, null, true, 20, 0, 30, false, false);
    // test that passing in an empty string as the cursor has the same effect as null
    validateCursorAndOffset(mds, 0, 10, "", true, 10, 0, 10, true, true);
    validateCursorAndOffset(mds, 0, 20, "", true, 20, 0, 20, false, false);
    validateCursorAndOffset(mds, 0, 30, "", true, 20, 0, 30, false, false);
    // request cursor, and use it
    String cursor = validateCursorAndOffset(mds, 0, 8, null, true, 8, 0, 8, true, true);
    cursor = validateCursorAndOffset(mds, 0, 8, cursor, true, 8, 8, 8, true, true);
    validateCursorAndOffset(mds, 0, 8, cursor, true, 4, 16, 8, false, false);
    // request a cursor that matches evenly with the number of results
    cursor = validateCursorAndOffset(mds, 0, 10, null, true, 10, 0, 10, true, true);
    validateCursorAndOffset(mds, 0, 10, cursor, true, 10, 10, 10, false, false);
    // ensure that offset and limit are superseded by cursor
    cursor = validateCursorAndOffset(mds, 0, 4, null, true, 4, 0, 4, true, true);
    cursor = validateCursorAndOffset(mds, 0, 0, cursor, true, 4, 4, 4, true, true);
    cursor = validateCursorAndOffset(mds, 10, 100, cursor, true, 4, 8, 4, true, true);
    cursor = validateCursorAndOffset(mds, 12, 2, cursor, true, 4, 12, 4, true, true);
    validateCursorAndOffset(mds, 1, 1, cursor, true, 4, 16, 4, false, false);
    // ensure that we can start searching without cursor, with offset, and request a cursor
    // whether a cursor is returned, is implementation dependent
    cursor = validateCursorAndOffset(mds, 4, 4, null, true, 4, 4, 4, true, null);
    validateCursorAndOffset(mds, 8, 4, cursor, true, 4, 8, 4, true, null);
    // clean up
    mds.batch(records.stream().map(MetadataRecord::getEntity).map(Drop::new).collect(Collectors.toList()), MutationOptions.DEFAULT);
}
Also used : IntStream(java.util.stream.IntStream) DESCRIPTION_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.DESCRIPTION_KEY) Arrays(java.util.Arrays) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) HashMap(java.util.HashMap) Random(java.util.Random) USER(io.cdap.cdap.api.metadata.MetadataScope.USER) ENTITY_NAME_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.ENTITY_NAME_KEY) CompletionService(java.util.concurrent.CompletionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SlowTests(io.cdap.cdap.test.SlowTests) TAG(io.cdap.cdap.spi.metadata.MetadataKind.TAG) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) Map(java.util.Map) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) PROPERTY(io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY) Tasks(io.cdap.cdap.common.utils.Tasks) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Beta(io.cdap.cdap.api.annotation.Beta) SYSTEM(io.cdap.cdap.api.metadata.MetadataScope.SYSTEM) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Throwables(com.google.common.base.Throwables) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Maps(com.google.common.collect.Maps) Schema(io.cdap.cdap.api.data.schema.Schema) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) TTL_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.TTL_KEY) Create(io.cdap.cdap.spi.metadata.MetadataMutation.Create) TimeUnit(java.util.concurrent.TimeUnit) CREATION_TIME_KEY(io.cdap.cdap.spi.metadata.MetadataConstants.CREATION_TIME_KEY) List(java.util.List) MetadataScope(io.cdap.cdap.api.metadata.MetadataScope) Assert(org.junit.Assert) Comparator(java.util.Comparator) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Collections(java.util.Collections) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) Test(org.junit.Test)

Example 29 with Drop

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

the class MetadataStorageTest method testCustomEntities.

@Test
public void testCustomEntities() throws IOException {
    MetadataEntity dataset = MetadataEntity.ofDataset("different", "stuff");
    MetadataEntity hype = MetadataEntity.builder().append("field", "value").append("hype", "custom").build();
    MetadataEntity field = MetadataEntity.builder().appendAsType("field", "val").append("hype", "irrel").build();
    Set<String> tags = tags("foo", "bar");
    MetadataRecord datasetRecord = new MetadataRecord(dataset, new Metadata(SYSTEM, tags, props(ENTITY_NAME_KEY, "stuff")));
    MetadataRecord hypeRecord = new MetadataRecord(hype, new Metadata(SYSTEM, tags, props(ENTITY_NAME_KEY, "custom")));
    MetadataRecord fieldRecord = new MetadataRecord(field, new Metadata(SYSTEM, tags, props(ENTITY_NAME_KEY, "irrel")));
    // validate update and read
    MetadataStorage mds = getMetadataStorage();
    mds.batch(ImmutableList.of(new Update(dataset, datasetRecord.getMetadata()), new Update(hype, hypeRecord.getMetadata()), new Update(field, fieldRecord.getMetadata())), MutationOptions.DEFAULT);
    Assert.assertEquals(datasetRecord.getMetadata(), mds.read(new Read(dataset)));
    Assert.assertEquals(hypeRecord.getMetadata(), mds.read(new Read(hype)));
    Assert.assertEquals(fieldRecord.getMetadata(), mds.read(new Read(field)));
    // search with type filters
    assertResults(mds, SearchRequest.of("*").build(), datasetRecord, hypeRecord, fieldRecord);
    assertResults(mds, SearchRequest.of("*").addType("dataset").build(), datasetRecord);
    assertResults(mds, SearchRequest.of("*").addType("hype").build(), hypeRecord);
    assertResults(mds, SearchRequest.of("*").addType("field").build(), fieldRecord);
    assertResults(mds, SearchRequest.of("*").addType("field").addType("nosuch").build(), fieldRecord);
    assertResults(mds, SearchRequest.of("*").addType("field").addType("hype").build(), fieldRecord, hypeRecord);
    // search on the type field
    assertResults(mds, SearchRequest.of("hype:custom").build(), hypeRecord);
    assertResults(mds, SearchRequest.of("hype:cust*").build(), hypeRecord);
    assertResults(mds, SearchRequest.of("hype:*").build(), hypeRecord);
    assertEmpty(mds, SearchRequest.of("field:value").build());
    assertResults(mds, SearchRequest.of("field:val*").build(), fieldRecord);
    assertResults(mds, SearchRequest.of("field:*").build(), fieldRecord);
    // clean up
    mds.batch(batch(new Drop(dataset), new Drop(hype), new Drop(field)), 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 30 with Drop

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

the class MetadataStorageTest method testVersionLessEntities.

@Test
public void testVersionLessEntities() throws Exception {
    MetadataEntity appWithoutVersion = ofAppNoVersion("nn", "app");
    MetadataEntity appWithVersion = MetadataEntity.builder(appWithoutVersion).append(MetadataEntity.VERSION, "42").build();
    MetadataEntity appWithDefaultVersion = MetadataEntity.builder(appWithoutVersion).append(MetadataEntity.VERSION, "-SNAPSHOT").build();
    testVersionLessEntities(appWithoutVersion, appWithVersion, appWithDefaultVersion);
    MetadataEntity programWithoutVersion = MetadataEntity.builder(appWithoutVersion).append(MetadataEntity.TYPE, "Service").appendAsType(MetadataEntity.PROGRAM, "pingService").build();
    MetadataEntity programWithVersion = MetadataEntity.builder(appWithVersion).append(MetadataEntity.TYPE, "Service").appendAsType(MetadataEntity.PROGRAM, "pingService").build();
    MetadataEntity programWithDefaultVersion = MetadataEntity.builder(appWithDefaultVersion).append(MetadataEntity.TYPE, "Service").appendAsType(MetadataEntity.PROGRAM, "pingService").build();
    testVersionLessEntities(programWithoutVersion, programWithVersion, programWithDefaultVersion);
    MetadataEntity scheduleWithoutVersion = MetadataEntity.builder(appWithoutVersion).appendAsType(MetadataEntity.SCHEDULE, "pingSchedule").build();
    MetadataEntity scheduleWithVersion = MetadataEntity.builder(appWithVersion).appendAsType(MetadataEntity.SCHEDULE, "pingSchedule").build();
    MetadataEntity scheduleWithDefaultVersion = MetadataEntity.builder(appWithDefaultVersion).appendAsType(MetadataEntity.SCHEDULE, "pingSchedule").build();
    testVersionLessEntities(scheduleWithoutVersion, scheduleWithVersion, scheduleWithDefaultVersion);
    // artifacts have version but it is not ignored
    MetadataEntity artifactWithVersion = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "nn").append(MetadataEntity.ARTIFACT, "artifact").append(MetadataEntity.VERSION, "42").build();
    MetadataEntity artifactWithDefaultVersion = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "nn").append(MetadataEntity.ARTIFACT, "artifact").append(MetadataEntity.VERSION, "-SNAPSHOT").build();
    MetadataStorage mds = getMetadataStorage();
    Metadata meta = new Metadata(ImmutableSet.of(new ScopedName(SYSTEM, "sys"), new ScopedName(USER, "usr")), ImmutableMap.of(new ScopedName(SYSTEM, "sp"), "sv", new ScopedName(USER, "up"), "uv"));
    // metadata can only be retrieved with the matching version
    mds.apply(new Create(artifactWithVersion, meta, ImmutableMap.of()), MutationOptions.DEFAULT);
    Assert.assertEquals(meta, mds.read(new Read(artifactWithVersion)));
    Assert.assertEquals(Metadata.EMPTY, mds.read(new Read(artifactWithDefaultVersion)));
    // metadata can only be dropped with the matching version
    mds.apply(new Drop(artifactWithDefaultVersion), MutationOptions.DEFAULT);
    Assert.assertEquals(meta, mds.read(new Read(artifactWithVersion)));
    Assert.assertEquals(Metadata.EMPTY, mds.read(new Read(artifactWithDefaultVersion)));
    // search returns the exact version
    assertResults(mds, SearchRequest.of("sp:sv").build(), new MetadataRecord(artifactWithVersion, meta));
    // actually drop it
    mds.apply(new Drop(artifactWithVersion), MutationOptions.DEFAULT);
    Assert.assertEquals(Metadata.EMPTY, mds.read(new Read(artifactWithVersion)));
    Assert.assertEquals(Metadata.EMPTY, mds.read(new Read(artifactWithDefaultVersion)));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Create(io.cdap.cdap.spi.metadata.MetadataMutation.Create) 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