Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaoMaWHU committed Oct 19, 2024
1 parent cf1e5ee commit 54a9ec4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ void save(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nonnull String metadata
*/
Map<Urn, Map<Class<? extends RecordTemplate>, Optional<? extends RecordTemplate>>> backfill(@Nonnull BackfillMode mode,
@Nonnull Map<Urn, Set<Class<? extends RecordTemplate>>> urnToAspect);

/**
* Delete the metadata from database.
*
* @param urn The identifier of the entity which the metadata is associated with.
* @param aspectClass The aspect class for the metadata.
* @param auditStamp audit stamp containing information on who and when the metadata is deleted.
*/
void delete(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nonnull AuditStamp auditStamp);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@ public void setEqualityTesters(Map<Class, GenericEqualityTester> equalityTesters
*/
public void save(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nonnull String metadata, @Nonnull AuditStamp auditStamp,
@Nullable IngestionTrackingContext trackingContext, @Nullable IngestionMode ingestionMode) {
saveCommon(urn, aspectClass, metadata, auditStamp, trackingContext, ingestionMode);
}

/* a common helper method for saving metadata */
void saveCommon(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nullable String metadata, @Nonnull AuditStamp auditStamp,
@Nullable IngestionTrackingContext trackingContext, @Nullable IngestionMode ingestionMode) {
runInTransactionWithRetry(() -> {
final Optional<GenericLocalDAO.MetadataWithExtraInfo> latest = queryLatest(urn, aspectClass);
RecordTemplate newValue = toRecordTemplate(aspectClass, metadata);

RecordTemplate newValue = null;
if (metadata != null) {
newValue = toRecordTemplate(aspectClass, metadata);
}

if (!latest.isPresent()) {
saveLatest(urn, aspectClass, newValue, null, auditStamp, null);
Expand Down Expand Up @@ -170,6 +180,11 @@ public Map<Urn, Map<Class<? extends RecordTemplate>, Optional<? extends RecordTe
return urnToAspects;
}

@Override
public void delete(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nonnull AuditStamp auditStamp) {
saveCommon(urn, aspectClass, null, auditStamp, null, null);
}

/**
* Emits backfill MAE for an aspect of an entity depending on the backfill mode.
*
Expand All @@ -195,7 +210,7 @@ private void backfill(@Nonnull BackfillMode mode, @Nonnull RecordTemplate aspect
/**
* Save metadata into database.
*/
private void saveLatest(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nonnull RecordTemplate newValue,
private void saveLatest(@Nonnull Urn urn, @Nonnull Class aspectClass, @Nullable RecordTemplate newValue,
@Nullable RecordTemplate currentValue, @Nonnull AuditStamp newAuditStamp, @Nullable AuditStamp currentAuditStamp) {

// Save oldValue as the largest version + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,22 @@ public Task<BackfillResult> backfill(
throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, String.format("Urn %s is malformed.", urn));
}
}

@Action(name = ACTION_DELETE)
@Nonnull
public Task<Void> delete(
@ActionParam(PARAM_URN) @Nonnull String urn,
@ActionParam(PARAM_ASPECT_CLASS) @Nonnull String aspectClass) {
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());

try {
Class clazz = this.getClass().getClassLoader().loadClass(aspectClass);
genericLocalDAO().delete(Urn.createFromCharSequence(urn), clazz, auditStamp);
return Task.value(null);
} catch (ClassNotFoundException e) {
throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, String.format("No such class %s.", aspectClass));
} catch (URISyntaxException e) {
throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, String.format("Urn %s is malformed.", urn));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private RestliConstants() { }
public static final String ACTION_RAW_INGEST_ASSET = "rawIngestAsset";
public static final String ACTION_LIST_URNS_FROM_INDEX = "listUrnsFromIndex";
public static final String ACTION_LIST_URNS = "listUrns";
public static final String ACTION_DELETE = "delete";
public static final String PARAM_INPUT = "input";
public static final String PARAM_ASPECTS = "aspects";
public static final String PARAM_ASPECT = "aspect";
Expand Down

0 comments on commit 54a9ec4

Please sign in to comment.