-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat(TCOMP-2475): Migration from higher version not protected for a connector #898
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
17c96b9
feat(TCOMP-2475): default undefined version to 1
undx 815c638
Merge branch 'master' into undx/TCOMP-2475-migration-prot
acatoire 8951b1a
Merge branch 'master' into undx/TCOMP-2475-migration-prot
acatoire bd91528
feat(TCOMP-2475): Improve API test
acatoire 46c6681
feat(TCOMP-2475): restore previous state (-1) for reproducing
undx 7ec3403
feat(TCOMP-2475): add logging
undx 7e28e01
feat(TCOMP-2475): add migration tests case environment (draft)
undx 1f6ce38
feat(TCOMP-2475): add logging informations
undx 77ccbfd
feat(TCOMP-2475): default undefined version to 1
undx 119fe7b
feat(TCOMP-2475): sonar comment
undx 320d449
feat(TCOMP-2475): skip migration from upper version
undx cc61774
feat(TCOMP-2475): adapt component migration test
undx 987393a
feat(TCOMP-2475): adapt old component migration test
undx 1d7aed5
feat(TCOMP-2475): chore format
undx 08d60de
feat(TCOMP-2475): restore initial defaults
undx da0f96a
feat(TCOMP-2475): remove reverted pr test
undx 4c91f86
Merge branch 'master' into undx/TCOMP-2475-migration-prot
undx 316b039
feat(TCOMP-2475): Deactivate equal API test
acatoire af785a1
Merge branch 'master' into undx/TCOMP-2475-migration-prot
acatoire 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
183 changes: 183 additions & 0 deletions
183
...t/component-server/src/test/java/org/talend/sdk/component/server/front/MigrationTest.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,183 @@ | ||
/** | ||
* Copyright (C) 2006-2024 Talend Inc. - www.talend.com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.talend.sdk.component.server.front; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
|
||
import org.apache.meecrowave.junit5.MonoMeecrowaveConfig; | ||
import org.junit.jupiter.api.Test; | ||
import org.talend.sdk.component.server.front.model.ConfigTypeNodes; | ||
import org.talend.sdk.component.server.test.ComponentClient; | ||
import org.talend.sdk.component.server.test.migration.MigrationDataSet; | ||
import org.talend.sdk.component.server.test.migration.MigrationDataStore; | ||
import org.talend.sdk.component.server.test.migration.MigrationInput; | ||
|
||
@MonoMeecrowaveConfig | ||
class MigrationTest { | ||
|
||
@Inject | ||
private ComponentClient client; | ||
|
||
@Inject | ||
private WebTarget base; | ||
|
||
private final String dataStoreId = "bWlncmF0aW9uLWNvbXBvbmVudCNtaWdyYXRpb24jZGF0YXN0b3JlI2RhdGFzdG9yZQ"; | ||
|
||
private final String dataSetId = "bWlncmF0aW9uLWNvbXBvbmVudCNtaWdyYXRpb24jZGF0YXNldCNkYXRhc2V0"; | ||
|
||
/** | ||
* component tests | ||
* registry version: 5 | ||
*/ | ||
@Test | ||
void migrateComponentLower() { | ||
final int incomingVersion = 3; | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.inputKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateComponent(getInputComponentId(), incomingVersion, conf); | ||
assertEquals("INPUT", migrated.get("level")); | ||
assertEquals(String.valueOf(MigrationInput.Version), migrated.get("currentVersion")); | ||
assertEquals(String.valueOf(incomingVersion), migrated.get("incomingVersion")); | ||
} | ||
|
||
@Test | ||
void migrateComponentEqual() { | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.inputKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateComponent(getInputComponentId(), MigrationInput.Version, conf); | ||
assertEquals("INPUT", migrated.get("level")); | ||
assertEquals(String.valueOf(MigrationInput.Version), migrated.get("currentVersion")); | ||
assertEquals(String.valueOf(MigrationInput.Version), migrated.get("incomingVersion")); | ||
} | ||
|
||
@Test | ||
void migrateComponentGreater() { | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.inputKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateComponent(getInputComponentId(), 6, conf); | ||
assertEquals(conf, migrated); | ||
} | ||
|
||
/** | ||
* dataset tests | ||
* registry version: undefined. | ||
*/ | ||
@Test | ||
void migrateDataSetLower() { | ||
final int incomingVersion = -1; | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.dataSetKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateConfigurationType(getDataSetID(), incomingVersion, conf); | ||
assertEquals("DATASET", migrated.get("configuration.level")); | ||
assertEquals(String.valueOf(MigrationDataSet.Version), migrated.get("configuration.currentVersion")); | ||
assertEquals(String.valueOf(incomingVersion), migrated.get("configuration.incomingVersion")); | ||
} | ||
|
||
@Test | ||
void migrateDataSetEqual() { | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.dataSetKey", "keylevel0"); | ||
// Version value not set defaults to 1 | ||
final Map<String, String> migrated = migrateConfigurationType(getDataSetID(), 1, conf); | ||
assertEquals(conf, migrated); | ||
} | ||
|
||
@Test | ||
void migrateDataSetGreater() { | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.dataSetKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateConfigurationType(getDataSetID(), 3, conf); | ||
assertEquals(conf, migrated); | ||
} | ||
|
||
/** | ||
* datastore tests | ||
* registry version: 2 | ||
*/ | ||
@Test | ||
void migrateDataStoreLower() { | ||
final int incomingVersion = 1; | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.dataStoreKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateConfigurationType(getDataStoreID(), incomingVersion, conf); | ||
assertEquals("DATASTORE", migrated.get("configuration.level")); | ||
assertEquals(String.valueOf(MigrationDataStore.Version), migrated.get("configuration.currentVersion")); | ||
assertEquals(String.valueOf(incomingVersion), migrated.get("configuration.incomingVersion")); | ||
} | ||
|
||
@Test | ||
void migrateDataStoreEqual() { | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.dataStoreKey", "keylevel0"); | ||
final Map<String, String> migrated = | ||
migrateConfigurationType(getDataStoreID(), MigrationDataStore.Version, conf); | ||
assertEquals(conf, migrated); | ||
} | ||
|
||
@Test | ||
void migrateDataStoreGreater() { | ||
Map<String, String> conf = new HashMap<>(); | ||
conf.put("configuration.dataStoreKey", "keylevel0"); | ||
final Map<String, String> migrated = migrateConfigurationType(getDataStoreID(), 3, conf); | ||
assertEquals(conf, migrated); | ||
} | ||
|
||
/** | ||
* end tests | ||
*/ | ||
|
||
private Map<String, String> migrateComponent(final String component, final int version, | ||
final Map<String, String> config) { | ||
return callMigrate("component", component, version, config); | ||
} | ||
|
||
private Map<String, String> migrateConfigurationType(final String configuration, final int version, | ||
final Map<String, String> config) { | ||
return callMigrate("configurationtype", configuration, version, config); | ||
} | ||
|
||
private Map<String, String> callMigrate(final String endpoint, final String id, final int version, | ||
final Map<String, String> config) { | ||
return base | ||
.path(String.format("/%s/migrate/%s/%d", endpoint, id, version)) | ||
.request(APPLICATION_JSON_TYPE) | ||
.post(Entity.entity(config, APPLICATION_JSON_TYPE)) | ||
.readEntity(Map.class); | ||
} | ||
|
||
private String getInputComponentId() { | ||
return client.getComponentId("migration", "Input"); | ||
} | ||
|
||
private String getDataSetID() { | ||
ConfigTypeNodes index = client.fetchConfigTypeNodes(); | ||
return index.getNodes().get(dataSetId).getId(); | ||
} | ||
|
||
private String getDataStoreID() { | ||
ConfigTypeNodes index = client.fetchConfigTypeNodes(); | ||
return index.getNodes().get(dataStoreId).getId(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
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.
Why not >=?
If the config version == the version, we shouldn't migrate it, right?
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.
Why do we call migration if versions ==
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.
There's a comment on jira issue concerning studio's migration handling.
Migration fails in that case and the job cannot be opened.
Same behavior observed in slack topic before the revert.
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.
Oh my...
Okay