You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by bo...@apache.org on 2023/10/20 14:15:26 UTC
[streampipes] 06/09: feat: implement data model for migration
This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch 2045-implement-migration-for-adapter-and-pipeline-element-configurations
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 0792a0112ce6a01d6fee9e79f135b5ddb545e564
Author: bossenti <bo...@posteo.de>
AuthorDate: Fri Oct 20 15:41:45 2023 +0200
feat: implement data model for migration
---
.../extensions/api/migration/AdapterMigrator.java | 25 ++++++++++++++
.../api/migration/DataProcessorMigrator.java | 27 +++++++++++++++
.../extensions/api/migration/DataSinkMigrator.java | 25 ++++++++++++++
.../extensions/api/migration/MigrationResult.java | 38 ++++++++++++++++++++++
.../extensions/api/migration/ModelMigrator.java | 38 ++++++++++++++++++++++
.../migration/AdapterMigrationRequest.java | 30 +++++++++++++++++
.../model/migration/ModelMigratorConfig.java | 33 +++++++++++++++++++
7 files changed, 216 insertions(+)
diff --git a/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/AdapterMigrator.java b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/AdapterMigrator.java
new file mode 100644
index 000000000..33c3d1920
--- /dev/null
+++ b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/AdapterMigrator.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.extensions.api.migration;
+
+import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
+import org.apache.streampipes.model.connect.adapter.AdapterDescription;
+
+public interface AdapterMigrator extends ModelMigrator<AdapterDescription, IStaticPropertyExtractor> {
+}
diff --git a/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/DataProcessorMigrator.java b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/DataProcessorMigrator.java
new file mode 100644
index 000000000..2c395ef86
--- /dev/null
+++ b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/DataProcessorMigrator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.extensions.api.migration;
+
+import org.apache.streampipes.extensions.api.extractor.IDataProcessorParameterExtractor;
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+
+public interface DataProcessorMigrator
+ extends ModelMigrator<DataProcessorInvocation, IDataProcessorParameterExtractor> {
+
+}
diff --git a/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/DataSinkMigrator.java b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/DataSinkMigrator.java
new file mode 100644
index 000000000..dafee59c4
--- /dev/null
+++ b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/DataSinkMigrator.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.extensions.api.migration;
+
+import org.apache.streampipes.extensions.api.extractor.IDataSinkParameterExtractor;
+import org.apache.streampipes.model.graph.DataSinkInvocation;
+
+public interface DataSinkMigrator extends ModelMigrator<DataSinkInvocation, IDataSinkParameterExtractor> {
+}
diff --git a/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/MigrationResult.java b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/MigrationResult.java
new file mode 100644
index 000000000..bb18c9567
--- /dev/null
+++ b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/MigrationResult.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.extensions.api.migration;
+
+import org.apache.streampipes.model.Notification;
+
+import java.util.List;
+
+public record MigrationResult<T> (boolean success, T element, List<Notification> messages){
+
+ public static <T> MigrationResult<T> failure(T element, List<Notification> messages) {
+ return new MigrationResult<>(false, element, messages);
+ }
+
+ public static <T> MigrationResult<T> failure(T element, Notification message) {
+ return failure(element, List.of(message));
+ }
+
+ public static <T> MigrationResult<T> success(T element) {
+ return new MigrationResult<>(true, element, List.of());
+ }
+}
diff --git a/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/ModelMigrator.java b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/ModelMigrator.java
new file mode 100644
index 000000000..d734cdfd8
--- /dev/null
+++ b/streampipes-extensions-api/src/main/java/org/apache/streampipes/extensions/api/migration/ModelMigrator.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.extensions.api.migration;
+
+import org.apache.streampipes.extensions.api.extractor.IParameterExtractor;
+import org.apache.streampipes.model.base.NamedStreamPipesEntity;
+import org.apache.streampipes.model.migration.ModelMigratorConfig;
+
+public interface ModelMigrator<T extends NamedStreamPipesEntity, ExT extends IParameterExtractor<?>> {
+
+ ModelMigratorConfig config();
+
+ /**
+ * Defines the migration to be performed.
+ * @param element Entity to be transformed.
+ * @param extractor Extractor that allows to handle static properties.
+ * @return Result of the migration that describes both outcomes: successful and failed migrations
+ * @throws RuntimeException in case any unexpected error occurs
+ */
+ MigrationResult<T> migrate(T element, ExT extractor) throws RuntimeException;
+
+}
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/extensions/migration/AdapterMigrationRequest.java b/streampipes-model/src/main/java/org/apache/streampipes/model/extensions/migration/AdapterMigrationRequest.java
new file mode 100644
index 000000000..4b372a9e2
--- /dev/null
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/extensions/migration/AdapterMigrationRequest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.model.extensions.migration;
+
+import org.apache.streampipes.model.connect.adapter.AdapterDescription;
+import org.apache.streampipes.model.migration.ModelMigratorConfig;
+
+/**
+ * Models a request that is sent from the core to an extensions service to mandate an adapter migration.
+ * @param adapterDescription adapter to be migrated
+ * @param modelMigratorConfig migration config that describes the migration to be applied to the adapter.
+ */
+public record AdapterMigrationRequest(AdapterDescription adapterDescription, ModelMigratorConfig modelMigratorConfig) {
+}
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/migration/ModelMigratorConfig.java b/streampipes-model/src/main/java/org/apache/streampipes/model/migration/ModelMigratorConfig.java
new file mode 100644
index 000000000..d667b1a99
--- /dev/null
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/migration/ModelMigratorConfig.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.streampipes.model.migration;
+
+import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix;
+
+/**
+ * The configuration element for a 'ModelMigrator'.
+ *
+ * @param targetAppId 'appId' of the model to be migrated
+ * @param modelType Type of the model to be migrated, e.g., adapter
+ * @param fromVersion Base version from which the migration starts
+ * @param toVersion Target version that the migration aims to achieve
+ */
+public record ModelMigratorConfig(String targetAppId, SpServiceTagPrefix modelType,
+ Integer fromVersion, Integer toVersion) {
+}