Search in sources :

Example 36 with AtlasException

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

the class StructInstance method setFloat.

public void setFloat(String attrName, float val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.FLOAT_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.FLOAT_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = false;
    floats[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 37 with AtlasException

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

the class AtlasServerIdSelector method selectServerId.

/**
 * Return the ID corresponding to this Atlas instance.
 *
 * The match is done by looking for an ID configured in {@link HAConfiguration#ATLAS_SERVER_IDS} key
 * that has a host:port entry for the key {@link HAConfiguration#ATLAS_SERVER_ADDRESS_PREFIX}+ID where
 * the host is a local IP address and port is set in the system property
 * {@link AtlasConstants#SYSTEM_PROPERTY_APP_PORT}.
 *
 * @param configuration
 * @return
 * @throws AtlasException if no ID is found that maps to a local IP Address or port
 */
public static String selectServerId(Configuration configuration) throws AtlasException {
    // ids are already trimmed by this method
    String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS);
    String matchingServerId = null;
    int appPort = Integer.parseInt(System.getProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT));
    for (String id : ids) {
        String hostPort = configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + id);
        if (!StringUtils.isEmpty(hostPort)) {
            InetSocketAddress socketAddress;
            try {
                socketAddress = NetUtils.createSocketAddr(hostPort);
            } catch (Exception e) {
                LOG.warn("Exception while trying to get socket address for {}", hostPort, e);
                continue;
            }
            if (!socketAddress.isUnresolved() && NetUtils.isLocalAddress(socketAddress.getAddress()) && appPort == socketAddress.getPort()) {
                LOG.info("Found matched server id {} with host port: {}", id, hostPort);
                matchingServerId = id;
                break;
            }
        } else {
            LOG.info("Could not find matching address entry for id: {}", id);
        }
    }
    if (matchingServerId == null) {
        String msg = String.format("Could not find server id for this instance. " + "Unable to find IDs matching any local host and port binding among %s", StringUtils.join(ids, ","));
        throw new AtlasException(msg);
    }
    return matchingServerId;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AtlasException(org.apache.atlas.AtlasException) AtlasException(org.apache.atlas.AtlasException)

Example 38 with AtlasException

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

the class StructInstance method setBigInt.

public void setBigInt(String attrName, BigInteger val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.BIGINTEGER_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.BIGINTEGER_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = val == null;
    bigIntegers[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 39 with AtlasException

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

the class StructInstance method getDouble.

public double getDouble(String attrName) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.DOUBLE_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic get method", attrName, getTypeName(), DataTypes.DOUBLE_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    if (nullFlags[nullPos]) {
        return DataTypes.DOUBLE_TYPE.nullValue();
    }
    return doubles[pos];
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 40 with AtlasException

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

the class StructInstance method setLong.

public void setLong(String attrName, long val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.LONG_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.LONG_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = false;
    longs[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AtlasException (org.apache.atlas.AtlasException)139 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)36 IOException (java.io.IOException)27 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 Configuration (org.apache.commons.configuration.Configuration)19 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)14 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 ArrayList (java.util.ArrayList)12 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)10 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 HashMap (java.util.HashMap)8 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 Properties (java.util.Properties)7 File (java.io.File)6 InputStream (java.io.InputStream)6 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)6