From 6a1da8dca4a1991cd4be4088889cc1705bae8b63 Mon Sep 17 00:00:00 2001 From: Tim <50115603+bossenti@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:57:47 +0200 Subject: [PATCH] refactor: replace `StorageManager` by `StorageDispatcher` (#2766) * refactor: replace `StorageManager` by `StorageDispatcher` * style: fix too long line * fix: adapt indentation --- .../recommender/ElementRecommender.java | 3 +- .../manager/template/PipelineGenerator.java | 9 ++-- .../template/PipelineTemplateGenerator.java | 7 ++- .../manager/verification/ElementVerifier.java | 46 +++++++++++-------- .../rest/impl/PipelineElementCategory.java | 6 ++- .../storage/management/StorageManager.java | 33 ------------- 6 files changed, 38 insertions(+), 66 deletions(-) delete mode 100644 streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/recommender/ElementRecommender.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/recommender/ElementRecommender.java index 92edbee27c..6cb0911b27 100644 --- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/recommender/ElementRecommender.java +++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/recommender/ElementRecommender.java @@ -36,7 +36,6 @@ import org.apache.streampipes.storage.api.INoSqlStorage; import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorage; import org.apache.streampipes.storage.management.StorageDispatcher; -import org.apache.streampipes.storage.management.StorageManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,7 +184,7 @@ private List getAll() { } private IPipelineElementDescriptionStorage getTripleStore() { - return StorageManager.INSTANCE.getPipelineElementStorage(); + return StorageDispatcher.INSTANCE.getNoSqlStore().getPipelineElementDescriptionStorage(); } private INoSqlStorage getNoSqlStorage() { diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineGenerator.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineGenerator.java index 19cec5d904..134e37a1d2 100644 --- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineGenerator.java +++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineGenerator.java @@ -27,7 +27,7 @@ import org.apache.streampipes.model.pipeline.PipelineModification; import org.apache.streampipes.model.template.BoundPipelineElement; import org.apache.streampipes.model.template.PipelineTemplateDescription; -import org.apache.streampipes.storage.management.StorageManager; +import org.apache.streampipes.storage.management.StorageDispatcher; import java.util.ArrayList; import java.util.Collections; @@ -126,10 +126,9 @@ private InvocableStreamPipesEntity clonePe(InvocableStreamPipesEntity pipelineEl } private SpDataStream getStream(String datasetId) { - return StorageManager - .INSTANCE - .getPipelineElementStorage() - .getEventStreamById(datasetId); + return StorageDispatcher.INSTANCE.getNoSqlStore() + .getPipelineElementDescriptionStorage() + .getEventStreamById(datasetId); } diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineTemplateGenerator.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineTemplateGenerator.java index 235e1b7e18..4531fc88f2 100644 --- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineTemplateGenerator.java +++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineTemplateGenerator.java @@ -29,7 +29,7 @@ import org.apache.streampipes.model.graph.DataSinkInvocation; import org.apache.streampipes.model.template.PipelineTemplateDescription; import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorage; -import org.apache.streampipes.storage.management.StorageManager; +import org.apache.streampipes.storage.management.StorageDispatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -131,8 +131,7 @@ protected DataSinkDescription getSink(String id) throws ElementNotFoundException } protected IPipelineElementDescriptionStorage getStorage() { - return StorageManager - .INSTANCE - .getPipelineElementStorage(); + return StorageDispatcher.INSTANCE.getNoSqlStore() + .getPipelineElementDescriptionStorage(); } } diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/verification/ElementVerifier.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/verification/ElementVerifier.java index 2537057698..797a40bf40 100644 --- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/verification/ElementVerifier.java +++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/verification/ElementVerifier.java @@ -36,30 +36,29 @@ import org.apache.streampipes.resource.management.SpResourceManager; import org.apache.streampipes.serializers.json.JacksonSerializer; import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorage; -import org.apache.streampipes.storage.management.StorageManager; +import org.apache.streampipes.storage.management.StorageDispatcher; import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; public abstract class ElementVerifier { - protected static final Logger LOGGER = Logger.getAnonymousLogger(); - private String graphData; private Class elementClass; - private boolean shouldTransform; + private final boolean shouldTransform; protected T elementDescription; protected List validationResults; protected List validators; - protected IPipelineElementDescriptionStorage storageApi = - StorageManager.INSTANCE.getPipelineElementStorage(); + protected IPipelineElementDescriptionStorage storageApi = StorageDispatcher + .INSTANCE + .getNoSqlStore() + .getPipelineElementDescriptionStorage(); public ElementVerifier(String graphData, Class elementClass) { this.elementClass = elementClass; @@ -119,7 +118,7 @@ public Message verifyAndAdd(String principalSid, boolean publicElement) throws S } - public Message verifyAndUpdate() throws SepaParseException { + public Message verifyAndUpdate() { try { this.elementDescription = transform(); } catch (JsonProcessingException e) { @@ -178,15 +177,19 @@ private List collectNotifications() { } private boolean isVerifiedSuccessfully() { - return validationResults.stream().noneMatch(validator -> (validator instanceof VerificationError)); + return validationResults.stream() + .noneMatch(validator -> (validator instanceof VerificationError)); } protected T transform() throws JsonProcessingException { - return JacksonSerializer.getObjectMapper().readValue(graphData, elementClass); + return JacksonSerializer.getObjectMapper() + .readValue(graphData, elementClass); } - private void createAndStorePermission(String principalSid, - boolean publicElement) { + private void createAndStorePermission( + String principalSid, + boolean publicElement + ) { Permission permission = makePermission( this.elementDescription.getElementId(), this.elementDescription.getClass(), @@ -196,17 +199,20 @@ private void createAndStorePermission(String principalSid, storeNewObjectPermission(permission); } - protected Permission makePermission(String objectInstanceId, - Class objectInstanceClass, - String principalSid, - boolean publicElement) { + protected Permission makePermission( + String objectInstanceId, + Class objectInstanceClass, + String principalSid, + boolean publicElement + ) { return PermissionBuilder - .create(objectInstanceId, objectInstanceClass, principalSid) - .publicElement(publicElement) - .build(); + .create(objectInstanceId, objectInstanceClass, principalSid) + .publicElement(publicElement) + .build(); } protected void storeNewObjectPermission(Permission permission) { - new SpResourceManager().managePermissions().create(permission); + new SpResourceManager().managePermissions() + .create(permission); } } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementCategory.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementCategory.java index 1b73e6fe93..9e1957e4a8 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementCategory.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementCategory.java @@ -24,7 +24,7 @@ import org.apache.streampipes.model.SpDataStream; import org.apache.streampipes.model.client.Category; import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource; -import org.apache.streampipes.storage.management.StorageManager; +import org.apache.streampipes.storage.management.StorageDispatcher; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -41,7 +41,9 @@ public class PipelineElementCategory extends AbstractAuthGuardedRestResource { @GetMapping(path = "/ep", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getEps() { - return ok(makeCategories(StorageManager.INSTANCE.getPipelineElementStorage().getAllDataStreams())); + return ok(makeCategories(StorageDispatcher.INSTANCE.getNoSqlStore() + .getPipelineElementDescriptionStorage() + .getAllDataStreams())); } @GetMapping(path = "/epa", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java b/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java deleted file mode 100644 index 01e9a58117..0000000000 --- a/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.storage.management; - -import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorage; -import org.apache.streampipes.storage.couchdb.CouchDbStorageManager; - -public enum StorageManager { - - INSTANCE; - - public IPipelineElementDescriptionStorage getPipelineElementStorage() { - return CouchDbStorageManager.INSTANCE.getPipelineElementDescriptionStorage(); - } - - -}