Skip to content

Commit

Permalink
add delete destination endpoint (#884)
Browse files Browse the repository at this point in the history
* refactor other handlers (source and destination) to use it instead of their own impls

* reformat code in tests to match new code style (fewer line breaks)
  • Loading branch information
cgardens authored Nov 11, 2020
1 parent 32dbb09 commit f83fd09
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 208 deletions.
19 changes: 19 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,25 @@ paths:
description: Connection not found
"422":
$ref: "#/components/responses/InvalidInput"
/v1/connections/delete:
post:
tags:
- connection
summary: Delete a connection
operationId: deleteConnection
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ConnectionIdRequestBody"
required: true
responses:
"204":
description: The resource was deleted successfully.
"404":
description: Connection not found
"422":
$ref: "#/components/responses/InvalidInput"
/v1/connections/sync:
post:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,12 @@ public ConnectionRead getConnection(@Valid ConnectionIdRequestBody connectionIdR
}

@Override
public DebugRead getDebuggingInfo() {
return execute(debugInfoHandler::getInfo);
public void deleteConnection(@Valid ConnectionIdRequestBody connectionIdRequestBody) {
execute(() -> {
connectionsHandler.deleteConnection(connectionIdRequestBody);
return null;
});

}

@Override
Expand All @@ -321,6 +325,13 @@ public JobInfoRead getJobInfo(@Valid JobIdRequestBody jobIdRequestBody) {
return execute(() -> jobHistoryHandler.getJobInfo(jobIdRequestBody));
}

// DEBUG INFO

@Override
public DebugRead getDebuggingInfo() {
return execute(debugInfoHandler::getInfo);
}

// WEB BACKEND

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ public ConnectionRead getConnection(ConnectionIdRequestBody connectionIdRequestB
return buildConnectionRead(connectionIdRequestBody.getConnectionId());
}

public void deleteConnection(ConnectionIdRequestBody connectionIdRequestBody) throws ConfigNotFoundException, IOException, JsonValidationException {
final ConnectionRead connectionRead = getConnection(connectionIdRequestBody);
deleteConnection(connectionRead);
}

public void deleteConnection(ConnectionRead connectionRead) throws ConfigNotFoundException, IOException, JsonValidationException {
final ConnectionUpdate connectionUpdate = new ConnectionUpdate()
.connectionId(connectionRead.getConnectionId())
.syncSchema(connectionRead.getSyncSchema())
.schedule(connectionRead.getSchedule())
.status(ConnectionStatus.DEPRECATED);

updateConnection(connectionUpdate);
}

private boolean isStandardSyncInWorkspace(final UUID workspaceId,
final StandardSync standardSync)
throws ConfigNotFoundException, IOException, JsonValidationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import io.airbyte.api.model.ConnectionRead;
import io.airbyte.api.model.ConnectionStatus;
import io.airbyte.api.model.ConnectionUpdate;
import io.airbyte.api.model.DestinationCreate;
import io.airbyte.api.model.DestinationDefinitionIdRequestBody;
import io.airbyte.api.model.DestinationDefinitionSpecificationRead;
Expand Down Expand Up @@ -110,13 +108,7 @@ public void deleteDestination(final DestinationIdRequestBody destinationIdReques
continue;
}

final ConnectionUpdate connectionUpdate = new ConnectionUpdate()
.connectionId(connectionRead.getConnectionId())
.syncSchema(connectionRead.getSyncSchema())
.schedule(connectionRead.getSchedule())
.status(ConnectionStatus.DEPRECATED);

connectionsHandler.updateConnection(connectionUpdate);
connectionsHandler.deleteConnection(connectionRead);
}

// persist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import io.airbyte.api.model.ConnectionRead;
import io.airbyte.api.model.ConnectionStatus;
import io.airbyte.api.model.ConnectionUpdate;
import io.airbyte.api.model.SourceCreate;
import io.airbyte.api.model.SourceDefinitionIdRequestBody;
import io.airbyte.api.model.SourceDefinitionSpecificationRead;
Expand Down Expand Up @@ -157,13 +155,7 @@ public void deleteSource(SourceIdRequestBody sourceIdRequestBody)
continue;
}

final ConnectionUpdate connectionUpdate = new ConnectionUpdate()
.connectionId(connectionRead.getConnectionId())
.syncSchema(connectionRead.getSyncSchema())
.schedule(connectionRead.getSchedule())
.status(ConnectionStatus.DEPRECATED);

connectionsHandler.updateConnection(connectionUpdate);
connectionsHandler.deleteConnection(connectionRead);
}

// persist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -85,11 +87,9 @@ void setUp() throws IOException {
void testCreateConnection() throws JsonValidationException, ConfigNotFoundException, IOException {
when(uuidGenerator.get()).thenReturn(standardSync.getConnectionId());

when(configRepository.getStandardSync(standardSync.getConnectionId()))
.thenReturn(standardSync);
when(configRepository.getStandardSync(standardSync.getConnectionId())).thenReturn(standardSync);

when(configRepository.getStandardSyncSchedule(standardSyncSchedule.getConnectionId()))
.thenReturn(standardSyncSchedule);
when(configRepository.getStandardSyncSchedule(standardSyncSchedule.getConnectionId())).thenReturn(standardSyncSchedule);

final ConnectionCreate connectionCreate = new ConnectionCreate()
.sourceId(standardSync.getSourceId())
Expand All @@ -102,16 +102,14 @@ void testCreateConnection() throws JsonValidationException, ConfigNotFoundExcept

final ConnectionRead actualConnectionRead = connectionsHandler.createConnection(connectionCreate);

final ConnectionRead expectedConnectionRead =
ConnectionHelpers.generateExpectedConnectionRead(
standardSync.getConnectionId(),
standardSync.getSourceId(),
standardSync.getDestinationId());
final ConnectionRead expectedConnectionRead = ConnectionHelpers.generateExpectedConnectionRead(
standardSync.getConnectionId(),
standardSync.getSourceId(),
standardSync.getDestinationId());

assertEquals(expectedConnectionRead, actualConnectionRead);

verify(configRepository).writeStandardSync(standardSync);

verify(configRepository).writeStandardSchedule(standardSyncSchedule);
}

Expand Down Expand Up @@ -152,14 +150,13 @@ void testUpdateConnection() throws JsonValidationException, ConfigNotFoundExcept

final ConnectionRead actualConnectionRead = connectionsHandler.updateConnection(connectionUpdate);

final ConnectionRead expectedConnectionRead =
ConnectionHelpers.generateExpectedConnectionRead(
standardSync.getConnectionId(),
standardSync.getSourceId(),
standardSync.getDestinationId())
.schedule(null)
.syncSchema(newApiSchema)
.status(ConnectionStatus.INACTIVE);
final ConnectionRead expectedConnectionRead = ConnectionHelpers.generateExpectedConnectionRead(
standardSync.getConnectionId(),
standardSync.getSourceId(),
standardSync.getDestinationId())
.schedule(null)
.syncSchema(newApiSchema)
.status(ConnectionStatus.INACTIVE);

assertEquals(expectedConnectionRead, actualConnectionRead);

Expand All @@ -175,8 +172,7 @@ void testGetConnection() throws JsonValidationException, ConfigNotFoundException
when(configRepository.getStandardSyncSchedule(standardSync.getConnectionId()))
.thenReturn(standardSyncSchedule);

final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody();
connectionIdRequestBody.setConnectionId(standardSync.getConnectionId());
final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody().connectionId(standardSync.getConnectionId());
final ConnectionRead actualConnectionRead = connectionsHandler.getConnection(connectionIdRequestBody);

assertEquals(ConnectionHelpers.generateExpectedConnectionRead(standardSync), actualConnectionRead);
Expand All @@ -201,6 +197,31 @@ void testListConnectionsForWorkspace() throws JsonValidationException, ConfigNot
actualConnectionReadList.getConnections().get(0));
}

@Test
void testDeleteConnection() throws JsonValidationException, IOException, ConfigNotFoundException {
final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody().connectionId(standardSync.getConnectionId());

final ConnectionRead connectionRead = ConnectionHelpers.generateExpectedConnectionRead(
standardSync.getConnectionId(),
standardSync.getSourceId(),
standardSync.getDestinationId());

final ConnectionUpdate expectedConnectionUpdate = new ConnectionUpdate()
.connectionId(connectionRead.getConnectionId())
.status(ConnectionStatus.DEPRECATED)
.syncSchema(connectionRead.getSyncSchema())
.schedule(connectionRead.getSchedule());

final ConnectionsHandler spiedConnectionsHandler = spy(connectionsHandler);
doReturn(connectionRead).when(spiedConnectionsHandler).getConnection(connectionIdRequestBody);
doReturn(null).when(spiedConnectionsHandler).updateConnection(expectedConnectionUpdate);

spiedConnectionsHandler.deleteConnection(connectionIdRequestBody);

verify(spiedConnectionsHandler).getConnection(connectionIdRequestBody);
verify(spiedConnectionsHandler).updateConnection(expectedConnectionUpdate);
}

@Test
void testEnumConversion() {
assertTrue(Enums.isCompatible(ConnectionStatus.class, StandardSync.Status.class));
Expand Down
Loading

0 comments on commit f83fd09

Please sign in to comment.