public void setExEntity(AtlasEntity exEntity) { this.exEntity = exEntity; this.atlasGuid = exEntity.getGuid(); }
public Map<EntityChangeType, List<AtlasEntity>> getChangedDataSetEntities() { final Map<EntityChangeType, List<AtlasEntity>> changedEntities = Stream .of(rootInputPortEntities.values().stream(), rootOutputPortEntities.values().stream(), queues.values().stream()) .flatMap(Function.identity()) .collect(Collectors.groupingBy(entity -> getEntityChangeType(entity.getGuid()))); updateAudit.add("CREATED DataSet entities=" + changedEntities.get(EntityChangeType.CREATED)); updateAudit.add("UPDATED DataSet entities=" + changedEntities.get(EntityChangeType.UPDATED)); updateAudit.add("DELETED DataSet entities=" + changedEntities.get(EntityChangeType.DELETED)); return changedEntities; }
public void setExEntity(AtlasEntity exEntity) { this.exEntity = exEntity; this.setAtlasGuid(exEntity.getGuid()); }
public Tuple<AtlasObjectId, AtlasEntity> getOrCreateQueue(String destinationComponentId) { final String qualifiedName = toQualifiedName(destinationComponentId); final Optional<AtlasObjectId> existingQueueId = findIdByQualifiedName(queues.keySet(), qualifiedName); if (existingQueueId.isPresent()) { final AtlasEntity entity = queues.get(existingQueueId.get()); stillExistingEntityGuids.add(entity.getGuid()); return new Tuple<>(existingQueueId.get(), entity); } else { final AtlasObjectId queueId = new AtlasObjectId(TYPE_NIFI_QUEUE, ATTR_QUALIFIED_NAME, qualifiedName); final AtlasEntity queue = new AtlasEntity(TYPE_NIFI_QUEUE); queue.setAttribute(ATTR_NIFI_FLOW, getAtlasObjectId()); queue.setAttribute(ATTR_QUALIFIED_NAME, qualifiedName); queue.setAttribute(ATTR_NAME, "queue"); queue.setAttribute(ATTR_DESCRIPTION, "Input queue for " + destinationComponentId); queues.put(queueId, queue); return new Tuple<>(queueId, queue); } }
final String guid = entity.getGuid(); entity.setGuid(guidAssignments.get(guid)); final String pathId = getComponentIdFromQualifiedName(toStr(entity.getAttribute(ATTR_QUALIFIED_NAME))); return changedEntities.entrySet().stream() .filter(entry -> !DELETED.equals(entry.getKey())).flatMap(entry -> entry.getValue().stream()) .map(path -> new AtlasObjectId(path.getGuid(), TYPE_NIFI_FLOW_PATH, Collections.singletonMap(ATTR_QUALIFIED_NAME, path.getAttribute(ATTR_QUALIFIED_NAME)))) .collect(Collectors.toSet());
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; } }
for (AtlasEntity entity : createdEntities) { final String guid = guidAssignments.get(entity.getGuid()); final String qualifiedName = toStr(entity.getAttribute(ATTR_QUALIFIED_NAME)); if (StringUtils.isEmpty(guid)) {
= atlasClient.searchEntityDef(new AtlasObjectId(TYPE_NIFI_FLOW_PATH, ATTR_QUALIFIED_NAME, flowPathQualifiedName)); final AtlasEntity flowPathEntity = flowPathExt.getEntity(); flowPathGuid = flowPathEntity.getGuid(); distinctInputs = toReferenceables(flowPathEntity.getAttribute(ATTR_INPUTS), metrics); distinctOutputs = toReferenceables(flowPathEntity.getAttribute(ATTR_OUTPUTS), metrics);
private AtlasEntity registerNiFiFlowEntity(final NiFiFlow nifiFlow) throws AtlasServiceException { final List<AtlasEntity> entities = new ArrayList<>(); final AtlasEntity.AtlasEntitiesWithExtInfo atlasEntities = new AtlasEntity.AtlasEntitiesWithExtInfo(entities); if (!nifiFlow.isMetadataUpdated()) { // Nothing has been changed, return existing entity. return nifiFlow.getExEntity(); } // Create parent flow entity using existing NiFiFlow entity if available, so that common properties are taken over. final AtlasEntity flowEntity = nifiFlow.getExEntity() != null ? new AtlasEntity(nifiFlow.getExEntity()) : new AtlasEntity(); flowEntity.setTypeName(TYPE_NIFI_FLOW); flowEntity.setVersion(1L); flowEntity.setAttribute(ATTR_NAME, nifiFlow.getFlowName()); flowEntity.setAttribute(ATTR_QUALIFIED_NAME, nifiFlow.toQualifiedName(nifiFlow.getRootProcessGroupId())); flowEntity.setAttribute(ATTR_URL, nifiFlow.getUrl()); flowEntity.setAttribute(ATTR_DESCRIPTION, nifiFlow.getDescription()); // If flowEntity is not persisted yet, then store nifi_flow entity to make nifiFlowId available for other entities. if (flowEntity.getGuid().startsWith("-")) { entities.add(flowEntity); final EntityMutationResponse mutationResponse = atlasClient.createEntities(atlasEntities); logger.debug("Registered a new nifi_flow entity, mutation response={}", mutationResponse); final String assignedNiFiFlowGuid = mutationResponse.getGuidAssignments().get(flowEntity.getGuid()); flowEntity.setGuid(assignedNiFiFlowGuid); nifiFlow.setAtlasGuid(assignedNiFiFlowGuid); } return flowEntity; }
public void addUpdated(String internalGuid, AtlasEntity entity, AtlasEntityType type, AtlasVertex atlasVertex) { if (!entityVsVertex.containsKey(internalGuid)) { // if the entity was already created/updated entitiesUpdated.add(entity); entityVsType.put(entity.getGuid(), type); entityVsVertex.put(entity.getGuid(), atlasVertex); if (!StringUtils.equals(internalGuid, entity.getGuid())) { guidAssignments.put(internalGuid, entity.getGuid()); entityVsVertex.put(internalGuid, atlasVertex); } } }
@JsonIgnore @Override public AtlasEntity getEntity(String guid) { AtlasEntity ret = super.getEntity(guid); if (ret == null && entity != null) { if (StringUtils.equals(guid, entity.getGuid())) { ret = entity; } } return ret; }
public Map<EntityChangeType, List<AtlasEntity>> getChangedDataSetEntities() { final Map<EntityChangeType, List<AtlasEntity>> changedEntities = Stream .of(rootInputPortEntities.values().stream(), rootOutputPortEntities.values().stream(), queues.values().stream()) .flatMap(Function.identity()) .collect(Collectors.groupingBy(entity -> getEntityChangeType(entity.getGuid()))); updateAudit.add("CREATED DataSet entities=" + changedEntities.get(EntityChangeType.CREATED)); updateAudit.add("UPDATED DataSet entities=" + changedEntities.get(EntityChangeType.UPDATED)); updateAudit.add("DELETED DataSet entities=" + changedEntities.get(EntityChangeType.DELETED)); return changedEntities; }
private String getTableId(String tableName) throws AtlasServiceException { Map<String, String> attributes = new HashMap<>(); attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName); AtlasEntity tableEntity = atlasClientV2.getEntityByAttribute(TABLE_TYPE, attributes).getEntity(); return tableEntity.getGuid(); } }
private void recordAddedEntityGuids(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) { guids.add(entityWithExtInfo.getEntity().getGuid()); if(entityWithExtInfo.getReferredEntities() != null) { guids.addAll(entityWithExtInfo.getReferredEntities().keySet()); } }
public void add(AtlasEntity entity) throws AtlasBaseException { String jsonData = convertToJSON(entity); saveToZip(entity.getGuid(), jsonData); recordAddedEntityGuids(entity); }
@Override protected void verify_testInverseReferenceAutoUpdate_Map(AtlasEntity a1, AtlasEntity b1, AtlasEntity b2, AtlasEntity b3) { Object value = a1.getAttribute("mapToB"); assertTrue(value instanceof Map); Map<String, AtlasObjectId> refMap = (Map<String, AtlasObjectId>) value; assertEquals(refMap.size(), 3); AtlasObjectId referencedEntityId = refMap.get("b3"); assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b3)); verifyReferenceValue(b1, "mappedFromA", a1.getGuid()); verifyReferenceValue(b2, "mappedFromA", a1.getGuid()); }
@Test(dataProvider = "zipFileStocks") public void iteratorBehavor_WorksAsExpected(ZipSource zipSource) throws IOException, AtlasBaseException { Assert.assertTrue(zipSource.hasNext()); List<String> creationOrder = zipSource.getCreationOrder(); for (int i = 0; i < creationOrder.size(); i++) { AtlasEntity e = zipSource.next(); assertNotNull(e); assertEquals(e.getGuid(), creationOrder.get(i)); } assertFalse(zipSource.hasNext()); }
@Override protected void verifyRelationshipAttributeUpdate_NonComposite_ManyToOne(AtlasEntity a1, AtlasEntity a2, AtlasEntity a3, AtlasEntity b) { verifyRelationshipAttributeValue(a1, "oneB", b.getGuid()); verifyRelationshipAttributeValue(a2, "oneB", b.getGuid()); verifyRelationshipAttributeList(b, "manyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2), getAtlasObjectId(a3))); }
@Test(dependsOnMethods = {"updateClassification_PropagateTrueToFalse"}) public void deleteClassification_PropagateTrue() throws AtlasBaseException { AtlasEntity hdfs_employees = getEntity(HDFS_PATH_EMPLOYEES); AtlasClassification tag1 = new AtlasClassification("tag1"); tag1.setPropagate(true); tag1.setEntityGuid(hdfs_employees.getGuid()); deleteClassification(hdfs_employees, tag1); List<String> propagatedToEntities = Arrays.asList(EMPLOYEES1_PROCESS, EMPLOYEES2_PROCESS, EMPLOYEES1_TABLE, EMPLOYEES2_TABLE, EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); assertClassificationNotExistInEntities(propagatedToEntities, tag1); }