-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added RPC invocation for PreUpdate #443
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ae7df55
Added invocation
1745064
Uodate map name
c4b8eb9
New interface design
de677eb
Fixed checkstyle error
e687357
Adding non-null
cf5391f
Removed stub dependency
aa5cdcc
Added Routing Map for action control
a48088b
Refactor tests
18e534b
Refactor test
54044a3
Added grpc registry
86de865
Checkstyle error
8b5abca
Added unit tests
a40bd9f
More unit tests
232f1dc
More unit tests and refactoring
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...pi/src/main/java/com/linkedin/metadata/dao/ingestion/preupdate/GrpcPreUpdateRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import javax.annotation.Nonnull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
/** | ||
* A registry which maintains mapping of aspects and their GrpcPreUpdateRoutingClient. | ||
*/ | ||
@Slf4j | ||
public class GrpcPreUpdateRegistry<ASPECT extends RecordTemplate> { | ||
|
||
private Map<Class<? extends RecordTemplate>, PreRoutingInfo> _preUpdateLambdaMap = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Get GrpcPreUpdateRoutingClient for an aspect. | ||
*/ | ||
public PreRoutingInfo getPreUpdateRoutingClient(@Nonnull final ASPECT aspect) { | ||
return _preUpdateLambdaMap.get(aspect.getClass()); | ||
} | ||
|
||
/** | ||
* Check if GrpcPreUpdateRoutingClient is registered for an aspect. | ||
*/ | ||
public boolean isRegistered(@Nonnull final Class<ASPECT> aspectClass) { | ||
return _preUpdateLambdaMap.containsKey(aspectClass); | ||
} | ||
|
||
/** | ||
* Register a pre update lambda for the given aspect. | ||
* @param aspectClass aspect class | ||
* @param preUpdateRoutingInfo pre update routing map | ||
*/ | ||
public void registerPreUpdateLambda(@Nonnull Class<? extends RecordTemplate> aspectClass, | ||
@Nonnull PreRoutingInfo preUpdateRoutingInfo) { | ||
log.info("Registering pre update lambda: {}, {}", aspectClass.getCanonicalName(), preUpdateRoutingInfo); | ||
_preUpdateLambdaMap.put(aspectClass, preUpdateRoutingInfo); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
dao-api/src/main/java/com/linkedin/metadata/dao/ingestion/preupdate/PreRoutingInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.google.protobuf.Message; | ||
import lombok.Data; | ||
|
||
|
||
@Data | ||
public class PreRoutingInfo { | ||
|
||
public PreUpdateClient<? extends Message> preUpdateClient; | ||
|
||
public enum RoutingAction { | ||
PROCEED, SKIP | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dao-api/src/main/java/com/linkedin/metadata/dao/ingestion/preupdate/PreUpdateClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.google.protobuf.Message; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.data.template.RecordTemplate; | ||
|
||
|
||
public interface PreUpdateClient<ASPECT extends RecordTemplate> { | ||
|
||
/** | ||
* Executes the gRPC pre-update logic, including building the request, | ||
* invoking the service, and handling the response. | ||
* | ||
* @param urn The URN of the entity to be updated. | ||
* @param aspect The aspect to be updated. | ||
* @return The updated aspect. | ||
*/ | ||
PreUpdateResponse<ASPECT> preUpdate(Urn urn, ASPECT aspect); | ||
|
||
/** | ||
* Converts a RecordTemplate URN to a gRPC-compatible Message. | ||
* | ||
* @param urn The RecordTemplate URN. | ||
* @return The gRPC-compatible Message URN. | ||
*/ | ||
Message convertUrnToMessage(Urn urn); | ||
|
||
/** | ||
* Converts a RecordTemplate Aspect to a gRPC-compatible Message Aspect. | ||
* | ||
* @param aspect The RecordTemplate aspect. | ||
* @return The gRPC-compatible Message aspect. | ||
*/ | ||
Message convertAspectToMessage(RecordTemplate aspect); | ||
|
||
/** | ||
* Converts a gRPC-compatible Message Aspect back to a RecordTemplate Aspect. | ||
* | ||
* @param messageAspect The Message aspect. | ||
* @return The RecordTemplate aspect. | ||
*/ | ||
RecordTemplate convertAspectToRecordTemplate(Message messageAspect); | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
dao-api/src/main/java/com/linkedin/metadata/dao/ingestion/preupdate/PreUpdateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import lombok.Data; | ||
|
||
|
||
@Data | ||
public class PreUpdateResponse<ASPECT extends RecordTemplate> { | ||
private final ASPECT updatedAspect; | ||
} |
2 changes: 1 addition & 1 deletion
2
...dao/ingestion/PreUpdateRoutingClient.java → ...ion/preupdate/PreUpdateRoutingClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...estliCompliantPreUpdateRoutingClient.java → ...estliCompliantPreUpdateRoutingClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...estion/RestliPreUpdateAspectRegistry.java → ...update/RestliPreUpdateAspectRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...rc/test/java/com/linkedin/metadata/dao/ingestion/preupdate/GrpcPreUpdateRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
import static org.testng.AssertJUnit.*; | ||
|
||
|
||
public class GrpcPreUpdateRegistryTest { | ||
|
||
private GrpcPreUpdateRegistry<RecordTemplate> registry; | ||
private PreRoutingInfo mockRoutingInfo; | ||
private RecordTemplate mockAspectInstance; | ||
|
||
@BeforeMethod | ||
public void setup() { | ||
registry = new GrpcPreUpdateRegistry<>(); | ||
mockRoutingInfo = mock(PreRoutingInfo.class); | ||
mockAspectInstance = mock(RecordTemplate.class); | ||
} | ||
|
||
@Test | ||
public void testRegisterPreUpdateLambda() throws InstantiationException, IllegalAccessException { | ||
registry.registerPreUpdateLambda(mockAspectInstance.getClass(), mockRoutingInfo); | ||
System.out.println(registry.getPreUpdateRoutingClient(mockAspectInstance)); | ||
assertTrue(registry.isRegistered((Class<RecordTemplate>) mockAspectInstance.getClass())); | ||
} | ||
|
||
@Test | ||
public void testGetPreUpdateRoutingClient() { | ||
registry.registerPreUpdateLambda(mockAspectInstance.getClass(), mockRoutingInfo); | ||
PreRoutingInfo retrievedRoutingMap = registry.getPreUpdateRoutingClient(mockAspectInstance); | ||
assertEquals(mockRoutingInfo, retrievedRoutingMap); | ||
} | ||
|
||
@Test | ||
public void testIsRegistered() { | ||
assertFalse(registry.isRegistered((Class<RecordTemplate>) mockAspectInstance.getClass())); | ||
registry.registerPreUpdateLambda(mockAspectInstance.getClass(), mockRoutingInfo); | ||
assertTrue(registry.isRegistered((Class<RecordTemplate>) mockAspectInstance.getClass())); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
dao-api/src/test/java/com/linkedin/metadata/dao/ingestion/preupdate/PreRoutingInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.google.protobuf.Message; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import static org.testng.AssertJUnit.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
|
||
public class PreRoutingInfoTest { | ||
private PreRoutingInfo routingInfo; | ||
private PreUpdateClient<? extends Message> mockPreUpdateClient; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
routingInfo = new PreRoutingInfo(); | ||
mockPreUpdateClient = mock(PreUpdateClient.class); | ||
} | ||
|
||
@Test | ||
public void testPreUpdateClientSetterAndGetter() { | ||
routingInfo.setPreUpdateClient(mockPreUpdateClient); | ||
assertEquals(mockPreUpdateClient, routingInfo.getPreUpdateClient()); | ||
} | ||
|
||
@Test | ||
public void testRoutingActionEnum() { | ||
assertEquals("PROCEED", PreRoutingInfo.RoutingAction.PROCEED.name()); | ||
assertEquals("SKIP", PreRoutingInfo.RoutingAction.SKIP.name()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...pi/src/test/java/com/linkedin/metadata/dao/ingestion/preupdate/PreUpdateResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.linkedin.metadata.dao.ingestion.preupdate; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
import static org.testng.AssertJUnit.*; | ||
|
||
|
||
public class PreUpdateResponseTest { | ||
@Test | ||
public void testConstructorAndGetter() { | ||
// Create a mock instance of RecordTemplate | ||
RecordTemplate mockAspect = mock(RecordTemplate.class); | ||
|
||
// Create an instance of PreUpdateResponse with the mock aspect | ||
PreUpdateResponse<RecordTemplate> response = new PreUpdateResponse<>(mockAspect); | ||
|
||
// Verify that the getter returns the correct value | ||
assertEquals(mockAspect, response.getUpdatedAspect()); | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...on/SamplePreUpdateAspectRegistryImpl.java → ...te/SamplePreUpdateAspectRegistryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we call this method? Should we do it through inject?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we will inject it in the AssetClass where we call the ingestion method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For RestliRegistry, I was setting it in DatasetLocalDao.