use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.
the class BasicTestSetup method loadEmployeeDataset.
protected void loadEmployeeDataset() {
if (!baseLoaded) {
loadBaseModels();
}
// Define employee dataset types
AtlasTypesDef employeeTypes = TestUtilsV2.defineDeptEmployeeTypes();
try {
typeDefStore.createTypesDef(employeeTypes);
} catch (AtlasBaseException e) {
fail("Employee Type setup is required");
}
// Define entities for department
AtlasEntity.AtlasEntitiesWithExtInfo deptEg2 = TestUtilsV2.createDeptEg2();
try {
entityStore.createOrUpdate(new AtlasEntityStream(deptEg2), false);
} catch (AtlasBaseException e) {
fail("Employee entity setup should've passed");
}
}
use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.
the class DSLQueriesTest method pollForData.
private void pollForData() throws InterruptedException {
Object[][] basicVerificationQueries = new Object[][] { { "hive_db", 3 }, { "hive_process", 7 }, { "hive_table", 10 }, { "hive_column", 17 }, { "hive_storagedesc", 1 }, { "Manager", 2 }, { "Employee", 4 } };
int pollingAttempts = 5;
// in msecs
int pollingBackoff = 0;
boolean success;
for (int attempt = 0; attempt < pollingAttempts; attempt++, pollingBackoff += attempt * 5000) {
LOG.debug("Polling -- Attempt {}, Backoff {}", attempt, pollingBackoff);
success = false;
for (Object[] verificationQuery : basicVerificationQueries) {
String query = (String) verificationQuery[0];
int expected = (int) verificationQuery[1];
try {
AtlasSearchResult result = discoveryService.searchUsingDslQuery(query, 25, 0);
if (result.getEntities() == null || result.getEntities().isEmpty()) {
LOG.warn("DSL {} returned no entities", query);
success = false;
} else if (result.getEntities().size() != expected) {
LOG.warn("DSL {} returned unexpected number of entities. Expected {} Actual {}", query, expected, result.getEntities().size());
success = false;
} else {
success = true;
}
} catch (AtlasBaseException e) {
LOG.error("Got exception for DSL {}, errorCode: {}", query, e.getAtlasErrorCode());
waitOrBailout(pollingAttempts, pollingBackoff, attempt);
}
}
// DSL queries were successful
if (success) {
LOG.info("Polling was success");
break;
} else {
waitOrBailout(pollingAttempts, pollingBackoff, attempt);
}
}
}
use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.
the class AtlasArrayFormatConverter method isValidValueV1.
@Override
public boolean isValidValueV1(Object v1Obj, AtlasType type) {
boolean ret = false;
if (v1Obj == null) {
return true;
}
if (type instanceof AtlasArrayType) {
AtlasArrayType arrType = (AtlasArrayType) type;
AtlasType elemType = arrType.getElementType();
AtlasFormatConverter elemConverter = null;
try {
elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
} catch (AtlasBaseException excp) {
LOG.warn("failed to get element converter. type={}", type.getTypeName(), excp);
ret = false;
}
if (elemConverter != null) {
if (v1Obj instanceof Collection) {
// for empty array
ret = true;
for (Object v1Elem : (Collection) v1Obj) {
ret = elemConverter.isValidValueV1(v1Elem, elemType);
if (!ret) {
break;
}
}
} else {
ret = elemConverter.isValidValueV1(v1Obj, elemType);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("AtlasArrayFormatConverter.isValidValueV1(type={}, value={}): {}", (v1Obj != null ? v1Obj.getClass().getCanonicalName() : null), v1Obj, ret);
}
return ret;
}
use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.
the class AtlasInstanceConverter method toAtlasEntities.
public AtlasEntitiesWithExtInfo toAtlasEntities(String[] jsonEntities) throws AtlasBaseException, AtlasException {
Referenceable[] referenceables = new Referenceable[jsonEntities.length];
for (int i = 0; i < jsonEntities.length; i++) {
referenceables[i] = AtlasType.fromV1Json(jsonEntities[i], Referenceable.class);
}
AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
ConverterContext context = new ConverterContext();
for (Referenceable referenceable : referenceables) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());
if (entityType == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
}
AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, context);
context.addEntity(entity);
}
AtlasEntitiesWithExtInfo ret = context.getEntities();
return ret;
}
use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.
the class AtlasObjectIdConverter method fromV2ToV1.
@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
Id ret = null;
if (v2Obj != null) {
if (v2Obj instanceof Map) {
Map v2Map = (Map) v2Obj;
String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
String typeName = (String) v2Map.get(AtlasObjectId.KEY_TYPENAME);
if (StringUtils.isEmpty(idStr)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
ret = new Id(idStr, 0, typeName);
} else if (v2Obj instanceof AtlasObjectId) {
// transient-id
AtlasObjectId objId = (AtlasObjectId) v2Obj;
ret = new Id(objId.getGuid(), 0, objId.getTypeName());
} else if (v2Obj instanceof AtlasEntity) {
AtlasEntity entity = (AtlasEntity) v2Obj;
ret = new Id(entity.getGuid(), entity.getVersion() == null ? 0 : entity.getVersion().intValue(), entity.getTypeName());
} else {
throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
}
}
return ret;
}
Aggregations