forked from apache/atlas
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre Processors for Domain Move #2876
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c48284d
Pre Processors for Domain Move
PRATHAM2002-DS 9bcd34e
uthorized function updated
PRATHAM2002-DS c7a9884
janusgraph version updated
PRATHAM2002-DS 84aa088
support for only UPDATE operation
PRATHAM2002-DS 9e6963d
update superdomain with parentdomain
PRATHAM2002-DS e893e1e
edge label changed
PRATHAM2002-DS 81fcc6a
logs removed
PRATHAM2002-DS 4c4d4e3
comments removed
PRATHAM2002-DS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...che/atlas/repository/store/graph/v2/preprocessor/datamesh/AbstractDomainPreProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/** | ||
PRATHAM2002-DS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.atlas.repository.store.graph.v2.preprocessor.datamesh; | ||
|
||
import org.apache.atlas.AtlasException; | ||
import org.apache.atlas.RequestContext; | ||
import org.apache.atlas.authorize.AtlasAuthorizationUtils; | ||
import org.apache.atlas.authorize.AtlasEntityAccessRequest; | ||
import org.apache.atlas.authorize.AtlasPrivilege; | ||
import org.apache.atlas.discovery.EntityDiscoveryService; | ||
import org.apache.atlas.exception.AtlasBaseException; | ||
import org.apache.atlas.model.discovery.IndexSearchParams; | ||
import org.apache.atlas.model.instance.AtlasEntity; | ||
import org.apache.atlas.model.instance.AtlasEntityHeader; | ||
import org.apache.atlas.repository.graphdb.AtlasGraph; | ||
import org.apache.atlas.repository.graphdb.AtlasVertex; | ||
import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; | ||
import org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessor; | ||
import org.apache.atlas.repository.store.graph.v2.preprocessor.glossary.AbstractGlossaryPreProcessor; | ||
import org.apache.atlas.type.AtlasEntityType; | ||
import org.apache.atlas.type.AtlasTypeRegistry; | ||
import org.apache.atlas.utils.AtlasPerfMetrics; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.atlas.repository.Constants.NAME; | ||
import static org.apache.atlas.repository.util.AtlasEntityUtils.mapOf; | ||
|
||
public abstract class AbstractDomainPreProcessor implements PreProcessor { | ||
private static final Logger LOG = LoggerFactory.getLogger(AbstractGlossaryPreProcessor.class); | ||
|
||
|
||
protected final AtlasTypeRegistry typeRegistry; | ||
protected final EntityGraphRetriever entityRetriever; | ||
|
||
protected EntityDiscoveryService discovery; | ||
|
||
AbstractDomainPreProcessor(AtlasTypeRegistry typeRegistry, EntityGraphRetriever entityRetriever, AtlasGraph graph) { | ||
this.entityRetriever = entityRetriever; | ||
this.typeRegistry = typeRegistry; | ||
|
||
try { | ||
this.discovery = new EntityDiscoveryService(typeRegistry, graph, null, null, null, null); | ||
} catch (AtlasException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public List<AtlasEntityHeader> indexSearchPaginated(Map<String, Object> dsl) throws AtlasBaseException { | ||
IndexSearchParams searchParams = new IndexSearchParams(); | ||
List<AtlasEntityHeader> ret = new ArrayList<>(); | ||
|
||
List<Map> sortList = new ArrayList<>(0); | ||
sortList.add(mapOf("__timestamp", mapOf("order", "asc"))); | ||
sortList.add(mapOf("__guid", mapOf("order", "asc"))); | ||
dsl.put("sort", sortList); | ||
|
||
int from = 0; | ||
int size = 100; | ||
boolean hasMore = true; | ||
do { | ||
dsl.put("from", from); | ||
dsl.put("size", size); | ||
searchParams.setDsl(dsl); | ||
|
||
List<AtlasEntityHeader> headers = discovery.directIndexSearch(searchParams).getEntities(); | ||
|
||
if (CollectionUtils.isNotEmpty(headers)) { | ||
ret.addAll(headers); | ||
} else { | ||
hasMore = false; | ||
} | ||
|
||
from += size; | ||
|
||
} while (hasMore); | ||
|
||
return ret; | ||
} | ||
|
||
protected void isAuthorized(AtlasEntityHeader sourceDomain, AtlasEntityHeader targetDomain) throws AtlasBaseException { | ||
|
||
// source -> CREATE + UPDATE + DELETE | ||
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, sourceDomain), | ||
"create on source Domain: ", sourceDomain.getAttribute(NAME)); | ||
|
||
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, sourceDomain), | ||
"update on source Domain: ", sourceDomain.getAttribute(NAME)); | ||
|
||
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, sourceDomain), | ||
"delete on source Domain: ", sourceDomain.getAttribute(NAME)); | ||
|
||
|
||
// target -> CREATE + UPDATE + DELETE | ||
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, targetDomain), | ||
"create on target Domain: ", targetDomain.getAttribute(NAME)); | ||
|
||
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, targetDomain), | ||
"update on target Domain: ", targetDomain.getAttribute(NAME)); | ||
|
||
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, targetDomain), | ||
"delete on target Domain: ", targetDomain.getAttribute(NAME)); | ||
} | ||
|
||
/** | ||
* Record the updated child entities, it will be used to send notification and store audit logs | ||
* @param entityVertex Child entity vertex | ||
* @param updatedAttributes Updated attributes while updating required attributes on updating collection | ||
*/ | ||
protected void recordUpdatedChildEntities(AtlasVertex entityVertex, Map<String, Object> updatedAttributes) { | ||
RequestContext requestContext = RequestContext.get(); | ||
AtlasPerfMetrics.MetricRecorder metricRecorder = requestContext.startMetricRecord("recordUpdatedChildEntities"); | ||
AtlasEntity entity = new AtlasEntity(); | ||
entity = entityRetriever.mapSystemAttributes(entityVertex, entity); | ||
entity.setAttributes(updatedAttributes); | ||
requestContext.cacheDifferentialEntity(new AtlasEntity(entity)); | ||
|
||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); | ||
|
||
//Add the min info attributes to entity header to be sent as part of notification | ||
if(entityType != null) { | ||
AtlasEntity finalEntity = entity; | ||
entityType.getMinInfoAttributes().values().stream().filter(attribute -> !updatedAttributes.containsKey(attribute.getName())).forEach(attribute -> { | ||
Object attrValue = null; | ||
try { | ||
attrValue = entityRetriever.getVertexAttribute(entityVertex, attribute); | ||
} catch (AtlasBaseException e) { | ||
LOG.error("Error while getting vertex attribute", e); | ||
} | ||
if(attrValue != null) { | ||
finalEntity.setAttribute(attribute.getName(), attrValue); | ||
} | ||
}); | ||
requestContext.recordEntityUpdate(new AtlasEntityHeader(finalEntity)); | ||
} | ||
|
||
requestContext.endMetricRecord(metricRecorder); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think DATA_PRODUCT_TYPE from common/src/main/java/org/apache/atlas/repository/Constants.java can be reused