Search in sources :

Example 91 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityREST method deleteClassification.

/**
 * Deletes a given classification from an existing entity represented by a guid.
 * @param guid      globally unique identifier for the entity
 * @param classificationName name of the classifcation
 */
@DELETE
@Path("/guid/{guid}/classification/{classificationName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteClassification(@PathParam("guid") String guid, @PathParam("classificationName") final String classificationName) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    Servlets.validateQueryParamLength("classificationName", classificationName);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteClassification(" + guid + "," + classificationName + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        ensureClassificationType(classificationName);
        entitiesStore.deleteClassifications(guid, new ArrayList<String>() {

            {
                add(classificationName);
            }
        });
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 92 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityREST method getClassification.

/**
 * Gets the list of classifications for a given entity represented by a guid.
 * @param guid globally unique identifier for the entity
 * @return classification for the given entity guid
 */
@GET
@Path("/guid/{guid}/classification/{classificationName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassification getClassification(@PathParam("guid") String guid, @PathParam("classificationName") final String classificationName) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    Servlets.validateQueryParamLength("classificationName", classificationName);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getClassification(" + guid + "," + classificationName + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        ensureClassificationType(classificationName);
        return entitiesStore.getClassification(guid, classificationName);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 93 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityREST method getClassifications.

/**
 * Gets the list of classifications for a given entity represented by a guid.
 * @param guid globally unique identifier for the entity
 * @return a list of classifications for the given entity guid
 */
@GET
@Path("/guid/{guid}/classifications")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasClassification.AtlasClassifications getClassifications(@PathParam("guid") String guid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getClassifications(" + guid + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        return new AtlasClassification.AtlasClassifications(entitiesStore.getClassifications(guid));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 94 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EntityREST method addClassifications.

/**
 * Adds classifications to an existing entity represented by a guid.
 * @param guid globally unique identifier for the entity
 */
@POST
@Path("/guid/{guid}/classifications")
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public void addClassifications(@PathParam("guid") final String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassifications(" + guid + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        entitiesStore.addClassifications(guid, classifications);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 95 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class ActiveInstanceState method update.

/**
 * Update state of the active server instance.
 *
 * This method writes this instance's Server Address to a shared node in Zookeeper.
 * This information is used by other passive instances to locate the current active server.
 * @throws Exception
 * @param serverId ID of this server instance
 */
public void update(String serverId) throws AtlasBaseException {
    try {
        CuratorFramework client = curatorFactory.clientInstance();
        HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.getZookeeperProperties(configuration);
        String atlasServerAddress = HAConfiguration.getBoundAddressForId(configuration, serverId);
        List<ACL> acls = Arrays.asList(new ACL[] { AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(), ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0)) });
        Stat serverInfo = client.checkExists().forPath(getZnodePath(zookeeperProperties));
        if (serverInfo == null) {
            client.create().withMode(CreateMode.EPHEMERAL).withACL(acls).forPath(getZnodePath(zookeeperProperties));
        }
        client.setData().forPath(getZnodePath(zookeeperProperties), atlasServerAddress.getBytes(Charset.forName("UTF-8")));
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.CURATOR_FRAMEWORK_UPDATE, e, "forPath: getZnodePath");
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Stat(org.apache.zookeeper.data.Stat) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HAConfiguration(org.apache.atlas.ha.HAConfiguration) ACL(org.apache.zookeeper.data.ACL) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 ArrayList (java.util.ArrayList)60 Test (org.testng.annotations.Test)60 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24