Skip to content

Commit

Permalink
Enhance API for use by cloud to provide per-connector billing info (#…
Browse files Browse the repository at this point in the history
…7893)

* Enhance API for use by cloud to provide per-connector billing information

* Add listAllConnectionsForWorkspace to include deleted

* Config for list all connections

* Merged master, and formatting

* Formatting

* Name change per PR suggestion

* Name change per PR suggestion

* Formatting again
  • Loading branch information
airbyte-jenny authored Nov 16, 2021
1 parent 8934f3e commit d6c684b
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 5 deletions.
49 changes: 48 additions & 1 deletion airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,30 @@ paths:
$ref: "#/components/responses/NotFoundResponse"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/connections/list_all:
post:
tags:
- connection
summary: Returns all connections for a workspace, including deleted connections.
description: List connections for workspace, including deleted connections.
operationId: listAllConnectionsForWorkspace
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/WorkspaceIdRequestBody"
required: true
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/ConnectionReadList"
"404":
$ref: "#/components/responses/NotFoundResponse"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/connections/get:
post:
tags:
Expand Down Expand Up @@ -1389,7 +1413,7 @@ paths:
post:
tags:
- web_backend
summary: Returns all connections for a workspace.
summary: Returns all non-deleted connections for a workspace.
operationId: webBackendListConnectionsForWorkspace
requestBody:
content:
Expand All @@ -1408,6 +1432,29 @@ paths:
$ref: "#/components/responses/NotFoundResponse"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/web_backend/connections/list_all:
post:
tags:
- web_backend
summary: Returns all connections for a workspace.
operationId: webBackendListAllConnectionsForWorkspace
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/WorkspaceIdRequestBody"
required: true
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/WebBackendConnectionReadList"
"404":
$ref: "#/components/responses/NotFoundResponse"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/web_backend/connections/get:
post:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ public ConnectionReadList listConnectionsForWorkspace(final WorkspaceIdRequestBo
return execute(() -> connectionsHandler.listConnectionsForWorkspace(workspaceIdRequestBody));
}

@Override
public ConnectionReadList listAllConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return execute(() -> connectionsHandler.listAllConnectionsForWorkspace(workspaceIdRequestBody));
}

@Override
public ConnectionReadList searchConnections(final ConnectionSearch connectionSearch) {
return execute(() -> connectionsHandler.searchConnections(connectionSearch));
Expand Down Expand Up @@ -607,6 +612,11 @@ public WebBackendConnectionReadList webBackendListConnectionsForWorkspace(final
return execute(() -> webBackendConnectionsHandler.webBackendListConnectionsForWorkspace(workspaceIdRequestBody));
}

@Override
public WebBackendConnectionReadList webBackendListAllConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return execute(() -> webBackendConnectionsHandler.webBackendListAllConnectionsForWorkspace(workspaceIdRequestBody));
}

@Override
public WebBackendConnectionReadList webBackendSearchConnections(final WebBackendConnectionSearch webBackendConnectionSearch) {
return execute(() -> webBackendConnectionsHandler.webBackendSearchConnections(webBackendConnectionSearch));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,20 @@ public ConnectionRead updateConnection(final ConnectionUpdate connectionUpdate)

public ConnectionReadList listConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody)
throws JsonValidationException, IOException, ConfigNotFoundException {
return listConnectionsForWorkspace(workspaceIdRequestBody, false);
}

public ConnectionReadList listAllConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody)
throws JsonValidationException, IOException, ConfigNotFoundException {
return listConnectionsForWorkspace(workspaceIdRequestBody, true);
}

public ConnectionReadList listConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody, final boolean includeDeleted)
throws JsonValidationException, IOException, ConfigNotFoundException {
final List<ConnectionRead> connectionReads = Lists.newArrayList();

for (final StandardSync standardSync : configRepository.listStandardSyncs()) {
if (standardSync.getStatus() == StandardSync.Status.DEPRECATED) {
if (standardSync.getStatus() == StandardSync.Status.DEPRECATED && !includeDeleted) {
continue;
}
if (!isStandardSyncInWorkspace(workspaceIdRequestBody.getWorkspaceId(), standardSync)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ public WebBackendConnectionReadList webBackendListConnectionsForWorkspace(final
return new WebBackendConnectionReadList().connections(reads);
}

public WebBackendConnectionReadList webBackendListAllConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody)
throws ConfigNotFoundException, IOException, JsonValidationException {

final List<WebBackendConnectionRead> reads = Lists.newArrayList();
for (final ConnectionRead connection : connectionsHandler.listAllConnectionsForWorkspace(workspaceIdRequestBody).getConnections()) {
reads.add(buildWebBackendConnectionRead(connection));
}
return new WebBackendConnectionReadList().connections(reads);
}

private WebBackendConnectionRead buildWebBackendConnectionRead(final ConnectionRead connectionRead)
throws ConfigNotFoundException, IOException, JsonValidationException {
final SourceRead source = getSourceRead(connectionRead);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ class ConnectionsHandlerTest {
private UUID workspaceId;
private UUID sourceDefinitionId;
private UUID sourceId;
private UUID deletedSourceId;
private UUID destinationDefinitionId;
private UUID destinationId;

private SourceConnection source;
private DestinationConnection destination;
private StandardSync standardSync;
private StandardSync standardSyncDeleted;
private UUID connectionId;
private UUID operationId;
private StandardSyncOperation standardSyncOperation;
Expand Down Expand Up @@ -109,6 +111,20 @@ void setUp() throws IOException, JsonValidationException, ConfigNotFoundExceptio
.withManual(false)
.withSchedule(ConnectionHelpers.generateBasicSchedule())
.withResourceRequirements(WorkerUtils.DEFAULT_RESOURCE_REQUIREMENTS);
standardSyncDeleted = new StandardSync()
.withConnectionId(connectionId)
.withName("presto to hudi2")
.withNamespaceDefinition(JobSyncConfig.NamespaceDefinitionType.SOURCE)
.withNamespaceFormat(null)
.withPrefix("presto_to_hudi2")
.withStatus(StandardSync.Status.DEPRECATED)
.withCatalog(ConnectionHelpers.generateBasicConfiguredAirbyteCatalog())
.withSourceId(sourceId)
.withDestinationId(destinationId)
.withOperationIds(List.of(operationId))
.withManual(false)
.withSchedule(ConnectionHelpers.generateBasicSchedule())
.withResourceRequirements(WorkerUtils.DEFAULT_RESOURCE_REQUIREMENTS);

standardSyncOperation = new StandardSyncOperation()
.withOperationId(operationId)
Expand All @@ -121,6 +137,7 @@ void setUp() throws IOException, JsonValidationException, ConfigNotFoundExceptio
connectionsHandler = new ConnectionsHandler(configRepository, uuidGenerator, workspaceHelper, trackingClient);

when(workspaceHelper.getWorkspaceForSourceIdIgnoreExceptions(sourceId)).thenReturn(workspaceId);
when(workspaceHelper.getWorkspaceForSourceIdIgnoreExceptions(deletedSourceId)).thenReturn(workspaceId);
when(workspaceHelper.getWorkspaceForDestinationIdIgnoreExceptions(destinationId)).thenReturn(workspaceId);
when(workspaceHelper.getWorkspaceForOperationIdIgnoreExceptions(operationId)).thenReturn(workspaceId);
}
Expand Down Expand Up @@ -321,18 +338,25 @@ void testGetConnection() throws JsonValidationException, ConfigNotFoundException
@Test
void testListConnectionsForWorkspace() throws JsonValidationException, ConfigNotFoundException, IOException {
when(configRepository.listStandardSyncs())
.thenReturn(Lists.newArrayList(standardSync));
.thenReturn(Lists.newArrayList(standardSync, standardSyncDeleted));
when(configRepository.getSourceConnection(source.getSourceId()))
.thenReturn(source);
when(configRepository.getStandardSync(standardSync.getConnectionId()))
.thenReturn(standardSync);

final WorkspaceIdRequestBody workspaceIdRequestBody = new WorkspaceIdRequestBody().workspaceId(source.getWorkspaceId());
final ConnectionReadList actualConnectionReadList = connectionsHandler.listConnectionsForWorkspace(workspaceIdRequestBody);

assertEquals(1, actualConnectionReadList.getConnections().size());
assertEquals(
ConnectionHelpers.generateExpectedConnectionRead(standardSync),
actualConnectionReadList.getConnections().get(0));

final ConnectionReadList actualConnectionReadListWithDeleted = connectionsHandler.listConnectionsForWorkspace(workspaceIdRequestBody, true);
final List<ConnectionRead> connections = actualConnectionReadListWithDeleted.getConnections();
assertEquals(2, connections.size());
assertEquals(ConnectionHelpers.generateExpectedConnectionRead(standardSync), connections.get(0));
assertEquals(ConnectionHelpers.generateExpectedConnectionRead(standardSyncDeleted), connections.get(1));

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ public void testWebBackendListConnectionsForWorkspace() throws ConfigNotFoundExc
assertEquals(expected, WebBackendConnectionReadList.getConnections().get(0));
}

@Test
public void testWebBackendListAllConnectionsForWorkspace() throws ConfigNotFoundException, IOException, JsonValidationException {
final WorkspaceIdRequestBody workspaceIdRequestBody = new WorkspaceIdRequestBody();
workspaceIdRequestBody.setWorkspaceId(sourceRead.getWorkspaceId());

final ConnectionReadList connectionReadList = new ConnectionReadList();
connectionReadList.setConnections(Collections.singletonList(connectionRead));
final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody();
connectionIdRequestBody.setConnectionId(connectionRead.getConnectionId());
when(connectionsHandler.listAllConnectionsForWorkspace(workspaceIdRequestBody)).thenReturn(connectionReadList);
when(operationsHandler.listOperationsForConnection(connectionIdRequestBody)).thenReturn(operationReadList);

final WebBackendConnectionReadList WebBackendConnectionReadList = wbHandler.webBackendListAllConnectionsForWorkspace(workspaceIdRequestBody);
assertEquals(1, WebBackendConnectionReadList.getConnections().size());
assertEquals(expected, WebBackendConnectionReadList.getConnections().get(0));
}

@Test
public void testWebBackendSearchConnections() throws ConfigNotFoundException, IOException, JsonValidationException {
final ConnectionReadList connectionReadList = new ConnectionReadList();
Expand Down
Loading

0 comments on commit d6c684b

Please sign in to comment.