Skip to content
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

Detect deleted entities quicker (#7303) #7319

Merged
merged 4 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7083,7 +7083,7 @@ public void deleteAnchoredEntity(List<String> anchoredEntityGUIDs,
* because it is a parent object. If it now has no anchor then it can be
* deleted because it is a child object.
*/
String derivedAnchorGUID = this.deriveAnchorGUID(entityGUID, entityTypeName, forLineage, forDuplicateProcessing, effectiveTime, methodName);
String derivedAnchorGUID = this.deriveAnchorGUID(entity.getGUID(), entityTypeName, forLineage, forDuplicateProcessing, effectiveTime, methodName);

if (derivedAnchorGUID == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ public AuditLogReport getReport()
*/
public static class AuditLogActivity
{
private volatile Map<Integer, List<String>> severityIdentificationMap = new HashMap<>();
private volatile Map<Integer, Integer> severityCountMap = new HashMap<>();
private final Map<Integer, List<String>> severityIdentificationMap = new HashMap<>();
private final Map<Integer, Integer> severityCountMap = new HashMap<>();

/**
* Update the maps with information about another log record.
Expand Down Expand Up @@ -466,10 +466,7 @@ synchronized Map<Integer, Integer> getSeverityCountMap()
result.put(severityCode, severityCount);
}

if (! result.isEmpty())
{
return result;
}
return result;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package org.odpi.openmetadata.frameworks.auditlog;

/**
* ComponentDescription is an interface implemented by a enum that describes the components using the audit log
* ComponentDescription is an interface implemented by an enum that describes the components using the audit log
*/
public interface ComponentDescription
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public interface ComponentDescription
String getComponentDescription();

/**
* URL link to the wiki page that describes this component. This provides more information to the log reader
* URL to the wiki page that describes this component. This provides more information to the log reader
* on the operation of the component.
*
* @return String URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public enum ComponentDevelopmentStatus
SAMPLE (3, "Sample", "This component is supplied as a sample. It can be used 'as is' or may be modified as desired."),
DEPRECATED (99, "Deprecated", "This component is deprecated an may be removed in a later release.");

private int ordinal;
private String name;
private String description;
private final int ordinal;
private final String name;
private final String description;

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
@JsonIgnoreProperties(ignoreUnknown=true)
public class AuditLogMessageDefinition extends MessageDefinition
{
private AuditLogRecordSeverity severity;
private final AuditLogRecordSeverity severity;

/**
* Constructor to save all the fixed values of a message. This is typically populated
* from an Enum message set. The constructor passes most values to the super class and just retains
* the additional value for the audit log.
*
* @param messageId unique Id for the message
* @param messageId unique id for the message
* @param severity severity of the message
* @param messageTemplate text for the message
* @param systemAction description of the action taken by the system when the condition happened
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@JsonIgnoreProperties(ignoreUnknown=true)
public class ExceptionMessageDefinition extends MessageDefinition
{
private int httpErrorCode;
private final int httpErrorCode;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
@JsonIgnoreProperties(ignoreUnknown=true)
public abstract class MessageDefinition
{
private String messageId;
private String messageTemplate;
private String systemAction;
private String userAction;
private final String messageId;
private final String messageTemplate;
private final String systemAction;
private final String userAction;

private String[] params;

Expand Down Expand Up @@ -93,7 +93,7 @@ public String getSystemAction()


/**
* Returns instructions on what to do next given that this situation has occurred.
* Returns instructions on what to do next, given that this situation has occurred.
*
* @return userAction String
*/
Expand All @@ -117,7 +117,6 @@ public String toString()
", systemAction='" + systemAction + '\'' +
", userAction='" + userAction + '\'' +
", params=" + Arrays.toString(params) +
", messageParams=" + Arrays.toString(getMessageParams()) +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ public EntityDetail isEntityKnown(String userId,
List<OMRSRepositoryConnector> cohortConnectors = enterpriseParentConnector.getCohortConnectors(methodName);

FederationControl federationControl = new ParallelFederationControl(userId, cohortConnectors, auditLog, methodName);
GetEntityDetailExecutor executor = new GetEntityDetailExecutor(userId, guid, false, auditLog, methodName);
GetEntityDetailExecutor executor = new GetEntityDetailExecutor(userId, guid, auditLog, methodName);

/*
* Ready to process the request. Create requests occur in the first repository that accepts the call.
Expand All @@ -904,7 +904,7 @@ public EntityDetail isEntityKnown(String userId,
*/
federationControl.executeCommand(executor);

return executor.isEntityKnown();
return executor.isEntityKnown(true);
}


Expand Down Expand Up @@ -994,7 +994,7 @@ public EntityDetail getEntityDetail(String userId,
List<OMRSRepositoryConnector> cohortConnectors = enterpriseParentConnector.getCohortConnectors(methodName);

FederationControl federationControl = new ParallelFederationControl(userId, cohortConnectors, auditLog, methodName);
GetEntityDetailExecutor executor = new GetEntityDetailExecutor(userId, guid, true, auditLog, methodName);
GetEntityDetailExecutor executor = new GetEntityDetailExecutor(userId, guid, auditLog, methodName);

federationControl.executeCommand(executor);

Expand Down Expand Up @@ -1657,7 +1657,7 @@ public Relationship isRelationshipKnown(String userId,
List<OMRSRepositoryConnector> 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.
Expand Down Expand Up @@ -1706,7 +1706,7 @@ public Relationship getRelationship(String userId,
List<OMRSRepositoryConnector> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.odpi.openmetadata.frameworks.auditlog.AuditLog;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Classification;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceStatus;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -120,18 +121,32 @@ public void saveClassifications(List<Classification> retrievedClassifications)
/**
* Return the accumulated classifications to the caller.
*
* @param returnDeletedClassifications should classifications in deleted status be returned?
* @return null or list of classifications
*/
List<Classification> getClassifications()
List<Classification> getClassifications(boolean returnDeletedClassifications)
{
if (allClassifications.isEmpty())
{
return null;
}
else
else if (returnDeletedClassifications)
{
return new ArrayList<>(allClassifications.values());
}
else
{
List<Classification> activeClassifications = new ArrayList<>();

for (Classification accumulatedClassification : allClassifications.values())
{
if (accumulatedClassification.getStatus() != InstanceStatus.DELETED)
{
activeClassifications.add(accumulatedClassification);
}
}
return activeClassifications;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ public List<String> getResultsForAugmentation()
* Extract the resulting entity and accumulated classifications. It should be called once all the executors have completed processing
* their request(s).
*
* @return list of entities
* @param returnDeletedClassifications should classifications in deleted status be returned?
* @return consolidated entity
*/
public EntityDetail getResult()
public EntityDetail getResult(boolean returnDeletedClassifications)
{
if (currentSavedEntity != null)
{
currentSavedEntity.setClassifications(super.getClassifications());
currentSavedEntity.setClassifications(super.getClassifications(returnDeletedClassifications));
mandy-chessell marked this conversation as resolved.
Show resolved Hide resolved

return currentSavedEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public EntitySummary getResult()
{
if (currentSavedEntity != null)
{
currentSavedEntity.setClassifications(super.getClassifications());
currentSavedEntity.setClassifications(super.getClassifications(false));
mandy-chessell marked this conversation as resolved.
Show resolved Hide resolved

return currentSavedEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class RelationshipsAccumulator extends QueryInstanceAccumulatorBase
{
private volatile Map<String, Relationship> accumulatedRelationships = new HashMap<>();
private final Map<String, Relationship> accumulatedRelationships = new HashMap<>();


/**
Expand Down Expand Up @@ -108,7 +108,7 @@ public synchronized void addRelationships(List<Relationship> 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).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
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.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceStatus;
import org.odpi.openmetadata.repositoryservices.enterprise.repositoryconnector.accumulators.EntityDetailAccumulator;
import org.odpi.openmetadata.repositoryservices.ffdc.OMRSErrorCode;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.*;

import java.util.Date;
Expand All @@ -27,7 +29,6 @@
*/
public class GetEntityDetailExecutor extends GetEntityExecutor
{
private boolean allExceptions = true;
private Date asOfTime = null;

private final EntityDetailAccumulator accumulator;
Expand All @@ -38,17 +39,15 @@ public class GetEntityDetailExecutor extends GetEntityExecutor
*
* @param userId unique identifier for requesting user.
* @param entityGUID unique identifier (guid) for the entity.
* @param allExceptions is the a isEntityKnown or getEntityDetail request.
* @param auditLog logging destination
* @param methodName calling method
*/
public GetEntityDetailExecutor(String userId,
String entityGUID,
boolean allExceptions,
AuditLog auditLog,
String methodName)
{
this(userId, entityGUID, allExceptions, new EntityDetailAccumulator(auditLog), methodName);
this(userId, entityGUID, new EntityDetailAccumulator(auditLog), methodName);
}


Expand All @@ -57,19 +56,15 @@ public GetEntityDetailExecutor(String userId,
*
* @param userId unique identifier for requesting user.
* @param entityGUID unique identifier (guid) for the entity.
* @param allExceptions is the a isEntityKnown or getEntityDetail request.
* @param accumulator to use
* @param methodName calling method
*/
private GetEntityDetailExecutor(String userId,
String entityGUID,
boolean allExceptions,
EntityDetailAccumulator accumulator,
String methodName)
{
super(userId, entityGUID, accumulator, methodName);

this.allExceptions = allExceptions;
this.accumulator = accumulator;
}

Expand Down Expand Up @@ -147,14 +142,7 @@ public boolean issueRequestToRepository(String metadataCollectio
EntityDetail retrievedEntity;
if (asOfTime == null)
{
if (allExceptions)
{
retrievedEntity = metadataCollection.getEntityDetail(userId, entityGUID);
}
else
{
retrievedEntity = metadataCollection.isEntityKnown(userId, entityGUID);
}
retrievedEntity = metadataCollection.isEntityKnown(userId, entityGUID);
}
else
{
Expand Down Expand Up @@ -211,17 +199,18 @@ public boolean issueRequestToRepository(String metadataCollectio
/**
* Returns the entity if the entity is stored in the metadata collection, otherwise null.
*
* @param returnDeletedClassifications should classifications in deleted status be returned?
* @return the entity details if the entity is found in the metadata collection; otherwise return null
* @throws InvalidParameterException the guid is null.
* @throws RepositoryErrorException there is a problem communicating with the metadata repository where
* the metadata collection is stored.
* @throws UserNotAuthorizedException the userId is not permitted to perform this operation.
*/
public EntityDetail isEntityKnown() throws InvalidParameterException,
RepositoryErrorException,
UserNotAuthorizedException
public EntityDetail isEntityKnown(boolean returnDeletedClassifications) throws InvalidParameterException,
RepositoryErrorException,
UserNotAuthorizedException
{
EntityDetail result = accumulator.getResult();
EntityDetail result = accumulator.getResult(returnDeletedClassifications);
if (result != null)
{
return result;
Expand Down Expand Up @@ -252,17 +241,31 @@ public EntityDetail getEntityDetail() throws InvalidParameterException,
EntityProxyOnlyException,
UserNotAuthorizedException
{
EntityDetail entity = this.isEntityKnown();
EntityDetail entity = this.isEntityKnown(false);

if (entity != null)
{
if (entity.getStatus() == InstanceStatus.DELETED)
{
throw new EntityNotKnownException(OMRSErrorCode.ENTITY_SOFT_DELETED.getMessageDefinition(entity.getType().getTypeDefName(),
mandy-chessell marked this conversation as resolved.
Show resolved Hide resolved
entity.getGUID(),
methodName,
repositoryName),
this.getClass().getName(),
methodName);
}

return entity;
}

accumulator.throwCapturedEntityProxyOnlyException();
accumulator.throwCapturedEntityNotKnownException();

return null;
throw new EntityNotKnownException(OMRSErrorCode.ENTITY_NOT_KNOWN.getMessageDefinition(entityGUID,
methodName,
repositoryName),
this.getClass().getName(),
methodName);
}


Expand Down
Loading