Search in sources :

Example 1 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class TypesJerseyResourceIT method testDuplicateSubmit.

@Test
public void testDuplicateSubmit() throws Exception {
    HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(), ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type));
    atlasClientV1.createType(typesDef);
    try {
        atlasClientV1.createType(typesDef);
        fail("Expected 409");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
    }
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 2 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class MetadataDiscoveryJerseyResourceIT method testSearchDSLLimits.

@Test
public void testSearchDSLLimits() throws Exception {
    //search without new parameters of limit and offset should work
    String dslQuery = "from " + DATABASE_TYPE + " name=\"" + dbName + "\"";
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("query", dslQuery);
    JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
    assertNotNull(response);
    //higher limit, all results returned
    JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
    assertEquals(results.length(), 1);
    //default limit and offset -1, all results returned
    results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
    assertEquals(results.length(), 1);
    //uses the limit parameter passed
    results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
    assertEquals(results.length(), 1);
    //uses the offset parameter passed
    results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
    assertEquals(results.length(), 0);
    //limit > 0
    try {
        atlasClientV1.searchByDSL(dslQuery, 0, 10);
        fail("Expected BAD_REQUEST");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
    }
    //limit > maxlimit
    try {
        atlasClientV1.searchByDSL(dslQuery, Integer.MAX_VALUE, 10);
        fail("Expected BAD_REQUEST");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
    }
    //offset >= 0
    try {
        atlasClientV1.searchByDSL(dslQuery, 10, -2);
        fail("Expected BAD_REQUEST");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) AtlasServiceException(org.apache.atlas.AtlasServiceException) JSONArray(org.codehaus.jettison.json.JSONArray) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 3 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class TypedefsJerseyResourceIT method testDuplicateCreate.

@Test
public void testDuplicateCreate() throws Exception {
    AtlasEntityDef type = createClassTypeDef(randomString(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(type);
    AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
    assertNotNull(created);
    try {
        created = clientV2.createAtlasTypeDefs(typesDef);
        fail("Expected 409");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 4 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testDeleteTrait.

@Test
public void testDeleteTrait() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
    String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    createType(traitDefinitionAsJSON);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
    atlasClientV1.deleteTrait(guid, traitName);
    try {
        atlasClientV1.getTraitDefinition(guid, traitName);
        fail("Deleted trait definition shouldn't exist");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
        assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) TraitType(org.apache.atlas.typesystem.types.TraitType) Id(org.apache.atlas.typesystem.persistence.Id) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 5 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testAddProperty.

@Test
public void testAddProperty() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(referenceable);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    //add property
    String description = "bar table - new desc";
    addProperty(guid, "description", description);
    JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
    Assert.assertNotNull(response);
    referenceable.set("description", description);
    //invalid property for the type
    try {
        addProperty(guid, "invalid_property", "bar table");
        Assert.fail("Expected AtlasServiceException");
    } catch (AtlasServiceException e) {
        Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
    }
    String currentTime = String.valueOf(new DateTime());
    // updating date attribute as string not supported in v2
    // addProperty(guid, "createTime", currentTime);
    response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
    Assert.assertNotNull(response);
    referenceable.set("createTime", currentTime);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.typesystem.persistence.Id) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

AtlasServiceException (org.apache.atlas.AtlasServiceException)14 Test (org.testng.annotations.Test)12 Referenceable (org.apache.atlas.typesystem.Referenceable)7 Id (org.apache.atlas.typesystem.persistence.Id)6 TraitType (org.apache.atlas.typesystem.types.TraitType)4 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2 Struct (org.apache.atlas.typesystem.Struct)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)1 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)1 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)1 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)1 TypesDef (org.apache.atlas.typesystem.TypesDef)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 DateTime (org.joda.time.DateTime)1