diff --git a/metadata-io/src/main/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceImpl.java b/metadata-io/src/main/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceImpl.java index d03c4dd808c7c0..167f79bf184947 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceImpl.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceImpl.java @@ -3,9 +3,9 @@ import static com.linkedin.metadata.Constants.INITIAL_VERSION_SORT_ID; import static com.linkedin.metadata.Constants.VERSION_PROPERTIES_ASPECT_NAME; import static com.linkedin.metadata.Constants.VERSION_SET_ENTITY_NAME; -import static com.linkedin.metadata.Constants.VERSION_SET_KEY_ASPECT_NAME; import static com.linkedin.metadata.Constants.VERSION_SET_PROPERTIES_ASPECT_NAME; import static com.linkedin.metadata.Constants.VERSION_SORT_ID_FIELD_NAME; +import static com.linkedin.metadata.aspect.validation.ConditionalWriteValidator.HTTP_HEADER_IF_VERSION_MATCH; import com.datahub.util.RecordUtils; import com.google.common.collect.ImmutableList; @@ -18,9 +18,10 @@ import com.linkedin.common.urn.Urn; import com.linkedin.common.urn.UrnUtils; import com.linkedin.data.template.SetMode; -import com.linkedin.entity.Aspect; +import com.linkedin.data.template.StringMap; import com.linkedin.events.metadata.ChangeType; import com.linkedin.metadata.aspect.AspectRetriever; +import com.linkedin.metadata.aspect.SystemAspect; import com.linkedin.metadata.entity.EntityService; import com.linkedin.metadata.entity.IngestResult; import com.linkedin.metadata.entity.RollbackResult; @@ -75,48 +76,52 @@ public List linkLatestVersion( List proposals = new ArrayList<>(); AspectRetriever aspectRetriever = opContext.getAspectRetriever(); String sortId; + Long versionSetConstraint; + Long versionPropertiesConstraint; + VersionSetKey versionSetKey = + (VersionSetKey) + EntityKeyUtils.convertUrnToEntityKey( + versionSet, opContext.getEntityRegistryContext().getKeyAspectSpec(versionSet)); + if (!versionSetKey.getEntityType().equals(newLatestVersion.getEntityType())) { + throw new IllegalArgumentException( + "Entity type must match Version Set's specified type: " + + versionSetKey.getEntityType() + + " invalid type: " + + newLatestVersion.getEntityType()); + } if (!aspectRetriever.entityExists(ImmutableSet.of(versionSet)).get(versionSet)) { - VersionSetKey versionSetKey = - (VersionSetKey) - EntityKeyUtils.convertUrnToEntityKey( - versionSet, opContext.getEntityRegistryContext().getKeyAspectSpec(versionSet)); - if (!versionSetKey.getEntityType().equals(newLatestVersion.getEntityType())) { - throw new IllegalArgumentException( - "Entity type must match Version Set's specified type: " - + versionSetKey.getEntityType() - + " invalid type: " - + newLatestVersion.getEntityType()); - } - MetadataChangeProposal versionSetKeyProposal = new MetadataChangeProposal(); - versionSetKeyProposal.setEntityUrn(versionSet); - versionSetKeyProposal.setEntityType(VERSION_SET_ENTITY_NAME); - versionSetKeyProposal.setAspectName(VERSION_SET_KEY_ASPECT_NAME); - versionSetKeyProposal.setAspect(GenericRecordUtils.serializeAspect(versionSetKey)); - versionSetKeyProposal.setChangeType(ChangeType.CREATE_ENTITY); - proposals.add(versionSetKeyProposal); sortId = INITIAL_VERSION_SORT_ID; + versionSetConstraint = -1L; + versionPropertiesConstraint = -1L; } else { - Aspect versionSetPropertiesAspect = - aspectRetriever.getLatestAspectObject(versionSet, VERSION_SET_PROPERTIES_ASPECT_NAME); + SystemAspect versionSetPropertiesAspect = + aspectRetriever.getLatestSystemAspect(versionSet, VERSION_SET_PROPERTIES_ASPECT_NAME); VersionSetProperties versionSetProperties = RecordUtils.toRecordTemplate( - VersionSetProperties.class, versionSetPropertiesAspect.data()); - Aspect latestVersion = - aspectRetriever.getLatestAspectObject( + VersionSetProperties.class, versionSetPropertiesAspect.getRecordTemplate().data()); + versionSetConstraint = + versionSetPropertiesAspect + .getSystemMetadataVersion() + .orElse(versionSetPropertiesAspect.getVersion()); + SystemAspect latestVersion = + aspectRetriever.getLatestSystemAspect( versionSetProperties.getLatest(), VERSION_PROPERTIES_ASPECT_NAME); VersionProperties latestVersionProperties = - RecordUtils.toRecordTemplate(VersionProperties.class, latestVersion.data()); + RecordUtils.toRecordTemplate( + VersionProperties.class, latestVersion.getRecordTemplate().data()); + versionPropertiesConstraint = + latestVersion.getSystemMetadataVersion().orElse(latestVersion.getVersion()); // When more impls for versioning scheme are set up, this will need to be resolved to the // correct scheme generation strategy sortId = AlphanumericSortIdGenerator.increment(latestVersionProperties.getSortId()); } - Aspect currentVersionPropertiesAspect = - aspectRetriever.getLatestAspectObject(newLatestVersion, VERSION_PROPERTIES_ASPECT_NAME); + SystemAspect currentVersionPropertiesAspect = + aspectRetriever.getLatestSystemAspect(newLatestVersion, VERSION_PROPERTIES_ASPECT_NAME); if (currentVersionPropertiesAspect != null) { VersionProperties currentVersionProperties = RecordUtils.toRecordTemplate( - VersionProperties.class, currentVersionPropertiesAspect.data()); + VersionProperties.class, currentVersionPropertiesAspect.getRecordTemplate().data()); if (currentVersionProperties.getVersionSet().equals(versionSet)) { return new ArrayList<>(); } else { @@ -157,7 +162,9 @@ public List linkLatestVersion( versionPropertiesProposal.setEntityType(newLatestVersion.getEntityType()); versionPropertiesProposal.setAspectName(VERSION_PROPERTIES_ASPECT_NAME); versionPropertiesProposal.setAspect(GenericRecordUtils.serializeAspect(versionProperties)); - // Error if properties already exist + versionPropertiesProposal.setChangeType(ChangeType.UPSERT); + StringMap headerMap = new StringMap(); + headerMap.put(HTTP_HEADER_IF_VERSION_MATCH, versionPropertiesConstraint.toString()); versionPropertiesProposal.setChangeType(ChangeType.UPSERT); proposals.add(versionPropertiesProposal); @@ -178,6 +185,9 @@ public List linkLatestVersion( versionSetPropertiesProposal.setAspect( GenericRecordUtils.serializeAspect(versionSetProperties)); versionSetPropertiesProposal.setChangeType(ChangeType.UPSERT); + StringMap versionSetHeaderMap = new StringMap(); + versionSetHeaderMap.put(HTTP_HEADER_IF_VERSION_MATCH, versionSetConstraint.toString()); + versionSetPropertiesProposal.setHeaders(versionSetHeaderMap); proposals.add(versionSetPropertiesProposal); return entityService.ingestProposal( @@ -201,14 +211,15 @@ public List unlinkVersion( OperationContext opContext, Urn versionSet, Urn linkedVersion) { List deletedAspects = new ArrayList<>(); AspectRetriever aspectRetriever = opContext.getAspectRetriever(); - Aspect linkedVersionPropertiesAspect = - aspectRetriever.getLatestAspectObject(linkedVersion, VERSION_PROPERTIES_ASPECT_NAME); + SystemAspect linkedVersionPropertiesAspect = + aspectRetriever.getLatestSystemAspect(linkedVersion, VERSION_PROPERTIES_ASPECT_NAME); // Not currently versioned, do nothing if (linkedVersionPropertiesAspect == null) { return deletedAspects; } VersionProperties linkedVersionProperties = - RecordUtils.toRecordTemplate(VersionProperties.class, linkedVersionPropertiesAspect.data()); + RecordUtils.toRecordTemplate( + VersionProperties.class, linkedVersionPropertiesAspect.getRecordTemplate().data()); Urn versionSetUrn = linkedVersionProperties.getVersionSet(); if (!versionSet.equals(versionSetUrn)) { throw new IllegalArgumentException( @@ -250,15 +261,20 @@ public List unlinkVersion( String updatedLatestVersionUrn = null; SearchEntityArray linkedEntities = linkedVersions.getEntities(); - Aspect versionSetPropertiesAspect = - aspectRetriever.getLatestAspectObject(versionSetUrn, VERSION_SET_PROPERTIES_ASPECT_NAME); + SystemAspect versionSetPropertiesAspect = + aspectRetriever.getLatestSystemAspect(versionSetUrn, VERSION_SET_PROPERTIES_ASPECT_NAME); if (versionSetPropertiesAspect == null) { throw new IllegalStateException( String.format( "Version Set Properties must exist if entity version exists: %s", versionSetUrn)); } VersionSetProperties versionSetProperties = - RecordUtils.toRecordTemplate(VersionSetProperties.class, versionSetPropertiesAspect.data()); + RecordUtils.toRecordTemplate( + VersionSetProperties.class, versionSetPropertiesAspect.getRecordTemplate().data()); + long versionConstraint = + versionSetPropertiesAspect + .getSystemMetadataVersion() + .orElse(versionSetPropertiesAspect.getVersion()); boolean isLatest = linkedVersion.equals(versionSetProperties.getLatest()); if (linkedEntities.size() == 2 && isLatest) { @@ -284,6 +300,7 @@ public List unlinkVersion( updatedLatestVersionUrn = maybePriorLatestVersion.getEntity().toString(); } else { // Delete Version Set if we are removing the last version + // TODO: Conditional deletes impl + only do the delete if version match RollbackRunResult deleteResult = entityService.deleteUrn(opContext, versionSetUrn); deletedAspects.addAll(deleteResult.getRollbackResults()); } @@ -309,6 +326,9 @@ public List unlinkVersion( versionSetPropertiesProposal.setAspect( GenericRecordUtils.serializeAspect(newVersionSetProperties)); versionSetPropertiesProposal.setChangeType(ChangeType.UPSERT); + StringMap headerMap = new StringMap(); + headerMap.put(HTTP_HEADER_IF_VERSION_MATCH, Long.toString(versionConstraint)); + versionSetPropertiesProposal.setHeaders(headerMap); entityService.ingestProposal( opContext, AspectsBatchImpl.builder() diff --git a/metadata-io/src/main/java/com/linkedin/metadata/search/SearchServiceSearchRetriever.java b/metadata-io/src/main/java/com/linkedin/metadata/search/SearchServiceSearchRetriever.java index 1bdfb612920aec..eda9e9e3a73157 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/search/SearchServiceSearchRetriever.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/search/SearchServiceSearchRetriever.java @@ -4,7 +4,9 @@ import com.linkedin.metadata.query.SearchFlags; import com.linkedin.metadata.query.filter.Filter; import com.linkedin.metadata.query.filter.SortCriterion; +import com.linkedin.metadata.query.filter.SortOrder; import io.datahubproject.metadata.context.OperationContext; +import java.util.ArrayList; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -35,12 +37,19 @@ public ScrollResult scroll( @Nullable String scrollId, int count, List sortCriteria) { + List finalCriteria = new ArrayList<>(sortCriteria); + if (sortCriteria.stream().noneMatch(sortCriterion -> "urn".equals(sortCriterion.getField()))) { + SortCriterion urnSort = new SortCriterion(); + urnSort.setField("urn"); + urnSort.setOrder(SortOrder.ASCENDING); + finalCriteria.add(urnSort); + } return searchService.scrollAcrossEntities( systemOperationContext.withSearchFlags(flags -> RETRIEVER_SEARCH_FLAGS), entities, "*", filters, - sortCriteria, + finalCriteria, scrollId, null, count); diff --git a/metadata-io/src/test/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceTest.java b/metadata-io/src/test/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceTest.java index 161693c4a9f4e8..40eb4288424491 100644 --- a/metadata-io/src/test/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceTest.java +++ b/metadata-io/src/test/java/com/linkedin/metadata/entity/versioning/EntityVersioningServiceTest.java @@ -2,7 +2,6 @@ import static com.linkedin.metadata.Constants.INITIAL_VERSION_SORT_ID; import static com.linkedin.metadata.Constants.VERSION_PROPERTIES_ASPECT_NAME; -import static com.linkedin.metadata.Constants.VERSION_SET_KEY_ASPECT_NAME; import static com.linkedin.metadata.Constants.VERSION_SET_PROPERTIES_ASPECT_NAME; import static org.mockito.Mockito.*; import static org.testng.Assert.*; @@ -15,15 +14,14 @@ import com.linkedin.common.urn.Urn; import com.linkedin.common.urn.UrnUtils; import com.linkedin.data.template.RecordTemplate; -import com.linkedin.entity.Aspect; import com.linkedin.metadata.aspect.AspectRetriever; +import com.linkedin.metadata.aspect.SystemAspect; import com.linkedin.metadata.aspect.batch.AspectsBatch; import com.linkedin.metadata.entity.EntityService; import com.linkedin.metadata.entity.EntityServiceAspectRetriever; import com.linkedin.metadata.entity.RollbackResult; import com.linkedin.metadata.entity.RollbackRunResult; import com.linkedin.metadata.entity.SearchRetriever; -import com.linkedin.metadata.key.VersionSetKey; import com.linkedin.metadata.models.registry.ConfigEntityRegistry; import com.linkedin.metadata.models.registry.EntityRegistry; import com.linkedin.metadata.models.registry.EntityRegistryException; @@ -134,20 +132,6 @@ public void testLinkLatestVersionNewVersionSet() throws Exception { assertEquals(versionProps.getComment(), "Test comment"); assertEquals(versionProps.getVersionSet(), TEST_VERSION_SET_URN); - List versionSetKeyAspect = - capturedAspects.get(0).getMCPItems().stream() - .filter(mcpItem -> VERSION_SET_KEY_ASPECT_NAME.equals(mcpItem.getAspectName())) - .map(mcpItem -> mcpItem.getAspect(VersionSetKey.class)) - .collect(Collectors.toList()); - - VersionSetKey versionSetKey = - (VersionSetKey) - versionSetKeyAspect.stream() - .filter(aspect -> aspect instanceof VersionSetKey) - .findFirst() - .orElseThrow(() -> new AssertionError("Version Set Key not found")); - assertEquals(versionSetKey.getId(), "123456"); - List versionSetPropertiesAspect = capturedAspects.get(0).getMCPItems().stream() .filter(mcpItem -> VERSION_SET_PROPERTIES_ASPECT_NAME.equals(mcpItem.getAspectName())) @@ -179,9 +163,10 @@ public void testLinkLatestVersionExistingVersionSet() throws Exception { new VersionSetProperties() .setVersioningScheme(VersioningScheme.ALPHANUMERIC_GENERATED_BY_DATAHUB) .setLatest(TEST_DATASET_URN); - Aspect mockVersionSetPropertiesAspect = mock(Aspect.class); - when(mockVersionSetPropertiesAspect.data()).thenReturn(existingVersionSetProps.data()); - when(mockAspectRetriever.getLatestAspectObject(eq(TEST_VERSION_SET_URN), anyString())) + SystemAspect mockVersionSetPropertiesAspect = mock(SystemAspect.class); + when(mockVersionSetPropertiesAspect.getRecordTemplate()).thenReturn(existingVersionSetProps); + when(mockVersionSetPropertiesAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect(eq(TEST_VERSION_SET_URN), anyString())) .thenReturn(mockVersionSetPropertiesAspect); // Mock existing version properties with a sort ID @@ -190,9 +175,10 @@ public void testLinkLatestVersionExistingVersionSet() throws Exception { .setSortId("AAAAAAAA") .setVersion(new VersionTag().setVersionTag("Label1")) .setVersionSet(TEST_VERSION_SET_URN); - Aspect mockVersionPropertiesAspect = mock(Aspect.class); - when(mockVersionPropertiesAspect.data()).thenReturn(existingVersionProps.data()); - when(mockAspectRetriever.getLatestAspectObject(eq(TEST_DATASET_URN), anyString())) + SystemAspect mockVersionPropertiesAspect = mock(SystemAspect.class); + when(mockVersionPropertiesAspect.getRecordTemplate()).thenReturn(existingVersionProps); + when(mockVersionPropertiesAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect(eq(TEST_DATASET_URN), anyString())) .thenReturn(mockVersionPropertiesAspect); // Capture the proposals @@ -233,18 +219,20 @@ public void testUnlinkInitialVersion() throws Exception { new VersionProperties() .setVersionSet(TEST_VERSION_SET_URN) .setSortId(INITIAL_VERSION_SORT_ID); - Aspect mockVersionPropsAspect = mock(Aspect.class); - when(mockVersionPropsAspect.data()).thenReturn(versionProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionPropsAspect = mock(SystemAspect.class); + when(mockVersionPropsAspect.getRecordTemplate()).thenReturn(versionProps); + when(mockVersionPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_DATASET_URN), eq(VERSION_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionPropsAspect); VersionSetProperties versionSetProps = new VersionSetProperties() .setVersioningScheme(VersioningScheme.ALPHANUMERIC_GENERATED_BY_DATAHUB) .setLatest(TEST_DATASET_URN); - Aspect mockVersionSetPropsAspect = mock(Aspect.class); - when(mockVersionSetPropsAspect.data()).thenReturn(versionSetProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionSetPropsAspect = mock(SystemAspect.class); + when(mockVersionSetPropsAspect.getRecordTemplate()).thenReturn(versionSetProps); + when(mockVersionSetPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_VERSION_SET_URN), eq(VERSION_SET_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionSetPropsAspect); @@ -315,9 +303,10 @@ public void testUnlinkLatestVersionWithPriorVersion() throws Exception { new VersionProperties() .setVersionSet(TEST_VERSION_SET_URN) .setSortId("AAAAAAAB"); // Not initial version - Aspect mockVersionPropsAspect = mock(Aspect.class); - when(mockVersionPropsAspect.data()).thenReturn(versionProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionPropsAspect = mock(SystemAspect.class); + when(mockVersionPropsAspect.getRecordTemplate()).thenReturn(versionProps); + when(mockVersionPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_DATASET_URN), eq(VERSION_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionPropsAspect); @@ -325,9 +314,10 @@ public void testUnlinkLatestVersionWithPriorVersion() throws Exception { new VersionSetProperties() .setVersioningScheme(VersioningScheme.ALPHANUMERIC_GENERATED_BY_DATAHUB) .setLatest(TEST_DATASET_URN); - Aspect mockVersionSetPropsAspect = mock(Aspect.class); - when(mockVersionSetPropsAspect.data()).thenReturn(versionSetProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionSetPropsAspect = mock(SystemAspect.class); + when(mockVersionSetPropsAspect.getRecordTemplate()).thenReturn(versionSetProps); + when(mockVersionSetPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_VERSION_SET_URN), eq(VERSION_SET_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionSetPropsAspect); @@ -371,13 +361,7 @@ public void testUnlinkLatestVersionWithPriorVersion() throws Exception { anyMap(), eq(true)); verify(mockEntityService).ingestProposal(eq(mockOpContext), any(), eq(false)); - verify(mockEntityService, never()) - .deleteAspect( - eq(mockOpContext), - eq(TEST_VERSION_SET_URN.toString()), - eq(VERSION_SET_PROPERTIES_ASPECT_NAME), - anyMap(), - eq(true)); + verify(mockEntityService, never()).deleteUrn(eq(mockOpContext), eq(TEST_VERSION_SET_URN)); } @Test @@ -388,9 +372,10 @@ public void testUnlinkNotLatestVersionWithPriorVersion() throws Exception { new VersionProperties() .setVersionSet(TEST_VERSION_SET_URN) .setSortId("AAAAAAAB"); // Not initial version - Aspect mockVersionPropsAspect = mock(Aspect.class); - when(mockVersionPropsAspect.data()).thenReturn(versionProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionPropsAspect = mock(SystemAspect.class); + when(mockVersionPropsAspect.getRecordTemplate()).thenReturn(versionProps); + when(mockVersionPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_DATASET_URN_2), eq(VERSION_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionPropsAspect); @@ -398,9 +383,10 @@ public void testUnlinkNotLatestVersionWithPriorVersion() throws Exception { new VersionSetProperties() .setVersioningScheme(VersioningScheme.ALPHANUMERIC_GENERATED_BY_DATAHUB) .setLatest(TEST_DATASET_URN); - Aspect mockVersionSetPropsAspect = mock(Aspect.class); - when(mockVersionSetPropsAspect.data()).thenReturn(versionSetProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionSetPropsAspect = mock(SystemAspect.class); + when(mockVersionSetPropsAspect.getRecordTemplate()).thenReturn(versionSetProps); + when(mockVersionSetPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_VERSION_SET_URN), eq(VERSION_SET_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionSetPropsAspect); @@ -447,13 +433,7 @@ public void testUnlinkNotLatestVersionWithPriorVersion() throws Exception { eq(VERSION_PROPERTIES_ASPECT_NAME), anyMap(), eq(true)); - verify(mockEntityService, never()) - .deleteAspect( - eq(mockOpContext), - eq(TEST_VERSION_SET_URN.toString()), - eq(VERSION_SET_PROPERTIES_ASPECT_NAME), - anyMap(), - eq(true)); + verify(mockEntityService, never()).deleteUrn(eq(mockOpContext), eq(TEST_VERSION_SET_URN)); } @Test @@ -464,9 +444,10 @@ public void testUnlinkNotReturnedSingleVersionWithPriorVersion() throws Exceptio new VersionProperties() .setVersionSet(TEST_VERSION_SET_URN) .setSortId("AAAAAAAB"); // Not initial version - Aspect mockVersionPropsAspect = mock(Aspect.class); - when(mockVersionPropsAspect.data()).thenReturn(versionProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionPropsAspect = mock(SystemAspect.class); + when(mockVersionPropsAspect.getRecordTemplate()).thenReturn(versionProps); + when(mockVersionPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_DATASET_URN_2), eq(VERSION_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionPropsAspect); @@ -474,9 +455,10 @@ public void testUnlinkNotReturnedSingleVersionWithPriorVersion() throws Exceptio new VersionSetProperties() .setVersioningScheme(VersioningScheme.ALPHANUMERIC_GENERATED_BY_DATAHUB) .setLatest(TEST_DATASET_URN_2); - Aspect mockVersionSetPropsAspect = mock(Aspect.class); - when(mockVersionSetPropsAspect.data()).thenReturn(versionSetProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionSetPropsAspect = mock(SystemAspect.class); + when(mockVersionSetPropsAspect.getRecordTemplate()).thenReturn(versionSetProps); + when(mockVersionSetPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_VERSION_SET_URN), eq(VERSION_SET_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionSetPropsAspect); @@ -519,13 +501,7 @@ public void testUnlinkNotReturnedSingleVersionWithPriorVersion() throws Exceptio anyMap(), eq(true)); verify(mockEntityService).ingestProposal(eq(mockOpContext), any(), eq(false)); - verify(mockEntityService, never()) - .deleteAspect( - eq(mockOpContext), - eq(TEST_VERSION_SET_URN.toString()), - eq(VERSION_SET_PROPERTIES_ASPECT_NAME), - anyMap(), - eq(true)); + verify(mockEntityService, never()).deleteUrn(eq(mockOpContext), eq(TEST_VERSION_SET_URN)); } @Test @@ -536,9 +512,10 @@ public void testUnlinkNotReturnedDoubleVersionWithPriorVersion() throws Exceptio new VersionProperties() .setVersionSet(TEST_VERSION_SET_URN) .setSortId("AAAAAAAB"); // Not initial version - Aspect mockVersionPropsAspect = mock(Aspect.class); - when(mockVersionPropsAspect.data()).thenReturn(versionProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionPropsAspect = mock(SystemAspect.class); + when(mockVersionPropsAspect.getRecordTemplate()).thenReturn(versionProps); + when(mockVersionPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_DATASET_URN_3), eq(VERSION_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionPropsAspect); @@ -546,9 +523,10 @@ public void testUnlinkNotReturnedDoubleVersionWithPriorVersion() throws Exceptio new VersionSetProperties() .setVersioningScheme(VersioningScheme.ALPHANUMERIC_GENERATED_BY_DATAHUB) .setLatest(TEST_DATASET_URN_3); - Aspect mockVersionSetPropsAspect = mock(Aspect.class); - when(mockVersionSetPropsAspect.data()).thenReturn(versionSetProps.data()); - when(mockAspectRetriever.getLatestAspectObject( + SystemAspect mockVersionSetPropsAspect = mock(SystemAspect.class); + when(mockVersionSetPropsAspect.getRecordTemplate()).thenReturn(versionSetProps); + when(mockVersionSetPropsAspect.getSystemMetadataVersion()).thenReturn(Optional.of(1L)); + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_VERSION_SET_URN), eq(VERSION_SET_PROPERTIES_ASPECT_NAME))) .thenReturn(mockVersionSetPropsAspect); @@ -592,20 +570,14 @@ public void testUnlinkNotReturnedDoubleVersionWithPriorVersion() throws Exceptio anyMap(), eq(true)); verify(mockEntityService).ingestProposal(eq(mockOpContext), any(), eq(false)); - verify(mockEntityService, never()) - .deleteAspect( - eq(mockOpContext), - eq(TEST_VERSION_SET_URN.toString()), - eq(VERSION_SET_PROPERTIES_ASPECT_NAME), - anyMap(), - eq(true)); + verify(mockEntityService, never()).deleteUrn(eq(mockOpContext), eq(TEST_VERSION_SET_URN)); } @Test public void testUnlinkNonVersionedEntity() throws Exception { // Mock no version properties aspect - when(mockAspectRetriever.getLatestAspectObject( + when(mockAspectRetriever.getLatestSystemAspect( eq(TEST_DATASET_URN), eq(VERSION_PROPERTIES_ASPECT_NAME))) .thenReturn(null); @@ -616,6 +588,7 @@ public void testUnlinkNonVersionedEntity() throws Exception { // Verify assertTrue(results.isEmpty()); verify(mockEntityService, never()).deleteAspect(any(), any(), any(), any(), anyBoolean()); + verify(mockEntityService, never()).deleteUrn(any(), any()); verify(mockSearchRetriever, never()).scroll(any(), any(), anyString(), anyInt(), any()); } }