Commit b1717f2e by Sarath Subramanian Committed by Madhan Neethiraj

ATLAS-1602: fixed IT failures in QuickStart and issues identified in coverity scan

parent 8bb31fdf
......@@ -32,7 +32,6 @@ import javax.ws.rs.core.UriBuilder;
import org.apache.atlas.model.metrics.AtlasMetrics;
import org.apache.atlas.security.SecureClientUtils;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
......@@ -319,7 +318,6 @@ public abstract class AtlasBaseClient {
}
} else {
T entity = clientResponse.getEntity(responseType);
LOG.info("Response = {}", AtlasType.toJson(entity));
return entity;
}
} catch (ClientHandlerException e) {
......
......@@ -20,8 +20,9 @@ package org.apache.atlas;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.typesystem.TypesDef;
......@@ -259,6 +260,8 @@ public class AtlasClient extends AtlasBaseClient {
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class EntityResult {
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
public static final String OP_CREATED = "created";
public static final String OP_UPDATED = "updated";
public static final String OP_DELETED = "deleted";
......@@ -314,12 +317,10 @@ public class AtlasClient extends AtlasBaseClient {
}
@Override
public String toString() {
return AtlasType.toJson(this);
}
public String toString() { return gson.toJson(this); }
public static EntityResult fromString(String json) throws AtlasServiceException {
return AtlasType.fromJson(json, EntityResult.class);
return gson.fromJson(json, EntityResult.class);
}
}
......
......@@ -56,6 +56,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -281,24 +282,28 @@ public class AtlasInstanceConverter {
case CREATE:
List<AtlasEntityHeader> createdEntities = mutatedEntities.get(EntityOperation.CREATE);
if (CollectionUtils.isNotEmpty(createdEntities)) {
Collections.reverse(createdEntities);
entityResult.set(EntityResult.OP_CREATED, getGuids(createdEntities));
}
break;
case UPDATE:
List<AtlasEntityHeader> updatedEntities = mutatedEntities.get(EntityOperation.UPDATE);
if (CollectionUtils.isNotEmpty(updatedEntities)) {
Collections.reverse(updatedEntities);
entityResult.set(EntityResult.OP_UPDATED, getGuids(updatedEntities));
}
break;
case PARTIAL_UPDATE:
List<AtlasEntityHeader> partialUpdatedEntities = mutatedEntities.get(EntityOperation.PARTIAL_UPDATE);
if (CollectionUtils.isNotEmpty(partialUpdatedEntities)) {
Collections.reverse(partialUpdatedEntities);
entityResult.set(EntityResult.OP_UPDATED, getGuids(partialUpdatedEntities));
}
break;
case DELETE:
List<AtlasEntityHeader> deletedEntities = mutatedEntities.get(EntityOperation.DELETE);
if (CollectionUtils.isNotEmpty(deletedEntities)) {
Collections.reverse(deletedEntities);
entityResult.set(EntityResult.OP_DELETED, getGuids(deletedEntities));
}
break;
......
......@@ -350,10 +350,6 @@ public class QuickStartV2 {
System.out.println("Created entity of type [" + ret.getTypeName() + "], guid: " + ret.getGuid());
}
if (ArrayUtils.isNotEmpty(traitNames)) {
entitiesClient.addClassifications(ret.getGuid(), toAtlasClassifications(traitNames));
}
return ret;
}
......
......@@ -98,6 +98,9 @@ public class DataSetLineageResource {
} 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));
......@@ -141,6 +144,9 @@ public class DataSetLineageResource {
} 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));
......@@ -184,6 +190,9 @@ public class DataSetLineageResource {
} 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));
......
......@@ -99,7 +99,10 @@ public class LineageResource {
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, e.getAtlasErrorCode().getHttpCode()));
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));
......@@ -143,7 +146,10 @@ public class LineageResource {
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, e.getAtlasErrorCode().getHttpCode()));
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));
......@@ -192,6 +198,9 @@ public class LineageResource {
} 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));
......
......@@ -150,6 +150,9 @@ public class MetadataDiscoveryResource {
} 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));
......@@ -225,6 +228,9 @@ public class MetadataDiscoveryResource {
} 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));
......@@ -272,6 +278,9 @@ public class MetadataDiscoveryResource {
} 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));
......
......@@ -121,12 +121,12 @@ public class TypesResource {
return Response.status(ClientResponse.Status.CREATED).entity(response).build();
} catch (AtlasBaseException e) {
LOG.error("Type creation failed", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (IllegalArgumentException e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to persist types due to V2 API error", e);
LOG.error("Unable to persist types", e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to persist types", e);
......@@ -187,11 +187,14 @@ public class TypesResource {
response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
response.put(AtlasClient.TYPES, typesResponse);
return Response.ok().entity(response).build();
} catch (AtlasBaseException | IllegalArgumentException e) {
} catch (AtlasBaseException e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (IllegalArgumentException e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to persist types due to V2 API error", e);
LOG.error("Unable to persist types", e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to persist types", e);
......@@ -237,10 +240,13 @@ public class TypesResource {
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (JSONException | IllegalArgumentException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
......@@ -292,7 +298,10 @@ public class TypesResource {
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.warn("TypesREST exception: {} {}", e.getClass().getSimpleName(), e.getMessage());
throw new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
throw new WebApplicationException(Servlets.getErrorResponse(e));
} catch (WebApplicationException e) {
LOG.error("Unable to get types list", e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to get types list", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
......
......@@ -20,6 +20,7 @@ package org.apache.atlas.web.util;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.LocalServletRequest;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
......@@ -137,6 +138,13 @@ public final class Servlets {
return url.toString();
}
public static Response getErrorResponse(AtlasBaseException e) {
String message = e.getMessage() == null ? "Failed with " + e.getClass().getName() : e.getMessage();
Response response = getErrorResponse(message, e.getAtlasErrorCode().getHttpCode());
return response;
}
public static Response getErrorResponse(Throwable e, Response.Status status) {
String message = e.getMessage() == null ? "Failed with " + e.getClass().getName() : e.getMessage();
Response response = getErrorResponse(message, status);
......
......@@ -28,6 +28,7 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.web.resources.BaseResourceIT;
import org.codehaus.jettison.json.JSONException;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -35,6 +36,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
......@@ -98,13 +100,13 @@ public class QuickStartV2IT extends BaseResourceIT {
private void verifyColumnsAreAddedToTable(AtlasEntity table) throws JSONException {
Map<String, Object> tableAttributes = table.getAttributes();
List<AtlasEntity> columns = (List<AtlasEntity>) tableAttributes.get("columns");
List<Map> columns = (List<Map>) tableAttributes.get("columns");
assertEquals(4, columns.size());
Map<String, Object> column = (Map) columns.get(0);
Map<String, Object> columnAttributes = (Map) column.get("attributes");
assertEquals(QuickStartV2.TIME_ID_COLUMN, columnAttributes.get("name"));
assertEquals("int", columnAttributes.get("dataType"));
for (Map colMap : columns) {
String colGuid = (String) colMap.get("guid");
assertNotNull(UUID.fromString(colGuid));
}
}
private void verifyDBIsLinkedToTable(AtlasEntity table) throws AtlasServiceException, JSONException {
......
......@@ -69,9 +69,11 @@ public class EntityResourceTest {
EntityMutationResponse resp = new EntityMutationResponse();
List<AtlasEntityHeader> headers = toAtlasEntityHeaders(guids);
if (CollectionUtils.isNotEmpty(headers)) {
for (AtlasEntityHeader entity : headers) {
resp.addEntity(EntityMutations.EntityOperation.DELETE, entity);
}
}
when(entitiesStore.deleteByIds(guids)).thenReturn(resp);
......
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