@Override public AtlasClientV2 createClient(String[] baseUrls) { return new AtlasClientV2(baseUrls, new String[]{user, password}); } }
? atlasClient.updateAtlasTypeDefs(type) : atlasClient.createAtlasTypeDefs(type); logger.debug("Result={}", atlasTypeDefsResult);
public AtlasEntity.AtlasEntityWithExtInfo searchEntityDef(AtlasObjectId id) throws AtlasServiceException { final String guid = id.getGuid(); if (!StringUtils.isEmpty(guid)) { return atlasClient.getEntityByGuid(guid); } final Map<String, String> attributes = new HashMap<>(); id.getUniqueAttributes().entrySet().stream().filter(entry -> entry.getValue() != null) .forEach(entry -> attributes.put(entry.getKey(), entry.getValue().toString())); return atlasClient.getEntityByAttribute(id.getTypeName(), attributes); }
void createTypes() throws Exception { AtlasTypesDef atlasTypesDef = createTypeDefinitions(); System.out.println("\nCreating sample types: "); atlasClientV2.createAtlasTypeDefs(atlasTypesDef); verifyTypesCreated(); }
private AtlasEntity createInstance(AtlasEntity entity, String[] traitNames) throws Exception { AtlasEntity ret = null; EntityMutationResponse response = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(entity)); List<AtlasEntityHeader> entities = response.getEntitiesByOperation(EntityOperation.CREATE); if (CollectionUtils.isNotEmpty(entities)) { AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid()); ret = getByGuidResponse.getEntity(); System.out.println("Created entity of type [" + ret.getTypeName() + "], guid: " + ret.getGuid()); } return ret; }
public EntityMutationResponse updateEntityByAttribute(String type, Map<String, String> attributes, AtlasEntityWithExtInfo entityInfo) throws AtlasServiceException { MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes); return callAPI(API_V2.UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type); }
public boolean typeWithGuidExists(String guid) { try { callAPI(API_V2.GET_TYPEDEF_BY_GUID, String.class, null, guid); } catch (AtlasServiceException e) { return false; } return true; }
@VisibleForTesting AtlasEntityWithExtInfo updateEntityInAtlas(AtlasEntityWithExtInfo entity) throws Exception { AtlasEntityWithExtInfo ret = null; EntityMutationResponse response = atlasClientV2.updateEntity(entity); if (response != null) { List<AtlasEntityHeader> entities = response.getUpdatedEntities(); if (CollectionUtils.isNotEmpty(entities)) { AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid()); ret = getByGuidResponse; LOG.info("Updated {} entity: name={}, guid={} ", ret.getEntity().getTypeName(), ret.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), ret.getEntity().getGuid()); } else { LOG.info("Entity: name={} ", entity.toString() + " not updated as it is unchanged from what is in Atlas" ); ret = entity; } } else { LOG.info("Entity: name={} ", entity.toString() + " not updated as it is unchanged from what is in Atlas" ); ret = entity; } return ret; }
private <T> T getTypeDefByGuid(final String guid, Class<T> typeDefClass) throws AtlasServiceException { String atlasPath = getAtlasPath(typeDefClass); API api = new API(String.format(GET_BY_GUID_TEMPLATE, atlasPath, guid), HttpMethod.GET, Response.Status.OK); return callAPI(api, typeDefClass, null); }
private AtlasEntityWithExtInfo findEntityInAtlas(String typeName, String qualifiedName) throws Exception { Map<String, String> attributes = Collections.singletonMap(QUALIFIED_NAME, qualifiedName); return atlasClientV2.getEntityByAttribute(typeName, attributes); }
public AtlasEnumDef getEnumDefByGuid(final String guid) throws AtlasServiceException { return getTypeDefByGuid(guid, AtlasEnumDef.class); }
public void deleteClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException { for (AtlasClassification c : classifications) { callAPI(formatPathParameters(API_V2.DELETE_CLASSIFICATION, guid, c.getTypeName()), AtlasClassifications.class, classifications); } }
private AtlasTypesDef getTypeDefs(String ... typeNames) throws AtlasServiceException { final AtlasTypesDef typeDefs = new AtlasTypesDef(); for (int i = 0; i < typeNames.length; i++) { final MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl(); searchParams.add(SearchFilter.PARAM_NAME, typeNames[i]); final AtlasTypesDef typeDef = atlasClient.getAllTypeDefs(new SearchFilter(searchParams)); typeDefs.getEntityDefs().addAll(typeDef.getEntityDefs()); } logger.debug("typeDefs={}", typeDefs); return typeDefs; }
private MultivaluedMap<String, String> attributesToQueryParams(Map<String, String> attributes) { return attributesToQueryParams(attributes, null); }
@Deprecated public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException { AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getStructDefs().add(structDef); AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); assert created != null; assert created.getStructDefs() != null; return created.getStructDefs().get(0); }
@VisibleForTesting AtlasEntityWithExtInfo createEntityInAtlas(AtlasEntityWithExtInfo entity) throws Exception { AtlasEntityWithExtInfo ret = null; EntityMutationResponse response = atlasClientV2.createEntity(entity); List<AtlasEntityHeader> entities = response.getCreatedEntities(); if (CollectionUtils.isNotEmpty(entities)) { AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid()); ret = getByGuidResponse; LOG.info("Created {} entity: name={}, guid={}", ret.getEntity().getTypeName(), ret.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), ret.getEntity().getGuid()); } return ret; }
public EntityMutationResponse updateEntityByAttribute(String type, Map<String, String> attributes, AtlasEntityWithExtInfo entityInfo) throws AtlasServiceException { MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes); return callAPI(UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type); }
public boolean typeWithNameExists(String name) { try { callAPI(API_V2.GET_TYPEDEF_BY_NAME, String.class, null, name); } catch (AtlasServiceException e) { return false; } return true; }
private AtlasEntityWithExtInfo updateEntityInAtlas(AtlasEntityWithExtInfo entity) throws Exception { AtlasEntityWithExtInfo ret = null; EntityMutationResponse response = atlasClientV2.updateEntity(entity); if (response != null) { List<AtlasEntityHeader> entities = response.getUpdatedEntities(); if (CollectionUtils.isNotEmpty(entities)) { AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid()); ret = getByGuidResponse; LOG.info("Updated {} entity: name={}, guid={} ", ret.getEntity().getTypeName(), ret.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), ret.getEntity().getGuid()); } else { LOG.info("Entity: name={} ", entity.toString() + " not updated as it is unchanged from what is in Atlas" ); ret = entity; } } else { LOG.info("Entity: name={} ", entity.toString() + " not updated as it is unchanged from what is in Atlas" ); ret = entity; } return ret; }
private <T> T getTypeDefByName(final String name, Class<T> typeDefClass) throws AtlasServiceException { String atlasPath = getAtlasPath(typeDefClass); API api = new API(String.format(GET_BY_NAME_TEMPLATE, atlasPath, name), HttpMethod.GET, Response.Status.OK); return callAPI(api, typeDefClass, null); }