Skip to content

Commit

Permalink
Merge pull request #3186 from atlanhq/PLT-1652-alias
Browse files Browse the repository at this point in the history
feat: rebuild alias endpoint
  • Loading branch information
sumandas0 authored Jun 4, 2024
2 parents 0e6e734 + f38a52a commit b4544eb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ public boolean updateAlias(AtlasEntity.AtlasEntityWithExtInfo accessControl, Atl
return true;
}

public void rebuildAlias(AtlasEntity.AtlasEntityWithExtInfo accessControl) throws AtlasBaseException {
String aliasName = getAliasName(accessControl.getEntity());

Map<String, Object> filter;

if (PERSONA_ENTITY_TYPE.equals(accessControl.getEntity().getTypeName())) {
filter = getFilterForPersona(accessControl);
} else {
filter = getFilterForPurpose(accessControl.getEntity());
}

ESAliasRequestBuilder requestBuilder = new ESAliasRequestBuilder();
requestBuilder.addAction(ADD, new AliasAction(getIndexNameFromAliasIfExists(VERTEX_INDEX_NAME), aliasName, filter));

graph.createOrUpdateESAlias(requestBuilder);
}

@Override
public boolean deleteAlias(String aliasName) throws AtlasBaseException {
graph.deleteESAlias(getIndexNameFromAliasIfExists(VERTEX_INDEX_NAME), aliasName);
Expand All @@ -161,6 +178,17 @@ private Map<String, Object> getFilterForPersona(AtlasEntity.AtlasEntityWithExtIn
return esClausesToFilter(allowClauseList);
}

private Map<String, Object> getFilterForPersona(AtlasEntity.AtlasEntityWithExtInfo persona) throws AtlasBaseException {
List<Map<String, Object>> allowClauseList = new ArrayList<>();

List<AtlasEntity> policies = getPolicies(persona);
if (CollectionUtils.isNotEmpty(policies)) {
personaPolicyToESDslClauses(policies, allowClauseList);
}

return esClausesToFilter(allowClauseList);
}

private Map<String, Object> getFilterForPurpose(AtlasEntity purpose) throws AtlasBaseException {

List<Map<String, Object>> allowClauseList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,6 @@ EntityMutationResponse deleteByUniqueAttributes(List<AtlasObjectId> objectIds)

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

public void repairAlias(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 @@ -147,6 +148,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 +166,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 @@ -2764,6 +2768,12 @@ private void repairMeanings(AtlasVertex assetVertex) {
}

}
@Override
public void repairAlias(String guid) throws AtlasBaseException {
// Fetch entity with extenfo
AtlasEntity.AtlasEntityWithExtInfo entity = entityRetriever.toAtlasEntityWithExtInfo(guid);
this.esAliasStore.rebuildAlias(entity);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -1932,4 +1932,11 @@ public void repairIndexByTypeName(@PathParam("typename") String typename, @Query
AtlasPerfTracer.log(perf);
}
}

@POST
@Path("/repairalias/{guid}")
@Timed
public void repairAlias(@PathParam("guid") String guid) throws AtlasBaseException {
entitiesStore.repairAlias(guid);
}
}

0 comments on commit b4544eb

Please sign in to comment.