Commit ec1b160a by apoorvnaik Committed by Madhan Neethiraj

ATLAS-1311: Integration tests for V2 Entity APIs

parent 3b1a7d09
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
# Maven # Maven
target target*
dependency-reduced-pom.xml dependency-reduced-pom.xml
core*.dmp core*.dmp
pom.xml.releaseBackup pom.xml.releaseBackup
......
...@@ -1337,7 +1337,7 @@ public class HiveHookIT extends HiveITBase { ...@@ -1337,7 +1337,7 @@ public class HiveHookIT extends HiveITBase {
* query = "alter table " + tableName + " STORED AS " + testFormat.toUpperCase(); * query = "alter table " + tableName + " STORED AS " + testFormat.toUpperCase();
* runCommand(query); * runCommand(query);
* tableRef = atlasClient.getEntity(tableId); * tableRef = atlasClientV1.getEntity(tableId);
* sdRef = (Referenceable)tableRef.get(HiveMetaStoreBridge.STORAGE_DESC); * sdRef = (Referenceable)tableRef.get(HiveMetaStoreBridge.STORAGE_DESC);
* Assert.assertEquals(sdRef.get(HiveMetaStoreBridge.STORAGE_DESC_INPUT_FMT), "org.apache.hadoop.hive.ql.io.orc.OrcInputFormat"); * Assert.assertEquals(sdRef.get(HiveMetaStoreBridge.STORAGE_DESC_INPUT_FMT), "org.apache.hadoop.hive.ql.io.orc.OrcInputFormat");
* Assert.assertEquals(sdRef.get(HiveMetaStoreBridge.STORAGE_DESC_OUTPUT_FMT), "org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat"); * Assert.assertEquals(sdRef.get(HiveMetaStoreBridge.STORAGE_DESC_OUTPUT_FMT), "org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat");
......
...@@ -27,6 +27,7 @@ import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; ...@@ -27,6 +27,7 @@ import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.api.json.JSONConfiguration; import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
import org.apache.atlas.security.SecureClientUtils; import org.apache.atlas.security.SecureClientUtils;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -276,12 +277,18 @@ public abstract class AtlasBaseClient { ...@@ -276,12 +277,18 @@ public abstract class AtlasBaseClient {
ClientResponse clientResponse = null; ClientResponse clientResponse = null;
int i = 0; int i = 0;
do { do {
if (LOG.isDebugEnabled()) {
LOG.debug("Calling API [ {} : {} ] {}", api.getMethod(), api.getPath(), requestObject != null ? "<== " + requestObject : "");
}
clientResponse = resource clientResponse = resource
.accept(JSON_MEDIA_TYPE) .accept(JSON_MEDIA_TYPE)
.type(JSON_MEDIA_TYPE) .type(JSON_MEDIA_TYPE)
.method(api.getMethod(), ClientResponse.class, requestObject); .method(api.getMethod(), ClientResponse.class, requestObject);
if (LOG.isDebugEnabled()) {
LOG.debug("API {} returned status {}", resource.getURI(), clientResponse.getStatus()); LOG.debug("API {} returned status {}", resource.getURI(), clientResponse.getStatus());
}
if (clientResponse.getStatus() == api.getExpectedStatus().getStatusCode()) { if (clientResponse.getStatus() == api.getExpectedStatus().getStatusCode()) {
if (null == responseType) { if (null == responseType) {
LOG.warn("No response type specified, returning null"); LOG.warn("No response type specified, returning null");
...@@ -291,12 +298,16 @@ public abstract class AtlasBaseClient { ...@@ -291,12 +298,16 @@ public abstract class AtlasBaseClient {
if (responseType == JSONObject.class) { if (responseType == JSONObject.class) {
String stringEntity = clientResponse.getEntity(String.class); String stringEntity = clientResponse.getEntity(String.class);
try { try {
return (T) new JSONObject(stringEntity); JSONObject jsonObject = new JSONObject(stringEntity);
LOG.info("Response = {}", jsonObject);
return (T) jsonObject;
} catch (JSONException e) { } catch (JSONException e) {
throw new AtlasServiceException(api, e); throw new AtlasServiceException(api, e);
} }
} else { } else {
return clientResponse.getEntity(responseType); T entity = clientResponse.getEntity(responseType);
LOG.info("Response = {}", AtlasType.toJson(entity));
return entity;
} }
} catch (ClientHandlerException e) { } catch (ClientHandlerException e) {
throw new AtlasServiceException(api, e); throw new AtlasServiceException(api, e);
...@@ -380,8 +391,7 @@ public abstract class AtlasBaseClient { ...@@ -380,8 +391,7 @@ public abstract class AtlasBaseClient {
WebResource resource = resourceCreator.createResource(); WebResource resource = resourceCreator.createResource();
try { try {
LOG.debug("Using resource {} for {} times", resource.getURI(), i); LOG.debug("Using resource {} for {} times", resource.getURI(), i);
JSONObject result = callAPIWithResource(api, resource, requestObject, JSONObject.class); return callAPIWithResource(api, resource, requestObject, JSONObject.class);
return result;
} catch (ClientHandlerException che) { } catch (ClientHandlerException che) {
if (i == (getNumberOfRetries() - 1)) { if (i == (getNumberOfRetries() - 1)) {
throw che; throw che;
...@@ -399,6 +409,12 @@ public abstract class AtlasBaseClient { ...@@ -399,6 +409,12 @@ public abstract class AtlasBaseClient {
return callAPIWithResource(api, getResource(api, params), requestObject, responseType); return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
} }
public <T> T callAPI(APIInfo api, Object requestBody, Class<T> responseType,
MultivaluedMap<String, String> queryParams, String... params) throws AtlasServiceException {
WebResource resource = getResource(api, queryParams, params);
return callAPIWithResource(api, resource, requestBody, responseType);
}
public <T> T callAPI(APIInfo api, Class<T> responseType, MultivaluedMap<String, String> queryParams, String... params) public <T> T callAPI(APIInfo api, Class<T> responseType, MultivaluedMap<String, String> queryParams, String... params)
throws AtlasServiceException { throws AtlasServiceException {
WebResource resource = getResource(api, queryParams, params); WebResource resource = getResource(api, queryParams, params);
...@@ -476,7 +492,7 @@ public abstract class AtlasBaseClient { ...@@ -476,7 +492,7 @@ public abstract class AtlasBaseClient {
return resource; return resource;
} }
protected APIInfo formatPath(APIInfo apiInfo, String ... params) { protected APIInfo formatPathForPathParams(APIInfo apiInfo, String ... params) {
return new APIInfo(String.format(apiInfo.getPath(), params), apiInfo.getMethod(), apiInfo.getExpectedStatus()); return new APIInfo(String.format(apiInfo.getPath(), params), apiInfo.getMethod(), apiInfo.getExpectedStatus());
} }
......
...@@ -108,7 +108,8 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -108,7 +108,8 @@ public class AtlasClient extends AtlasBaseClient {
public static final String PROCESS_ATTRIBUTE_OUTPUTS = "outputs"; public static final String PROCESS_ATTRIBUTE_OUTPUTS = "outputs";
public static final String REFERENCEABLE_SUPER_TYPE = "Referenceable"; public static final String REFERENCEABLE_SUPER_TYPE = "Referenceable";
public static final String REFERENCEABLE_ATTRIBUTE_NAME = "qualifiedName"; public static final String QUALIFIED_NAME = "qualifiedName";
public static final String REFERENCEABLE_ATTRIBUTE_NAME = QUALIFIED_NAME;
public static final String UNKNOWN_STATUS = "Unknown status"; public static final String UNKNOWN_STATUS = "Unknown status";
...@@ -593,7 +594,7 @@ public class AtlasClient extends AtlasBaseClient { ...@@ -593,7 +594,7 @@ public class AtlasClient extends AtlasBaseClient {
JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() { JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
@Override @Override
public WebResource createResource() { public WebResource createResource() {
WebResource resource = getResource(api, "qualifiedName"); WebResource resource = getResource(api, QUALIFIED_NAME);
resource = resource.queryParam(TYPE, entityType); resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName); resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue); resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
......
...@@ -18,21 +18,23 @@ ...@@ -18,21 +18,23 @@
package org.apache.atlas; package org.apache.atlas;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications; import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityWithAssociations;
import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import java.util.List;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
import static org.apache.atlas.model.instance.AtlasEntity.AtlasEntities;
public class AtlasEntitiesClientV2 extends AtlasBaseClient { public class AtlasEntitiesClientV2 extends AtlasBaseClient {
...@@ -40,19 +42,24 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient { ...@@ -40,19 +42,24 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient {
public static final String ENTITIES_API = BASE_URI + "v2/entities/"; public static final String ENTITIES_API = BASE_URI + "v2/entities/";
private static final APIInfo GET_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.GET, Response.Status.OK); private static final APIInfo GET_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.GET, Response.Status.OK);
private static final APIInfo GET_ENTITY_WITH_ASSOCIATION_BY_GUID = new APIInfo(ENTITY_API + "guid/%s/associations", HttpMethod.GET, Response.Status.OK);
private static final APIInfo CREATE_ENTITY = new APIInfo(ENTITY_API, HttpMethod.POST, Response.Status.OK); private static final APIInfo CREATE_ENTITY = new APIInfo(ENTITY_API, HttpMethod.POST, Response.Status.OK);
private static final APIInfo UPDATE_ENTITY = CREATE_ENTITY; private static final APIInfo UPDATE_ENTITY = CREATE_ENTITY;
private static final APIInfo GET_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/%s/attribute/%s", HttpMethod.GET, Response.Status.OK);
private static final APIInfo UPDATE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/%s/attribute/%s", HttpMethod.PUT, Response.Status.OK);
private static final APIInfo DELETE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/%s/attribute/%s", HttpMethod.DELETE, Response.Status.OK);
private static final APIInfo UPDATE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.PUT, Response.Status.OK); private static final APIInfo UPDATE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.PUT, Response.Status.OK);
private static final APIInfo DELETE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.DELETE, Response.Status.OK); private static final APIInfo DELETE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.DELETE, Response.Status.OK);
private static final APIInfo DELETE_ENTITY_BY_GUIDS = new APIInfo(ENTITIES_API + "guids/", HttpMethod.DELETE, Response.Status.OK);
private static final APIInfo GET_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.GET, Response.Status.OK); private static final APIInfo GET_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.GET, Response.Status.OK);
private static final APIInfo ADD_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.POST, Response.Status.OK); private static final APIInfo ADD_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.POST, Response.Status.NO_CONTENT);
private static final APIInfo UPDATE_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.PUT, Response.Status.OK);
private static final APIInfo DELETE_CLASSIFICATION = new APIInfo(ENTITY_API + "guid/%s/classification/%s", HttpMethod.DELETE, Response.Status.OK);
private static final APIInfo UPDATE_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.PUT, Response.Status.OK);
private static final APIInfo DELETE_CLASSIFICATION = new APIInfo(ENTITY_API + "guid/%s/classification/%s", HttpMethod.DELETE, Response.Status.NO_CONTENT);
private static final APIInfo GET_ENTITIES = new APIInfo(ENTITIES_API + "guids/", HttpMethod.GET, Response.Status.OK); private static final APIInfo GET_ENTITIES = new APIInfo(ENTITIES_API + "guids/", HttpMethod.GET, Response.Status.OK);
private static final APIInfo CREATE_ENTITIES = new APIInfo(ENTITIES_API, HttpMethod.POST, Response.Status.OK); private static final APIInfo CREATE_ENTITIES = new APIInfo(ENTITIES_API, HttpMethod.POST, Response.Status.OK);
private static final APIInfo UPDATE_ENTITIES = CREATE_ENTITIES; private static final APIInfo UPDATE_ENTITIES = CREATE_ENTITIES;
private static final APIInfo DELETE_ENTITIES = new APIInfo(ENTITIES_API + "guids/", HttpMethod.GET, Response.Status.OK); private static final APIInfo DELETE_ENTITIES = new APIInfo(ENTITIES_API + "guids/", HttpMethod.GET, Response.Status.NO_CONTENT);
private static final APIInfo SEARCH_ENTITIES = new APIInfo(ENTITIES_API, HttpMethod.GET, Response.Status.OK); private static final APIInfo SEARCH_ENTITIES = new APIInfo(ENTITIES_API, HttpMethod.GET, Response.Status.OK);
public AtlasEntitiesClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) { public AtlasEntitiesClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) {
...@@ -80,6 +87,32 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient { ...@@ -80,6 +87,32 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient {
return callAPI(GET_ENTITY_BY_GUID, null, AtlasEntity.class, guid); return callAPI(GET_ENTITY_BY_GUID, null, AtlasEntity.class, guid);
} }
public AtlasEntities getEntityByGuids(List<String> guids) throws AtlasServiceException {
return callAPI(GET_ENTITY_BY_GUID, AtlasEntities.class, "guid", guids);
}
public AtlasEntityWithAssociations getEntityWithAssociationByGuid(String guid) throws AtlasServiceException {
return callAPI(formatPathForPathParams(GET_ENTITY_WITH_ASSOCIATION_BY_GUID, guid), null, AtlasEntityWithAssociations.class);
}
public AtlasEntity getEntityByAttribute(String type, String attribute, String value) throws AtlasServiceException {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("value", value);
return callAPI(formatPathForPathParams(GET_ENTITY_BY_ATTRIBUTE, type, attribute), AtlasEntity.class, queryParams);
}
public EntityMutationResponse updateEntityByAttribute(String type, String attribute, String value, AtlasEntity entity) throws AtlasServiceException {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("value", value);
return callAPI(formatPathForPathParams(UPDATE_ENTITY_BY_ATTRIBUTE, type, attribute), entity, EntityMutationResponse.class, queryParams);
}
public EntityMutationResponse deleteEntityByAttribute(String type, String attribute, String value) throws AtlasServiceException {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("value", value);
return callAPI(formatPathForPathParams(DELETE_ENTITY_BY_ATTRIBUTE, type, attribute), null, EntityMutationResponse.class, queryParams);
}
public EntityMutationResponse createEntity(AtlasEntity atlasEntity) throws AtlasServiceException { public EntityMutationResponse createEntity(AtlasEntity atlasEntity) throws AtlasServiceException {
return callAPI(CREATE_ENTITY, atlasEntity, EntityMutationResponse.class); return callAPI(CREATE_ENTITY, atlasEntity, EntityMutationResponse.class);
} }
...@@ -89,31 +122,35 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient { ...@@ -89,31 +122,35 @@ public class AtlasEntitiesClientV2 extends AtlasBaseClient {
} }
public EntityMutationResponse updateEntity(String guid, AtlasEntity atlasEntity) throws AtlasServiceException { public EntityMutationResponse updateEntity(String guid, AtlasEntity atlasEntity) throws AtlasServiceException {
return callAPI(UPDATE_ENTITY, atlasEntity, EntityMutationResponse.class, guid); return callAPI(UPDATE_ENTITY_BY_GUID, atlasEntity, EntityMutationResponse.class, guid);
} }
public AtlasEntity deleteEntityByGuid(String guid) throws AtlasServiceException { public AtlasEntity deleteEntityByGuid(String guid) throws AtlasServiceException {
return callAPI(DELETE_ENTITY_BY_GUID, null, AtlasEntity.class, guid); return callAPI(DELETE_ENTITY_BY_GUID, null, AtlasEntity.class, guid);
} }
public EntityMutationResponse deleteEntityByGuid(List<String> guids) throws AtlasServiceException {
return callAPI(DELETE_ENTITY_BY_GUIDS, EntityMutationResponse.class, "guid", guids);
}
public AtlasClassifications getClassifications(String guid) throws AtlasServiceException { public AtlasClassifications getClassifications(String guid) throws AtlasServiceException {
return callAPI(formatPath(GET_CLASSIFICATIONS, guid), null, AtlasClassifications.class); return callAPI(formatPathForPathParams(GET_CLASSIFICATIONS, guid), null, AtlasClassifications.class);
} }
public void addClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException { public void addClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
callAPI(formatPath(ADD_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class); callAPI(formatPathForPathParams(ADD_CLASSIFICATIONS, guid), classifications, null, (String[]) null);
} }
public void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException { public void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
callAPI(formatPath(UPDATE_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class); callAPI(formatPathForPathParams(UPDATE_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class);
} }
public void deleteClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException { public void deleteClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
callAPI(formatPath(GET_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class); callAPI(formatPathForPathParams(GET_CLASSIFICATIONS, guid), classifications, AtlasClassifications.class);
} }
public void deleteClassification(String guid, String classificationName) throws AtlasServiceException { public void deleteClassification(String guid, String classificationName) throws AtlasServiceException {
callAPI(formatPath(DELETE_CLASSIFICATION, guid, classificationName), null, AtlasClassifications.class); callAPI(formatPathForPathParams(DELETE_CLASSIFICATION, guid, classificationName), null, null);
} }
// Entities operations // Entities operations
......
...@@ -32,7 +32,7 @@ public class AtlasServiceException extends Exception { ...@@ -32,7 +32,7 @@ public class AtlasServiceException extends Exception {
} }
public AtlasServiceException(AtlasBaseClient.APIInfo api, Exception e) { public AtlasServiceException(AtlasBaseClient.APIInfo api, Exception e) {
super("Metadata service API " + api + " failed", e); super("Metadata service API " + api.getMethod() + " : " + api.getPath() + " failed", e);
} }
public AtlasServiceException(AtlasClient.API api, WebApplicationException e) throws JSONException { public AtlasServiceException(AtlasClient.API api, WebApplicationException e) throws JSONException {
......
...@@ -37,10 +37,19 @@ import javax.ws.rs.core.Response; ...@@ -37,10 +37,19 @@ import javax.ws.rs.core.Response;
public class AtlasTypedefClientV2 extends AtlasBaseClient { public class AtlasTypedefClientV2 extends AtlasBaseClient {
private static final String BASE_URI = "api/atlas/v2/types/"; private static final String BASE_URI = "api/atlas/v2/types/";
private static final String ENUMDEF_URI = BASE_URI + "enumdef/";
private static final String STRUCTDEF_URI = BASE_URI + "structdef/";
private static final String ENTITYDEF_URI = BASE_URI + "entitydef/";
private static final String CLASSIFICATIONDEF_URI = BASE_URI + "classificationdef/";
private static final String TYPEDEFS_PATH = BASE_URI + "typedefs/"; private static final String TYPEDEFS_PATH = BASE_URI + "typedefs/";
private static final String GET_BY_NAME_TEMPLATE = BASE_URI + "%s/name/%s"; private static final String GET_BY_NAME_TEMPLATE = BASE_URI + "%s/name/%s";
private static final String GET_BY_GUID_TEMPLATE = BASE_URI + "%s/guid/%s"; private static final String GET_BY_GUID_TEMPLATE = BASE_URI + "%s/guid/%s";
private static final APIInfo CREATE_ENUM_DEF = new APIInfo(ENUMDEF_URI, HttpMethod.POST, Response.Status.OK);
private static final APIInfo CREATE_STRUCT_DEF = new APIInfo(STRUCTDEF_URI, HttpMethod.POST, Response.Status.OK);
private static final APIInfo CREATE_ENTITY_DEF = new APIInfo(ENTITYDEF_URI, HttpMethod.POST, Response.Status.OK);
private static final APIInfo CREATE_CLASSIFICATION_DEF = new APIInfo(CLASSIFICATIONDEF_URI, HttpMethod.POST, Response.Status.OK);
private static final APIInfo GET_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.GET, Response.Status.OK); private static final APIInfo GET_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.GET, Response.Status.OK);
private static final APIInfo CREATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.POST, Response.Status.OK); private static final APIInfo CREATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.POST, Response.Status.OK);
private static final APIInfo UPDATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.PUT, Response.Status.OK); private static final APIInfo UPDATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_PATH, HttpMethod.PUT, Response.Status.OK);
...@@ -108,6 +117,24 @@ public class AtlasTypedefClientV2 extends AtlasBaseClient { ...@@ -108,6 +117,24 @@ public class AtlasTypedefClientV2 extends AtlasBaseClient {
return getTypeDefByGuid(guid, AtlasEntityDef.class); return getTypeDefByGuid(guid, AtlasEntityDef.class);
} }
public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasServiceException {
return callAPI(CREATE_ENUM_DEF, AtlasType.toJson(enumDef), AtlasEnumDef.class);
}
public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException {
return callAPI(CREATE_STRUCT_DEF, AtlasType.toJson(structDef), AtlasStructDef.class);
}
public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException {
return callAPI(CREATE_ENTITY_DEF, AtlasType.toJson(entityDef), AtlasEntityDef.class);
}
public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef)
throws AtlasServiceException {
return callAPI(CREATE_CLASSIFICATION_DEF, AtlasType.toJson(classificationDef), AtlasClassificationDef.class);
}
/** /**
* Bulk create APIs for all atlas type definitions, only new definitions will be created. * Bulk create APIs for all atlas type definitions, only new definitions will be created.
* Any changes to the existing definitions will be discarded * Any changes to the existing definitions will be discarded
......
...@@ -103,6 +103,15 @@ public class SearchFilter { ...@@ -103,6 +103,15 @@ public class SearchFilter {
} }
} }
public void setParam(String name, List<String> values) {
if (name != null) {
if (params == null) {
params = new MultivaluedMapImpl();
}
params.put(name, values);
}
}
public long getStartIndex() { public long getStartIndex() {
return startIndex; return startIndex;
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package org.apache.atlas.model.instance; package org.apache.atlas.model.instance;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonAutoDetect;
......
...@@ -82,7 +82,7 @@ public final class GraphToTypedInstanceMapper { ...@@ -82,7 +82,7 @@ public final class GraphToTypedInstanceMapper {
LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime); LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime);
Id id = new Id(guid, (Integer) GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY), Id id = new Id(guid, Integer.parseInt(String.valueOf(GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY))),
typeName, state); typeName, state);
LOG.debug("Created id {} for instance type {}", id, typeName); LOG.debug("Created id {} for instance type {}", id, typeName);
......
...@@ -117,6 +117,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { ...@@ -117,6 +117,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
@Override @Override
public AtlasEntity.AtlasEntities searchEntities(final SearchFilter searchFilter) throws AtlasBaseException { public AtlasEntity.AtlasEntities searchEntities(final SearchFilter searchFilter) throws AtlasBaseException {
// TODO: Add checks here to ensure that typename and supertype are mandatory in the requests
return null; return null;
} }
} }
...@@ -22,15 +22,14 @@ import com.google.common.collect.ImmutableList; ...@@ -22,15 +22,14 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef; import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef; import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypeDefHeader; import org.apache.atlas.model.typedef.AtlasTypeDefHeader;
import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasArrayType; import org.apache.atlas.type.AtlasArrayType;
...@@ -63,9 +62,9 @@ import java.util.Set; ...@@ -63,9 +62,9 @@ import java.util.Set;
import static org.apache.atlas.AtlasErrorCode.INVALID_TYPE_DEFINITION; import static org.apache.atlas.AtlasErrorCode.INVALID_TYPE_DEFINITION;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ON_DELETE; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ON_DELETE;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_VAL_CASCADE;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_FOREIGN_KEY; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_FOREIGN_KEY;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_MAPPED_FROM_REF; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_MAPPED_FROM_REF;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_VAL_CASCADE;
import static org.apache.atlas.type.AtlasTypeUtil.isArrayType; import static org.apache.atlas.type.AtlasTypeUtil.isArrayType;
......
...@@ -40,6 +40,7 @@ import org.apache.atlas.typesystem.ITypedStruct; ...@@ -40,6 +40,7 @@ import org.apache.atlas.typesystem.ITypedStruct;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.EntityNotFoundException;
import org.apache.atlas.typesystem.exception.TraitNotFoundException;
import org.apache.atlas.typesystem.exception.TypeNotFoundException; import org.apache.atlas.typesystem.exception.TypeNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -143,7 +144,7 @@ public class AtlasInstanceRestAdapters { ...@@ -143,7 +144,7 @@ public class AtlasInstanceRestAdapters {
} }
public static AtlasBaseException toAtlasBaseException(AtlasException e) { public static AtlasBaseException toAtlasBaseException(AtlasException e) {
if ( e instanceof EntityNotFoundException) { if ( e instanceof EntityNotFoundException || e instanceof TraitNotFoundException) {
return new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, e); return new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, e);
} }
......
...@@ -18,15 +18,8 @@ ...@@ -18,15 +18,8 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import java.io.UnsupportedEncodingException; import com.google.gson.Gson;
import java.net.URLDecoder; import com.google.gson.JsonSyntaxException;
import java.util.Collection;
import java.util.Map;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.atlas.catalog.JsonSerializer; import org.apache.atlas.catalog.JsonSerializer;
import org.apache.atlas.catalog.Request; import org.apache.atlas.catalog.Request;
import org.apache.atlas.catalog.ResourceProvider; import org.apache.atlas.catalog.ResourceProvider;
...@@ -40,8 +33,13 @@ import org.apache.atlas.repository.graph.AtlasGraphProvider; ...@@ -40,8 +33,13 @@ import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gson.Gson; import javax.ws.rs.core.Context;
import com.google.gson.JsonSyntaxException; import javax.ws.rs.core.UriInfo;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Collection;
import java.util.Map;
/** /**
* Base class for all v1 API services. * Base class for all v1 API services.
......
...@@ -47,17 +47,7 @@ import org.slf4j.LoggerFactory; ...@@ -47,17 +47,7 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
......
...@@ -19,7 +19,13 @@ ...@@ -19,7 +19,13 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.catalog.*; import org.apache.atlas.catalog.BaseRequest;
import org.apache.atlas.catalog.CollectionRequest;
import org.apache.atlas.catalog.DefaultTypeSystem;
import org.apache.atlas.catalog.EntityResourceProvider;
import org.apache.atlas.catalog.EntityTagResourceProvider;
import org.apache.atlas.catalog.InstanceRequest;
import org.apache.atlas.catalog.Result;
import org.apache.atlas.catalog.exception.CatalogException; import org.apache.atlas.catalog.exception.CatalogException;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
...@@ -28,9 +34,22 @@ import org.slf4j.Logger; ...@@ -28,9 +34,22 @@ import org.slf4j.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.*; import javax.ws.rs.DELETE;
import javax.ws.rs.core.*; import javax.ws.rs.GET;
import java.util.*; import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** /**
* Service which handles API requests for v1 entity resources. * Service which handles API requests for v1 entity resources.
......
...@@ -20,7 +20,6 @@ package org.apache.atlas.web.resources; ...@@ -20,7 +20,6 @@ package org.apache.atlas.web.resources;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.catalog.*; import org.apache.atlas.catalog.*;
import org.apache.atlas.catalog.Request;
import org.apache.atlas.catalog.exception.CatalogException; import org.apache.atlas.catalog.exception.CatalogException;
import org.apache.atlas.catalog.exception.InvalidPayloadException; import org.apache.atlas.catalog.exception.InvalidPayloadException;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
...@@ -30,8 +29,18 @@ import org.slf4j.Logger; ...@@ -30,8 +29,18 @@ import org.slf4j.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.*; import javax.ws.rs.DELETE;
import javax.ws.rs.core.*; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
......
...@@ -17,30 +17,24 @@ ...@@ -17,30 +17,24 @@
*/ */
package org.apache.atlas.web.rest; package org.apache.atlas.web.rest;
import com.google.inject.Inject;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasEntityWithAssociations;
import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.services.MetadataService; import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.web.adapters.AtlasFormatConverters;
import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters; import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toAtlasBaseException; import javax.inject.Inject;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toEntityMutationResponse;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
...@@ -53,8 +47,13 @@ import javax.ws.rs.Produces; ...@@ -53,8 +47,13 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Arrays;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toAtlasBaseException;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toEntityMutationResponse;
@Path("v2/entities") @Path("v2/entities")
...@@ -67,19 +66,16 @@ public class EntitiesREST { ...@@ -67,19 +66,16 @@ public class EntitiesREST {
@Context @Context
private HttpServletRequest httpServletRequest; private HttpServletRequest httpServletRequest;
@Inject private final MetadataService metadataService;
private MetadataService metadataService;
private AtlasTypeRegistry typeRegistry;
@Inject private final AtlasInstanceRestAdapters restAdapters;
AtlasInstanceRestAdapters restAdapters;
@Inject @Inject
public EntitiesREST(AtlasEntityStore entitiesStore, AtlasTypeRegistry atlasTypeRegistry) { public EntitiesREST(AtlasEntityStore entitiesStore, MetadataService metadataService, AtlasInstanceRestAdapters restAdapters) {
LOG.info("EntitiesRest Init"); LOG.info("EntitiesRest Init");
this.entitiesStore = entitiesStore; this.entitiesStore = entitiesStore;
this.typeRegistry = atlasTypeRegistry; this.metadataService = metadataService;
this.restAdapters = restAdapters;
} }
/******* /*******
...@@ -174,9 +170,24 @@ public class EntitiesREST { ...@@ -174,9 +170,24 @@ public class EntitiesREST {
@GET @GET
@Produces(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityHeader.AtlasEntityHeaders searchEntities() throws AtlasBaseException { public AtlasEntityHeader.AtlasEntityHeaders searchEntities() throws AtlasBaseException {
//SearchFilter searchFilter SearchFilter searchFilter = getSearchFilter();
//TODO: Need to handle getEntitiesByType for older API AtlasEntity.AtlasEntities atlasEntities = entitiesStore.searchEntities(searchFilter);
return null; AtlasEntityHeader.AtlasEntityHeaders entityHeaders = new AtlasEntityHeader.AtlasEntityHeaders();
entityHeaders.setList(new LinkedList<AtlasEntityHeader>());
for (AtlasEntity atlasEntity : atlasEntities.getList()) {
entityHeaders.getList().add(new AtlasEntityHeader(atlasEntity.getTypeName(), atlasEntity.getAttributes()));
}
return entityHeaders;
}
private SearchFilter getSearchFilter() {
SearchFilter searchFilter = new SearchFilter();
if (null != httpServletRequest && null != httpServletRequest.getParameterMap()) {
for (Map.Entry<String, String[]> entry : httpServletRequest.getParameterMap().entrySet()) {
searchFilter.setParam(entry.getKey(), Arrays.asList(entry.getValue()));
}
}
return searchFilter;
} }
} }
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
*/ */
package org.apache.atlas.web.rest; package org.apache.atlas.web.rest;
import com.google.inject.Inject;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
...@@ -42,17 +41,9 @@ import org.apache.commons.lang3.StringUtils; ...@@ -42,17 +41,9 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -69,14 +60,19 @@ public class EntityREST { ...@@ -69,14 +60,19 @@ public class EntityREST {
private static final Logger LOG = LoggerFactory.getLogger(EntityREST.class); private static final Logger LOG = LoggerFactory.getLogger(EntityREST.class);
@Inject private final AtlasTypeRegistry typeRegistry;
AtlasTypeRegistry typeRegistry;
@Inject private final AtlasInstanceRestAdapters restAdapters;
AtlasInstanceRestAdapters restAdapters;
private final MetadataService metadataService;
@Inject @Inject
private MetadataService metadataService; public EntityREST(AtlasTypeRegistry typeRegistry, AtlasInstanceRestAdapters restAdapters, MetadataService metadataService) {
this.typeRegistry = typeRegistry;
this.restAdapters = restAdapters;
this.metadataService = metadataService;
}
/** /**
* Create or Update an entity if it already exists * Create or Update an entity if it already exists
* *
...@@ -323,6 +319,8 @@ public class EntityREST { ...@@ -323,6 +319,8 @@ public class EntityREST {
final ITypedStruct trait = restAdapters.getTrait(classification); final ITypedStruct trait = restAdapters.getTrait(classification);
try { try {
metadataService.addTrait(guid, trait); metadataService.addTrait(guid, trait);
} catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e);
} catch (AtlasException e) { } catch (AtlasException e) {
throw toAtlasBaseException(e); throw toAtlasBaseException(e);
} }
......
...@@ -14,17 +14,15 @@ ...@@ -14,17 +14,15 @@
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security" xmlns:security="http://www.springframework.org/schema/security"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"> http://www.springframework.org/schema/context/spring-context-3.1.xsd">
......
...@@ -12,15 +12,8 @@ ...@@ -12,15 +12,8 @@
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:context="http://www.springframework.org/schema/context" http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="classpath:/spring-security.xml" /> <import resource="classpath:/spring-security.xml" />
......
...@@ -52,7 +52,7 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -52,7 +52,7 @@ public class QuickStartIT extends BaseResourceIT {
} }
private Referenceable getDB(String dbName) throws AtlasServiceException, JSONException { private Referenceable getDB(String dbName) throws AtlasServiceException, JSONException {
return serviceClient.getEntity(QuickStart.DATABASE_TYPE, "name", dbName); return atlasClientV1.getEntity(QuickStart.DATABASE_TYPE, "name", dbName);
} }
@Test @Test
...@@ -68,7 +68,7 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -68,7 +68,7 @@ public class QuickStartIT extends BaseResourceIT {
} }
private Referenceable getTable(String tableName) throws AtlasServiceException { private Referenceable getTable(String tableName) throws AtlasServiceException {
return serviceClient.getEntity(QuickStart.TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName); return atlasClientV1.getEntity(QuickStart.TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
} }
private void verifyTrait(Referenceable table) throws JSONException { private void verifyTrait(Referenceable table) throws JSONException {
...@@ -95,7 +95,7 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -95,7 +95,7 @@ public class QuickStartIT extends BaseResourceIT {
@Test @Test
public void testProcessIsAdded() throws AtlasServiceException, JSONException { public void testProcessIsAdded() throws AtlasServiceException, JSONException {
Referenceable loadProcess = serviceClient.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
QuickStart.LOAD_SALES_DAILY_PROCESS); QuickStart.LOAD_SALES_DAILY_PROCESS);
assertEquals(QuickStart.LOAD_SALES_DAILY_PROCESS, loadProcess.get(AtlasClient.NAME)); assertEquals(QuickStart.LOAD_SALES_DAILY_PROCESS, loadProcess.get(AtlasClient.NAME));
...@@ -123,7 +123,7 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -123,7 +123,7 @@ public class QuickStartIT extends BaseResourceIT {
String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE); String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE);
String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE); String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE);
JSONObject inputGraph = serviceClient.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE); JSONObject inputGraph = atlasClientV1.getInputGraph(QuickStart.SALES_FACT_DAILY_MV_TABLE);
JSONObject vertices = (JSONObject) ((JSONObject) inputGraph.get("values")).get("vertices"); JSONObject vertices = (JSONObject) ((JSONObject) inputGraph.get("values")).get("vertices");
JSONObject edges = (JSONObject) ((JSONObject) inputGraph.get("values")).get("edges"); JSONObject edges = (JSONObject) ((JSONObject) inputGraph.get("values")).get("edges");
...@@ -142,7 +142,7 @@ public class QuickStartIT extends BaseResourceIT { ...@@ -142,7 +142,7 @@ public class QuickStartIT extends BaseResourceIT {
@Test @Test
public void testViewIsAdded() throws AtlasServiceException, JSONException { public void testViewIsAdded() throws AtlasServiceException, JSONException {
Referenceable view = serviceClient.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW); Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW);
assertEquals(QuickStart.PRODUCT_DIM_VIEW, view.get(AtlasClient.NAME)); assertEquals(QuickStart.PRODUCT_DIM_VIEW, view.get(AtlasClient.NAME));
......
...@@ -65,8 +65,8 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -65,8 +65,8 @@ public class EntityNotificationIT extends BaseResourceIT {
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
createTypeDefinitions(); createTypeDefinitionsV1();
Referenceable HiveDBInstance = createHiveDBInstance(DATABASE_NAME); Referenceable HiveDBInstance = createHiveDBInstanceV1(DATABASE_NAME);
dbId = createInstance(HiveDBInstance); dbId = createInstance(HiveDBInstance);
List<NotificationConsumer<EntityNotification>> consumers = List<NotificationConsumer<EntityNotification>> consumers =
...@@ -77,7 +77,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -77,7 +77,7 @@ public class EntityNotificationIT extends BaseResourceIT {
@Test @Test
public void testCreateEntity() throws Exception { public void testCreateEntity() throws Exception {
Referenceable tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME, dbId); Referenceable tableInstance = createHiveTableInstanceV1(DATABASE_NAME, TABLE_NAME, dbId);
tableId = createInstance(tableInstance); tableId = createInstance(tableInstance);
final String guid = tableId._getId(); final String guid = tableId._getId();
...@@ -93,7 +93,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -93,7 +93,7 @@ public class EntityNotificationIT extends BaseResourceIT {
final String guid = tableId._getId(); final String guid = tableId._getId();
serviceClient.updateEntityAttribute(guid, property, newValue); atlasClientV1.updateEntityAttribute(guid, property, newValue);
waitForNotification(notificationConsumer, MAX_WAIT_TIME, waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.ENTITY_UPDATE, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.ENTITY_UPDATE, HIVE_TABLE_TYPE, guid));
...@@ -103,10 +103,10 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -103,10 +103,10 @@ public class EntityNotificationIT extends BaseResourceIT {
public void testDeleteEntity() throws Exception { public void testDeleteEntity() throws Exception {
final String tableName = "table-" + randomString(); final String tableName = "table-" + randomString();
final String dbName = "db-" + randomString(); final String dbName = "db-" + randomString();
Referenceable HiveDBInstance = createHiveDBInstance(dbName); Referenceable HiveDBInstance = createHiveDBInstanceV1(dbName);
Id dbId = createInstance(HiveDBInstance); Id dbId = createInstance(HiveDBInstance);
Referenceable tableInstance = createHiveTableInstance(dbName, tableName, dbId); Referenceable tableInstance = createHiveTableInstanceV1(dbName, tableName, dbId);
final Id tableId = createInstance(tableInstance); final Id tableId = createInstance(tableInstance);
final String guid = tableId._getId(); final String guid = tableId._getId();
...@@ -115,7 +115,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -115,7 +115,7 @@ public class EntityNotificationIT extends BaseResourceIT {
final String name = (String) tableInstance.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME); final String name = (String) tableInstance.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME);
serviceClient.deleteEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name); atlasClientV1.deleteEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
waitForNotification(notificationConsumer, MAX_WAIT_TIME, waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.ENTITY_DELETE, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.ENTITY_DELETE, HIVE_TABLE_TYPE, guid));
...@@ -138,7 +138,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -138,7 +138,7 @@ public class EntityNotificationIT extends BaseResourceIT {
final String guid = tableId._getId(); final String guid = tableId._getId();
serviceClient.addTrait(guid, traitInstance); atlasClientV1.addTrait(guid, traitInstance);
EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid));
...@@ -163,7 +163,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -163,7 +163,7 @@ public class EntityNotificationIT extends BaseResourceIT {
traitInstanceJSON = InstanceSerialization.toJson(traitInstance, true); traitInstanceJSON = InstanceSerialization.toJson(traitInstance, true);
LOG.debug("Trait instance = " + traitInstanceJSON); LOG.debug("Trait instance = " + traitInstanceJSON);
serviceClient.addTrait(guid, traitInstance); atlasClientV1.addTrait(guid, traitInstance);
entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.TRAIT_ADD, HIVE_TABLE_TYPE, guid));
...@@ -184,7 +184,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -184,7 +184,7 @@ public class EntityNotificationIT extends BaseResourceIT {
public void testDeleteTrait() throws Exception { public void testDeleteTrait() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
serviceClient.deleteTrait(guid, traitName); atlasClientV1.deleteTrait(guid, traitName);
EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME, EntityNotification entityNotification = waitForNotification(notificationConsumer, MAX_WAIT_TIME,
newNotificationPredicate(EntityNotification.OperationType.TRAIT_DELETE, HIVE_TABLE_TYPE, guid)); newNotificationPredicate(EntityNotification.OperationType.TRAIT_DELETE, HIVE_TABLE_TYPE, guid));
......
...@@ -39,6 +39,9 @@ import static org.mockito.Mockito.verify; ...@@ -39,6 +39,9 @@ import static org.mockito.Mockito.verify;
@Guice(modules = NotificationModule.class) @Guice(modules = NotificationModule.class)
public class NotificationHookConsumerKafkaTest { public class NotificationHookConsumerKafkaTest {
public static final String NAME = "name";
public static final String DESCRIPTION = "description";
public static final String QUALIFIED_NAME = "qualifiedName";
@Inject @Inject
private NotificationInterface notificationInterface; private NotificationInterface notificationInterface;
...@@ -128,9 +131,9 @@ public class NotificationHookConsumerKafkaTest { ...@@ -128,9 +131,9 @@ public class NotificationHookConsumerKafkaTest {
Referenceable createEntity() { Referenceable createEntity() {
final Referenceable entity = new Referenceable(AtlasClient.DATA_SET_SUPER_TYPE); final Referenceable entity = new Referenceable(AtlasClient.DATA_SET_SUPER_TYPE);
entity.set("name", "db" + randomString()); entity.set(NAME, "db" + randomString());
entity.set("description", randomString()); entity.set(DESCRIPTION, randomString());
entity.set("qualifiedName", randomString()); entity.set(QUALIFIED_NAME, randomString());
return entity; return entity;
} }
......
...@@ -37,7 +37,7 @@ public class AdminJerseyResourceIT extends BaseResourceIT { ...@@ -37,7 +37,7 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetVersion() throws Exception { public void testGetVersion() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null);
Assert.assertNotNull(response); Assert.assertNotNull(response);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties"); PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
......
...@@ -53,13 +53,13 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -53,13 +53,13 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
createTypeDefinitions(); createTypeDefinitionsV1();
setupInstances(); setupInstances();
} }
@Test @Test
public void testInputsGraph() throws Exception { public void testInputsGraph() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph"); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("inputs graph = " + response); System.out.println("inputs graph = " + response);
...@@ -78,9 +78,9 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -78,9 +78,9 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testInputsGraphForEntity() throws Exception { public void testInputsGraphForEntity() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
salesMonthlyTable).getId()._getId(); salesMonthlyTable).getId()._getId();
JSONObject results = serviceClient.getInputGraphForEntity(tableId); JSONObject results = atlasClientV1.getInputGraphForEntity(tableId);
Assert.assertNotNull(results); Assert.assertNotNull(results);
Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true); Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
...@@ -95,7 +95,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -95,7 +95,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testOutputsGraph() throws Exception { public void testOutputsGraph() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph"); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("outputs graph= " + response); System.out.println("outputs graph= " + response);
...@@ -114,9 +114,9 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -114,9 +114,9 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testOutputsGraphForEntity() throws Exception { public void testOutputsGraphForEntity() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
salesFactTable).getId()._getId(); salesFactTable).getId()._getId();
JSONObject results = serviceClient.getOutputGraphForEntity(tableId); JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId);
Assert.assertNotNull(results); Assert.assertNotNull(results);
Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true); Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
...@@ -131,7 +131,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -131,7 +131,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSchema() throws Exception { public void testSchema() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema"); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema");
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("schema = " + response); System.out.println("schema = " + response);
...@@ -156,8 +156,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -156,8 +156,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSchemaForEntity() throws Exception { public void testSchemaForEntity() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
JSONObject results = serviceClient.getSchemaForEntity(tableId); JSONObject results = atlasClientV1.getSchemaForEntity(tableId);
Assert.assertNotNull(results); Assert.assertNotNull(results);
JSONArray rows = results.getJSONArray("rows"); JSONArray rows = results.getJSONArray("rows");
...@@ -175,12 +175,12 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -175,12 +175,12 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForInvalidTable() throws Exception { public void testSchemaForInvalidTable() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, "blah", "schema"); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
} }
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForDB() throws Exception { public void testSchemaForDB() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema"); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
} }
private void setupInstances() throws Exception { private void setupInstances() throws Exception {
...@@ -238,9 +238,9 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -238,9 +238,9 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
Id database(String name, String description, String owner, String locationUri, String... traitNames) Id database(String name, String description, String owner, String locationUri, String... traitNames)
throws Exception { throws Exception {
Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames); Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
referenceable.set("name", name); referenceable.set(NAME, name);
referenceable.set("qualifiedName", name); referenceable.set(QUALIFIED_NAME, name);
referenceable.set("clusterName", locationUri + name); referenceable.set(CLUSTER_NAME, locationUri + name);
referenceable.set("description", description); referenceable.set("description", description);
referenceable.set("owner", owner); referenceable.set("owner", owner);
referenceable.set("locationUri", locationUri); referenceable.set("locationUri", locationUri);
...@@ -251,8 +251,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT { ...@@ -251,8 +251,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
Referenceable column(String name, String type, String comment, String... traitNames) throws Exception { Referenceable column(String name, String type, String comment, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames); Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
referenceable.set("name", name); referenceable.set(NAME, name);
referenceable.set("qualifiedName", name); referenceable.set(QUALIFIED_NAME, name);
referenceable.set("type", type); referenceable.set("type", type);
referenceable.set("comment", comment); referenceable.set("comment", comment);
......
...@@ -60,19 +60,19 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -60,19 +60,19 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
createTypeDefinitions(); createTypeDefinitionsV1();
setupInstances(); setupInstances();
} }
@Test @Test
public void testInputLineageInfo() throws Exception { public void testInputLineageInfo() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId(); AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION); queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5"); queryParams.add(DEPTH_PARAM, "5");
JSONObject response = serviceClient.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId); JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("input lineage info = " + response System.out.println("input lineage info = " + response
); );
...@@ -94,13 +94,13 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -94,13 +94,13 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
@Test @Test
public void testOutputLineageInfo() throws Exception { public void testOutputLineageInfo() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId(); AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION); queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
queryParams.add(DEPTH_PARAM, "5"); queryParams.add(DEPTH_PARAM, "5");
JSONObject response = serviceClient.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId); JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("output lineage info = " + response); System.out.println("output lineage info = " + response);
...@@ -122,13 +122,13 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI ...@@ -122,13 +122,13 @@ public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceI
@Test @Test
public void testLineageInfo() throws Exception { public void testLineageInfo() throws Exception {
String tableId = serviceClient.getEntity(HIVE_TABLE_TYPE, String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId(); AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION); queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
queryParams.add(DEPTH_PARAM, "5"); queryParams.add(DEPTH_PARAM, "5");
JSONObject response = serviceClient.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId); JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
Assert.assertNotNull(response); Assert.assertNotNull(response);
System.out.println("both lineage info = " + response); System.out.println("both lineage info = " + response);
......
...@@ -76,18 +76,18 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -76,18 +76,18 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
public void testSubmit() throws Exception { public void testSubmit() throws Exception {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
try{ try{
serviceClient.getType(typeDefinition.typeName); atlasClientV1.getType(typeDefinition.typeName);
} catch (AtlasServiceException ase){ } catch (AtlasServiceException ase){
String typesAsJSON = TypesSerialization.toJson(typeDefinition, false); String typesAsJSON = TypesSerialization.toJson(typeDefinition, false);
System.out.println("typesAsJSON = " + typesAsJSON); System.out.println("typesAsJSON = " + typesAsJSON);
JSONObject response = serviceClient.callAPIWithBody(AtlasClient.API.CREATE_TYPE, typesAsJSON); JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_TYPE, typesAsJSON);
Assert.assertNotNull(response); Assert.assertNotNull(response);
JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES); JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES);
assertEquals(typesAdded.length(), 1); assertEquals(typesAdded.length(), 1);
assertEquals(typesAdded.getJSONObject(0).getString("name"), typeDefinition.typeName); assertEquals(typesAdded.getJSONObject(0).getString(NAME), typeDefinition.typeName);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));} Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
} }
} }
...@@ -95,14 +95,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -95,14 +95,14 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testDuplicateSubmit() throws Exception { public void testDuplicateSubmit() throws Exception {
HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(), HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(),
ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
TypesDef typesDef = TypesDef typesDef =
TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type)); ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type));
serviceClient.createType(typesDef); atlasClientV1.createType(typesDef);
try { try {
serviceClient.createType(typesDef); atlasClientV1.createType(typesDef);
fail("Expected 409"); fail("Expected 409");
} catch (AtlasServiceException e) { } catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode()); assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
...@@ -113,24 +113,24 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -113,24 +113,24 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
public void testUpdate() throws Exception { public void testUpdate() throws Exception {
HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
.createClassTypeDef(randomString(), ImmutableSet.<String>of(), .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
List<String> typesCreated = serviceClient.createType(TypesSerialization.toJson(typeDefinition, false)); List<String> typesCreated = atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
assertEquals(typesCreated.size(), 1); assertEquals(typesCreated.size(), 1);
assertEquals(typesCreated.get(0), typeDefinition.typeName); assertEquals(typesCreated.get(0), typeDefinition.typeName);
//Add attribute description //Add attribute description
typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName,
ImmutableSet.<String>of(), ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
createOptionalAttrDef("description", DataTypes.STRING_TYPE)); createOptionalAttrDef(DESCRIPTION, DataTypes.STRING_TYPE));
TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
ImmutableList.of(typeDefinition)); ImmutableList.of(typeDefinition));
List<String> typesUpdated = serviceClient.updateType(typeDef); List<String> typesUpdated = atlasClientV1.updateType(typeDef);
assertEquals(typesUpdated.size(), 1); assertEquals(typesUpdated.size(), 1);
Assert.assertTrue(typesUpdated.contains(typeDefinition.typeName)); Assert.assertTrue(typesUpdated.contains(typeDefinition.typeName));
TypesDef updatedTypeDef = serviceClient.getType(typeDefinition.typeName); TypesDef updatedTypeDef = atlasClientV1.getType(typeDefinition.typeName);
assertNotNull(updatedTypeDef); assertNotNull(updatedTypeDef);
HierarchicalTypeDefinition<ClassType> updatedType = updatedTypeDef.classTypesAsJavaList().get(0); HierarchicalTypeDefinition<ClassType> updatedType = updatedTypeDef.classTypesAsJavaList().get(0);
...@@ -142,7 +142,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -142,7 +142,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) { for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
System.out.println("typeName = " + typeDefinition.typeName); System.out.println("typeName = " + typeDefinition.typeName);
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.DEFINITION)); Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
...@@ -153,7 +153,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -153,7 +153,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList(); List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList();
for (HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) { for (HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) {
for (AttributeDefinition attrDef : classType.attributeDefinitions) { for (AttributeDefinition attrDef : classType.attributeDefinitions) {
if ("name".equals(attrDef.name)) { if (NAME.equals(attrDef.name)) {
assertEquals(attrDef.isIndexable, true); assertEquals(attrDef.isIndexable, true);
assertEquals(attrDef.isUnique, true); assertEquals(attrDef.isUnique, true);
} }
...@@ -164,12 +164,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -164,12 +164,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class) @Test(expectedExceptions = AtlasServiceException.class)
public void testGetDefinitionForNonexistentType() throws Exception { public void testGetDefinitionForNonexistentType() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, "blah"); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, "blah");
} }
@Test(dependsOnMethods = "testSubmit") @Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception { public void testGetTypeNames() throws Exception {
JSONObject response = serviceClient.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, (String[]) null); JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, (String[]) null);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
...@@ -190,7 +190,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -190,7 +190,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", DataTypes.TypeCategory.TRAIT.name()); queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
JSONObject response = serviceClient.callAPIWithQueryParams(AtlasClient.API.LIST_TYPES, queryParams); JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.LIST_TYPES, queryParams);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
...@@ -212,7 +212,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -212,7 +212,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
String c = createType(TypesSerialization.toJson( String c = createType(TypesSerialization.toJson(
TypesUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(a, b), attr), false)).get(0); TypesUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(a, b), attr), false)).get(0);
List<String> results = serviceClient.listTypes(DataTypes.TypeCategory.CLASS, a, b); List<String> results = atlasClientV1.listTypes(DataTypes.TypeCategory.CLASS, a, b);
assertEquals(results, Arrays.asList(a1), "Results: " + results); assertEquals(results, Arrays.asList(a1), "Results: " + results);
} }
...@@ -234,16 +234,16 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -234,16 +234,16 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil
.createClassTypeDef("database", ImmutableSet.<String>of(), .createClassTypeDef("database", ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("qualifiedName", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE));
typeDefinitions.add(databaseTypeDefinition); typeDefinitions.add(databaseTypeDefinition);
HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil
.createClassTypeDef("table", ImmutableSet.<String>of(), .createClassTypeDef("table", ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("qualifiedName", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE),
createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)), createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)),
createOptionalAttrDef("created", DataTypes.DATE_TYPE), createOptionalAttrDef("created", DataTypes.DATE_TYPE),
createOptionalAttrDef("parameters", createOptionalAttrDef("parameters",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment