final String qualifiedName = toStr(entity.getAttribute(ATTR_QUALIFIED_NAME)); if (StringUtils.isEmpty(guid)) { logger.warn("GUID was not assigned for {}::{} for some reason.", entity.getTypeName(), qualifiedName); continue; switch (entity.getTypeName()) { case TYPE_NIFI_INPUT_PORT: entityMap = nifiFlow.getRootInputPortEntities(); break; default: throw new RuntimeException(entity.getTypeName() + " is not expected."); final AtlasObjectId idWithGuid = new AtlasObjectId(guid, entity.getTypeName(), Collections.singletonMap(ATTR_QUALIFIED_NAME, qualifiedName)); entityMap.put(idWithGuid, entity); .filter(entry -> !DELETED.equals(entry.getKey())) .flatMap(entry -> entry.getValue().stream()) .filter(entity -> changedTypeNames.contains(entity.getTypeName())) .collect(Collectors.groupingBy(AtlasEntity::getTypeName));
private AtlasEntity createOrUpdateRootGroupPortEntity(boolean isInput, String qualifiedName, String portName) { final Map<AtlasObjectId, AtlasEntity> ports = isInput ? rootInputPortEntities : rootOutputPortEntities; final Optional<AtlasObjectId> existingPortId = findIdByQualifiedName(ports.keySet(), qualifiedName); final String typeName = isInput ? TYPE_NIFI_INPUT_PORT : TYPE_NIFI_OUTPUT_PORT; if (existingPortId.isPresent()) { final AtlasEntity entity = ports.get(existingPortId.get()); final String portGuid = entity.getGuid(); stillExistingEntityGuids.add(portGuid); final Object currentName = entity.getAttribute(ATTR_NAME); if (isUpdated(currentName, portName)) { // Update port name and set updated flag. entity.setAttribute(ATTR_NAME, portName); updatedEntityGuids.add(portGuid); updateAudit.add(String.format("Name of %s %s changed from %s to %s", entity.getTypeName(), portGuid, currentName, portName)); } return entity; } else { final AtlasEntity entity = new AtlasEntity(typeName); entity.setAttribute(ATTR_NIFI_FLOW, getAtlasObjectId()); entity.setAttribute(ATTR_NAME, portName); entity.setAttribute(ATTR_QUALIFIED_NAME, qualifiedName); final AtlasObjectId portId = new AtlasObjectId(typeName, ATTR_QUALIFIED_NAME, qualifiedName); ports.put(portId, entity); return entity; } }
private void addAttributeTypes(AtlasStructType structType, ExportContext context) { for (AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { addType(attributeDef.getTypeName(), context); } }
public static AtlasObjectId getObjectId(AtlasEntity entity) { String qualifiedName = (String) entity.getAttribute(ATTRIBUTE_QUALIFIED_NAME); AtlasObjectId ret = new AtlasObjectId(entity.getGuid(), entity.getTypeName(), Collections.singletonMap(ATTRIBUTE_QUALIFIED_NAME, qualifiedName)); return ret; }
private void mapRelationshipAttributes(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (entityType == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, entity.getTypeName()); } for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { Object attrValue = mapVertexToRelationshipAttribute(entityVertex, entityType, attribute); entity.setRelationshipAttribute(attribute.getName(), attrValue); } }
public void setAttribute(EntityAttribute attribute, String attributeValue) { if (attribute.appliesToEntityType(entity.getTypeName())) { entity.setAttribute(attribute.getAttributeName(), attributeValue); } }
@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; }
private void addTypes(AtlasEntity entity, ExportContext context) { addEntityType(entity.getTypeName(), context); if(CollectionUtils.isNotEmpty(entity.getClassifications())) { for (AtlasClassification c : entity.getClassifications()) { addClassificationType(c.getTypeName(), context); } } }
@Test public void testEntityTypeDefaultValue() { AtlasEntity defValue = entityType.createDefaultValue(); assertNotNull(defValue); assertEquals(defValue.getTypeName(), entityType.getTypeName()); }
@Test public void testEntityTypeDefaultValue() { AtlasEntity defValue = entityType.createDefaultValue(); assertNotNull(defValue); assertEquals(defValue.getTypeName(), entityType.getTypeName()); }
private 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; }
private 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; }
private void verifyExportForHrDataForConnected(ZipSource zipSource) throws IOException, AtlasBaseException { assertNotNull(zipSource.getCreationOrder()); assertTrue(zipSource.getCreationOrder().size() == 2); assertTrue(zipSource.hasNext()); AtlasEntity entity = zipSource.next(); assertNotNull(entity); assertTrue(entity.getTypeName().equals("Department")); assertEquals(entity.getStatus(), AtlasEntity.Status.ACTIVE); verifyTypeDefs(zipSource); }
private void verifyExportForFullEmployeeData(ZipSource zipSource) throws AtlasBaseException { final List<String> expectedEntityTypes = Arrays.asList(new String[]{"Manager", "Employee", "Department"}); assertNotNull(zipSource.getCreationOrder()); assertTrue(zipSource.hasNext()); while (zipSource.hasNext()) { AtlasEntity entity = zipSource.next(); assertNotNull(entity); assertEquals(AtlasEntity.Status.ACTIVE, entity.getStatus()); assertTrue(expectedEntityTypes.contains(entity.getTypeName())); } verifyTypeDefs(zipSource); }
private void assertApplyTransform(List<BaseEntityHandler> handlers) { for (AtlasEntity entity : getAllEntities()) { applyTransforms(entity, handlers); if(entity.getTypeName().equals("hive_db") && entity.getAttribute("qualifiedName").equals("hr@cl1")) { assertNotNull(entity.getClassifications()); } else{ assertNull(entity.getClassifications()); } } }
private AtlasEntityHeader constructHeader(AtlasEntity entity, final AtlasEntityType type, AtlasVertex vertex) { AtlasEntityHeader header = new AtlasEntityHeader(entity.getTypeName()); header.setGuid(getIdFromVertex(vertex)); for (AtlasAttribute attribute : type.getUniqAttributes().values()) { header.setAttribute(attribute.getName(), entity.getAttribute(attribute.getName())); } return header; }
private void renameStorageDesc(AtlasEntityWithExtInfo oldEntityExtInfo, AtlasEntityWithExtInfo newEntityExtInfo, List<HookNotification> notifications) { AtlasEntity oldSd = getStorageDescEntity(oldEntityExtInfo); AtlasEntity newSd = getStorageDescEntity(newEntityExtInfo); if (oldSd != null && newSd != null) { AtlasObjectId oldSdId = new AtlasObjectId(oldSd.getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldSd.getAttribute(ATTRIBUTE_QUALIFIED_NAME)); newSd.removeAttribute(ATTRIBUTE_TABLE); notifications.add(new EntityPartialUpdateRequestV2(getUserName(), oldSdId, new AtlasEntityWithExtInfo(newSd))); } }
private float updateImportMetrics(AtlasEntity.AtlasEntityWithExtInfo currentEntity, EntityMutationResponse resp, AtlasImportResult importResult, Set<String> processedGuids, int currentIndex, int streamSize, float currentPercent) { updateImportMetrics("entity:%s:created", resp.getCreatedEntities(), processedGuids, importResult); updateImportMetrics("entity:%s:updated", resp.getUpdatedEntities(), processedGuids, importResult); updateImportMetrics("entity:%s:deleted", resp.getDeletedEntities(), processedGuids, importResult); String lastEntityImported = String.format("entity:last-imported:%s:[%s]:(%s)", currentEntity.getEntity().getTypeName(), currentIndex, currentEntity.getEntity().getGuid()); return updateImportProgress(LOG, currentIndex, streamSize, currentPercent, lastEntityImported); }
private float updateImportMetrics(AtlasEntity.AtlasEntityWithExtInfo currentEntity, EntityMutationResponse resp, AtlasImportResult importResult, Set<String> processedGuids, int currentIndex, int streamSize, float currentPercent) { updateImportMetrics("entity:%s:created", resp.getCreatedEntities(), processedGuids, importResult); updateImportMetrics("entity:%s:updated", resp.getUpdatedEntities(), processedGuids, importResult); updateImportMetrics("entity:%s:deleted", resp.getDeletedEntities(), processedGuids, importResult); String lastEntityImported = String.format("entity:last-imported:%s:[%s]:(%s)", currentEntity.getEntity().getTypeName(), currentIndex, currentEntity.getEntity().getGuid()); return updateImportProgress(LOG, currentIndex + 1, streamSize, currentPercent, lastEntityImported); }
private void addNewRegions(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) throws AtlasBaseException { Map map = (Map) entityWithExtInfo.getEntity().getAttribute(RDBMS_DB_REGIONS_PROPERTY); AtlasEntity region1 = getDefaultTableEntity("r1"); AtlasEntity region2 = getDefaultTableEntity("r2"); map.put("north", new AtlasObjectId(region1.getGuid(), region1.getTypeName())); map.put("south", new AtlasObjectId(region2.getGuid(), region2.getTypeName())); entityWithExtInfo.addReferredEntity(region1); entityWithExtInfo.addReferredEntity(region2); }