From d6a6ddc58626fe33ed8f2958835da594a5f0994b Mon Sep 17 00:00:00 2001 From: Mandy Chessell Date: Mon, 16 Jan 2023 12:26:08 +0000 Subject: [PATCH] Detect deleted relationship as fast as possible Signed-off-by: Mandy Chessell --- .../EnterpriseOMRSMetadataCollection.java | 4 +- .../RelationshipsAccumulator.java | 4 +- .../executors/GetEntityDetailExecutor.java | 2 - .../executors/GetRelationshipExecutor.java | 38 ++++++++++--------- .../executors/RepositoryExecutorBase.java | 2 + 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/EnterpriseOMRSMetadataCollection.java b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/EnterpriseOMRSMetadataCollection.java index 98a28e32f88..d41ce3cd8f3 100644 --- a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/EnterpriseOMRSMetadataCollection.java +++ b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/EnterpriseOMRSMetadataCollection.java @@ -1657,7 +1657,7 @@ public Relationship isRelationshipKnown(String userId, List cohortConnectors = enterpriseParentConnector.getCohortConnectors(methodName); FederationControl federationControl = new SequentialFederationControl(userId, cohortConnectors, auditLog, methodName); - GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, false, auditLog, methodName); + GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, auditLog, methodName); /* * Ready to process the request. Create requests occur in the first repository that accepts the call. @@ -1706,7 +1706,7 @@ public Relationship getRelationship(String userId, List cohortConnectors = enterpriseParentConnector.getCohortConnectors(methodName); FederationControl federationControl = new SequentialFederationControl(userId, cohortConnectors, auditLog, methodName); - GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, true, auditLog, methodName); + GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, auditLog, methodName); /* * Ready to process the request. Create requests occur in the first repository that accepts the call. diff --git a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/accumulators/RelationshipsAccumulator.java b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/accumulators/RelationshipsAccumulator.java index 07cb5ba9063..a94ef870ef4 100644 --- a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/accumulators/RelationshipsAccumulator.java +++ b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/accumulators/RelationshipsAccumulator.java @@ -20,7 +20,7 @@ */ public class RelationshipsAccumulator extends QueryInstanceAccumulatorBase { - private volatile Map accumulatedRelationships = new HashMap<>(); + private final Map accumulatedRelationships = new HashMap<>(); /** @@ -108,7 +108,7 @@ public synchronized void addRelationships(List relationships, /** - * Extract the results - this will the a unique list of relationships selected from the instances + * Extract the results - this will a list of unique relationships selected from the instances * supplied to this accumulator. It should be called once all the executors have completed processing * their request(s). * diff --git a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetEntityDetailExecutor.java b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetEntityDetailExecutor.java index 03c48b87a3b..aee40d71fee 100644 --- a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetEntityDetailExecutor.java +++ b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetEntityDetailExecutor.java @@ -241,8 +241,6 @@ public EntityDetail getEntityDetail() throws InvalidParameterException, EntityProxyOnlyException, UserNotAuthorizedException { - final String repositoryName = "Enterprise"; - EntityDetail entity = this.isEntityKnown(false); if (entity != null) diff --git a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetRelationshipExecutor.java b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetRelationshipExecutor.java index 4a169db992b..bc406d7087c 100644 --- a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetRelationshipExecutor.java +++ b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/GetRelationshipExecutor.java @@ -5,8 +5,10 @@ import org.odpi.openmetadata.frameworks.auditlog.AuditLog; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceStatus; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship; import org.odpi.openmetadata.repositoryservices.enterprise.repositoryconnector.accumulators.MaintenanceAccumulator; +import org.odpi.openmetadata.repositoryservices.ffdc.OMRSErrorCode; import org.odpi.openmetadata.repositoryservices.ffdc.exception.*; import java.util.Date; @@ -19,7 +21,7 @@ public class GetRelationshipExecutor extends RepositoryExecutorBase private final MaintenanceAccumulator accumulator; private final String relationshipGUID; - private boolean allExceptions = true; + private Date asOfTime = null; private Relationship retrievedRelationship = null; @@ -30,13 +32,11 @@ public class GetRelationshipExecutor extends RepositoryExecutorBase * * @param userId unique identifier for requesting user * @param relationshipGUID unique identifier (guid) for the relationship - * @param allExceptions is the a isRelationshipKnown or getRelationship request * @param auditLog logging destination * @param methodName calling method */ public GetRelationshipExecutor(String userId, String relationshipGUID, - boolean allExceptions, AuditLog auditLog, String methodName) { @@ -45,7 +45,6 @@ public GetRelationshipExecutor(String userId, this.accumulator = new MaintenanceAccumulator(auditLog); this.relationshipGUID = relationshipGUID; - this.allExceptions = allExceptions; } @@ -96,22 +95,11 @@ public boolean issueRequestToRepository(String metadataCollectio */ if (asOfTime == null) { - if (allExceptions) - { - retrievedRelationship = metadataCollection.getRelationship(userId, - relationshipGUID); - } - else - { - retrievedRelationship = metadataCollection.isRelationshipKnown(userId, - relationshipGUID); - } + retrievedRelationship = metadataCollection.isRelationshipKnown(userId, relationshipGUID); } else { - retrievedRelationship = metadataCollection.getRelationship(userId, - relationshipGUID, - asOfTime); + retrievedRelationship = metadataCollection.getRelationship(userId, relationshipGUID, asOfTime); } if (retrievedRelationship != null) { @@ -191,12 +179,26 @@ public Relationship getRelationship() throws InvalidParameterException, if (relationship != null) { + if (relationship.getStatus() == InstanceStatus.DELETED) + { + throw new RelationshipNotKnownException(OMRSErrorCode.RELATIONSHIP_SOFT_DELETED.getMessageDefinition(relationship.getType().getTypeDefName(), + relationship.getGUID(), + methodName, + repositoryName), + this.getClass().getName(), + methodName); + } + return relationship; } accumulator.throwCapturedRelationshipNotKnownException(); - return null; + throw new RelationshipNotKnownException(OMRSErrorCode.RELATIONSHIP_NOT_KNOWN.getMessageDefinition(relationshipGUID, + methodName, + repositoryName), + this.getClass().getName(), + methodName); } diff --git a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/RepositoryExecutorBase.java b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/RepositoryExecutorBase.java index 33d06a072c0..10d98a0c13d 100644 --- a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/RepositoryExecutorBase.java +++ b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/enterprise/repositoryconnector/executors/RepositoryExecutorBase.java @@ -6,6 +6,8 @@ public abstract class RepositoryExecutorBase implements RepositoryExecutor { + final String repositoryName = "Enterprise"; + protected String methodName; protected String userId;