Skip to content

Commit

Permalink
Merge pull request #3196 from atlanhq/PLT-1652-alias
Browse files Browse the repository at this point in the history
feat: rebuild ES aliases required for accesscontrol like persona/purpose
  • Loading branch information
sumandas0 authored Jun 5, 2024
2 parents d59dc31 + dbf011b commit 2e90c35
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasEntityHeaders;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasHasLineageRequests;
import org.apache.atlas.model.instance.EntityMutationResponse;
Expand Down Expand Up @@ -364,4 +363,6 @@ EntityMutationResponse deleteByUniqueAttributes(List<AtlasObjectId> objectIds)

void repairMeaningAttributeForTerms(List<String> termGuids) throws AtlasBaseException;

void repairAccesscontrolAlias(String guid) throws AtlasBaseException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.patches.PatchContext;
import org.apache.atlas.repository.patches.ReIndexPatch;
import org.apache.atlas.repository.store.aliasstore.ESAliasStore;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.repository.store.graph.EntityGraphDiscovery;
Expand Down Expand Up @@ -115,6 +116,7 @@
import static org.apache.atlas.repository.graph.GraphHelper.getStatus;
import static org.apache.atlas.repository.store.graph.v2.EntityGraphMapper.validateLabels;
import static org.apache.atlas.repository.store.graph.v2.tasks.MeaningsTaskFactory.*;
import static org.apache.atlas.repository.util.AccessControlUtils.REL_ATTR_POLICIES;
import static org.apache.atlas.type.Constants.HAS_LINEAGE;
import static org.apache.atlas.type.Constants.HAS_LINEAGE_VALID;
import static org.apache.atlas.type.Constants.MEANINGS_TEXT_PROPERTY_KEY;
Expand Down Expand Up @@ -147,6 +149,8 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
private final AtlasRelationshipStore atlasRelationshipStore;
private final FeatureFlagStore featureFlagStore;

private final ESAliasStore esAliasStore;

@Inject
public AtlasEntityStoreV2(AtlasGraph graph, DeleteHandlerDelegate deleteDelegate, RestoreHandlerV1 restoreHandlerV1, AtlasTypeRegistry typeRegistry,
IAtlasEntityChangeNotifier entityChangeNotifier, EntityGraphMapper entityGraphMapper, TaskManagement taskManagement,
Expand All @@ -163,6 +167,7 @@ public AtlasEntityStoreV2(AtlasGraph graph, DeleteHandlerDelegate deleteDelegate
this.taskManagement = taskManagement;
this.atlasRelationshipStore = atlasRelationshipStore;
this.featureFlagStore = featureFlagStore;
this.esAliasStore = new ESAliasStore(graph, entityRetriever);

try {
this.discovery = new EntityDiscoveryService(typeRegistry, graph, null, null, null, null);
Expand Down Expand Up @@ -2703,6 +2708,35 @@ private void repairMeanings(AtlasVertex assetVertex) {
}

}
@Override
public void repairAccesscontrolAlias(String guid) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metric = RequestContext.get().startMetricRecord("repairAlias");
// Fetch accesscontrolEntity with extInfo
AtlasEntity.AtlasEntityWithExtInfo accesscontrolEntity = entityRetriever.toAtlasEntityWithExtInfo(guid);

AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new AtlasEntityHeader(accesscontrolEntity.getEntity())));

// Validate accesscontrolEntity status
if (accesscontrolEntity.getEntity().getStatus() != ACTIVE) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_DELETED, guid);
}

// Validate accesscontrolEntity type
String entityType = accesscontrolEntity.getEntity().getTypeName();
if (!PERSONA_ENTITY_TYPE.equals(entityType)) {
throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, entityType);
}

List<AtlasObjectId> policies = (List<AtlasObjectId>) accesscontrolEntity.getEntity().getRelationshipAttribute(REL_ATTR_POLICIES);
for (AtlasObjectId policy : policies) {
accesscontrolEntity.addReferredEntity(entityRetriever.toAtlasEntity(policy));
}

// Rebuild alias
this.esAliasStore.updateAlias(accesscontrolEntity, null);

RequestContext.get().endMetricRecord(metric);
}
}


25 changes: 25 additions & 0 deletions webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
Original file line number Diff line number Diff line change
Expand Up @@ -1930,4 +1930,29 @@ public void repairIndexByTypeName(@PathParam("typename") String typename, @Query
AtlasPerfTracer.log(perf);
}
}

@POST
@Path("/repair/accesscontrolAlias/{guid}")
@Timed
public void repairAccessControlAlias(@PathParam("guid") String guid) throws AtlasBaseException {
Servlets.validateQueryParamLength("guid", guid);

AtlasPerfTracer perf = null;


try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.repairAccessControlAlias");
}

entitiesStore.repairAccesscontrolAlias(guid);

LOG.info("Repaired access control alias for entity with guid {}", guid);

} finally {
AtlasPerfTracer.log(perf);
}


}
}

0 comments on commit 2e90c35

Please sign in to comment.