/** * @return True when required NiFi types are already created. */ public boolean isNiFiTypeDefsRegistered() throws AtlasServiceException { final Set<String> typeNames = ENTITIES.keySet(); final Map<String, AtlasEntityDef> existingDefs = getTypeDefs(typeNames.toArray(new String[typeNames.size()])).getEntityDefs().stream() .collect(Collectors.toMap(AtlasEntityDef::getName, Function.identity())); return typeNames.stream().allMatch(existingDefs::containsKey); }
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; }
final Map<String, AtlasEntityDef> existingDefs = getTypeDefs(typeNames.toArray(new String[typeNames.size()])).getEntityDefs().stream() .collect(Collectors.toMap(AtlasEntityDef::getName, Function.identity())); type.getEntityDefs().add(entity);
@Deprecated public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException { AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getEntityDefs().add(entityDef); AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); assert created != null; assert created.getEntityDefs() != null; return created.getEntityDefs().get(0); }
@Deprecated public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException { AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getEntityDefs().add(entityDef); AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); assert created != null; assert created.getEntityDefs() != null; return created.getEntityDefs().get(0); }
@Deprecated public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException { AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getEntityDefs().add(entityDef); AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef); assert created != null; assert created.getEntityDefs() != null; return created.getEntityDefs().get(0); }
/** * @return True when required NiFi types are already created. */ public boolean isNiFiTypeDefsRegistered() throws AtlasServiceException { final Set<String> typeNames = ENTITIES.keySet(); final Map<String, AtlasEntityDef> existingDefs = getTypeDefs(typeNames.toArray(new String[typeNames.size()])).getEntityDefs().stream() .collect(Collectors.toMap(AtlasEntityDef::getName, Function.identity())); return typeNames.stream().allMatch(existingDefs::containsKey); }
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 void updateMetricsForTypesDef(AtlasTypesDef typeDefinitionMap, AtlasImportResult result) { result.incrementMeticsCounter("typedef:classification", typeDefinitionMap.getClassificationDefs().size()); result.incrementMeticsCounter("typedef:enum", typeDefinitionMap.getEnumDefs().size()); result.incrementMeticsCounter("typedef:entitydef", typeDefinitionMap.getEntityDefs().size()); result.incrementMeticsCounter("typedef:struct", typeDefinitionMap.getStructDefs().size()); } }
@Test(dependsOnMethods = "testGet") public void testSearchFunctionality() { SearchFilter searchFilter = new SearchFilter(); searchFilter.setParam(SearchFilter.PARAM_SUPERTYPE, "Person"); try { AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter); assertNotNull(typesDef); assertNotNull(typesDef.getEntityDefs()); assertEquals(typesDef.getEntityDefs().size(), 3); } catch (AtlasBaseException e) { fail("Search should've succeeded", e); } }
@Test public void filterInternalType() throws AtlasBaseException { SearchFilter searchFilter = new SearchFilter(); FilterUtil.addParamsToHideInternalType(searchFilter); AtlasTypesDef filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter); assertNotNull(filteredTypeDefs); Optional<AtlasEntityDef> anyInternal = filteredTypeDefs.getEntityDefs().stream().filter(e -> e.getSuperTypes().contains("__internal")).findAny(); assertFalse(anyInternal.isPresent()); }
@Test public void filterInternalType() throws AtlasBaseException { SearchFilter searchFilter = new SearchFilter(); FilterUtil.addParamsToHideInternalType(searchFilter); AtlasTypesDef filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter); assertNotNull(filteredTypeDefs); Optional<AtlasEntityDef> anyInternal = filteredTypeDefs.getEntityDefs().stream().filter(e -> e.getSuperTypes().contains("__internal")).findAny(); assertFalse(anyInternal.isPresent()); }
public static AtlasEntityDef getEntityWithInvalidSuperType() { AtlasEntityDef entityDef = simpleType().getEntityDefs().get(0); entityDef.addSuperType("!@#$%"); return entityDef; }
@DataProvider public Object[][] allCreatedTypes(){ // Capture all the types that are getting created or updated here. AtlasTypesDef updatedTypeDefs = TestUtilsV2.defineValidUpdatedDeptEmployeeTypes(); AtlasTypesDef allTypeDefs = new AtlasTypesDef(); allTypeDefs.getEnumDefs().addAll(updatedTypeDefs.getEnumDefs()); allTypeDefs.getStructDefs().addAll(updatedTypeDefs.getStructDefs()); allTypeDefs.getClassificationDefs().addAll(updatedTypeDefs.getClassificationDefs()); allTypeDefs.getEntityDefs().addAll(updatedTypeDefs.getEntityDefs()); allTypeDefs.getEntityDefs().addAll(TestUtilsV2.getEntityWithValidSuperType()); return new Object[][] {{allTypeDefs}}; }
private void verifyTypeDefs(ZipSource zipSource) throws AtlasBaseException { assertEquals(zipSource.getTypesDef().getEnumDefs().size(), 1); assertEquals(zipSource.getTypesDef().getClassificationDefs().size(), 0); assertEquals(zipSource.getTypesDef().getStructDefs().size(), 1); assertEquals(zipSource.getTypesDef().getEntityDefs().size(), 4); } }
private void assertTraitMap(TypesDefScrubber typesDefScrubber, AtlasTypesDef td, int classificationIndex, String expectedStructName, int attrIndex) { String label = typesDefScrubber.getEdgeLabel(td.getEntityDefs().get(0).getName(), td.getEntityDefs().get(0).getAttributeDefs().get(attrIndex).getName()); assertTrue(typesDefScrubber.getTraitToTypeMap().containsKey(label)); assertEquals(typesDefScrubber.getTraitToTypeMap().get(label).getTypeName(), td.getClassificationDefs().get(classificationIndex).getName()); assertEquals(typesDefScrubber.getTraitToTypeMap().get(label).getLegacyTypeName(), expectedStructName); }
private void assertTraitMap(TypesDefScrubber typesDefScrubber, AtlasTypesDef td, int classificationIndex, String expectedStructName, int attrIndex) { String label = typesDefScrubber.getEdgeLabel(td.getEntityDefs().get(0).getName(), td.getEntityDefs().get(0).getAttributeDefs().get(attrIndex).getName()); assertTrue(typesDefScrubber.getTraitToTypeMap().containsKey(label)); assertEquals(typesDefScrubber.getTraitToTypeMap().get(label).getTypeName(), td.getClassificationDefs().get(classificationIndex).getName()); assertEquals(typesDefScrubber.getTraitToTypeMap().get(label).getLegacyTypeName(), expectedStructName); }
private void updateEntityDef(AtlasTypesDef typeDefinitionMap, AtlasImportResult result) throws AtlasBaseException { for (AtlasEntityDef def : typeDefinitionMap.getEntityDefs()) { AtlasEntityDef existing = typeRegistry.getEntityDefByName(def.getName()); if (existing != null && addAttributes(existing, def)) { typeDefStore.updateEntityDefByName(existing.getName(), existing); result.incrementMeticsCounter("typedef:entitydef:update"); } } }
public void removeTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { if (null != typesDef && !typesDef.isEmpty()) { removeTypesWithNoRefResolve(typesDef.getEnumDefs()); removeTypesWithNoRefResolve(typesDef.getStructDefs()); removeTypesWithNoRefResolve(typesDef.getClassificationDefs()); removeTypesWithNoRefResolve(typesDef.getEntityDefs()); removeTypesWithNoRefResolve(typesDef.getRelationshipDefs()); resolveReferences(); } }
public static void populateSystemAttributes(AtlasTypesDef typesDef) { populateSystemAttributes(typesDef.getEnumDefs()); populateSystemAttributes(typesDef.getStructDefs()); populateSystemAttributes(typesDef.getClassificationDefs()); populateSystemAttributes(typesDef.getEntityDefs()); populateSystemAttributes(typesDef.getRelationshipDefs()); }