-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scope operations by workspace #4845
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8dc45b8
scope operations by workspace
cgardens 75b8d6c
add validation to connection for when operations are from the wrong w…
cgardens 3c64501
migration tests
cgardens b3f0c72
put some PEP8 in your java
cgardens 8ffa4e1
add test if operation ids are not set
cgardens 4558891
fix test
cgardens b7cf788
add workspace id
cgardens d8a3018
fix webapp operations
cgardens 1871050
blanksapce
cgardens 1c8cbee
Bump version: 0.27.5-alpha → 0.28.0-alpha
cgardens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/WorkspaceFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.config.persistence; | ||
|
||
import io.airbyte.config.DestinationConnection; | ||
import io.airbyte.config.SourceConnection; | ||
import java.util.UUID; | ||
|
||
// todo (cgardens) - this is just a utility for this PR. will need to figure out the "right" way to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as the comment says, i expect this to be thrown out once @jrhizor merges his stuff. if that's not the case i can make this better. |
||
// do this with jared. | ||
public class WorkspaceFinder { | ||
|
||
public static UUID getWorkspaceForSourceId(SourceConnection source) { | ||
return source.getWorkspaceId(); | ||
} | ||
|
||
public static UUID getWorkspaceForDestination(DestinationConnection destination) { | ||
return destination.getWorkspaceId(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
airbyte-migration/src/main/java/io/airbyte/migrate/migrations/MigrationV0_28_0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.migrate.migrations; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import io.airbyte.migrate.Migration; | ||
import io.airbyte.migrate.MigrationUtils; | ||
import io.airbyte.migrate.ResourceId; | ||
import io.airbyte.migrate.ResourceType; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
public class MigrationV0_28_0 extends BaseMigration implements Migration { | ||
|
||
private static final UUID DEFAULT_WORKSPACE_ID = UUID.fromString("5ae6b09b-fdec-41af-aaf7-7d94cfc33ef6"); | ||
|
||
private static final ResourceId CONNECTION_RESOURCE_ID = ResourceId.fromConstantCase(ResourceType.CONFIG, "STANDARD_SYNC"); | ||
private static final ResourceId SOURCE_RESOURCE_ID = ResourceId.fromConstantCase(ResourceType.CONFIG, "SOURCE_CONNECTION"); | ||
private static final ResourceId OPERATION_RESOURCE_ID = ResourceId.fromConstantCase(ResourceType.CONFIG, "STANDARD_SYNC_OPERATION"); | ||
|
||
private static final String MIGRATION_VERSION = "0.28.0-alpha"; | ||
@VisibleForTesting | ||
protected final Migration previousMigration; | ||
|
||
public MigrationV0_28_0(Migration previousMigration) { | ||
super(previousMigration); | ||
this.previousMigration = previousMigration; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return MIGRATION_VERSION; | ||
} | ||
|
||
private static final Path RESOURCE_PATH = Path.of("migrations/migrationV0_28_0/airbyte_config"); | ||
|
||
@Override | ||
public Map<ResourceId, JsonNode> getOutputSchema() { | ||
final Map<ResourceId, JsonNode> outputSchema = new HashMap<>(previousMigration.getOutputSchema()); | ||
outputSchema.put( | ||
OPERATION_RESOURCE_ID, | ||
MigrationUtils.getSchemaFromResourcePath(RESOURCE_PATH, OPERATION_RESOURCE_ID)); | ||
return outputSchema; | ||
} | ||
|
||
@Override | ||
public void migrate(Map<ResourceId, Stream<JsonNode>> inputDataImmutable, | ||
Map<ResourceId, Consumer<JsonNode>> outputData) { | ||
// we need to figure out which workspace to associate an operation with. we use the following | ||
// strategy to avoid ever storing too much info in memory: | ||
// 1. iterate over connectors stream | ||
// 2. build mapping of connections to source | ||
// 3. build mapping of operation ids to connections | ||
// 4. iterate over sources stream | ||
// 5. build mapping of sources to workspaces | ||
// 6. iterate over operations stream, | ||
// 7. map from operation => connection => source => workspace. set that workspace for the operation. | ||
// 8. if no mapping use default workspace id | ||
|
||
final Map<UUID, UUID> connectionIdToSourceId = new HashMap<>(); | ||
final Map<UUID, UUID> operationIdToConnectionId = new HashMap<>(); | ||
final Map<UUID, UUID> sourceIdToWorkspaceId = new HashMap<>(); | ||
|
||
final Map<ResourceId, Stream<JsonNode>> inputData = new HashMap<>(inputDataImmutable); | ||
// process connections. | ||
inputData.remove(CONNECTION_RESOURCE_ID).forEach(r -> { | ||
final UUID connectionId = UUID.fromString(r.get("connectionId").asText()); | ||
final UUID sourceId = UUID.fromString(r.get("sourceId").asText()); | ||
connectionIdToSourceId.put(connectionId, sourceId); | ||
if (r.hasNonNull("operationIds")) { | ||
r.get("operationIds").forEach(operationIdString -> { | ||
final UUID operationId = UUID.fromString(operationIdString.asText()); | ||
operationIdToConnectionId.put(operationId, connectionId); | ||
}); | ||
} | ||
|
||
outputData.get(CONNECTION_RESOURCE_ID).accept(r); | ||
}); | ||
// process sources. | ||
inputData.remove(SOURCE_RESOURCE_ID).forEach(r -> { | ||
final UUID sourceId = UUID.fromString(r.get("sourceId").asText()); | ||
final UUID workspaceId = UUID.fromString(r.get("workspaceId").asText()); | ||
sourceIdToWorkspaceId.put(sourceId, workspaceId); | ||
|
||
outputData.get(SOURCE_RESOURCE_ID).accept(r); | ||
}); | ||
// process operations. | ||
inputData.remove(OPERATION_RESOURCE_ID).forEach(r -> { | ||
final UUID operationId = UUID.fromString(r.get("operationId").asText()); | ||
|
||
final UUID workspaceId; | ||
final UUID connectionId = operationIdToConnectionId.get(operationId); | ||
if (connectionId == null) { | ||
workspaceId = DEFAULT_WORKSPACE_ID; | ||
} else { | ||
final UUID sourceId = connectionIdToSourceId.get(connectionId); | ||
workspaceId = sourceIdToWorkspaceId.get(sourceId); | ||
} | ||
((ObjectNode) r).put("workspaceId", workspaceId.toString()); | ||
|
||
outputData.get(OPERATION_RESOURCE_ID).accept(r); | ||
}); | ||
|
||
// process the remaining resources. | ||
for (final Map.Entry<ResourceId, Stream<JsonNode>> entry : inputData.entrySet()) { | ||
final Consumer<JsonNode> recordConsumer = outputData.get(entry.getKey()); | ||
entry.getValue().forEach(recordConsumer); | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...-migration/src/main/resources/migrations/migrationV0_28_0/airbyte_config/OperatorDbt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
"$schema": http://json-schema.org/draft-07/schema# | ||
"$id": https://github.com/airbytehq/airbyte/blob/master/airbyte-config/models/src/main/resources/types/OperatorDbt.yaml | ||
title: OperatorDbt | ||
description: Settings for a DBT operator | ||
type: object | ||
required: | ||
- gitRepoUrl | ||
additionalProperties: false | ||
properties: | ||
gitRepoUrl: | ||
type: string | ||
gitRepoBranch: | ||
type: string | ||
dockerImage: | ||
type: string | ||
dbtArguments: | ||
type: string |
13 changes: 13 additions & 0 deletions
13
.../src/main/resources/migrations/migrationV0_28_0/airbyte_config/OperatorNormalization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"$schema": http://json-schema.org/draft-07/schema# | ||
"$id": https://github.com/airbytehq/airbyte/blob/master/airbyte-config/models/src/main/resources/types/OperatorNormalization.yaml | ||
title: OperatorNormalization | ||
description: Settings for a normalization operator | ||
type: object | ||
additionalProperties: false | ||
properties: | ||
option: | ||
type: string | ||
enum: | ||
- basic | ||
#- unnesting |
10 changes: 10 additions & 0 deletions
10
...migration/src/main/resources/migrations/migrationV0_28_0/airbyte_config/OperatorType.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"$schema": http://json-schema.org/draft-07/schema# | ||
"$id": https://github.com/airbytehq/airbyte/blob/master/airbyte-config/models/src/main/resources/types/OperatorType.yaml | ||
title: OperatorType | ||
description: Type of Operator | ||
type: string | ||
enum: | ||
# - destination | ||
- normalization | ||
- dbt |
34 changes: 34 additions & 0 deletions
34
.../src/main/resources/migrations/migrationV0_28_0/airbyte_config/StandardSyncOperation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
"$schema": http://json-schema.org/draft-07/schema# | ||
"$id": https://github.com/airbytehq/airbyte/blob/master/airbyte-config/models/src/main/resources/types/StandardSyncOperation.yaml | ||
title: StandardSyncOperation | ||
description: Configuration of an operation to apply during a sync | ||
type: object | ||
required: | ||
- workspaceId | ||
- operationId | ||
- name | ||
- operatorType | ||
additionalProperties: false | ||
properties: | ||
operationId: | ||
type: string | ||
format: uuid | ||
name: | ||
type: string | ||
# Instead of this type field, we would prefer a json schema "oneOf" but unfortunately, | ||
# the jsonschema2pojo does not seem to support it yet: https://github.com/joelittlejohn/jsonschema2pojo/issues/392 | ||
operatorType: | ||
"$ref": OperatorType.yaml | ||
operatorNormalization: | ||
"$ref": OperatorNormalization.yaml | ||
operatorDbt: | ||
"$ref": OperatorDbt.yaml | ||
tombstone: | ||
description: | ||
if not set or false, the configuration is active. if true, then this | ||
configuration is permanently off. | ||
type: boolean | ||
workspaceId: | ||
type: string | ||
format: uuid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clarifying naming here. This struct was used for 2 endpoints:
operations/check
andwebackend/connections/update
(which is really an update or create. the check endpoint does not need all the fields the update endpoint needs. So i split them into 2 different structs with only the fields they need and more granular names.