Skip to content

Conversation

gordalina
Copy link
Contributor

@gordalina gordalina commented Mar 5, 2021

What

Closes #1735
Adds /workspaces/create and /workspaces/delete.

How

This adds tombstone to the workspace.
This also adds a check to prevent returning destinations and sources that have been tombstones.

Questions

I see that you are using TrackingClientSingleton.get().identify(); when updating a workspace. I don't think we need to do that for the new workspaces - but I leave that decision to you.

Pre-merge Checklist

  • Run integration tests
  • Publish Docker images

Recommended reading order

  1. WorkspacesHandler

Copy link
Contributor

@michel-tricot michel-tricot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks great! added a few comments!

final DestinationConnection dci = configRepository.getDestinationConnection(destinationId);

if (dci.getTombstone()) {
throw new NotFoundException("Could not find destination");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you send a ConfigNotFoundException instead?

final SourceConnection sourceConnection = configRepository.getSourceConnection(sourceId);

if (sourceConnection.getTombstone()) {
throw new NotFoundException("Could not find source connection");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

final StandardWorkspace workspace = configRepository.getStandardWorkspace(workspaceId);

if (workspace.getTombstone()) {
throw new NotFoundException("Could not find workspace");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. We can add a boolean to getStandardWorkspace to indicate if you want to include the tombstone ones or not. This way you can let the config repo throw the ConfigNotFoundException.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The good thing about adding that boolean is that people will have to make the conscious choice of including tombstoned or not. Less risk of forgetting to filter out the tombstoned


private StandardWorkspace getWorkspaceBySlug(String slug)
throws JsonValidationException, IOException, KnownException {
for (StandardWorkspace workspace : configRepository.listStandardWorkspaces()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea for the prototype.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead actually. What about adding a configRepository::getStandardWorkspaceBySlug (with the tombstone boolean as well)


final WorkspaceRead created = workspacesHandler.createWorkspace(workspaceCreate);

assertTrue(created.getWorkspaceId() instanceof UUID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is a bit brittle here. What about: Injecting the uuid generator in a protected constructor and mock it so you can control the value of the uuid and you can just do a assertEqual(expectedWorkspaceRead, created)

Here is an example of how we do it: io/airbyte/server/handlers/DestinationDefinitionsHandler.java:53

@gordalina
Copy link
Contributor Author

@michel-tricot addressed all your comments & added a 0.17.0 migration

@gordalina gordalina requested a review from michel-tricot March 9, 2021 02:20
@sherifnada
Copy link
Contributor

@cgardens is it too late to include this in 0.17.0 release?

@michel-tricot
Copy link
Contributor

LGTM! You will just need to rename the migrations (we released 0.17.0 in the meantime).

@michel-tricot
Copy link
Contributor

I'll merge it after that

Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Sam,

First, sorry for the slow follow up on this. There was some confusion about how was going to follow up on your PR. This was my bad.

Second, thanks for contributing this! It looks great. I have have one last round of comments. I'm hoping they are all clear and straight forward. Of course, let me know if you have any questions.

After that, I will merge this PR (for real this time--I know we said this once before already 😉 ). I don't know what your time looks like right now, so if you can't get to these, it not the end of the world. If you just say, "sorry I'm busy right now", I will just merge the PR as is and tweak the things I mentioned in my review. You've done the hard part, there's just a couple tweaks that I'm seeing based on some knowledge of some weird assumptions that we've made.

Let me know! Looking forward to getting this merged.

Comment on lines 1209 to 1212
initialSetupComplete:
type: boolean
displaySetupWizard:
type: boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think instead of exposing these in the API, you can hide them and just set them to false in the handler. i thin it's reasonable that these 2 fields will always be false when the workspace is created.

@@ -70,7 +70,7 @@ private static void initialize() {
@VisibleForTesting
static TrackingIdentity getTrackingIdentity(ConfigRepository configRepository, String airbyteVersion) {
try {
final StandardWorkspace workspace = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID);
final StandardWorkspace workspace = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to give you a little context, the concept of a "workspace" and a "deployment" are conflated in our system right now. that has been okay so far because there is only one workspace. the reason i mention it, is that we still to be able to use the default workspace for deployment info (even if the default workspace has been deleted).

all that being said, i think that just means we want true here instead of false. if the default workspace is ever deleted we still want this method to be able to access it.

@@ -9,6 +9,7 @@ required:
- name
- slug
- initialSetupComplete
- tombstone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the code i think you already check that if tombstone is not set that we treat it as false. i think that means that this field then doesn't need to be required. making it not required should mean that we should be able to not need to do a migration.

Up to you, if you feel like it should be required, then we can keep the migration and just drop the check you're doing in the config repository. LMK if that's not clear.

@@ -157,7 +157,7 @@ private void checkImport(Path tempFolder) throws IOException, JsonValidationExce

private Optional<UUID> getCurrentCustomerId() {
try {
return Optional.of(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID).getCustomerId());
return Optional.of(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, false).getCustomerId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. i think we want true. we want the default workspace to be returned even if deleted here.

Comment on lines 75 to 78
final StandardWorkspace standardWorkspace = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, false);
if (standardWorkspace != null)
writeConfigsToArchive(storageRoot, ConfigSchema.STANDARD_WORKSPACE, List.of(standardWorkspace));
else
Copy link
Contributor

@cgardens cgardens Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final StandardWorkspace standardWorkspace = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, false);
if (standardWorkspace != null)
writeConfigsToArchive(storageRoot, ConfigSchema.STANDARD_WORKSPACE, List.of(standardWorkspace));
else
writeConfigsToArchive(storageRoot, ConfigSchema.STANDARD_WORKSPACE, configRepository.listStandardWorkspaces(true));

I think we can get rid of lines 75-79 and just replace it with this. we just want to do the list of all workspaces (regardless of whether they've been deleted). github didn't let me include line 79 in the suggestion comment, so unfortunately this suggestion can't be purely committed automatically.

@@ -44,7 +44,7 @@ public HealthCheckHandler(ConfigRepository configRepository) {
public HealthCheckRead health() {
boolean databaseHealth = false;
try {
databaseHealth = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID) != null;
databaseHealth = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID, false) != null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true here too. we don't want the healthcheck to fail because the default workspace was deleted.

@gordalina gordalina requested a review from cgardens March 11, 2021 23:46
Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing! thanks for the fast turn around!

@cgardens cgardens merged commit 73044ac into airbytehq:master Mar 11, 2021
@cgardens cgardens changed the title Add create & delete workspaces to API 🎉 Add create & delete workspaces to API Mar 12, 2021
@cgardens cgardens changed the title 🎉 Add create & delete workspaces to API 🎉 Add create & delete workspaces to API Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable workspace creation/deletion
4 participants