631 lines
25 KiB
Java
Raw Normal View History

2019-08-31 20:51:14 -07:00
package com.linkedin.metadata.dao;
import com.linkedin.common.AuditStamp;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.schema.validation.CoercionMode;
import com.linkedin.data.schema.validation.RequiredMode;
import com.linkedin.data.schema.validation.UnrecognizedFieldMode;
import com.linkedin.data.schema.validation.ValidateDataAgainstSchema;
import com.linkedin.data.schema.validation.ValidationOptions;
import com.linkedin.data.schema.validation.ValidationResult;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.data.template.UnionTemplate;
import com.linkedin.metadata.dao.equality.DefaultEqualityTester;
import com.linkedin.metadata.dao.equality.EqualityTester;
import com.linkedin.metadata.dao.exception.ModelValidationException;
import com.linkedin.metadata.dao.producer.BaseMetadataEventProducer;
import com.linkedin.metadata.dao.retention.IndefiniteRetention;
import com.linkedin.metadata.dao.retention.Retention;
import com.linkedin.metadata.dao.retention.TimeBasedRetention;
import com.linkedin.metadata.dao.retention.VersionBasedRetention;
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
import com.linkedin.metadata.dao.storage.LocalDAOStorageConfig;
2019-08-31 20:51:14 -07:00
import com.linkedin.metadata.query.ExtraInfo;
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
import com.linkedin.metadata.query.IndexFilter;
2019-08-31 20:51:14 -07:00
import java.time.Clock;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
2019-08-31 20:51:14 -07:00
import java.util.Map;
import java.util.Optional;
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
import java.util.Set;
2019-08-31 20:51:14 -07:00
import java.util.UUID;
import java.util.function.BiConsumer;
2019-08-31 20:51:14 -07:00
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.Value;
/**
* A base class for all Local DAOs.
*
* Local DAO is a standardized interface to store and retrieve aspects from a document store.
*
* @param <ASPECT_UNION> must be a valid aspect union type defined in com.linkedin.metadata.aspect
* @param <URN> must be the entity URN type in {@code ASPECT_UNION}
*/
public abstract class BaseLocalDAO<ASPECT_UNION extends UnionTemplate, URN extends Urn>
extends BaseReadDAO<ASPECT_UNION, URN> {
@Value
static class AspectEntry<ASPECT extends RecordTemplate> {
ASPECT aspect;
2019-08-31 20:51:14 -07:00
ExtraInfo extraInfo;
}
@Value
static class AddResult<ASPECT extends RecordTemplate> {
ASPECT oldValue;
ASPECT newValue;
2019-08-31 20:51:14 -07:00
}
private static final String DEFAULT_ID_NAMESPACE = "global";
private static final IndefiniteRetention INDEFINITE_RETENTION = new IndefiniteRetention();
private static final int DEFAULT_MAX_TRANSACTION_RETRY = 3;
protected final BaseMetadataEventProducer _producer;
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
protected final LocalDAOStorageConfig _storageConfig;
2019-08-31 20:51:14 -07:00
// Maps an aspect class to the corresponding retention policy
private final Map<Class<? extends RecordTemplate>, Retention> _aspectRetentionMap = new HashMap<>();
// Maps as aspect class to a list of post-update hooks
private final Map<Class<? extends RecordTemplate>, List<BiConsumer<Urn, RecordTemplate>>> _aspectPostUpdateHooksMap =
new HashMap<>();
2019-08-31 20:51:14 -07:00
// Maps an aspect class to the corresponding equality tester
private final Map<Class<? extends RecordTemplate>, EqualityTester<? extends RecordTemplate>>
_aspectEqualityTesterMap = new HashMap<>();
private boolean _modelValidationOnWrite = true;
// Always emit MAE on every update regardless if there's any actual change in value
private boolean _alwaysEmitAuditEvent = false;
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
// Opt in to emit Aspect Specific MAE, at initial migration stage, always emit the event
private boolean _emitAspectSpecificAuditEvent = false;
// Flag for enabling reads and writes to local secondary index
private boolean _enableLocalSecondaryIndex = false;
// Flag for backfilling local secondary index
private boolean _backfillLocalSecondaryIndex = false;
2019-08-31 20:51:14 -07:00
private Clock _clock = Clock.systemUTC();
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
/**
* Constructor for BaseLocalDAO
*
* @param aspectUnionClass containing union of all supported aspects. Must be a valid aspect union defined in com.linkedin.metadata.aspect
* @param producer {@link BaseMetadataEventProducer} for the metadata event producer
*/
2019-08-31 20:51:14 -07:00
public BaseLocalDAO(@Nonnull Class<ASPECT_UNION> aspectUnionClass, @Nonnull BaseMetadataEventProducer producer) {
super(aspectUnionClass);
_producer = producer;
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
_storageConfig = LocalDAOStorageConfig.builder().build();
}
/**
* Constructor for BaseLocalDAO
*
* @param producer {@link BaseMetadataEventProducer} for the metadata event producer
* @param storageConfig {@link LocalDAOStorageConfig} containing storage config of full list of supported aspects
*/
public BaseLocalDAO(@Nonnull BaseMetadataEventProducer producer, @Nonnull LocalDAOStorageConfig storageConfig) {
super(storageConfig.getAspectStorageConfigMap().keySet());
_producer = producer;
_storageConfig = storageConfig;
2019-08-31 20:51:14 -07:00
}
/**
* For tests to override the internal clock
*/
public void setClock(@Nonnull Clock clock) {
_clock = clock;
}
/**
* Sets {@link Retention} for a specific aspect type.
*/
public <ASPECT extends RecordTemplate> void setRetention(@Nonnull Class<ASPECT> aspectClass,
@Nonnull Retention retention) {
checkValidAspect(aspectClass);
_aspectRetentionMap.put(aspectClass, retention);
}
/**
* Gets the {@link Retention} for an aspect type, or {@link IndefiniteRetention} if none is registered.
*/
@Nonnull
public <ASPECT extends RecordTemplate> Retention getRetention(@Nonnull Class<ASPECT> aspectClass) {
checkValidAspect(aspectClass);
return _aspectRetentionMap.getOrDefault(aspectClass, INDEFINITE_RETENTION);
}
/**
* Registers a post-update hook for a specific aspect.
*
* The hook will be invoked with the latest value of an aspect after it's updated. There's no guarantee on the order
* of invocation when multiple hooks are added for a single aspect. Adding the same hook again will result in
* {@link IllegalArgumentException} thrown. Hooks are invoked in the order they're registered.
*/
public <URN extends Urn, ASPECT extends RecordTemplate> void addPostUpdateHook(@Nonnull Class<ASPECT> aspectClass,
@Nonnull BiConsumer<URN, ASPECT> postUpdateHook) {
checkValidAspect(aspectClass);
// TODO: Also validate Urn once we convert all aspect models to PDL with proper annotation
final List<BiConsumer<Urn, RecordTemplate>> hooks =
_aspectPostUpdateHooksMap.getOrDefault(aspectClass, new LinkedList<>());
if (hooks.contains(postUpdateHook)) {
throw new IllegalArgumentException("Adding an already-registered hook");
}
hooks.add((BiConsumer<Urn, RecordTemplate>) postUpdateHook);
_aspectPostUpdateHooksMap.put(aspectClass, hooks);
}
2019-08-31 20:51:14 -07:00
/**
* Sets the {@link EqualityTester} for a specific aspect type.
*/
public <ASPECT extends RecordTemplate> void setEqualityTester(@Nonnull Class<ASPECT> aspectClass,
@Nonnull EqualityTester<ASPECT> tester) {
checkValidAspect(aspectClass);
_aspectEqualityTesterMap.put(aspectClass, tester);
}
/**
* Gets the {@link EqualityTester} for an aspect, or {@link DefaultEqualityTester} if none is registered.
*/
@Nonnull
public <ASPECT extends RecordTemplate> EqualityTester<ASPECT> getEqualityTester(@Nonnull Class<ASPECT> aspectClass) {
checkValidAspect(aspectClass);
return (EqualityTester<ASPECT>) _aspectEqualityTesterMap.computeIfAbsent(aspectClass,
key -> new DefaultEqualityTester<ASPECT>());
}
/**
* Enables or disables model validation before persisting.
*/
public void enableModelValidationOnWrite(boolean enabled) {
_modelValidationOnWrite = enabled;
}
/**
* Sets if MAE should be always emitted after each update even if there's no actual value change.
*/
public void setAlwaysEmitAuditEvent(boolean alwaysEmitAuditEvent) {
_alwaysEmitAuditEvent = alwaysEmitAuditEvent;
}
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
/**
* Sets if aspect specific MAE should be always emitted after each update even if there's no actual value change.
*/
public void setEmitAspectSpecificAuditEvent(boolean emitAspectSpecificAuditEvent) {
_emitAspectSpecificAuditEvent = emitAspectSpecificAuditEvent;
}
/**
* Sets if writes to local secondary index enabled
* @deprecated Use {@link #enableLocalSecondaryIndex(boolean)} instead
*/
public void setWriteToLocalSecondaryIndex(boolean writeToLocalSecondaryIndex) {
_enableLocalSecondaryIndex = writeToLocalSecondaryIndex;
}
/**
* Enables reads from and writes to local secondary index
*/
public void enableLocalSecondaryIndex(boolean enableLocalSecondaryIndex) {
_enableLocalSecondaryIndex = enableLocalSecondaryIndex;
}
/**
* Gets if reads and writes to local secondary index are enabled
*/
public boolean isLocalSecondaryIndexEnabled() {
return _enableLocalSecondaryIndex;
}
/**
* Sets if local secondary index backfilling is enabled
*/
public void setBackfillLocalSecondaryIndex(boolean backfillLocalSecondaryIndex) {
_backfillLocalSecondaryIndex = backfillLocalSecondaryIndex;
}
2019-08-31 20:51:14 -07:00
/**
* Adds a new version of aspect for an entity.
*
* The new aspect will have an automatically assigned version number, which is guaranteed to be positive and
* monotonically increasing. Older versions of aspect will be purged automatically based on the retention setting.
* A MetadataAuditEvent is also emitted if there's an actual update.
*
* @param urn the URN for the entity the aspect is attached to
* @param auditStamp the audit stamp for the operation
* @param updateLambda a lambda expression that takes the previous version of aspect and returns the new version
* @return {@link RecordTemplate} of the new value of aspect
2019-08-31 20:51:14 -07:00
*/
corp-identity-gms 1.0.0 -> 1.0.25: 1.0.24: Corp user search across teams and skills 1.0.21: Make /corpGroups /gridUsers /gridGroups extend BaseEntityResource 1.0.17: Use correct util function to load resource file 1.0.16: Add ingest, backfill & getSnapshot action methods to all top-level resources in corp-identity-gms 1.0.13: Onboard search query templates on corp-identity-gms 1.0.9: Fix batch get and add client for batch get 1.0.8: Change package name for corpuser search config 1.0.7: Use search config to get autocomplete field 1.0.6: Implement searchable client 1.0.5: Auto-complete backend support 1.0.3: Add search API metadata-models 24.0.0 -> 38.1.6: 38.1.3: Index active status to corp user search index 38.1.2: Change update response to create response for create API 38.0.10: Mark BaseAspectResource as deprecated 38.0.9: Allow TYPEREF items which have primitive types for arrays in models 38.0.7: Add get-and-set-if-absent function to Local DAO 38.0.6: Add find entities with one relationship in query dao 38.0.4: Fix the inconsistency use of constants and urn params in query dao 38.0.2: Parse source map to obtain the urn 38.0.1: Search document validator in Index Builder 38.0.0: Add urns to search result metadata 37.0.7: Refactor the query dao 37.0.6: Use test models in neo4j dao 37.0.5: Drop metadata model structural assumptions made in neo4j DAOs 37.0.2: Return empty list from getBrowsePaths if browsePaths field doesn't exist 36.0.3: Drop elasticsearch-dao's metadata-models dependency 35.0.10: ES Search DAO to handle null values 35.0.5: Ebean local Dao query string match 35.0.4: Drop all search & browse configs that have been moved to individual GMS 35.0.3: Add ReportTo relationship model 35.0.0: Load resource file properly 34.0.9: Make RestliAuditor injectable 34.0.8: Use encoded query in the test resource 34.0.4: Handle empty aspects param correctly for backfill & getSnapshot actions 34.0.1: Remove corp user specific files from metadata-models 34.0.0: Add backfill & getSnapshot actions to BaseEntityResource 32.0.16: Merge data template classes into metadata-dao's main artifact 32.0.14: Replace "update" method with "ingest" action in BaseEntityResource 32.0.13: Make fliter & sortCriteria parameters optional as they should have been 32.0.12: Move AspectVersion & SnapshotKey back to their original namespaces 32.0.11: Break metadata-dao's dependency on metadata-models 32.0.10: Move model validators to a separate module 32.0.9: Extract principal from the request context for user AuditStamp 32.0.8: Fixing nullability annotations for search/autocomplete/browse resources & daos 32.0.7: Move DAO-specific models to metadata-dao module 32.0.4: Fix search finder not returning total search results count 32.0.3: Implement get_all using search index 32.0.2: Add missing nullability annotation 32.0.1: Use more consistent naming for the test models 31.0.1: Use test-specific metadata models in metadata-dao 31.0.0: Add sort order to Search Dao 30.0.2: Rename Aspect test model to AspectUnion to avoid confusion 30.0.1: Committing migration for metadata-models. 30.0.0: Add default autocomplete field in search config 29.0.16: Modify testcase to account for empty filters 29.0.15: Add searchable interface that clients can use 29.0.14: Use test-specific metadata models in ebean-dao 29.0.12: Move TestUtils to metadata-test-models module 29.0.11: Refactor all tests in metadata-restli to use test models 29.0.10: Move li-metadata-test-utils, metadata-test-models, metadata-test-utils into a new metadata-testing directory to improve code organization. Note that this is a backward compatible change as this doesn't alter the produced artifacts. 29.0.9: Move test-specific models to a stand-alone module 29.0.2: Refactor the rest of validators 28.0.3: Refactor validateSchema for aspect 28.0.2: Implement searchDao for CorpUserInfo. 27.0.16: Refactor for ModelValidation tests 27.0.10: Add new relationship union to model utils 27.0.9: Add plugin to rest client factory 27.0.6: Add rest high level factory 27.0.5: Fix a test bug when reviewing the code 27.0.4: Add create via lambda API to BaseVersionedAspectResource 27.0.2: Change return type of search finder to capture search result metadata in BaseSearchableEntityResource 27.0.1: Drop the unnecessary get method from BaseEntityResource 27.0.0: Add BaseBrowsableEntityResource 26.0.15: Add autocomplete action to BaseSearchableEntityResource 26.0.14: Add BaseSearchableEntityResource 26.0.13: Add getUrnFromDocument & urnClassForDocument util methods that are needed in future RBs 26.0.11: Add BaseVersionedAspectResource 26.0.9: Index signals associated with dataset relevance 26.0.4: Support namespace for ID generation 26.0.1: Fix inconsistent instance variable naming in SearchResult 25.0.6: Add entity-snapshot conversion 25.0.5: Use test-specific metadata models in metadata-restli 25.0.3: Add aspect filtering to BaseEntityResource 24.0.9: Add update method to BaseEntityResource 24.0.7: Fix for parameter types of getBrowsePaths action method MP_VERSION=corp-identity-gms:1.0.25 MP_VERSION=metadata-models:38.1.6 MP_VERSION=wherehows-samza:1.0.29
2019-10-02 11:08:52 -07:00
@Nonnull
public <ASPECT extends RecordTemplate> ASPECT add(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
@Nonnull Function<Optional<ASPECT>, ASPECT> updateLambda, @Nonnull AuditStamp auditStamp,
2019-08-31 20:51:14 -07:00
int maxTransactionRetry) {
checkValidAspect(aspectClass);
final EqualityTester<ASPECT> equalityTester = getEqualityTester(aspectClass);
final AddResult<ASPECT> result = runInTransactionWithRetry(() -> {
2019-08-31 20:51:14 -07:00
// 1. Compute newValue based on oldValue
AspectEntry<ASPECT> latest = getLatest(urn, aspectClass);
final ASPECT oldValue = latest == null ? null : latest.getAspect();
final ASPECT newValue = updateLambda.apply(Optional.ofNullable(oldValue));
2019-08-31 20:51:14 -07:00
checkValidAspect(newValue.getClass());
if (_modelValidationOnWrite) {
validateAgainstSchema(newValue);
}
// 2. Skip saving if there's no actual change
if (oldValue != null && equalityTester.equals(oldValue, newValue)) {
return new AddResult<>(oldValue, oldValue);
2019-08-31 20:51:14 -07:00
}
// 3. Save the newValue as the latest version
long largestVersion =
saveLatest(urn, aspectClass, oldValue, latest == null ? null : latest.getExtraInfo().getAudit(), newValue,
auditStamp);
2019-08-31 20:51:14 -07:00
// 4. Apply retention policy
2019-08-31 20:51:14 -07:00
applyRetention(urn, aspectClass, getRetention(aspectClass), largestVersion);
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
// 5. Save to local secondary index
if (_enableLocalSecondaryIndex) {
saveToLocalSecondaryIndex(urn, newValue, largestVersion);
}
return new AddResult<>(oldValue, newValue);
2019-08-31 20:51:14 -07:00
}, maxTransactionRetry);
final ASPECT oldValue = result.getOldValue();
final ASPECT newValue = result.getNewValue();
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
// 6. Produce MAE after a successful update
if (_alwaysEmitAuditEvent || oldValue != newValue) {
_producer.produceMetadataAuditEvent(urn, oldValue, newValue);
}
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
// TODO: Replace step 6 with step 6.1 with diff option after pipeline is fully migrated to aspect specific events.
// 6.1. Produce aspect specific MAE after a successful update
if (_emitAspectSpecificAuditEvent) {
_producer.produceAspectSpecificMetadataAuditEvent(urn, oldValue, newValue);
}
// 7. Invoke post-update hooks if there's any
if (_aspectPostUpdateHooksMap.containsKey(aspectClass)) {
_aspectPostUpdateHooksMap.get(aspectClass).forEach(hook -> hook.accept(urn, newValue));
}
return newValue;
2019-08-31 20:51:14 -07:00
}
/**
* Similar to {@link #add(Urn, Class, Function, AuditStamp, int)} but uses the default maximum transaction retry.
*/
corp-identity-gms 1.0.0 -> 1.0.25: 1.0.24: Corp user search across teams and skills 1.0.21: Make /corpGroups /gridUsers /gridGroups extend BaseEntityResource 1.0.17: Use correct util function to load resource file 1.0.16: Add ingest, backfill & getSnapshot action methods to all top-level resources in corp-identity-gms 1.0.13: Onboard search query templates on corp-identity-gms 1.0.9: Fix batch get and add client for batch get 1.0.8: Change package name for corpuser search config 1.0.7: Use search config to get autocomplete field 1.0.6: Implement searchable client 1.0.5: Auto-complete backend support 1.0.3: Add search API metadata-models 24.0.0 -> 38.1.6: 38.1.3: Index active status to corp user search index 38.1.2: Change update response to create response for create API 38.0.10: Mark BaseAspectResource as deprecated 38.0.9: Allow TYPEREF items which have primitive types for arrays in models 38.0.7: Add get-and-set-if-absent function to Local DAO 38.0.6: Add find entities with one relationship in query dao 38.0.4: Fix the inconsistency use of constants and urn params in query dao 38.0.2: Parse source map to obtain the urn 38.0.1: Search document validator in Index Builder 38.0.0: Add urns to search result metadata 37.0.7: Refactor the query dao 37.0.6: Use test models in neo4j dao 37.0.5: Drop metadata model structural assumptions made in neo4j DAOs 37.0.2: Return empty list from getBrowsePaths if browsePaths field doesn't exist 36.0.3: Drop elasticsearch-dao's metadata-models dependency 35.0.10: ES Search DAO to handle null values 35.0.5: Ebean local Dao query string match 35.0.4: Drop all search & browse configs that have been moved to individual GMS 35.0.3: Add ReportTo relationship model 35.0.0: Load resource file properly 34.0.9: Make RestliAuditor injectable 34.0.8: Use encoded query in the test resource 34.0.4: Handle empty aspects param correctly for backfill & getSnapshot actions 34.0.1: Remove corp user specific files from metadata-models 34.0.0: Add backfill & getSnapshot actions to BaseEntityResource 32.0.16: Merge data template classes into metadata-dao's main artifact 32.0.14: Replace "update" method with "ingest" action in BaseEntityResource 32.0.13: Make fliter & sortCriteria parameters optional as they should have been 32.0.12: Move AspectVersion & SnapshotKey back to their original namespaces 32.0.11: Break metadata-dao's dependency on metadata-models 32.0.10: Move model validators to a separate module 32.0.9: Extract principal from the request context for user AuditStamp 32.0.8: Fixing nullability annotations for search/autocomplete/browse resources & daos 32.0.7: Move DAO-specific models to metadata-dao module 32.0.4: Fix search finder not returning total search results count 32.0.3: Implement get_all using search index 32.0.2: Add missing nullability annotation 32.0.1: Use more consistent naming for the test models 31.0.1: Use test-specific metadata models in metadata-dao 31.0.0: Add sort order to Search Dao 30.0.2: Rename Aspect test model to AspectUnion to avoid confusion 30.0.1: Committing migration for metadata-models. 30.0.0: Add default autocomplete field in search config 29.0.16: Modify testcase to account for empty filters 29.0.15: Add searchable interface that clients can use 29.0.14: Use test-specific metadata models in ebean-dao 29.0.12: Move TestUtils to metadata-test-models module 29.0.11: Refactor all tests in metadata-restli to use test models 29.0.10: Move li-metadata-test-utils, metadata-test-models, metadata-test-utils into a new metadata-testing directory to improve code organization. Note that this is a backward compatible change as this doesn't alter the produced artifacts. 29.0.9: Move test-specific models to a stand-alone module 29.0.2: Refactor the rest of validators 28.0.3: Refactor validateSchema for aspect 28.0.2: Implement searchDao for CorpUserInfo. 27.0.16: Refactor for ModelValidation tests 27.0.10: Add new relationship union to model utils 27.0.9: Add plugin to rest client factory 27.0.6: Add rest high level factory 27.0.5: Fix a test bug when reviewing the code 27.0.4: Add create via lambda API to BaseVersionedAspectResource 27.0.2: Change return type of search finder to capture search result metadata in BaseSearchableEntityResource 27.0.1: Drop the unnecessary get method from BaseEntityResource 27.0.0: Add BaseBrowsableEntityResource 26.0.15: Add autocomplete action to BaseSearchableEntityResource 26.0.14: Add BaseSearchableEntityResource 26.0.13: Add getUrnFromDocument & urnClassForDocument util methods that are needed in future RBs 26.0.11: Add BaseVersionedAspectResource 26.0.9: Index signals associated with dataset relevance 26.0.4: Support namespace for ID generation 26.0.1: Fix inconsistent instance variable naming in SearchResult 25.0.6: Add entity-snapshot conversion 25.0.5: Use test-specific metadata models in metadata-restli 25.0.3: Add aspect filtering to BaseEntityResource 24.0.9: Add update method to BaseEntityResource 24.0.7: Fix for parameter types of getBrowsePaths action method MP_VERSION=corp-identity-gms:1.0.25 MP_VERSION=metadata-models:38.1.6 MP_VERSION=wherehows-samza:1.0.29
2019-10-02 11:08:52 -07:00
@Nonnull
public <ASPECT extends RecordTemplate> ASPECT add(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
@Nonnull Function<Optional<ASPECT>, ASPECT> updateLambda, @Nonnull AuditStamp auditStamp) {
corp-identity-gms 1.0.0 -> 1.0.25: 1.0.24: Corp user search across teams and skills 1.0.21: Make /corpGroups /gridUsers /gridGroups extend BaseEntityResource 1.0.17: Use correct util function to load resource file 1.0.16: Add ingest, backfill & getSnapshot action methods to all top-level resources in corp-identity-gms 1.0.13: Onboard search query templates on corp-identity-gms 1.0.9: Fix batch get and add client for batch get 1.0.8: Change package name for corpuser search config 1.0.7: Use search config to get autocomplete field 1.0.6: Implement searchable client 1.0.5: Auto-complete backend support 1.0.3: Add search API metadata-models 24.0.0 -> 38.1.6: 38.1.3: Index active status to corp user search index 38.1.2: Change update response to create response for create API 38.0.10: Mark BaseAspectResource as deprecated 38.0.9: Allow TYPEREF items which have primitive types for arrays in models 38.0.7: Add get-and-set-if-absent function to Local DAO 38.0.6: Add find entities with one relationship in query dao 38.0.4: Fix the inconsistency use of constants and urn params in query dao 38.0.2: Parse source map to obtain the urn 38.0.1: Search document validator in Index Builder 38.0.0: Add urns to search result metadata 37.0.7: Refactor the query dao 37.0.6: Use test models in neo4j dao 37.0.5: Drop metadata model structural assumptions made in neo4j DAOs 37.0.2: Return empty list from getBrowsePaths if browsePaths field doesn't exist 36.0.3: Drop elasticsearch-dao's metadata-models dependency 35.0.10: ES Search DAO to handle null values 35.0.5: Ebean local Dao query string match 35.0.4: Drop all search & browse configs that have been moved to individual GMS 35.0.3: Add ReportTo relationship model 35.0.0: Load resource file properly 34.0.9: Make RestliAuditor injectable 34.0.8: Use encoded query in the test resource 34.0.4: Handle empty aspects param correctly for backfill & getSnapshot actions 34.0.1: Remove corp user specific files from metadata-models 34.0.0: Add backfill & getSnapshot actions to BaseEntityResource 32.0.16: Merge data template classes into metadata-dao's main artifact 32.0.14: Replace "update" method with "ingest" action in BaseEntityResource 32.0.13: Make fliter & sortCriteria parameters optional as they should have been 32.0.12: Move AspectVersion & SnapshotKey back to their original namespaces 32.0.11: Break metadata-dao's dependency on metadata-models 32.0.10: Move model validators to a separate module 32.0.9: Extract principal from the request context for user AuditStamp 32.0.8: Fixing nullability annotations for search/autocomplete/browse resources & daos 32.0.7: Move DAO-specific models to metadata-dao module 32.0.4: Fix search finder not returning total search results count 32.0.3: Implement get_all using search index 32.0.2: Add missing nullability annotation 32.0.1: Use more consistent naming for the test models 31.0.1: Use test-specific metadata models in metadata-dao 31.0.0: Add sort order to Search Dao 30.0.2: Rename Aspect test model to AspectUnion to avoid confusion 30.0.1: Committing migration for metadata-models. 30.0.0: Add default autocomplete field in search config 29.0.16: Modify testcase to account for empty filters 29.0.15: Add searchable interface that clients can use 29.0.14: Use test-specific metadata models in ebean-dao 29.0.12: Move TestUtils to metadata-test-models module 29.0.11: Refactor all tests in metadata-restli to use test models 29.0.10: Move li-metadata-test-utils, metadata-test-models, metadata-test-utils into a new metadata-testing directory to improve code organization. Note that this is a backward compatible change as this doesn't alter the produced artifacts. 29.0.9: Move test-specific models to a stand-alone module 29.0.2: Refactor the rest of validators 28.0.3: Refactor validateSchema for aspect 28.0.2: Implement searchDao for CorpUserInfo. 27.0.16: Refactor for ModelValidation tests 27.0.10: Add new relationship union to model utils 27.0.9: Add plugin to rest client factory 27.0.6: Add rest high level factory 27.0.5: Fix a test bug when reviewing the code 27.0.4: Add create via lambda API to BaseVersionedAspectResource 27.0.2: Change return type of search finder to capture search result metadata in BaseSearchableEntityResource 27.0.1: Drop the unnecessary get method from BaseEntityResource 27.0.0: Add BaseBrowsableEntityResource 26.0.15: Add autocomplete action to BaseSearchableEntityResource 26.0.14: Add BaseSearchableEntityResource 26.0.13: Add getUrnFromDocument & urnClassForDocument util methods that are needed in future RBs 26.0.11: Add BaseVersionedAspectResource 26.0.9: Index signals associated with dataset relevance 26.0.4: Support namespace for ID generation 26.0.1: Fix inconsistent instance variable naming in SearchResult 25.0.6: Add entity-snapshot conversion 25.0.5: Use test-specific metadata models in metadata-restli 25.0.3: Add aspect filtering to BaseEntityResource 24.0.9: Add update method to BaseEntityResource 24.0.7: Fix for parameter types of getBrowsePaths action method MP_VERSION=corp-identity-gms:1.0.25 MP_VERSION=metadata-models:38.1.6 MP_VERSION=wherehows-samza:1.0.29
2019-10-02 11:08:52 -07:00
return add(urn, aspectClass, updateLambda, auditStamp, DEFAULT_MAX_TRANSACTION_RETRY);
2019-08-31 20:51:14 -07:00
}
/**
* Similar to {@link #add(Urn, Class, Function, AuditStamp)} but takes the new value directly.
*/
corp-identity-gms 1.0.0 -> 1.0.25: 1.0.24: Corp user search across teams and skills 1.0.21: Make /corpGroups /gridUsers /gridGroups extend BaseEntityResource 1.0.17: Use correct util function to load resource file 1.0.16: Add ingest, backfill & getSnapshot action methods to all top-level resources in corp-identity-gms 1.0.13: Onboard search query templates on corp-identity-gms 1.0.9: Fix batch get and add client for batch get 1.0.8: Change package name for corpuser search config 1.0.7: Use search config to get autocomplete field 1.0.6: Implement searchable client 1.0.5: Auto-complete backend support 1.0.3: Add search API metadata-models 24.0.0 -> 38.1.6: 38.1.3: Index active status to corp user search index 38.1.2: Change update response to create response for create API 38.0.10: Mark BaseAspectResource as deprecated 38.0.9: Allow TYPEREF items which have primitive types for arrays in models 38.0.7: Add get-and-set-if-absent function to Local DAO 38.0.6: Add find entities with one relationship in query dao 38.0.4: Fix the inconsistency use of constants and urn params in query dao 38.0.2: Parse source map to obtain the urn 38.0.1: Search document validator in Index Builder 38.0.0: Add urns to search result metadata 37.0.7: Refactor the query dao 37.0.6: Use test models in neo4j dao 37.0.5: Drop metadata model structural assumptions made in neo4j DAOs 37.0.2: Return empty list from getBrowsePaths if browsePaths field doesn't exist 36.0.3: Drop elasticsearch-dao's metadata-models dependency 35.0.10: ES Search DAO to handle null values 35.0.5: Ebean local Dao query string match 35.0.4: Drop all search & browse configs that have been moved to individual GMS 35.0.3: Add ReportTo relationship model 35.0.0: Load resource file properly 34.0.9: Make RestliAuditor injectable 34.0.8: Use encoded query in the test resource 34.0.4: Handle empty aspects param correctly for backfill & getSnapshot actions 34.0.1: Remove corp user specific files from metadata-models 34.0.0: Add backfill & getSnapshot actions to BaseEntityResource 32.0.16: Merge data template classes into metadata-dao's main artifact 32.0.14: Replace "update" method with "ingest" action in BaseEntityResource 32.0.13: Make fliter & sortCriteria parameters optional as they should have been 32.0.12: Move AspectVersion & SnapshotKey back to their original namespaces 32.0.11: Break metadata-dao's dependency on metadata-models 32.0.10: Move model validators to a separate module 32.0.9: Extract principal from the request context for user AuditStamp 32.0.8: Fixing nullability annotations for search/autocomplete/browse resources & daos 32.0.7: Move DAO-specific models to metadata-dao module 32.0.4: Fix search finder not returning total search results count 32.0.3: Implement get_all using search index 32.0.2: Add missing nullability annotation 32.0.1: Use more consistent naming for the test models 31.0.1: Use test-specific metadata models in metadata-dao 31.0.0: Add sort order to Search Dao 30.0.2: Rename Aspect test model to AspectUnion to avoid confusion 30.0.1: Committing migration for metadata-models. 30.0.0: Add default autocomplete field in search config 29.0.16: Modify testcase to account for empty filters 29.0.15: Add searchable interface that clients can use 29.0.14: Use test-specific metadata models in ebean-dao 29.0.12: Move TestUtils to metadata-test-models module 29.0.11: Refactor all tests in metadata-restli to use test models 29.0.10: Move li-metadata-test-utils, metadata-test-models, metadata-test-utils into a new metadata-testing directory to improve code organization. Note that this is a backward compatible change as this doesn't alter the produced artifacts. 29.0.9: Move test-specific models to a stand-alone module 29.0.2: Refactor the rest of validators 28.0.3: Refactor validateSchema for aspect 28.0.2: Implement searchDao for CorpUserInfo. 27.0.16: Refactor for ModelValidation tests 27.0.10: Add new relationship union to model utils 27.0.9: Add plugin to rest client factory 27.0.6: Add rest high level factory 27.0.5: Fix a test bug when reviewing the code 27.0.4: Add create via lambda API to BaseVersionedAspectResource 27.0.2: Change return type of search finder to capture search result metadata in BaseSearchableEntityResource 27.0.1: Drop the unnecessary get method from BaseEntityResource 27.0.0: Add BaseBrowsableEntityResource 26.0.15: Add autocomplete action to BaseSearchableEntityResource 26.0.14: Add BaseSearchableEntityResource 26.0.13: Add getUrnFromDocument & urnClassForDocument util methods that are needed in future RBs 26.0.11: Add BaseVersionedAspectResource 26.0.9: Index signals associated with dataset relevance 26.0.4: Support namespace for ID generation 26.0.1: Fix inconsistent instance variable naming in SearchResult 25.0.6: Add entity-snapshot conversion 25.0.5: Use test-specific metadata models in metadata-restli 25.0.3: Add aspect filtering to BaseEntityResource 24.0.9: Add update method to BaseEntityResource 24.0.7: Fix for parameter types of getBrowsePaths action method MP_VERSION=corp-identity-gms:1.0.25 MP_VERSION=metadata-models:38.1.6 MP_VERSION=wherehows-samza:1.0.29
2019-10-02 11:08:52 -07:00
@Nonnull
public <ASPECT extends RecordTemplate> ASPECT add(@Nonnull URN urn, @Nonnull ASPECT newValue,
2019-08-31 20:51:14 -07:00
@Nonnull AuditStamp auditStamp) {
return add(urn, (Class<ASPECT>) newValue.getClass(), ignored -> newValue, auditStamp);
2019-08-31 20:51:14 -07:00
}
private <ASPECT extends RecordTemplate> void applyRetention(@Nonnull URN urn, @Nonnull Class<ASPECT> aspectClass,
@Nonnull Retention retention, long largestVersion) {
if (retention instanceof IndefiniteRetention) {
return;
}
if (retention instanceof VersionBasedRetention) {
applyVersionBasedRetention(aspectClass, urn, (VersionBasedRetention) retention, largestVersion);
return;
}
if (retention instanceof TimeBasedRetention) {
applyTimeBasedRetention(aspectClass, urn, (TimeBasedRetention) retention, _clock.millis());
return;
}
}
/**
* Saves the latest aspect
*
* @param urn the URN for the entity the aspect is attached to
* @param aspectClass the aspectClass of the aspect being saved
* @param oldEntry {@link RecordTemplate} of the previous latest value of aspect, null if new value is the first version
* @param oldAuditStamp the audit stamp of the previous latest aspect, null if new value is the first version
* @param newEntry {@link RecordTemplate} of the new latest value of aspect
* @param newAuditStamp the audit stamp for the operation
* @return the largestVersion
*/
protected abstract <ASPECT extends RecordTemplate> long saveLatest(@Nonnull URN urn,
@Nonnull Class<ASPECT> aspectClass, @Nullable ASPECT oldEntry, @Nullable AuditStamp oldAuditStamp,
@Nonnull ASPECT newEntry, @Nonnull AuditStamp newAuditStamp);
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
/**
* Saves the new value of an aspect to local secondary index
*
* @param urn the URN for the entity the aspect is attached to
* @param newValue {@link RecordTemplate} of the new value of aspect
* @param version version of the aspect
*/
protected abstract <ASPECT extends RecordTemplate> void saveToLocalSecondaryIndex(@Nonnull URN urn,
@Nullable ASPECT newValue, long version);
/**
* Returns list of urns from local secondary index that satisfy the given filter conditions.
*
* @param indexFilter {@link IndexFilter} containing filter conditions to be applied
* @param lastUrn last urn of the previous fetched page. For the first page, this should be set as NULL
* @param pageSize maximum number of distinct urns to return
* @return {@link ListResult} of urns from local secondary index that satisfy the given filter conditions
*/
@Nonnull
public abstract ListResult<Urn> listUrns(@Nonnull IndexFilter indexFilter, @Nullable URN lastUrn, int pageSize);
2019-08-31 20:51:14 -07:00
/**
* Runs the given lambda expression in a transaction with a limited number of retries.
*
* @param block the lambda expression to run
* @param maxTransactionRetry maximum number of transaction retries before throwing an exception
* @param <T> type for the result object
* @return the result object from a successfully committed transaction
*/
@Nonnull
2019-08-31 20:51:14 -07:00
protected abstract <T> T runInTransactionWithRetry(@Nonnull Supplier<T> block, int maxTransactionRetry);
/**
* Gets the latest version of a specific aspect type for an entity
*
* @param urn {@link Urn} for the entity
* @param aspectClass the type of aspect to get
* @return the latest version for the aspect type, or null if there's none
*/
@Nullable
protected abstract <ASPECT extends RecordTemplate> AspectEntry<ASPECT> getLatest(@Nonnull URN urn,
2019-08-31 20:51:14 -07:00
@Nonnull Class<ASPECT> aspectClass);
/**
* Gets the next version to use for an entity's specific aspect type.
*
* @param urn {@link Urn} for the entity
* @param aspectClass the type of aspect to get
* @return the next version number to use, or {@link #LATEST_VERSION} if there's no previous versions
*/
protected abstract <ASPECT extends RecordTemplate> long getNextVersion(@Nonnull URN urn,
@Nonnull Class<ASPECT> aspectClass);
/**
* Saves an aspect for an entity with specific version & {@link AuditStamp}.
*
* @param urn {@link Urn} for the entity
* @param value the aspect to save
* @param auditStamp the {@link AuditStamp} for the aspect
* @param version the version for the aspect
* @param insert use insert, instead of update, operation to save
*/
protected abstract void save(@Nonnull URN urn, @Nonnull RecordTemplate value, @Nonnull AuditStamp auditStamp,
long version, boolean insert);
/**
* Applies version-based retention against a specific aspect type for an entity
*
* @param aspectClass the type of aspect to apply retention to
* @param urn {@link Urn} for the entity
* @param retention the retention configuration
* @param largestVersion the largest version number for the aspect type
*/
protected abstract <ASPECT extends RecordTemplate> void applyVersionBasedRetention(@Nonnull Class<ASPECT> aspectClass,
@Nonnull URN urn, @Nonnull VersionBasedRetention retention, long largestVersion);
/**
* Applies time-based retention against a specific aspect type for an entity
*
* @param aspectClass the type of aspect to apply retention to
* @param urn {@link Urn} for the entity
* @param retention the retention configuration
* @param currentTime the current timestamp
*/
protected abstract <ASPECT extends RecordTemplate> void applyTimeBasedRetention(@Nonnull Class<ASPECT> aspectClass,
@Nonnull URN urn, @Nonnull TimeBasedRetention retention, long currentTime);
/**
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
* Emits backfill MAE for the latest version of an aspect of an entity and also backfills local
* secondary index if writes & backfill enabled
2019-08-31 20:51:14 -07:00
*
* @param aspectClass the type of aspect to backfill
* @param urn {@link Urn} for the entity
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
* @return the aspect emitted in the backfill message
*/
@Nonnull
public <ASPECT extends RecordTemplate> Optional<ASPECT> backfill(@Nonnull Class<ASPECT> aspectClass,
@Nonnull URN urn) {
checkValidAspect(aspectClass);
Optional<ASPECT> aspect = get(aspectClass, urn, LATEST_VERSION);
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
aspect.ifPresent(value -> backfill(value, urn));
2019-08-31 20:51:14 -07:00
return aspect;
}
Update metadata-models to head! (#1811) metadata-models 80.0.0 -> 90.0.13: 90.0.13: Roll forward: Fix the open source build by avoiding URN method that isn't part of the open source URN. 90.0.2: Refactor listUrnsFromIndex method 90.0.0: Start distinguishing between [] aspects vs null aspects input param 89.0.4: Fix the open source build by avoiding URN method that isn't part of the open source URN. 89.0.2: fix some test case name 89.0.0: META-12686: Made the MXE_v5 topics become strictly ACL'ed to avoid the wildcard write ACL as "MetadataXEvent.+" 88.0.6: change DAO to take Storage Config as input 88.0.3: Add a comment on lack of avro generation for MXEv5 + add MXEv5 to the pegasus validation task. 87.0.15: META-12651: Integrate the metadata-models-ext with metadata-models 87.0.13: add StorageConfig to Local DAO 87.0.3: Treat empty aspect vs optional aspect same until all clients are migrated 87.0.2: Treat empty aspect vs optional aspect differently 87.0.1: META-12533: Skip processing unregistered aspect specific MAE. 83.0.6: action method to return list of urns from strong consistent index 83.0.4: Change input param type for batch backfill 83.0.3: Implement batch backfill 83.0.1: Implement support for OR filter in browse query 82.0.10: Throw UnsupportedOperationException for unsupported condition types in search filter 82.0.6: Implement local secondary backfilling index as part of backfill method 82.0.5: [strongly consistent index] implement getUrns method 82.0.4: Add indexing urn fields to the local secondary index 82.0.0: Render Delta fiels in the MCE_v5. 81.0.1: Add pegasus to avro conversion for FMCE 80.0.4: add get all support for BaseSingleAspectEntitySimpleKeyResource 80.0.2: Add a BaseSearchWriterDAO with an ESBulkWriterDAO implementation. 80.0.1: META-12254: Produce aspect specific MAE with always emit option 80.0.0: Convert getNodesInTraversedPath to getSubgraph to return complete view of the subgraph (nodes+edges)
2020-08-19 16:06:29 -07:00
/**
* Similar to {@link #backfill(Class, URN)} but gets a set of aspect classes and do a batch backfill
*/
@Nonnull
public Map<Class<? extends RecordTemplate>, Optional<? extends RecordTemplate>> backfill(
@Nonnull Set<Class<? extends RecordTemplate>> aspectClasses, @Nonnull URN urn) {
checkValidAspects(aspectClasses);
Map<Class<? extends RecordTemplate>, Optional<? extends RecordTemplate>> aspects = get(aspectClasses, urn);
aspects.forEach((aspectClass, aspect) -> aspect.ifPresent(value -> backfill(value, urn)));
return aspects;
}
/**
* Similar to {@link #backfill(Class, URN)} but gets a set of urns and do a batch backfill
*/
@Nonnull
public <ASPECT extends RecordTemplate> Map<URN, Optional<ASPECT>> backfill(@Nonnull Class<ASPECT> aspectClass,
@Nonnull Set<URN> urns) {
checkValidAspect(aspectClass);
final Map<URN, Optional<ASPECT>> urnToAspects = get(aspectClass, urns);
urnToAspects.forEach((urn, aspect) -> aspect.ifPresent(value -> backfill(value, urn)));
return urnToAspects;
}
/**
* Similar to {@link #backfill(Class, URN)} but gets a set of aspect classes and a set of URNs and do a batch backfill
*/
@Nonnull
public Map<URN, Map<Class<? extends RecordTemplate>, Optional<? extends RecordTemplate>>> backfill(
@Nonnull Set<Class<? extends RecordTemplate>> aspectClasses, @Nonnull Set<URN> urns) {
checkValidAspects(aspectClasses);
final Map<URN, Map<Class<? extends RecordTemplate>, Optional<? extends RecordTemplate>>> urnToAspects = get(aspectClasses, urns);
urnToAspects.forEach((urn, aspects) -> {
aspects.forEach((aspectClass, aspect) -> aspect.ifPresent(value -> backfill(value, urn)));
});
return urnToAspects;
}
/**
* Emits backfill MAE for an aspect of an entity and also backfills local secondary index if writes & backfill enabled
*
* @param aspect aspect to backfill
* @param urn {@link Urn} for the entity
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
*/
private <ASPECT extends RecordTemplate> void backfill(@Nonnull ASPECT aspect, @Nonnull URN urn) {
// Backfill local secondary index as well if writes & backfill enabled
if (_enableLocalSecondaryIndex && _backfillLocalSecondaryIndex) {
saveToLocalSecondaryIndex(urn, aspect, FIRST_VERSION);
}
_producer.produceMetadataAuditEvent(urn, aspect, aspect);
}
2019-08-31 20:51:14 -07:00
/**
* Paginates over all available versions of an aspect for an entity.
*
* @param aspectClass the type of the aspect to query
* @param urn {@link Urn} for the entity
* @param start the starting offset of the page
* @param pageSize the size of the page
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
* @return a {@link ListResult} containing a list of version numbers and other pagination information
*/
@Nonnull
public abstract <ASPECT extends RecordTemplate> ListResult<Long> listVersions(@Nonnull Class<ASPECT> aspectClass,
@Nonnull URN urn, int start, int pageSize);
/**
* Paginates over all URNs for entities that have a specific aspect.
*
* @param aspectClass the type of the aspect to query
* @param start the starting offset of the page
* @param pageSize the size of the page
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
* @return a {@link ListResult} containing a list of URN and other pagination information
*/
@Nonnull
public abstract <ASPECT extends RecordTemplate> ListResult<Urn> listUrns(@Nonnull Class<ASPECT> aspectClass,
int start, int pageSize);
/**
* Paginates over all versions of an aspect for a specific Urn.
*
* @param aspectClass the type of the aspect to query
* @param urn {@link Urn} for the entity
* @param start the starting offset of the page
* @param pageSize the size of the page
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
* @return a {@link ListResult} containing a list of aspects and other pagination information
*/
@Nonnull
public abstract <ASPECT extends RecordTemplate> ListResult<ASPECT> list(@Nonnull Class<ASPECT> aspectClass,
@Nonnull URN urn, int start, int pageSize);
/**
* Paginates over a specific version of a specific aspect for all Urns
*
* @param aspectClass the type of the aspect to query
* @param version the version of the aspect
* @param start the starting offset of the page
* @param pageSize the size of the page
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
* @return a {@link ListResult} containing a list of aspects and other pagination information
*/
@Nonnull
public abstract <ASPECT extends RecordTemplate> ListResult<ASPECT> list(@Nonnull Class<ASPECT> aspectClass,
long version, int start, int pageSize);
/**
* Paginates over the latest version of a specific aspect for all Urns
*
* @param aspectClass the type of the aspect to query
* @param start the starting offset of the page
* @param pageSize the size of the page
* @param <ASPECT> must be a supported aspect type in {@code ASPECT_UNION}.
* @return a {@link ListResult} containing a list of aspects and other pagination information
*/
@Nonnull
public abstract <ASPECT extends RecordTemplate> ListResult<ASPECT> list(@Nonnull Class<ASPECT> aspectClass, int start,
int pageSize);
/**
* Generates a new string ID that's guaranteed to be globally unique.
*/
@Nonnull
public String newStringId() {
return UUID.randomUUID().toString();
}
/**
* Generates a new numeric ID that's guaranteed to increase monotonically within the given namespace.
*/
public abstract long newNumericId(@Nonnull String namespace, int maxTransactionRetry);
/**
* Similar to {@link #newNumericId(String, int)} but uses default maximum transaction retry count.
*/
public long newNumericId(@Nonnull String namespace) {
return newNumericId(namespace, DEFAULT_MAX_TRANSACTION_RETRY);
}
/**
* Similar to {@link #newNumericId(String, int)} but uses a single global namespace
*/
public long newNumericId() {
return newNumericId(DEFAULT_ID_NAMESPACE);
}
/**
* Validates a model against its schema.
*/
protected void validateAgainstSchema(@Nonnull RecordTemplate model) {
ValidationResult result = ValidateDataAgainstSchema.validate(model,
new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT, CoercionMode.NORMAL,
UnrecognizedFieldMode.DISALLOW));
if (!result.isValid()) {
throw new ModelValidationException(result.getMessages().toString());
}
}
}