Skip to content

Commit

Permalink
馃悰 Handle workspace id for operations in web backend (#5040)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens committed Jul 28, 2021
1 parent 1353c82 commit 871c2f2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
3 changes: 3 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Expand Up @@ -2266,9 +2266,12 @@ components:
required:
- name
- operatorConfiguration
- workspaceId
properties:
operationId:
$ref: "#/components/schemas/OperationId"
workspaceId:
$ref: "#/components/schemas/WorkspaceId"
name:
type: string
operatorConfiguration:
Expand Down
Expand Up @@ -177,8 +177,7 @@ public ConfigurationApi(final ConfigRepository configRepository,
destinationHandler,
jobHistoryHandler,
schedulerHandler,
operationsHandler,
workspaceHelper);
operationsHandler);
webBackendSourceHandler = new WebBackendSourceHandler(sourceHandler, schedulerHandler, workspaceHelper);
webBackendDestinationHandler = new WebBackendDestinationHandler(destinationHandler, schedulerHandler, workspaceHelper);
healthCheckHandler = new HealthCheckHandler(configRepository);
Expand Down
Expand Up @@ -282,6 +282,7 @@ private List<UUID> updateOperations(WebBackendConnectionUpdate webBackendConnect
.getConnection(new ConnectionIdRequestBody().connectionId(webBackendConnectionUpdate.getConnectionId()));
final List<UUID> originalOperationIds = new ArrayList<>(connectionRead.getOperationIds());
final List<UUID> operationIds = new ArrayList<>();

for (var operationCreateOrUpdate : webBackendConnectionUpdate.getOperations()) {
if (operationCreateOrUpdate.getOperationId() == null || !originalOperationIds.contains(operationCreateOrUpdate.getOperationId())) {
final OperationCreate operationCreate = toOperationCreate(operationCreateOrUpdate);
Expand All @@ -296,19 +297,29 @@ private List<UUID> updateOperations(WebBackendConnectionUpdate webBackendConnect
return operationIds;
}

private UUID getWorkspaceIdForConnection(UUID connectionId) throws JsonValidationException, ConfigNotFoundException, IOException {
final UUID sourceId = connectionsHandler.getConnection(new ConnectionIdRequestBody().connectionId(connectionId)).getSourceId();
return getWorkspaceIdForSource(sourceId);
}

private UUID getWorkspaceIdForSource(UUID sourceId) throws JsonValidationException, ConfigNotFoundException, IOException {
return sourceHandler.getSource(new SourceIdRequestBody().sourceId(sourceId)).getWorkspaceId();
}

@VisibleForTesting
protected static OperationCreate toOperationCreate(WebBackendOperationCreateOrUpdate operationCreateOrUpdate) {
OperationCreate operationCreate = new OperationCreate();
final OperationCreate operationCreate = new OperationCreate();

operationCreate.name(operationCreateOrUpdate.getName());
operationCreate.workspaceId(operationCreateOrUpdate.getWorkspaceId());
operationCreate.operatorConfiguration(operationCreateOrUpdate.getOperatorConfiguration());

return operationCreate;
}

@VisibleForTesting
protected static OperationUpdate toOperationUpdate(WebBackendOperationCreateOrUpdate operationCreateOrUpdate) {
OperationUpdate operationUpdate = new OperationUpdate();
final OperationUpdate operationUpdate = new OperationUpdate();

operationUpdate.operationId(operationCreateOrUpdate.getOperationId());
operationUpdate.name(operationCreateOrUpdate.getName());
Expand All @@ -319,7 +330,7 @@ protected static OperationUpdate toOperationUpdate(WebBackendOperationCreateOrUp

@VisibleForTesting
protected static ConnectionCreate toConnectionCreate(WebBackendConnectionCreate webBackendConnectionCreate, List<UUID> operationIds) {
ConnectionCreate connectionCreate = new ConnectionCreate();
final ConnectionCreate connectionCreate = new ConnectionCreate();

connectionCreate.name(webBackendConnectionCreate.getName());
connectionCreate.namespaceDefinition(webBackendConnectionCreate.getNamespaceDefinition());
Expand All @@ -338,7 +349,7 @@ protected static ConnectionCreate toConnectionCreate(WebBackendConnectionCreate

@VisibleForTesting
protected static ConnectionUpdate toConnectionUpdate(WebBackendConnectionUpdate webBackendConnectionUpdate, List<UUID> operationIds) {
ConnectionUpdate connectionUpdate = new ConnectionUpdate();
final ConnectionUpdate connectionUpdate = new ConnectionUpdate();

connectionUpdate.connectionId(webBackendConnectionUpdate.getConnectionId());
connectionUpdate.namespaceDefinition(webBackendConnectionUpdate.getNamespaceDefinition());
Expand Down
Expand Up @@ -117,20 +117,20 @@ class WebBackendConnectionsHandlerTest {
public void setup() throws IOException, JsonValidationException, ConfigNotFoundException {
connectionsHandler = mock(ConnectionsHandler.class);
operationsHandler = mock(OperationsHandler.class);
SourceHandler sourceHandler = mock(SourceHandler.class);
DestinationHandler destinationHandler = mock(DestinationHandler.class);
JobHistoryHandler jobHistoryHandler = mock(JobHistoryHandler.class);
final SourceHandler sourceHandler = mock(SourceHandler.class);
final DestinationHandler destinationHandler = mock(DestinationHandler.class);
final JobHistoryHandler jobHistoryHandler = mock(JobHistoryHandler.class);
schedulerHandler = mock(SchedulerHandler.class);
wbHandler = new WebBackendConnectionsHandler(connectionsHandler, sourceHandler, destinationHandler, jobHistoryHandler, schedulerHandler,
operationsHandler);

final StandardSourceDefinition standardSourceDefinition = SourceDefinitionHelpers.generateSource();
SourceConnection source = SourceHelpers.generateSource(UUID.randomUUID());
final SourceConnection source = SourceHelpers.generateSource(UUID.randomUUID());
sourceRead = SourceHelpers.getSourceRead(source, standardSourceDefinition);

final StandardDestinationDefinition destinationDefinition = DestinationDefinitionHelpers.generateDestination();
final DestinationConnection destination = DestinationHelpers.generateDestination(UUID.randomUUID());
DestinationRead destinationRead = DestinationHelpers.getDestinationRead(destination, destinationDefinition);
final DestinationRead destinationRead = DestinationHelpers.getDestinationRead(destination, destinationDefinition);

final StandardSync standardSync = ConnectionHelpers.generateSyncWithSourceId(source.getSourceId());
connectionRead = ConnectionHelpers.generateExpectedConnectionRead(standardSync);
Expand Down Expand Up @@ -403,7 +403,7 @@ public void testForConnectionUpdateCompleteness() {

@Test
void testUpdateConnection() throws JsonValidationException, ConfigNotFoundException, IOException {
WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
final WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
.namespaceDefinition(expected.getNamespaceDefinition())
.namespaceFormat(expected.getNamespaceFormat())
.prefix(expected.getPrefix())
Expand Down Expand Up @@ -432,7 +432,7 @@ void testUpdateConnection() throws JsonValidationException, ConfigNotFoundExcept

assertEquals(expected.getSyncCatalog(), connectionRead.getSyncCatalog());

ConnectionIdRequestBody connectionId = new ConnectionIdRequestBody().connectionId(connectionRead.getConnectionId());
final ConnectionIdRequestBody connectionId = new ConnectionIdRequestBody().connectionId(connectionRead.getConnectionId());
verify(schedulerHandler, times(0)).resetConnection(connectionId);
verify(schedulerHandler, times(0)).syncConnection(connectionId);
}
Expand All @@ -443,7 +443,7 @@ void testUpdateConnectionWithOperations() throws JsonValidationException, Config
.name("Test Operation")
.operationId(connectionRead.getOperationIds().get(0));
final OperationUpdate operationUpdate = WebBackendConnectionsHandler.toOperationUpdate(operationCreateOrUpdate);
WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
final WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
.namespaceDefinition(expected.getNamespaceDefinition())
.namespaceFormat(expected.getNamespaceFormat())
.prefix(expected.getPrefix())
Expand Down Expand Up @@ -480,7 +480,7 @@ void testUpdateConnectionWithOperations() throws JsonValidationException, Config

@Test
void testUpdateConnectionWithUpdatedSchema() throws JsonValidationException, ConfigNotFoundException, IOException {
WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
final WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
.namespaceDefinition(expected.getNamespaceDefinition())
.namespaceFormat(expected.getNamespaceFormat())
.prefix(expected.getPrefix())
Expand All @@ -506,7 +506,7 @@ void testUpdateConnectionWithUpdatedSchema() throws JsonValidationException, Con
.status(expected.getStatus())
.schedule(expected.getSchedule()));

WebBackendConnectionRead connectionRead = wbHandler.webBackendUpdateConnection(updateBody);
final WebBackendConnectionRead connectionRead = wbHandler.webBackendUpdateConnection(updateBody);

assertEquals(expectedWithNewSchema.getSyncCatalog(), connectionRead.getSyncCatalog());

Expand Down
7 changes: 5 additions & 2 deletions airbyte-webapp/src/core/domain/connection/OperationService.ts
Expand Up @@ -8,9 +8,12 @@ class OperationService extends AirbyteRequestService {
}

public async check(
body: Operation
operation: Operation
): Promise<{ status: "succeeded" | "failed"; message: string }> {
const rs = ((await this.fetch(`${this.url}/check`, body)) as any) as {
const rs = ((await this.fetch(
`${this.url}/check`,
operation.operatorConfiguration
)) as any) as {
status: "succeeded" | "failed";
message: string;
};
Expand Down
1 change: 1 addition & 0 deletions docs/reference/api/generated-api-html/index.html
Expand Up @@ -6244,6 +6244,7 @@ <h3><a name="WebBackendOperationCreateOrUpdate"><code>WebBackendOperationCreateO
<div class='model-description'></div>
<div class="field-items">
<div class="param">operationId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">workspaceId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">name </div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> </div>
<div class="param">operatorConfiguration </div><div class="param-desc"><span class="param-type"><a href="#OperatorConfiguration">OperatorConfiguration</a></span> </div>
</div> <!-- field-items -->
Expand Down

0 comments on commit 871c2f2

Please sign in to comment.