Search in sources :

Example 46 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity 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 47 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity 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 48 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity 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)

Example 49 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by caskdata.

the class AuditMessageTypeAdapter method deserialize.

@Override
public AuditMessage deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    long timeMillis = jsonObj.get("time").getAsLong();
    MetadataEntity metadataEntity;
    EntityId entityId = context.deserialize(jsonObj.getAsJsonObject("entityId"), EntityId.class);
    if (entityId != null) {
        metadataEntity = entityId.toMetadataEntity();
    } else {
        metadataEntity = context.deserialize(jsonObj.getAsJsonObject("metadataEntity"), MetadataEntity.class);
    }
    String user = jsonObj.get("user").getAsString();
    AuditType auditType = context.deserialize(jsonObj.getAsJsonPrimitive("type"), AuditType.class);
    AuditPayload payload;
    JsonObject jsonPayload = jsonObj.getAsJsonObject("payload");
    switch(auditType) {
        case METADATA_CHANGE:
            payload = context.deserialize(jsonPayload, MetadataPayload.class);
            break;
        case ACCESS:
            payload = context.deserialize(jsonPayload, AccessPayload.class);
            break;
        default:
            payload = AuditPayload.EMPTY_PAYLOAD;
    }
    return new AuditMessage(timeMillis, metadataEntity, user, auditType, payload);
}
Also used : EntityId(io.cdap.cdap.proto.id.EntityId) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) AccessPayload(io.cdap.cdap.proto.audit.payload.access.AccessPayload) AuditMessage(io.cdap.cdap.proto.audit.AuditMessage) AuditType(io.cdap.cdap.proto.audit.AuditType) JsonObject(com.google.gson.JsonObject) AuditPayload(io.cdap.cdap.proto.audit.AuditPayload) MetadataPayload(io.cdap.cdap.proto.audit.payload.metadata.MetadataPayload)

Example 50 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.

the class DefaultMetadataServiceClientTest method testDrop.

@Test
public void testDrop() throws Exception {
    final MetadataEntity dropEntity = MetadataEntity.builder().append("drop", "test").build();
    createMetadataMutation(new MetadataMutation.Create(dropEntity, testMetadata, CREATE_DIRECTIVES));
    // confirm that the create was successful
    Assert.assertEquals(testMetadata.getProperties(MetadataScope.SYSTEM), getMetadataProperties(dropEntity, MetadataScope.SYSTEM));
    Assert.assertEquals(testMetadata.getTags(MetadataScope.SYSTEM), getMetadataTags(dropEntity, MetadataScope.SYSTEM));
    Assert.assertEquals(testMetadata.getProperties(MetadataScope.USER), getMetadataProperties(dropEntity, MetadataScope.USER));
    Assert.assertEquals(testMetadata.getTags(MetadataScope.USER), getMetadataTags(dropEntity, MetadataScope.USER));
    dropMetadataMutation(new MetadataMutation.Drop(dropEntity));
    Assert.assertEquals(Collections.EMPTY_MAP, getMetadataProperties(dropEntity, MetadataScope.SYSTEM));
    Assert.assertEquals(Collections.EMPTY_SET, getMetadataTags(dropEntity, MetadataScope.SYSTEM));
    Assert.assertEquals(Collections.EMPTY_MAP, getMetadataProperties(dropEntity, MetadataScope.USER));
    Assert.assertEquals(Collections.EMPTY_SET, getMetadataTags(dropEntity, MetadataScope.USER));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) Test(org.junit.Test)

Aggregations

MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)192 Test (org.junit.Test)114 Drop (io.cdap.cdap.spi.metadata.MetadataMutation.Drop)58 Update (io.cdap.cdap.spi.metadata.MetadataMutation.Update)56 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)34 HashMap (java.util.HashMap)30 HashSet (java.util.HashSet)30 Map (java.util.Map)28 ImmutableMap (com.google.common.collect.ImmutableMap)26 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 Remove (io.cdap.cdap.spi.metadata.MetadataMutation.Remove)24 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)22 List (java.util.List)22 Metadata (io.cdap.cdap.spi.metadata.Metadata)20 Create (io.cdap.cdap.spi.metadata.MetadataMutation.Create)20 Set (java.util.Set)20 Collectors (java.util.stream.Collectors)20 Nullable (javax.annotation.Nullable)20 Path (javax.ws.rs.Path)20