Skip to content

Commit

Permalink
update open api in correct place (#14652)
Browse files Browse the repository at this point in the history
* update open api in correct place
  • Loading branch information
alovew authored Jul 13, 2022
1 parent bfc2646 commit 2285c2e
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 25 deletions.
23 changes: 23 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,27 @@ paths:
$ref: "#/components/schemas/WebBackendConnectionRead"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/web_backend/connections/updateNew:
post:
operationId: webBackendUpdateConnectionNew
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/WebBackendConnectionUpdate"
required: true
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/WebBackendConnectionRead"
description: Successful operation
"422":
$ref: "#/components/responses/InvalidInputResponse"
summary: Update a connection
tags:
- web_backend
/v1/web_backend/connections/search:
post:
tags:
Expand Down Expand Up @@ -3313,6 +3334,8 @@ components:
$ref: "#/components/schemas/ResourceRequirements"
withRefreshedCatalog:
type: boolean
skipReset:
type: boolean
operations:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ public WebBackendConnectionRead webBackendUpdateConnection(final WebBackendConne
return execute(() -> webBackendConnectionsHandler.webBackendUpdateConnection(webBackendConnectionUpdate));
}

// @Override
@Override
public WebBackendConnectionRead webBackendUpdateConnectionNew(final WebBackendConnectionUpdate webBackendConnectionUpdate) {
return execute(() -> webBackendConnectionsHandler.webBackendUpdateConnectionNew(webBackendConnectionUpdate));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,39 +384,39 @@ public WebBackendConnectionRead webBackendUpdateConnectionNew(final WebBackendCo
throws ConfigNotFoundException, IOException, JsonValidationException {
final List<UUID> operationIds = updateOperations(webBackendConnectionUpdate);
final ConnectionUpdate connectionUpdate = toConnectionUpdate(webBackendConnectionUpdate, operationIds);

final UUID connectionId = webBackendConnectionUpdate.getConnectionId();

final ConfiguredAirbyteCatalog existingConfiguredCatalog =
configRepository.getConfiguredCatalogForConnection(connectionId);
final io.airbyte.protocol.models.AirbyteCatalog existingCatalog = CatalogHelpers.configuredCatalogToCatalog(existingConfiguredCatalog);
final AirbyteCatalog apiExistingCatalog = CatalogConverter.toApi(existingCatalog);
final AirbyteCatalog newAirbyteCatalog = webBackendConnectionUpdate.getSyncCatalog();
final CatalogDiff catalogDiff = connectionsHandler.getDiff(apiExistingCatalog, newAirbyteCatalog);

final List<StreamDescriptor> apiStreamsToReset = getStreamsToReset(catalogDiff);
List<io.airbyte.protocol.models.StreamDescriptor> streamsToReset =
apiStreamsToReset.stream().map(ProtocolConverters::streamDescriptorToProtocol).toList();

ConnectionRead connectionRead;
connectionRead = connectionsHandler.updateConnection(connectionUpdate);

if (!streamsToReset.isEmpty()) {
final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody().connectionId(connectionId);
final ConnectionStateType stateType = getStateType(connectionIdRequestBody);
final Boolean skipReset = webBackendConnectionUpdate.getSkipReset() != null ? webBackendConnectionUpdate.getSkipReset() : false;
if (!skipReset) {
final io.airbyte.protocol.models.AirbyteCatalog existingCatalog = CatalogHelpers.configuredCatalogToCatalog(existingConfiguredCatalog);
final AirbyteCatalog apiExistingCatalog = CatalogConverter.toApi(existingCatalog);
final AirbyteCatalog newAirbyteCatalog = webBackendConnectionUpdate.getSyncCatalog();
final CatalogDiff catalogDiff = connectionsHandler.getDiff(apiExistingCatalog, newAirbyteCatalog);

if (stateType == ConnectionStateType.LEGACY || stateType == ConnectionStateType.NOT_SET || stateType == ConnectionStateType.GLOBAL) {
streamsToReset = configRepository.getAllStreamsForConnection(connectionId);
final List<StreamDescriptor> apiStreamsToReset = getStreamsToReset(catalogDiff);
List<io.airbyte.protocol.models.StreamDescriptor> streamsToReset =
apiStreamsToReset.stream().map(ProtocolConverters::streamDescriptorToProtocol).toList();

if (!streamsToReset.isEmpty()) {
final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody().connectionId(connectionId);
final ConnectionStateType stateType = getStateType(connectionIdRequestBody);

if (stateType == ConnectionStateType.LEGACY) {
streamsToReset = configRepository.getAllStreamsForConnection(connectionId);
}
ManualOperationResult manualOperationResult = eventRunner.synchronousResetConnection(
webBackendConnectionUpdate.getConnectionId(),
streamsToReset);
verifyManualOperationResult(manualOperationResult);
manualOperationResult = eventRunner.startNewManualSync(webBackendConnectionUpdate.getConnectionId());
verifyManualOperationResult(manualOperationResult);
connectionRead = connectionsHandler.getConnection(connectionUpdate.getConnectionId());
}
ManualOperationResult manualOperationResult = eventRunner.synchronousResetConnection(
webBackendConnectionUpdate.getConnectionId(),
streamsToReset);
verifyManualOperationResult(manualOperationResult);
manualOperationResult = eventRunner.startNewManualSync(webBackendConnectionUpdate.getConnectionId());
verifyManualOperationResult(manualOperationResult);
connectionRead = connectionsHandler.getConnection(connectionUpdate.getConnectionId());
}

return buildWebBackendConnectionRead(connectionRead);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,49 @@ void testUpdateConnectionWithUpdatedSchemaPerStreamNoStreamsToReset() throws Jso
orderVerifier.verify(eventRunner, times(0)).startNewManualSync(connectionId.getConnectionId());
}

@Test
public void testUpdateConnectionWithSkipReset() throws JsonValidationException, ConfigNotFoundException, IOException {
final WebBackendConnectionUpdate updateBody = new WebBackendConnectionUpdate()
.namespaceDefinition(expected.getNamespaceDefinition())
.namespaceFormat(expected.getNamespaceFormat())
.prefix(expected.getPrefix())
.connectionId(expected.getConnectionId())
.schedule(expected.getSchedule())
.status(expected.getStatus())
.syncCatalog(expectedWithNewSchema.getSyncCatalog())
.skipReset(true);

when(configRepository.getConfiguredCatalogForConnection(expected.getConnectionId()))
.thenReturn(ConnectionHelpers.generateBasicConfiguredAirbyteCatalog());
when(operationsHandler.listOperationsForConnection(any())).thenReturn(operationReadList);
when(connectionsHandler.getConnection(expected.getConnectionId())).thenReturn(
new ConnectionRead().connectionId(expected.getConnectionId()));
final ConnectionRead connectionRead = new ConnectionRead()
.connectionId(expected.getConnectionId())
.sourceId(expected.getSourceId())
.destinationId(expected.getDestinationId())
.name(expected.getName())
.namespaceDefinition(expected.getNamespaceDefinition())
.namespaceFormat(expected.getNamespaceFormat())
.prefix(expected.getPrefix())
.syncCatalog(expectedWithNewSchema.getSyncCatalog())
.status(expected.getStatus())
.schedule(expected.getSchedule());
when(connectionsHandler.updateConnection(any())).thenReturn(connectionRead);

final WebBackendConnectionRead result = wbHandler.webBackendUpdateConnectionNew(updateBody);

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

final ConnectionIdRequestBody connectionId = new ConnectionIdRequestBody().connectionId(result.getConnectionId());
verify(schedulerHandler, times(0)).resetConnection(connectionId);
verify(schedulerHandler, times(0)).syncConnection(connectionId);
verify(connectionsHandler, times(0)).getDiff(any(), any());
verify(connectionsHandler, times(1)).updateConnection(any());
verify(eventRunner, times(0)).synchronousResetConnection(any(), any());
verify(eventRunner, times(0)).startNewManualSync(any());
}

@Test
public void testUpdateSchemaWithDiscoveryFromEmpty() {
final AirbyteCatalog original = new AirbyteCatalog().streams(List.of());
Expand Down
201 changes: 201 additions & 0 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ <h4><a href="#WebBackend">WebBackend</a></h4>
<li><a href="#webBackendListConnectionsForWorkspace"><code><span class="http-method">post</span> /v1/web_backend/connections/list</code></a></li>
<li><a href="#webBackendSearchConnections"><code><span class="http-method">post</span> /v1/web_backend/connections/search</code></a></li>
<li><a href="#webBackendUpdateConnection"><code><span class="http-method">post</span> /v1/web_backend/connections/update</code></a></li>
<li><a href="#webBackendUpdateConnectionNew"><code><span class="http-method">post</span> /v1/web_backend/connections/updateNew</code></a></li>
</ul>
<h4><a href="#Workspace">Workspace</a></h4>
<ul>
Expand Down Expand Up @@ -9661,6 +9662,205 @@ <h4 class="field-label">422</h4>
<a href="#InvalidInputExceptionInfo">InvalidInputExceptionInfo</a>
</div> <!-- method -->
<hr/>
<div class="method"><a name="webBackendUpdateConnectionNew"/>
<div class="method-path">
<a class="up" href="#__Methods">Up</a>
<pre class="post"><code class="huge"><span class="http-method">post</span> /v1/web_backend/connections/updateNew</code></pre></div>
<div class="method-summary">Update a connection (<span class="nickname">webBackendUpdateConnectionNew</span>)</div>
<div class="method-notes"></div>


<h3 class="field-label">Consumes</h3>
This API call consumes the following media types via the <span class="header">Content-Type</span> request header:
<ul>
<li><code>application/json</code></li>
</ul>

<h3 class="field-label">Request body</h3>
<div class="field-items">
<div class="param">WebBackendConnectionUpdate <a href="#WebBackendConnectionUpdate">WebBackendConnectionUpdate</a> (required)</div>

<div class="param-desc"><span class="param-type">Body Parameter</span> &mdash; </div>

</div> <!-- field-items -->




<h3 class="field-label">Return type</h3>
<div class="return-type">
<a href="#WebBackendConnectionRead">WebBackendConnectionRead</a>

</div>

<!--Todo: process Response Object and its headers, schema, examples -->

<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
"sourceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"latestSyncJobCreatedAt" : 0,
"prefix" : "prefix",
"destination" : {
"connectionConfiguration" : {
"user" : "charles"
},
"destinationName" : "destinationName",
"name" : "name",
"destinationDefinitionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"destinationId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
},
"isSyncing" : true,
"source" : {
"sourceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"connectionConfiguration" : {
"user" : "charles"
},
"name" : "name",
"sourceDefinitionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"sourceName" : "sourceName",
"workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
},
"destinationId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"catalogDiff" : {
"transforms" : [ {
"streamDescriptor" : {
"name" : "name",
"namespace" : "namespace"
},
"transformType" : "add_stream",
"updateStream" : [ {
"updateFieldSchema" : { },
"fieldName" : [ "fieldName", "fieldName" ],
"addField" : { },
"transformType" : "add_field",
"removeField" : { }
}, {
"updateFieldSchema" : { },
"fieldName" : [ "fieldName", "fieldName" ],
"addField" : { },
"transformType" : "add_field",
"removeField" : { }
} ]
}, {
"streamDescriptor" : {
"name" : "name",
"namespace" : "namespace"
},
"transformType" : "add_stream",
"updateStream" : [ {
"updateFieldSchema" : { },
"fieldName" : [ "fieldName", "fieldName" ],
"addField" : { },
"transformType" : "add_field",
"removeField" : { }
}, {
"updateFieldSchema" : { },
"fieldName" : [ "fieldName", "fieldName" ],
"addField" : { },
"transformType" : "add_field",
"removeField" : { }
} ]
} ]
},
"resourceRequirements" : {
"cpu_limit" : "cpu_limit",
"memory_request" : "memory_request",
"memory_limit" : "memory_limit",
"cpu_request" : "cpu_request"
},
"schedule" : {
"units" : 0,
"timeUnit" : "minutes"
},
"operations" : [ {
"name" : "name",
"operationId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"operatorConfiguration" : {
"normalization" : {
"option" : "basic"
},
"dbt" : {
"gitRepoBranch" : "gitRepoBranch",
"dockerImage" : "dockerImage",
"dbtArguments" : "dbtArguments",
"gitRepoUrl" : "gitRepoUrl"
}
},
"workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
}, {
"name" : "name",
"operationId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"operatorConfiguration" : {
"normalization" : {
"option" : "basic"
},
"dbt" : {
"gitRepoBranch" : "gitRepoBranch",
"dockerImage" : "dockerImage",
"dbtArguments" : "dbtArguments",
"gitRepoUrl" : "gitRepoUrl"
}
},
"workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
} ],
"catalogId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"name" : "name",
"syncCatalog" : {
"streams" : [ {
"stream" : {
"sourceDefinedPrimaryKey" : [ [ "sourceDefinedPrimaryKey", "sourceDefinedPrimaryKey" ], [ "sourceDefinedPrimaryKey", "sourceDefinedPrimaryKey" ] ],
"supportedSyncModes" : [ null, null ],
"sourceDefinedCursor" : true,
"name" : "name",
"namespace" : "namespace",
"defaultCursorField" : [ "defaultCursorField", "defaultCursorField" ]
},
"config" : {
"aliasName" : "aliasName",
"cursorField" : [ "cursorField", "cursorField" ],
"selected" : true,
"primaryKey" : [ [ "primaryKey", "primaryKey" ], [ "primaryKey", "primaryKey" ] ]
}
}, {
"stream" : {
"sourceDefinedPrimaryKey" : [ [ "sourceDefinedPrimaryKey", "sourceDefinedPrimaryKey" ], [ "sourceDefinedPrimaryKey", "sourceDefinedPrimaryKey" ] ],
"supportedSyncModes" : [ null, null ],
"sourceDefinedCursor" : true,
"name" : "name",
"namespace" : "namespace",
"defaultCursorField" : [ "defaultCursorField", "defaultCursorField" ]
},
"config" : {
"aliasName" : "aliasName",
"cursorField" : [ "cursorField", "cursorField" ],
"selected" : true,
"primaryKey" : [ [ "primaryKey", "primaryKey" ], [ "primaryKey", "primaryKey" ] ]
}
} ]
},
"connectionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"namespaceFormat" : "${SOURCE_NAMESPACE}",
"operationIds" : [ null, null ]
}</code></pre>

<h3 class="field-label">Produces</h3>
This API call produces the following media types according to the <span class="header">Accept</span> request header;
the media type will be conveyed by the <span class="header">Content-Type</span> response header.
<ul>
<li><code>application/json</code></li>
</ul>

<h3 class="field-label">Responses</h3>
<h4 class="field-label">200</h4>
Successful operation
<a href="#WebBackendConnectionRead">WebBackendConnectionRead</a>
<h4 class="field-label">422</h4>
Input failed validation
<a href="#InvalidInputExceptionInfo">InvalidInputExceptionInfo</a>
</div> <!-- method -->
<hr/>
<h1><a name="Workspace">Workspace</a></h1>
<div class="method"><a name="createWorkspace"/>
<div class="method-path">
Expand Down Expand Up @@ -11783,6 +11983,7 @@ <h3><a name="WebBackendConnectionUpdate"><code>WebBackendConnectionUpdate</code>
<div class="param">status </div><div class="param-desc"><span class="param-type"><a href="#ConnectionStatus">ConnectionStatus</a></span> </div>
<div class="param">resourceRequirements (optional)</div><div class="param-desc"><span class="param-type"><a href="#ResourceRequirements">ResourceRequirements</a></span> </div>
<div class="param">withRefreshedCatalog (optional)</div><div class="param-desc"><span class="param-type"><a href="#boolean">Boolean</a></span> </div>
<div class="param">skipReset (optional)</div><div class="param-desc"><span class="param-type"><a href="#boolean">Boolean</a></span> </div>
<div class="param">operations (optional)</div><div class="param-desc"><span class="param-type"><a href="#WebBackendOperationCreateOrUpdate">array[WebBackendOperationCreateOrUpdate]</a></span> </div>
<div class="param">sourceCatalogId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
</div> <!-- field-items -->
Expand Down

0 comments on commit 2285c2e

Please sign in to comment.