Skip to content

Commit 703cfa2

Browse files
Merge pull request #2268 from atlanhq/beta-master-syncer
Beta master syncer
2 parents 5071809 + f1eaf05 commit 703cfa2

File tree

4 files changed

+48
-55
lines changed

4 files changed

+48
-55
lines changed

repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,45 @@ public static String getDelimitedClassificationNames(Collection<String> classifi
18691869
return ret;
18701870
}
18711871

1872+
/**
1873+
* Get all the active parents
1874+
* @param vertex entity vertex
1875+
* @param parentEdgeLabel Edge label of parent
1876+
* @return Iterator of children vertices
1877+
*/
1878+
public static Iterator<AtlasVertex> getActiveParentVertices(AtlasVertex vertex, String parentEdgeLabel) throws AtlasBaseException {
1879+
return getActiveVertices(vertex, parentEdgeLabel, AtlasEdgeDirection.IN);
1880+
}
1881+
1882+
/**
1883+
* Get all the active children of category
1884+
* @param vertex entity vertex
1885+
* @param childrenEdgeLabel Edge label of children
1886+
* @return Iterator of children vertices
1887+
*/
1888+
public static Iterator<AtlasVertex> getActiveChildrenVertices(AtlasVertex vertex, String childrenEdgeLabel) throws AtlasBaseException {
1889+
return getActiveVertices(vertex, childrenEdgeLabel, AtlasEdgeDirection.OUT);
1890+
}
1891+
1892+
public static Iterator<AtlasVertex> getActiveVertices(AtlasVertex vertex, String childrenEdgeLabel, AtlasEdgeDirection direction) throws AtlasBaseException {
1893+
AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("CategoryPreProcessor.getEdges");
1894+
1895+
try {
1896+
return vertex.query()
1897+
.direction(direction)
1898+
.label(childrenEdgeLabel)
1899+
.has(STATE_PROPERTY_KEY, ACTIVE_STATE_VALUE)
1900+
.vertices()
1901+
.iterator();
1902+
} catch (Exception e) {
1903+
LOG.error("Error while getting active children of category for edge label " + childrenEdgeLabel, e);
1904+
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
1905+
}
1906+
finally {
1907+
RequestContext.get().endMetricRecord(metricRecorder);
1908+
}
1909+
}
1910+
18721911
private static Set<String> parseLabelsString(String labels) {
18731912
Set<String> ret = new HashSet<>();
18741913

repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/AbstractGlossaryPreProcessor.java

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.atlas.model.instance.AtlasObjectId;
3333
import org.apache.atlas.model.tasks.AtlasTask;
3434
import org.apache.atlas.repository.graph.GraphHelper;
35-
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
3635
import org.apache.atlas.repository.graphdb.AtlasGraph;
3736
import org.apache.atlas.repository.graphdb.AtlasVertex;
3837
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
@@ -50,13 +49,11 @@
5049

5150
import java.util.ArrayList;
5251
import java.util.HashSet;
53-
import java.util.Iterator;
5452
import java.util.List;
5553
import java.util.Map;
5654
import java.util.Set;
5755
import java.util.stream.Collectors;
5856

59-
import static org.apache.atlas.repository.Constants.ACTIVE_STATE_VALUE;
6057
import static org.apache.atlas.repository.Constants.ATLAS_GLOSSARY_TERM_ENTITY_TYPE;
6158
import static org.apache.atlas.repository.Constants.ELASTICSEARCH_PAGINATION_SIZE;
6259
import static org.apache.atlas.repository.Constants.NAME;
@@ -109,13 +106,7 @@ public void termExists(String termName, String glossaryQName) throws AtlasBaseEx
109106
List<AtlasEntityHeader> terms = indexSearchPaginated(dsl);
110107

111108
if (CollectionUtils.isNotEmpty(terms)) {
112-
for (AtlasEntityHeader term : terms) {
113-
String name = (String) term.getAttribute(NAME);
114-
if (termName.equals(name)) {
115-
ret = true;
116-
break;
117-
}
118-
}
109+
ret = terms.stream().map(term -> (String) term.getAttribute(NAME)).anyMatch(name -> termName.equals(name));
119110
}
120111

121112
if (ret) {
@@ -143,8 +134,7 @@ public void createAndQueueTask(String taskType,
143134
public boolean checkEntityTermAssociation(String termQName) throws AtlasBaseException {
144135
List<AtlasEntityHeader> entityHeader;
145136
entityHeader = discovery.searchUsingTermQualifiedName(0,1,termQName,null,null);
146-
Boolean hasEntityAssociation = entityHeader != null ? true : false;
147-
return hasEntityAssociation;
137+
return entityHeader != null;
148138
}
149139

150140
public List<AtlasEntityHeader> indexSearchPaginated(Map<String, Object> dsl) throws AtlasBaseException {
@@ -234,45 +224,6 @@ public void updateMeaningsAttributesInEntitiesOnTermUpdate(String currentTermNam
234224
}
235225
}
236226

237-
/**
238-
* Get all the active parents
239-
* @param vertex entity vertex
240-
* @param parentEdgeLabel Edge label of parent
241-
* @return Iterator of children vertices
242-
*/
243-
protected Iterator<AtlasVertex> getActiveParents(AtlasVertex vertex, String parentEdgeLabel) throws AtlasBaseException {
244-
return getEdges(vertex, parentEdgeLabel, AtlasEdgeDirection.IN);
245-
}
246-
247-
/**
248-
* Get all the active children of category
249-
* @param vertex entity vertex
250-
* @param childrenEdgeLabel Edge label of children
251-
* @return Iterator of children vertices
252-
*/
253-
protected Iterator<AtlasVertex> getActiveChildren(AtlasVertex vertex, String childrenEdgeLabel) throws AtlasBaseException {
254-
return getEdges(vertex, childrenEdgeLabel, AtlasEdgeDirection.OUT);
255-
}
256-
257-
protected Iterator getEdges(AtlasVertex vertex, String childrenEdgeLabel, AtlasEdgeDirection direction) throws AtlasBaseException {
258-
AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("CategoryPreProcessor.getEdges");
259-
260-
try {
261-
return vertex.query()
262-
.direction(direction)
263-
.label(childrenEdgeLabel)
264-
.has(STATE_PROPERTY_KEY, ACTIVE_STATE_VALUE)
265-
.vertices()
266-
.iterator();
267-
} catch (Exception e) {
268-
LOG.error("Error while getting active children of category for edge label " + childrenEdgeLabel, e);
269-
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
270-
}
271-
finally {
272-
RequestContext.get().endMetricRecord(metricRecorder);
273-
}
274-
}
275-
276227
protected void isAuthorized(AtlasEntityHeader sourceGlossary, AtlasEntityHeader targetGlossary) throws AtlasBaseException {
277228

278229
// source -> CREATE + UPDATE + DELETE

repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/CategoryPreProcessor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import static org.apache.atlas.repository.Constants.GUID_PROPERTY_KEY;
6565
import static org.apache.atlas.repository.Constants.NAME;
6666
import static org.apache.atlas.repository.Constants.QUALIFIED_NAME;
67+
import static org.apache.atlas.repository.graph.GraphHelper.getActiveChildrenVertices;
68+
import static org.apache.atlas.repository.graph.GraphHelper.getActiveParentVertices;
6769
import static org.apache.atlas.repository.graph.GraphHelper.getTypeName;
6870
import static org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessorUtils.*;
6971
import static org.apache.atlas.repository.store.graph.v2.tasks.MeaningsTaskFactory.UPDATE_ENTITY_MEANINGS_ON_TERM_UPDATE;
@@ -229,15 +231,15 @@ private void moveChildrenToAnotherGlossary(AtlasVertex childCategoryVertex,
229231
GraphHelper.setModifiedTime(childCategoryVertex, System.currentTimeMillis());
230232

231233
// move terms to target Glossary
232-
Iterator<AtlasVertex> terms = getActiveChildren(childCategoryVertex, CATEGORY_TERMS_EDGE_LABEL);
234+
Iterator<AtlasVertex> terms = getActiveChildrenVertices(childCategoryVertex, CATEGORY_TERMS_EDGE_LABEL);
233235

234236
while (terms.hasNext()) {
235237
AtlasVertex termVertex = terms.next();
236238
moveChildTermToAnotherGlossary(termVertex, updatedQualifiedName, sourceGlossaryQualifiedName, targetGlossaryQualifiedName);
237239
}
238240

239241
// Get all children categories of current category
240-
Iterator<AtlasVertex> childCategories = getActiveChildren(childCategoryVertex, CATEGORY_PARENT_EDGE_LABEL);
242+
Iterator<AtlasVertex> childCategories = getActiveChildrenVertices(childCategoryVertex, CATEGORY_PARENT_EDGE_LABEL);
241243

242244
while (childCategories.hasNext()) {
243245
AtlasVertex childVertex = childCategories.next();
@@ -310,7 +312,7 @@ private void validateParentForGlossaryChange(AtlasEntity category,
310312

311313
if (!category.hasRelationshipAttribute(CATEGORY_PARENT)) {
312314
// parentCategory not present in payload, check in store
313-
Iterator<AtlasVertex> parentItr = getActiveParents(categoryVertex, CATEGORY_PARENT_EDGE_LABEL);
315+
Iterator<AtlasVertex> parentItr = getActiveParentVertices(categoryVertex, CATEGORY_PARENT_EDGE_LABEL);
314316

315317
if (parentItr.hasNext()) {
316318
AtlasVertex parentCategory = parentItr.next();

repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.List;
4848

4949
import static org.apache.atlas.repository.Constants.*;
50+
import static org.apache.atlas.repository.graph.GraphHelper.getActiveParentVertices;
5051
import static org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessorUtils.*;
5152
import static org.apache.atlas.repository.store.graph.v2.tasks.MeaningsTaskFactory.UPDATE_ENTITY_MEANINGS_ON_TERM_UPDATE;
5253

@@ -201,7 +202,7 @@ public String moveTermToAnotherGlossary(AtlasEntity entity, AtlasVertex vertex,
201202
whether category belongs to target glossary, if not throw an exception
202203
*/
203204
if (!entity.hasRelationshipAttribute(ATTR_CATEGORIES)) {
204-
Iterator<AtlasVertex> categoriesItr = getActiveParents(vertex, CATEGORY_TERMS_EDGE_LABEL);
205+
Iterator<AtlasVertex> categoriesItr = getActiveParentVertices(vertex, CATEGORY_TERMS_EDGE_LABEL);
205206

206207
if (categoriesItr.hasNext()) {
207208
AtlasVertex categoryVertex = categoriesItr.next();

0 commit comments

Comments
 (0)