http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java b/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java index 53acf56..308f18d 100644 --- a/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java +++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java @@ -21,31 +21,20 @@ import com.google.common.annotations.VisibleForTesting; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasException; import org.apache.atlas.listener.EntityChangeListener; +import org.apache.atlas.model.v1.instance.Referenceable; +import org.apache.atlas.model.v1.instance.Struct; import org.apache.atlas.notification.entity.EntityNotification; import org.apache.atlas.notification.entity.EntityNotificationImpl; import org.apache.atlas.repository.graph.GraphHelper; -import org.apache.atlas.typesystem.IReferenceableInstance; -import org.apache.atlas.typesystem.IStruct; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.Struct; -import org.apache.atlas.typesystem.types.FieldMapping; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.TypeSystem; +import org.apache.atlas.type.AtlasClassificationType; +import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.configuration.Configuration; import org.springframework.stereotype.Component; import javax.inject.Inject; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Listen to the repository for entity changes and produce entity change notifications. @@ -54,7 +43,7 @@ import java.util.Set; public class NotificationEntityChangeListener implements EntityChangeListener { private final NotificationInterface notificationInterface; - private final TypeSystem typeSystem; + private final AtlasTypeRegistry typeRegistry; private Map<String, List<String>> notificationAttributesCache = new HashMap<>(); private static final String ATLAS_ENTITY_NOTIFICATION_PROPERTY = "atlas.notification.entity"; @@ -68,44 +57,44 @@ public class NotificationEntityChangeListener implements EntityChangeListener { * Construct a NotificationEntityChangeListener. * * @param notificationInterface the notification framework interface - * @param typeSystem the Atlas type system + * @param typeRegistry the Atlas type system */ @Inject - public NotificationEntityChangeListener(NotificationInterface notificationInterface, TypeSystem typeSystem) { + public NotificationEntityChangeListener(NotificationInterface notificationInterface, AtlasTypeRegistry typeRegistry) { this.notificationInterface = notificationInterface; - this.typeSystem = typeSystem; + this.typeRegistry = typeRegistry; } // ----- EntityChangeListener ---------------------------------------------- @Override - public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException { + public void onEntitiesAdded(Collection<Referenceable> entities, boolean isImport) throws AtlasException { notifyOfEntityEvent(entities, EntityNotification.OperationType.ENTITY_CREATE); } @Override - public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException { + public void onEntitiesUpdated(Collection<Referenceable> entities, boolean isImport) throws AtlasException { notifyOfEntityEvent(entities, EntityNotification.OperationType.ENTITY_UPDATE); } @Override - public void onTraitsAdded(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException { + public void onTraitsAdded(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException { notifyOfEntityEvent(Collections.singleton(entity), EntityNotification.OperationType.TRAIT_ADD); } @Override - public void onTraitsDeleted(ITypedReferenceableInstance entity, Collection<String> traitNames) throws AtlasException { + public void onTraitsDeleted(Referenceable entity, Collection<String> traitNames) throws AtlasException { notifyOfEntityEvent(Collections.singleton(entity), EntityNotification.OperationType.TRAIT_DELETE); } @Override - public void onTraitsUpdated(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException { + public void onTraitsUpdated(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException { notifyOfEntityEvent(Collections.singleton(entity), EntityNotification.OperationType.TRAIT_UPDATE); } @Override - public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException { + public void onEntitiesDeleted(Collection<Referenceable> entities, boolean isImport) throws AtlasException { notifyOfEntityEvent(entities, EntityNotification.OperationType.ENTITY_DELETE); } @@ -115,57 +104,46 @@ public class NotificationEntityChangeListener implements EntityChangeListener { // ----- helper methods ---------------------------------------------------- @VisibleForTesting - public static List<IStruct> getAllTraits(IReferenceableInstance entityDefinition, - TypeSystem typeSystem) throws AtlasException { - List<IStruct> traitInfo = new LinkedList<>(); - for (String traitName : entityDefinition.getTraits()) { - IStruct trait = entityDefinition.getTrait(traitName); - String typeName = trait.getTypeName(); - Map<String, Object> valuesMap = trait.getValuesMap(); - traitInfo.add(new Struct(typeName, valuesMap)); - traitInfo.addAll(getSuperTraits(typeName, valuesMap, typeSystem)); - } - return traitInfo; - } - - private static List<IStruct> getSuperTraits( - String typeName, Map<String, Object> values, TypeSystem typeSystem) throws AtlasException { + public static List<Struct> getAllTraits(Referenceable entityDefinition, AtlasTypeRegistry typeRegistry) throws AtlasException { + List<Struct> ret = new ArrayList<>(); - List<IStruct> superTypes = new LinkedList<>(); + for (String traitName : entityDefinition.getTraitNames()) { + Struct trait = entityDefinition.getTrait(traitName); + AtlasClassificationType traitType = typeRegistry.getClassificationTypeByName(traitName); + Set<String> superTypeNames = traitType != null ? traitType.getAllSuperTypes() : null; - TraitType traitDef = typeSystem.getDataType(TraitType.class, typeName); - Set<String> superTypeNames = traitDef.getAllSuperTypeNames(); + ret.add(trait); - for (String superTypeName : superTypeNames) { - TraitType superTraitDef = typeSystem.getDataType(TraitType.class, superTypeName); + if (CollectionUtils.isNotEmpty(superTypeNames)) { + for (String superTypeName : superTypeNames) { + Struct superTypeTrait = new Struct(superTypeName); - Map<String, Object> superTypeValues = new HashMap<>(); + if (MapUtils.isNotEmpty(trait.getValues())) { + AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); - FieldMapping fieldMapping = superTraitDef.fieldMapping(); + if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) { + Map<String, Object> attributes = new HashMap<>(); - if (fieldMapping != null) { - Set<String> superTypeAttributeNames = fieldMapping.fields.keySet(); + // TODO: add superTypeTrait attributess - for (String superTypeAttributeName : superTypeAttributeNames) { - if (values.containsKey(superTypeAttributeName)) { - superTypeValues.put(superTypeAttributeName, values.get(superTypeAttributeName)); + superTypeTrait.setValues(attributes); + } } + + ret.add(superTypeTrait); } } - IStruct superTrait = new Struct(superTypeName, superTypeValues); - superTypes.add(superTrait); - superTypes.addAll(getSuperTraits(superTypeName, values, typeSystem)); } - return superTypes; + return ret; } // send notification of entity change - private void notifyOfEntityEvent(Collection<ITypedReferenceableInstance> entityDefinitions, + private void notifyOfEntityEvent(Collection<Referenceable> entityDefinitions, EntityNotification.OperationType operationType) throws AtlasException { List<EntityNotification> messages = new LinkedList<>(); - for (IReferenceableInstance entityDefinition : entityDefinitions) { + for (Referenceable entityDefinition : entityDefinitions) { if(GraphHelper.isInternalType(entityDefinition.getTypeName())) { continue; } @@ -182,7 +160,7 @@ public class NotificationEntityChangeListener implements EntityChangeListener { } } - EntityNotificationImpl notification = new EntityNotificationImpl(entity, operationType, getAllTraits(entity, typeSystem)); + EntityNotificationImpl notification = new EntityNotificationImpl(entity, operationType, getAllTraits(entity, typeRegistry)); messages.add(notification); }
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java index 4646bff..d5b73e0 100644 --- a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java +++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java @@ -25,12 +25,12 @@ import org.apache.atlas.AtlasBaseClient; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasServiceException; -import org.apache.atlas.RequestContext; import org.apache.atlas.RequestContextV1; import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.kafka.AtlasKafkaMessage; import org.apache.atlas.listener.ActiveStateChangeHandler; import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.v1.instance.Referenceable; import org.apache.atlas.notification.hook.HookNotification.EntityCreateRequest; import org.apache.atlas.notification.hook.HookNotification.EntityDeleteRequest; import org.apache.atlas.notification.hook.HookNotification.EntityPartialUpdateRequest; @@ -43,7 +43,6 @@ import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.service.Service; import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.web.filters.AuditFilter; import org.apache.atlas.web.service.ServiceState; @@ -345,13 +344,13 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl try { // Used for intermediate conversions during create and update - AtlasEntity.AtlasEntitiesWithExtInfo entities; + AtlasEntity.AtlasEntitiesWithExtInfo entities = null; for (int numRetries = 0; numRetries < maxRetries; numRetries++) { if (LOG.isDebugEnabled()) { LOG.debug("handleMessage({}): attempt {}", message.getType().name(), numRetries); } try { - RequestContext requestContext = RequestContext.createContext(); + RequestContextV1 requestContext = RequestContextV1.get(); requestContext.setUser(messageUser); switch (message.getType()) { @@ -363,7 +362,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl audit(messageUser, api.getMethod(), api.getNormalizedPath()); } - entities = instanceConverter.toAtlasEntities(createRequest.getEntities()); + // TODO: entities = instanceConverter.toAtlasEntities(createRequest.getEntities()); atlasEntityStore.createOrUpdate(new AtlasEntityStream(entities), false); break; @@ -378,7 +377,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl } Referenceable referenceable = partialUpdateRequest.getEntity(); - entities = instanceConverter.toAtlasEntity(referenceable); + // TODO: entities = instanceConverter.toAtlasEntity(referenceable); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(partialUpdateRequest.getTypeName()); String guid = AtlasGraphUtilsV1.getGuidByUniqueAttributes(entityType, new HashMap<String, Object>() { @@ -421,7 +420,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl audit(messageUser, api.getMethod(), api.getNormalizedPath()); } - entities = instanceConverter.toAtlasEntities(updateRequest.getEntities()); + // TODO: entities = instanceConverter.toAtlasEntities(updateRequest.getEntities()); atlasEntityStore.createOrUpdate(new AtlasEntityStream(entities), false); break; @@ -448,7 +447,6 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl return; } } finally { - RequestContext.clear(); RequestContextV1.clear(); } } http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java index e8020db..1d553e0 100644 --- a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java +++ b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java @@ -19,7 +19,7 @@ package org.apache.atlas.web.filters; import org.apache.atlas.ApplicationProperties; -import org.apache.atlas.RequestContext; +import org.apache.atlas.RequestContextV1; import org.apache.atlas.security.SecurityProperties; import org.apache.atlas.utils.AuthenticationUtil; import org.apache.atlas.web.security.AtlasAuthenticationProvider; @@ -311,7 +311,7 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter { try { String requestUser = httpRequest.getRemoteUser(); NDC.push(requestUser + ":" + httpRequest.getMethod() + httpRequest.getRequestURI()); - RequestContext requestContext = RequestContext.get(); + RequestContextV1 requestContext = RequestContextV1.get(); if (requestContext != null) { requestContext.setUser(requestUser); } http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java index 191388a..3225b0e 100755 --- a/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java +++ b/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java @@ -20,7 +20,6 @@ package org.apache.atlas.web.filters; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasException; -import org.apache.atlas.RequestContext; import org.apache.atlas.RequestContextV1; import org.apache.atlas.metrics.Metrics; import org.apache.atlas.util.AtlasRepositoryConfiguration; @@ -70,7 +69,8 @@ public class AuditFilter implements Filter { try { currentThread.setName(formatName(oldName, requestId)); - RequestContext requestContext = RequestContext.createContext(); + RequestContextV1.clear(); + RequestContextV1 requestContext = RequestContextV1.get(); requestContext.setUser(user); recordAudit(httpRequest, requestTimeISO9601, user); filterChain.doFilter(request, response); @@ -79,7 +79,6 @@ public class AuditFilter implements Filter { ((HttpServletResponse) response).setHeader(AtlasClient.REQUEST_ID, requestId); currentThread.setName(oldName); recordMetrics(); - RequestContext.clear(); RequestContextV1.clear(); } } @@ -120,7 +119,7 @@ public class AuditFilter implements Filter { public static void recordMetrics() { //record metrics - Metrics requestMetrics = RequestContext.getMetrics(); + Metrics requestMetrics = RequestContextV1.getMetrics(); if (!requestMetrics.isEmpty()) { METRICS_LOG.info("{}", requestMetrics); } http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java deleted file mode 100644 index 435659e..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.web.resources; - -import org.apache.atlas.AtlasClient; -import org.apache.atlas.discovery.DiscoveryException; -import org.apache.atlas.discovery.LineageService; -import org.apache.atlas.typesystem.exception.EntityNotFoundException; -import org.apache.atlas.utils.AtlasPerfTracer; -import org.apache.atlas.web.util.Servlets; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; - -/** - * Jersey Resource for Hive Table Lineage. - */ -@Path("lineage/hive") -@Singleton -@Service -@Deprecated -public class DataSetLineageResource { - - private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class); - private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.DataSetLineageResource"); - - private final LineageService lineageService; - - /** - * Created by the Guice ServletModule and injected with the - * configured LineageService. - * - * @param lineageService lineage service handle - */ - @Inject - public DataSetLineageResource(LineageService lineageService) { - this.lineageService = lineageService; - } - - /** - * Returns the inputs graph for a given entity. - * - * @param tableName table name - */ - @GET - @Path("table/{tableName}/inputs/graph") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response inputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> DataSetLineageResource.inputsGraph({})", tableName); - } - - AtlasPerfTracer perf = null; - - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.inputsGraph(tableName=" + tableName + ")"); - } - - final String jsonResult = lineageService.getInputsGraph(tableName); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put("tableName", tableName); - response.put(AtlasClient.RESULTS, new JSONObject(jsonResult)); - - return Response.ok(response).build(); - } catch (EntityNotFoundException e) { - LOG.error("table entity not found for {}", tableName); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get lineage inputs graph for table {}", tableName, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get lineage inputs graph for table {}", tableName, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get lineage inputs graph for table {}", tableName, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - } - } - - /** - * Returns the outputs graph for a given entity. - * - * @param tableName table name - */ - @GET - @Path("table/{tableName}/outputs/graph") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response outputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> DataSetLineageResource.outputsGraph({})", tableName); - } - - AtlasPerfTracer perf = null; - - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.outputsGraph(tableName=" + tableName + ")"); - } - - final String jsonResult = lineageService.getOutputsGraph(tableName); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put("tableName", tableName); - response.put(AtlasClient.RESULTS, new JSONObject(jsonResult)); - - return Response.ok(response).build(); - } catch (EntityNotFoundException e) { - LOG.error("table entity not found for {}", tableName); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get lineage outputs graph for table {}", tableName, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get lineage outputs graph for table {}", tableName, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get lineage outputs graph for table {}", tableName, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - } - } - - /** - * Return the schema for the given tableName. - * - * @param tableName table name - */ - @GET - @Path("table/{tableName}/schema") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response schema(@Context HttpServletRequest request, @PathParam("tableName") String tableName) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> DataSetLineageResource.schema({})", tableName); - } - - AtlasPerfTracer perf = null; - - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.schema(tableName=" + tableName + ")"); - } - - final String jsonResult = lineageService.getSchema(tableName); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put("tableName", tableName); - response.put(AtlasClient.RESULTS, new JSONObject(jsonResult)); - - return Response.ok(response).build(); - } catch (EntityNotFoundException e) { - LOG.error("table entity not found for {}", tableName); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get schema for table {}", tableName, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get schema for table {}", tableName, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get schema for table {}", tableName, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java index 8b56507..1cbfc14 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java @@ -28,29 +28,21 @@ import org.apache.atlas.AtlasException; import org.apache.atlas.CreateUpdateEntitiesResult; import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.instance.AtlasClassification; -import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.*; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; -import org.apache.atlas.model.instance.EntityMutationResponse; -import org.apache.atlas.model.instance.GuidMapping; import org.apache.atlas.model.legacy.EntityResult; +import org.apache.atlas.model.v1.instance.Id; +import org.apache.atlas.model.v1.instance.Referenceable; +import org.apache.atlas.model.v1.instance.Struct; import org.apache.atlas.repository.converters.AtlasInstanceConverter; import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream; import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; -import org.apache.atlas.services.MetadataService; import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.typesystem.IStruct; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.exception.EntityExistsException; -import org.apache.atlas.typesystem.exception.EntityNotFoundException; -import org.apache.atlas.typesystem.json.InstanceSerialization; -import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.ValueConversionException; +import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.ParamChecker; import org.apache.atlas.web.rest.EntityREST; @@ -98,7 +90,6 @@ public class EntityResource { private static final String TRAIT_NAME = "traitName"; - private final MetadataService metadataService; private final AtlasInstanceConverter restAdapters; private final AtlasEntityStore entitiesStore; private final AtlasTypeRegistry typeRegistry; @@ -110,19 +101,12 @@ public class EntityResource { @Context private ResourceContext resourceContext; - /** - * Created by the Guice ServletModule and injected with the - * configured MetadataService. - * - * @param metadataService metadata service handle - */ + @Inject - public EntityResource(MetadataService metadataService, AtlasInstanceConverter restAdapters, - AtlasEntityStore entitiesStore, AtlasTypeRegistry typeRegistry, EntityREST entityREST) { - this.metadataService = metadataService; - this.restAdapters = restAdapters; - this.entitiesStore = entitiesStore; - this.typeRegistry = typeRegistry; + public EntityResource(AtlasInstanceConverter restAdapters, AtlasEntityStore entitiesStore, AtlasTypeRegistry typeRegistry, EntityREST entityREST) { + this.restAdapters = restAdapters; + this.entitiesStore = entitiesStore; + this.typeRegistry = typeRegistry; this.entityREST = entityREST; } @@ -149,22 +133,28 @@ public class EntityResource { String entities = Servlets.getRequestPayload(request); //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray + JSONArray jsonEntities = null; + try { - new JSONArray(entities); + jsonEntities = new JSONArray(entities); } catch (JSONException e) { final String finalEntities = entities; - entities = new JSONArray() {{ + jsonEntities = new JSONArray() {{ put(finalEntities); - }}.toString(); + }}; } - entityJson = AtlasClient.toString(new JSONArray(entities)); + String[] jsonStrings = new String[jsonEntities.length()]; + + for (int i = 0; i < jsonEntities.length(); i++) { + jsonStrings[i] = jsonEntities.getString(i); + } if (LOG.isDebugEnabled()) { - LOG.debug("submitting entities {} ", entityJson); + LOG.debug("submitting entities {} ", jsonEntities); } - AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(entities); + AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings); EntityMutationResponse mutationResponse = entityREST.createOrUpdate(entitiesInfo); final List<String> guids = restAdapters.getGuids(mutationResponse.getCreatedEntities()); @@ -183,12 +173,6 @@ public class EntityResource { } catch (AtlasBaseException e) { LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); throw toWebApplicationException(e); - } catch(EntityExistsException e) { - LOG.error("Unique constraint violation for entity entityDef={}", entityJson, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT)); - } catch (ValueConversionException ve) { - LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve); - throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause() != null ? ve.getCause() : ve, Response.Status.BAD_REQUEST)); } catch (AtlasException | IllegalArgumentException e) { LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); @@ -224,13 +208,13 @@ public class EntityResource { return locationURI; } - private JSONObject getResponse(EntityResult entityResult) throws AtlasException, JSONException { + private JSONObject getResponse(EntityResult entityResult) throws AtlasBaseException, AtlasException, JSONException { CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult(); result.setEntityResult(entityResult); return getResponse(result); } - private JSONObject getResponse(CreateUpdateEntitiesResult result) throws AtlasException, JSONException { + private JSONObject getResponse(CreateUpdateEntitiesResult result) throws AtlasBaseException, AtlasException, JSONException { JSONObject response = new JSONObject(); EntityResult entityResult = result.getEntityResult(); GuidMapping mapping = result.getGuidMapping(); @@ -239,12 +223,12 @@ public class EntityResource { response.put(AtlasClient.ENTITIES, new JSONObject(entityResult.toString()).get(AtlasClient.ENTITIES)); String sampleEntityId = getSample(result.getEntityResult()); if (sampleEntityId != null) { - String entityDefinition = metadataService.getEntityDefinitionJson(sampleEntityId); + String entityDefinition = getEntityJson(sampleEntityId); response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition)); } } if(mapping != null) { - response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(AtlasType.toJson(mapping)).get(AtlasClient.GUID_ASSIGNMENTS)); + response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(AtlasType.toV1Json(mapping)).get(AtlasClient.GUID_ASSIGNMENTS)); } return response; } @@ -270,14 +254,18 @@ public class EntityResource { } final String entities = Servlets.getRequestPayload(request); + JSONArray jsonEntities = new JSONArray(entities); + String[] jsonStrings = new String[jsonEntities.length()]; - entityJson = AtlasClient.toString(new JSONArray(entities)); + for (int i = 0; i < jsonEntities.length(); i++) { + jsonStrings[i] = jsonEntities.getString(i); + } if (LOG.isDebugEnabled()) { LOG.info("updating entities {} ", entityJson); } - AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(entities); + AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings); EntityMutationResponse mutationResponse = entityREST.createOrUpdate(entitiesInfo); CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse); @@ -290,12 +278,6 @@ public class EntityResource { } catch (AtlasBaseException e) { LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); throw toWebApplicationException(e); - } catch(EntityExistsException e) { - LOG.error("Unique constraint violation for entityDef={}", entityJson, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT)); - } catch (ValueConversionException ve) { - LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve); - throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause(), Response.Status.BAD_REQUEST)); } catch (AtlasException | IllegalArgumentException e) { LOG.error("Unable to persist entity instance entityDef={}", entityJson, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); @@ -367,7 +349,7 @@ public class EntityResource { LOG.debug("Partially updating entity by unique attribute {} {} {} {} ", entityType, attribute, value, entityJson); } - Referenceable updatedEntity = InstanceSerialization.fromJsonReferenceable(entityJson, true); + Referenceable updatedEntity = AtlasType.fromV1Json(entityJson, Referenceable.class); entityType = ParamChecker.notEmpty(entityType, "Entity type cannot be null"); attribute = ParamChecker.notEmpty(attribute, "attribute name cannot be null"); @@ -379,10 +361,10 @@ public class EntityResource { // update referenceable with Id if not specified in payload Id updateId = updatedEntity.getId(); - if (updateId != null && !updateId.isAssigned()) { + if (updateId != null && !AtlasTypeUtil.isAssignedGuid(updateId.getId())) { String guid = AtlasGraphUtilsV1.getGuidByUniqueAttributes(getEntityType(entityType), attributes); - updatedEntity.replaceWithNewId(new Id(guid, 0, updatedEntity.getTypeName())); + updatedEntity.setId(new Id(guid, 0, updatedEntity.getTypeName())); } AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntity(updatedEntity); @@ -398,15 +380,6 @@ public class EntityResource { } catch (AtlasBaseException e) { LOG.error("Unable to partially update entity {} {}:{}.{}", entityJson, entityType, attribute, value, e); throw toWebApplicationException(e); - } catch (ValueConversionException ve) { - LOG.error("Unable to persist entity instance due to a deserialization error {} ", entityJson, ve); - throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause(), Response.Status.BAD_REQUEST)); - } catch(EntityExistsException e) { - LOG.error("Unique constraint violation for entity {} ", entityJson, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT)); - } catch (EntityNotFoundException e) { - LOG.error("An entity with type={} and qualifiedName={} does not exist {} ", entityType, value, entityJson, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); } catch (AtlasException | IllegalArgumentException e) { LOG.error("Unable to partially update entity {} {}:{}.{}", entityJson, entityType, attribute, value, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); @@ -474,13 +447,13 @@ public class EntityResource { LOG.debug("partially updating entity for guid {} : {} ", guid, entityJson); } - Referenceable updatedEntity = InstanceSerialization.fromJsonReferenceable(entityJson, true); + Referenceable updatedEntity = AtlasType.fromV1Json(entityJson, Referenceable.class); // update referenceable with Id if not specified in payload Id updateId = updatedEntity.getId(); - if (updateId != null && !updateId.isAssigned()) { - updatedEntity.replaceWithNewId(new Id(guid, 0, updatedEntity.getTypeName())); + if (updateId != null && !AtlasTypeUtil.isAssignedGuid(updateId.getId())) { + updatedEntity.setId(new Id(guid, 0, updatedEntity.getTypeName())); } AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntity(updatedEntity); @@ -496,9 +469,6 @@ public class EntityResource { } catch (AtlasBaseException e) { LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e); throw toWebApplicationException(e); - } catch (EntityNotFoundException e) { - LOG.error("An entity with GUID={} does not exist {} ", guid, entityJson, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); } catch (AtlasException | IllegalArgumentException e) { LOG.error("Unable to update entity by GUID {} {}", guid, entityJson, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); @@ -544,9 +514,6 @@ public class EntityResource { } catch (AtlasBaseException e) { LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e); throw toWebApplicationException(e); - } catch (EntityNotFoundException e) { - LOG.error("An entity with GUID={} does not exist {} ", guid, value, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); } catch (AtlasException | IllegalArgumentException e) { LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); @@ -617,13 +584,6 @@ public class EntityResource { } catch (AtlasBaseException e) { LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e); throw toWebApplicationException(e); - } catch (EntityNotFoundException e) { - if(guids != null && !guids.isEmpty()) { - LOG.error("An entity with GUID={} does not exist ", guids, e); - } else { - LOG.error("An entity with qualifiedName {}-{}-{} does not exist", entityType, attribute, value, e); - } - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); } catch (AtlasException | IllegalArgumentException e) { LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); @@ -666,7 +626,8 @@ public class EntityResource { } guid = ParamChecker.notEmpty(guid, "guid cannot be null"); - final String entityDefinition = metadataService.getEntityDefinitionJson(guid); + + String entityDefinition = getEntityJson(guid); JSONObject response = new JSONObject(); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); @@ -681,11 +642,7 @@ public class EntityResource { } return Response.status(status).entity(response).build(); - - } catch (EntityNotFoundException e) { - LOG.error("An entity with GUID={} does not exist ", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); - } catch (AtlasException | IllegalArgumentException e) { + } catch (IllegalArgumentException e) { LOG.error("Bad GUID={} ", guid, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); } catch (WebApplicationException e) { @@ -716,7 +673,7 @@ public class EntityResource { LOG.debug("Fetching entity list for type={} ", entityType); } - final List<String> entityList = metadataService.getEntityList(entityType); + final List<String> entityList = new ArrayList<>(); // TODO: metadataService.getEntityList(entityType); JSONObject response = new JSONObject(); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); @@ -728,7 +685,7 @@ public class EntityResource { } catch (NullPointerException e) { LOG.error("Entity type cannot be null", e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (AtlasException | IllegalArgumentException e) { + } catch (IllegalArgumentException e) { LOG.error("Unable to get entity list for type {}", entityType, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); } catch (WebApplicationException e) { @@ -804,10 +761,9 @@ public class EntityResource { String entityDefinition = null; if (entityInfo != null) { - AtlasEntity entity = entityInfo.getEntity(); - final ITypedReferenceableInstance instance = restAdapters.getITypedReferenceable(entity); + Referenceable instance = restAdapters.getReferenceable(entityInfo); - entityDefinition = InstanceSerialization.toJson(instance, true); + entityDefinition = AtlasType.toV1Json(instance); } JSONObject response = new JSONObject(); @@ -926,8 +882,8 @@ public class EntityResource { JSONArray traits = new JSONArray(); for (AtlasClassification classification : classifications) { - IStruct trait = restAdapters.getTrait(classification); - traits.put(new JSONObject(InstanceSerialization.toJson(trait, true))); + Struct trait = restAdapters.getTrait(classification); + traits.put(new JSONObject(AtlasType.toV1Json(trait))); } JSONObject response = new JSONObject(); @@ -984,11 +940,11 @@ public class EntityResource { final AtlasClassification classification = entitiesStore.getClassification(guid, traitName); - IStruct traitDefinition = restAdapters.getTrait(classification); + Struct traitDefinition = restAdapters.getTrait(classification); JSONObject response = new JSONObject(); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put(AtlasClient.RESULTS, new JSONObject(InstanceSerialization.toJson(traitDefinition, true))); + response.put(AtlasClient.RESULTS, new JSONObject(AtlasType.toV1Json(traitDefinition))); return Response.ok(response).build(); @@ -1044,7 +1000,7 @@ public class EntityResource { add(guid); }}; - entitiesStore.addClassification(guids, restAdapters.getClassification(InstanceSerialization.fromJsonStruct(traitDefinition, true))); + entitiesStore.addClassification(guids, restAdapters.toAtlasClassification(AtlasType.fromV1Json(traitDefinition, Struct.class))); URI locationURI = getLocationURI(new ArrayList<String>() {{ add(guid); @@ -1160,13 +1116,13 @@ public class EntityResource { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")"); } - List<EntityAuditEvent> events = metadataService.getAuditEvents(guid, startKey, count); + List<EntityAuditEvent> events = new ArrayList<>(); // TODO: metadataService.getAuditEvents(guid, startKey, count); JSONObject response = new JSONObject(); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.EVENTS, getJSONArray(events)); return Response.ok(response).build(); - } catch (AtlasException | IllegalArgumentException e) { + } catch (IllegalArgumentException e) { LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); } catch (WebApplicationException e) { @@ -1216,4 +1172,12 @@ public class EntityResource { return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode())); } + + private String getEntityJson(String guid) throws AtlasBaseException { + AtlasEntityWithExtInfo entity = entitiesStore.getById(guid); + Referenceable referenceable = restAdapters.getReferenceable(entity); + String entityJson = AtlasType.toV1Json(referenceable); + + return entityJson; + } } http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java deleted file mode 100644 index cba8ccf..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.web.resources; - -import org.apache.atlas.AtlasClient; -import org.apache.atlas.discovery.AtlasLineageService; -import org.apache.atlas.discovery.DiscoveryException; -import org.apache.atlas.discovery.LineageService; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.lineage.AtlasLineageInfo; -import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection; -import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.typesystem.exception.EntityNotFoundException; -import org.apache.atlas.typesystem.exception.SchemaNotFoundException; -import org.apache.atlas.utils.AtlasPerfTracer; -import org.apache.atlas.web.util.LineageUtils; -import org.apache.atlas.web.util.Servlets; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; - -@Path("lineage") -@Singleton -@Service -@Deprecated -public class LineageResource { - private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class); - private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.LineageResource"); - - private final AtlasLineageService atlasLineageService; - private final LineageService lineageService; - private final AtlasTypeRegistry typeRegistry; - - /** - * Created by the Guice ServletModule and injected with the - * configured LineageService. - * - * @param lineageService lineage service handle - */ - @Inject - public LineageResource(LineageService lineageService, AtlasLineageService atlasLineageService, AtlasTypeRegistry typeRegistry) { - this.lineageService = lineageService; - this.atlasLineageService = atlasLineageService; - this.typeRegistry = typeRegistry; - } - - /** - * Returns input lineage graph for the given entity id. - * @param guid dataset entity id - * @return - */ - @GET - @Path("{guid}/inputs/graph") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response inputsGraph(@PathParam("guid") String guid) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> LineageResource.inputsGraph({})", guid); - } - - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.inputsGraph(" + guid + ")"); - } - - AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.INPUT, -1); - final String result = LineageUtils.toLineageStruct(lineageInfo, typeRegistry); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put(AtlasClient.RESULTS, new JSONObject(result)); - - return Response.ok(response).build(); - } catch (AtlasBaseException e) { - LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e)); - } catch (WebApplicationException e) { - LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e); - throw e; - } catch (JSONException e) { - LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== LineageResource.inputsGraph({})", guid); - } - } - } - - /** - * Returns the outputs graph for a given entity id. - * - * @param guid dataset entity id - */ - @GET - @Path("{guid}/outputs/graph") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response outputsGraph(@PathParam("guid") String guid) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> LineageResource.outputsGraph({})", guid); - } - - AtlasPerfTracer perf = null; - - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.outputsGraph(" + guid + ")"); - } - - AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.OUTPUT, -1); - final String result = LineageUtils.toLineageStruct(lineageInfo, typeRegistry); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put(AtlasClient.RESULTS, new JSONObject(result)); - - return Response.ok(response).build(); - } catch (AtlasBaseException e) { - LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e)); - } catch (WebApplicationException e) { - LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e); - throw e; - } catch (JSONException e) { - LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== LineageResource.outputsGraph({})", guid); - } - } - } - - /** - * Returns the schema for the given dataset id. - * - * @param guid dataset entity id - */ - @GET - @Path("{guid}/schema") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response schema(@PathParam("guid") String guid) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> LineageResource.schema({})", guid); - } - - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.schema(" + guid + ")"); - } - - final String jsonResult = lineageService.getSchemaForEntity(guid); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put(AtlasClient.RESULTS, new JSONObject(jsonResult)); - - return Response.ok(response).build(); - } catch (SchemaNotFoundException e) { - LOG.error("schema not found for {}", guid); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); - } catch (EntityNotFoundException e) { - LOG.error("table entity not found for {}", guid); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get schema for entity guid={}", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get schema for entity guid={}", guid, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get schema for entity={}", guid, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== LineageResource.schema({})", guid); - } - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java deleted file mode 100755 index d7c66d3..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java +++ /dev/null @@ -1,409 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.web.resources; - -import com.google.common.base.Preconditions; -import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasConfiguration; -import org.apache.atlas.classification.InterfaceAudience; -import org.apache.atlas.discovery.DiscoveryException; -import org.apache.atlas.discovery.DiscoveryService; -import org.apache.atlas.query.QueryParams; -import org.apache.atlas.utils.AtlasPerfTracer; -import org.apache.atlas.utils.ParamChecker; -import org.apache.atlas.web.util.Servlets; -import org.apache.commons.configuration.Configuration; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; -import java.util.List; -import java.util.Map; - -/** - * Jersey Resource for metadata operations. - */ -@Path("discovery") -@Singleton -@Service -@Deprecated -public class MetadataDiscoveryResource { - - private static final Logger LOG = LoggerFactory.getLogger(MetadataDiscoveryResource.class); - private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.MetadataDiscoveryResource"); - private static final String QUERY_TYPE_DSL = "dsl"; - private static final String QUERY_TYPE_GREMLIN = "gremlin"; - private static final String QUERY_TYPE_FULLTEXT = "full-text"; - private static final String LIMIT_OFFSET_DEFAULT = "-1"; - - private final DiscoveryService discoveryService; - - private final boolean gremlinSearchEnabled; - private static Configuration applicationProperties = null; - private static final String ENABLE_GREMLIN_SEARCH_PROPERTY = "atlas.search.gremlin.enable"; - - /** - * Created by the Guice ServletModule and injected with the - * configured DiscoveryService. - * - * @param discoveryService metadata service handle - */ - @Inject - public MetadataDiscoveryResource(DiscoveryService discoveryService, Configuration configuration) { - this.discoveryService = discoveryService; - applicationProperties = configuration; - gremlinSearchEnabled = applicationProperties != null && applicationProperties.getBoolean(ENABLE_GREMLIN_SEARCH_PROPERTY, false); - } - - /** - * Search using a given query. - * - * @param query search query in DSL format falling back to full text. - * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value - * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0 - * @return JSON representing the type and results. - */ - @GET - @Path("search") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response search(@QueryParam("query") String query, - @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, - @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) { - boolean dslQueryFailed = false; - Response response = null; - try { - response = searchUsingQueryDSL(query, limit, offset); - if (response.getStatus() != Response.Status.OK.getStatusCode()) { - dslQueryFailed = true; - } - } catch (Exception e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Error while running DSL. Switching to fulltext for query {}", query, e); - } - - dslQueryFailed = true; - } - - if ( dslQueryFailed ) { - response = searchUsingFullText(query, limit, offset); - } - - return response; - } - - /** - * Search using query DSL format. - * - * @param dslQuery search query in DSL format. - * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value - * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0 - * Limit and offset in API are used in conjunction with limit and offset in DSL query - * Final limit = min(API limit, max(query limit - API offset, 0)) - * Final offset = API offset + query offset - * - * @return JSON representing the type and results. - */ - @GET - @Path("search/dsl") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery, - @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, - @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset); - } - - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingQueryDSL(" + dslQuery + ", " + limit + ", " + offset + ")"); - } - - dslQuery = ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null"); - QueryParams queryParams = validateQueryParams(limit, offset); - final String jsonResultStr = discoveryService.searchByDSL(dslQuery, queryParams); - - JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build(); - - return Response.ok(response).build(); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset); - } - } - } - - private QueryParams validateQueryParams(int limitParam, int offsetParam) { - int maxLimit = AtlasConfiguration.SEARCH_MAX_LIMIT.getInt(); - int defaultLimit = AtlasConfiguration.SEARCH_DEFAULT_LIMIT.getInt(); - - int limit = defaultLimit; - boolean limitSet = (limitParam != Integer.valueOf(LIMIT_OFFSET_DEFAULT)); - if (limitSet) { - ParamChecker.lessThan(limitParam, maxLimit, "limit"); - ParamChecker.greaterThan(limitParam, 0, "limit"); - limit = limitParam; - } - - int offset = 0; - boolean offsetSet = (offsetParam != Integer.valueOf(LIMIT_OFFSET_DEFAULT)); - if (offsetSet) { - ParamChecker.greaterThan(offsetParam, -1, "offset"); - offset = offsetParam; - } - - return new QueryParams(limit, offset); - } - - /** - * Search using raw gremlin query format. - * - * @param gremlinQuery search query in raw gremlin format. - * @return JSON representing the type and results. - */ - @GET - @Path("search/gremlin") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - @InterfaceAudience.Private - public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> MetadataDiscoveryResource.searchUsingGremlinQuery({})", gremlinQuery); - } - - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingGremlinQuery(" + gremlinQuery + ")"); - } - - if (!gremlinSearchEnabled) { - throw new DiscoveryException("Gremlin search is not enabled."); - } - - gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty"); - final List<Map<String, String>> results = discoveryService.searchByGremlin(gremlinQuery); - - JSONObject response = new JSONObject(); - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put(AtlasClient.QUERY, gremlinQuery); - response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN); - - JSONArray list = new JSONArray(); - for (Map<String, String> result : results) { - list.put(new JSONObject(result)); - } - response.put(AtlasClient.RESULTS, list); - response.put(AtlasClient.COUNT, list.length()); - - return Response.ok(response).build(); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== MetadataDiscoveryResource.searchUsingGremlinQuery({})", gremlinQuery); - } - } - } - - /** - * Search using full text search. - * - * @param query search query. - * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value - * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0 - * @return JSON representing the type and results. - */ - @GET - @Path("search/fulltext") - @Consumes(Servlets.JSON_MEDIA_TYPE) - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response searchUsingFullText(@QueryParam("query") String query, - @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, - @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset); - } - - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingFullText(" + query + ", " + limit + ", " + offset + ")"); - } - - query = ParamChecker.notEmpty(query, "query cannot be null or empty"); - QueryParams queryParams = validateQueryParams(limit, offset); - final String jsonResultStr = discoveryService.searchByFullText(query, queryParams); - JSONArray rowsJsonArr = new JSONArray(jsonResultStr); - - JSONObject response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build(); - return Response.ok(response).build(); - } catch (DiscoveryException | IllegalArgumentException e) { - LOG.error("Unable to get entity list for query {}", query, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); - } catch (WebApplicationException e) { - LOG.error("Unable to get entity list for query {}", query, e); - throw e; - } catch (Throwable e) { - LOG.error("Unable to get entity list for query {}", query, e); - throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); - } finally { - AtlasPerfTracer.log(perf); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset); - } - } - } - - private class JsonResponseBuilder { - - protected int count = 0; - protected String query; - protected String queryType; - protected JSONObject response; - - JsonResponseBuilder() { - this.response = new JSONObject(); - } - - protected JsonResponseBuilder count(int count) { - this.count = count; - return this; - } - - public JsonResponseBuilder query(String query) { - this.query = query; - return this; - } - - public JsonResponseBuilder queryType(String queryType) { - this.queryType = queryType; - return this; - } - - protected JSONObject build() throws JSONException { - - Preconditions.checkNotNull(query, "Query cannot be null"); - Preconditions.checkNotNull(queryType, "Query Type must be specified"); - Preconditions.checkArgument(count >= 0, "Search Result count should be > 0"); - - response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); - response.put(AtlasClient.QUERY, query); - response.put(AtlasClient.QUERY_TYPE, queryType); - response.put(AtlasClient.COUNT, count); - return response; - } - } - - private class DSLJSONResponseBuilder extends JsonResponseBuilder { - - DSLJSONResponseBuilder() { - super(); - } - - private JSONObject dslResults; - - public DSLJSONResponseBuilder results(JSONObject dslResults) { - this.dslResults = dslResults; - return this; - } - - public DSLJSONResponseBuilder results(String dslResults) throws JSONException { - return results(new JSONObject(dslResults)); - } - - @Override - public JSONObject build() throws JSONException { - Preconditions.checkNotNull(dslResults); - JSONArray rowsJsonArr = dslResults.getJSONArray(AtlasClient.ROWS); - count(rowsJsonArr.length()); - queryType(QUERY_TYPE_DSL); - JSONObject response = super.build(); - response.put(AtlasClient.RESULTS, rowsJsonArr); - response.put(AtlasClient.DATATYPE, dslResults.get(AtlasClient.DATATYPE)); - return response; - } - - } - - private class FullTextJSonResponseBuilder extends JsonResponseBuilder { - - private JSONArray fullTextResults; - - public FullTextJSonResponseBuilder results(JSONArray fullTextResults) { - this.fullTextResults = fullTextResults; - return this; - } - - public FullTextJSonResponseBuilder results(String dslResults) throws JSONException { - return results(new JSONArray(dslResults)); - } - - public FullTextJSonResponseBuilder() { - super(); - } - - @Override - public JSONObject build() throws JSONException { - Preconditions.checkNotNull(fullTextResults); - count(fullTextResults.length()); - queryType(QUERY_TYPE_FULLTEXT); - - JSONObject response = super.build(); - response.put(AtlasClient.RESULTS, fullTextResults); - return response; - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java index a9c5509..8225936 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java @@ -23,10 +23,10 @@ import com.sun.jersey.api.core.ResourceContext; import org.apache.atlas.AtlasClient; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.model.v1.typedef.TypesDef; import org.apache.atlas.store.AtlasTypeDefStore; +import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.typesystem.TypesDef; -import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.repository.converters.TypeConverterUtil; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.web.rest.TypesREST; @@ -237,7 +237,7 @@ public class TypesResource { try { TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);; - String typeDefinition = TypesSerialization.toJson(typesDef); + String typeDefinition = AtlasType.toV1Json(typesDef); response.put(AtlasClient.TYPENAME, typeName); response.put(AtlasClient.DEFINITION, new JSONObject(typeDefinition)); http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/main/java/org/apache/atlas/web/util/LineageUtils.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/util/LineageUtils.java b/webapp/src/main/java/org/apache/atlas/web/util/LineageUtils.java index ad2a697..e653328 100644 --- a/webapp/src/main/java/org/apache/atlas/web/util/LineageUtils.java +++ b/webapp/src/main/java/org/apache/atlas/web/util/LineageUtils.java @@ -23,13 +23,11 @@ import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.lineage.AtlasLineageInfo; import org.apache.atlas.model.typedef.AtlasBaseTypeDef; -import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.apache.atlas.model.v1.instance.Struct; +import org.apache.atlas.repository.Constants; import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.typesystem.Struct; -import org.apache.atlas.typesystem.json.InstanceSerialization; -import org.apache.atlas.typesystem.types.TypeSystem; import java.util.ArrayList; import java.util.HashMap; @@ -38,8 +36,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX; -import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX; public final class LineageUtils { private LineageUtils() {} @@ -66,11 +62,10 @@ public final class LineageUtils { if (isDataSet(entityHeader.getTypeName(), registry)) { Map<String, Object> vertexIdMap = new HashMap<>(); - TypeSystem.IdType idType = TypeSystem.getInstance().getIdType(); - vertexIdMap.put(idType.idAttrName(), guid); - vertexIdMap.put(idType.stateAttrName(), (entityHeader.getStatus() == AtlasEntity.Status.ACTIVE) ? "ACTIVE" : "DELETED"); - vertexIdMap.put(idType.typeNameAttrName(), entityHeader.getTypeName()); + vertexIdMap.put(Constants.ATTRIBUTE_NAME_GUID, guid); + vertexIdMap.put(Constants.ATTRIBUTE_NAME_STATE, (entityHeader.getStatus() == AtlasEntity.Status.ACTIVE) ? "ACTIVE" : "DELETED"); + vertexIdMap.put(Constants.ATTRIBUTE_NAME_TYPENAME, entityHeader.getTypeName()); Object qualifiedName = entityHeader.getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME); if (qualifiedName == null) { @@ -110,7 +105,7 @@ public final class LineageUtils { map.put(VERTICES_ATTR_NAME, verticesMap); map.put(EDGES_ATTR_NAME, edgesMap); - ret = InstanceSerialization.toJson(constructResultStruct(map, false), false); + ret = AtlasType.toV1Json(constructResultStruct(map, false)); } return ret; @@ -121,7 +116,7 @@ public final class LineageUtils { return new Struct(TEMP_STRUCT_ID_RESULT, values); } - return new Struct(org.apache.atlas.query.TypeUtils.TEMP_STRUCT_NAME_PREFIX() + COUNTER.getAndIncrement(), values); + return new Struct(Constants.TEMP_STRUCT_NAME_PREFIX + COUNTER.getAndIncrement(), values); } private static boolean isDataSet(String typeName, AtlasTypeRegistry registry) throws AtlasBaseException { http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java b/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java index 592c2a6..8461ba3 100644 --- a/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java +++ b/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java @@ -20,8 +20,8 @@ package org.apache.atlas.examples; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasServiceException; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.persistence.Id; +import org.apache.atlas.model.v1.instance.Id; +import org.apache.atlas.model.v1.instance.Referenceable; import org.apache.atlas.web.integration.BaseResourceIT; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException;