final String guid = entity.getGuid(); entity.setGuid(guidAssignments.get(guid)); final String pathId = getComponentIdFromQualifiedName(toStr(entity.getAttribute(ATTR_QUALIFIED_NAME))); final NiFiFlowPath path = nifiFlow.getFlowPaths().get(pathId); path.setExEntity(entity); logger.debug("Updated FlowPath entities mutation response={}", mutationResponse); updatedEntities.forEach(entity -> { final String pathId = getComponentIdFromQualifiedName(toStr(entity.getAttribute(ATTR_QUALIFIED_NAME))); final NiFiFlowPath path = nifiFlow.getFlowPaths().get(pathId); path.setExEntity(entity); .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());
nifiFlow.setDescription(toStr(attributes.get(ATTR_DESCRIPTION))); nifiFlow.getQueues().putAll(toQualifiedNameIds(toAtlasObjectIds(nifiFlowEntity.getAttribute(ATTR_QUEUES)))); nifiFlow.getRootInputPortEntities().putAll(toQualifiedNameIds(toAtlasObjectIds(nifiFlowEntity.getAttribute(ATTR_INPUT_PORTS)))); nifiFlow.getRootOutputPortEntities().putAll(toQualifiedNameIds(toAtlasObjectIds(nifiFlowEntity.getAttribute(ATTR_OUTPUT_PORTS)))); final String pathQualifiedName = toStr(flowPathEntity.getAttribute(ATTR_QUALIFIED_NAME)); final NiFiFlowPath flowPath = new NiFiFlowPath(getComponentIdFromQualifiedName(pathQualifiedName)); if (flowPathEntity.hasAttribute(ATTR_URL)) { final Matcher urlMatcher = FLOW_PATH_URL_PATTERN.matcher(toStr(flowPathEntity.getAttribute(ATTR_URL))); if (urlMatcher.matches()) { flowPath.setGroupId(urlMatcher.group(1)); flowPath.setName(toStr(flowPathEntity.getAttribute(ATTR_NAME))); flowPath.getInputs().addAll(toQualifiedNameIds(toAtlasObjectIds(flowPathEntity.getAttribute(ATTR_INPUTS))).keySet()); flowPath.getOutputs().addAll(toQualifiedNameIds(toAtlasObjectIds(flowPathEntity.getAttribute(ATTR_OUTPUTS))).keySet()); flowPath.startTrackingChanges(nifiFlow);
metrics.dataSetSearched++; final AtlasEntity.AtlasEntityWithExtInfo refExt = atlasClient.searchEntityDef(new AtlasObjectId(guid, typeName)); final String qualifiedName = (String) refExt.getEntity().getAttribute(ATTR_QUALIFIED_NAME); typedQualifiedNameToRef.put(toTypedQualifiedName(typeName, qualifiedName), new Referenceable(guid, typeName, Collections.EMPTY_MAP)); return qualifiedName;
return null; final Map<String, Object> uniqueAttrs = Collections.singletonMap(ATTR_QUALIFIED_NAME, entity.getAttribute(ATTR_QUALIFIED_NAME)); return new Tuple<>(new AtlasObjectId(id.getGuid(), id.getTypeName(), uniqueAttrs), entity); } catch (AtlasServiceException e) {
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; } }
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);
final AtlasEntity flowPathEntity = flowPathExt.getEntity(); flowPathGuid = flowPathEntity.getGuid(); distinctInputs = toReferenceables(flowPathEntity.getAttribute(ATTR_INPUTS), metrics); distinctOutputs = toReferenceables(flowPathEntity.getAttribute(ATTR_OUTPUTS), metrics);
public AtlasUserProfile from(AtlasEntity entity) { AtlasUserProfile profile = new AtlasUserProfile(); profile.setGuid(entity.getGuid()); profile.setName((String) entity.getAttribute(PROPERTY_USER_NAME)); profile.setFullName((String) entity.getAttribute(PROPERTY_FULL_NAME)); return profile; }
protected void verifyReferenceList(AtlasEntity entity, String refName, List<AtlasObjectId> expectedValues) { Object refValue = entity.getAttribute(refName); assertTrue(refValue instanceof List); List<AtlasObjectId> refList = (List<AtlasObjectId>) refValue; assertEquals(refList.size(), expectedValues.size()); if (expectedValues.size() > 0) { assertTrue(refList.containsAll(expectedValues)); } } }
@Test public void verifyCreate() throws AtlasBaseException { String expectedQualifiedName = getQualifiedName(expectedPath + "/", expectedClusterName); AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = hdfsPathEntityCreator.getCreateEntity(expectedPath, expectedClusterName); assertNotNull(entityWithExtInfo); AtlasEntity entity = entityWithExtInfo.getEntity(); assertEquals(entity.getAttribute(HdfsPathEntityCreator.HDFS_PATH_ATTRIBUTE_NAME_PATH), expectedPath + "/"); assertEquals(entity.getAttribute(HDFS_PATH_ATTRIBUTE_QUALIFIED_NAME),expectedQualifiedName); assertEquals(entity.getAttribute(HDFS_PATH_ATTRIBUTE_NAME_NAME), expectedPath + "/"); assertEquals(entity.getAttribute(HDFS_PATH_ATTRIBUTE_NAME_CLUSTER_NAME), expectedClusterName); }
private AtlasEntity toHiveTableEntity(AtlasEntity entHiveDb, String tableName) { AtlasEntity entHiveTable = new AtlasEntity(HiveDataTypes.HIVE_TABLE.getName()); String qualifiedName = HiveMetaStoreBridge.getTableQualifiedName((String)entHiveDb.getAttribute(AtlasConstants.CLUSTER_NAME_ATTRIBUTE), (String)entHiveDb.getAttribute(AtlasClient.NAME), tableName); entHiveTable.setAttribute(AtlasClient.NAME, tableName.toLowerCase()); entHiveTable.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, qualifiedName); entHiveTable.setAttribute(ATTRIBUTE_DB, AtlasTypeUtil.getAtlasObjectId(entHiveDb)); return entHiveTable; }
@Test public void transformEntityWith2Transforms() throws AtlasBaseException { AtlasEntity entity = getHiveTableAtlasEntity(); String attrValue = (String) entity.getAttribute(qualifiedName); transform.apply(entity); assertEquals(entity.getAttribute(qualifiedName), applyDefaultTransform(attrValue)); }
private String[] getExtEntityExpectedValues(AtlasEntityWithExtInfo entityWithExtInfo) { String[] ret = new String[entityWithExtInfo.getReferredEntities().size()]; for (int i = 0; i < ret.length; i++) { String attrValue = (String) entityWithExtInfo.getReferredEntities().get(Integer.toString(i)).getAttribute(qualifiedName); ret[i] = attrValue.replace(lowerCaseCL1, lowerCaseCL2); } return ret; }
@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(), 1); AtlasObjectId referencedEntityId = refMap.get("b3"); assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b3)); verifyReferenceValue(b1, "mappedFromA", null); verifyReferenceValue(b2, "mappedFromA", null); }
@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(), 1); AtlasObjectId referencedEntityId = refMap.get("b3"); assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b3)); verifyReferenceValue(b1, "mappedFromA", null); verifyReferenceValue(b2, "mappedFromA", null); }
@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()); }
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 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))); } }