-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mcp-canonical-command
- Loading branch information
Showing
41 changed files
with
1,230 additions
and
469 deletions.
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
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
52 changes: 52 additions & 0 deletions
52
...va/com/linkedin/datahub/graphql/resolvers/ingest/execution/RollbackIngestionResolver.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,52 @@ | ||
package com.linkedin.datahub.graphql.resolvers.ingest.execution; | ||
|
||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.RollbackIngestionInput; | ||
import com.linkedin.datahub.graphql.resolvers.ingest.IngestionAuthUtils; | ||
import com.linkedin.entity.client.EntityClient; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
|
||
public class RollbackIngestionResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
private final EntityClient _entityClient; | ||
|
||
public RollbackIngestionResolver(final EntityClient entityClient) { | ||
_entityClient = entityClient; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(final DataFetchingEnvironment environment) throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
if (!IngestionAuthUtils.canManageIngestion(context)) { | ||
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
} | ||
|
||
final RollbackIngestionInput input = bindArgument(environment.getArgument("input"), RollbackIngestionInput.class); | ||
final String runId = input.getRunId(); | ||
|
||
rollbackIngestion(runId, context); | ||
return true; | ||
}); | ||
} | ||
|
||
public CompletableFuture<Boolean> rollbackIngestion(final String runId, final QueryContext context) { | ||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
_entityClient.rollbackIngestion(runId, context.getAuthentication()); | ||
return true; | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to rollback ingestion execution", e); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |
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
82 changes: 82 additions & 0 deletions
82
...om/linkedin/datahub/graphql/resolvers/ingest/execution/RollbackIngestionResolverTest.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,82 @@ | ||
package com.linkedin.datahub.graphql.resolvers.ingest.execution; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.RollbackIngestionInput; | ||
import com.linkedin.entity.client.EntityClient; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import org.mockito.Mockito; | ||
import org.testng.annotations.Test; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ingest.IngestTestUtils.*; | ||
import static org.testng.Assert.*; | ||
|
||
|
||
public class RollbackIngestionResolverTest { | ||
|
||
private static final String RUN_ID = "testRunId"; | ||
private static final RollbackIngestionInput TEST_INPUT = new RollbackIngestionInput(RUN_ID); | ||
|
||
@Test | ||
public void testGetSuccess() throws Exception { | ||
// Create resolver | ||
EntityClient mockClient = Mockito.mock(EntityClient.class); | ||
RollbackIngestionResolver resolver = new RollbackIngestionResolver(mockClient); | ||
|
||
// Execute resolver | ||
QueryContext mockContext = getMockAllowContext(); | ||
DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class); | ||
Mockito.when(mockEnv.getArgument(Mockito.eq("input"))).thenReturn(TEST_INPUT); | ||
Mockito.when(mockEnv.getContext()).thenReturn(mockContext); | ||
|
||
Boolean result = resolver.get(mockEnv).get(); | ||
assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void testGetUnauthorized() throws Exception { | ||
// Create resolver | ||
EntityClient mockClient = Mockito.mock(EntityClient.class); | ||
RollbackIngestionResolver resolver = new RollbackIngestionResolver(mockClient); | ||
|
||
// Execute resolver | ||
DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class); | ||
QueryContext mockContext = getMockDenyContext(); | ||
Mockito.when(mockEnv.getArgument(Mockito.eq("input"))).thenReturn(TEST_INPUT); | ||
Mockito.when(mockEnv.getContext()).thenReturn(mockContext); | ||
|
||
assertThrows(RuntimeException.class, () -> resolver.get(mockEnv).join()); | ||
Mockito.verify(mockClient, Mockito.times(0)).rollbackIngestion( | ||
Mockito.eq(RUN_ID), | ||
Mockito.any(Authentication.class)); | ||
} | ||
|
||
@Test | ||
public void testRollbackIngestionMethod() throws Exception { | ||
EntityClient mockClient = Mockito.mock(EntityClient.class); | ||
RollbackIngestionResolver resolver = new RollbackIngestionResolver(mockClient); | ||
|
||
QueryContext mockContext = getMockAllowContext(); | ||
resolver.rollbackIngestion(RUN_ID, mockContext).get(); | ||
|
||
Mockito.verify(mockClient, Mockito.times(1)).rollbackIngestion( | ||
Mockito.eq(RUN_ID), | ||
Mockito.any(Authentication.class) | ||
); | ||
} | ||
|
||
@Test | ||
public void testGetEntityClientException() throws Exception { | ||
EntityClient mockClient = Mockito.mock(EntityClient.class); | ||
Mockito.doThrow(RuntimeException.class).when(mockClient).rollbackIngestion( | ||
Mockito.any(), | ||
Mockito.any(Authentication.class)); | ||
|
||
RollbackIngestionResolver resolver = new RollbackIngestionResolver(mockClient); | ||
|
||
QueryContext mockContext = getMockAllowContext(); | ||
|
||
assertThrows(RuntimeException.class, () -> resolver.rollbackIngestion(RUN_ID, mockContext).join()); | ||
} | ||
} | ||
|
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
Oops, something went wrong.