diff options
author | andre.schmid <andre.schmid@est.tech> | 2020-05-13 19:11:38 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-06-01 06:38:17 +0000 |
commit | 1e9c8c5f47a707dc8ea1d7cff7ef39b91462b137 (patch) | |
tree | af756321160cc221b66b5819841cb5160e14c262 /catalog-be/src/main/java/org | |
parent | 6fc8a352e6b0d32bf166c0547d5fe9d1507917e7 (diff) |
Plugin to customize prop. during Service creation
Creates an entry point to customize properties of a Service
Component before its creation.
Change-Id: I102a70b37eec498dd9c6df009c38da57d0e5b17f
Issue-ID: SDC-3062
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java | 27 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/plugins/ServiceCreationPlugin.java | 43 |
2 files changed, 67 insertions, 3 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index bd29e9ab81..bdcc67c744 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -27,6 +27,7 @@ import com.google.common.base.Strings; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import fj.data.Either; +import java.util.Comparator; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.ListUtils; @@ -115,6 +116,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils; +import org.openecomp.sdc.be.plugins.ServiceCreationPlugin; import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; import org.openecomp.sdc.be.resources.data.ComponentInstanceData; import org.openecomp.sdc.be.resources.data.ComponentMetadataData; @@ -198,6 +200,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { private final NodeFilterValidator serviceFilterValidator; private ServiceTypeValidator serviceTypeValidator; + private List<ServiceCreationPlugin> serviceCreationPluginList; @Autowired public void setServiceTypeValidator(ServiceTypeValidator serviceTypeValidator) { @@ -887,6 +890,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { createServiceApiArtifactsData(service, user); setToscaArtifactsPlaceHolders(service, user); generateAndAddInputsFromGenericTypeProperties(service, fetchAndSetDerivedFromGenericType(service)); + beforeCreate(service); Either<Service, StorageOperationStatus> dataModelResponse = toscaOperationFacade.createToscaComponent(service); @@ -909,6 +913,22 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } } + private void beforeCreate(final Service service) { + if (CollectionUtils.isEmpty(serviceCreationPluginList)) { + return; + } + serviceCreationPluginList.stream() + .sorted(Comparator.comparingInt(ServiceCreationPlugin::getOrder)) + .forEach(serviceCreationPlugin -> { + try { + serviceCreationPlugin.beforeCreate(service); + } catch (final Exception e) { + log.error("An error has occurred while running the serviceCreationPlugin '{}'", + serviceCreationPlugin.getClass(), e); + } + }); + } + @SuppressWarnings("unchecked") private void createServiceApiArtifactsData(Service service, User user) { // create mandatory artifacts @@ -2735,7 +2755,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { return Either.left(serviceFilterResult); } - - - + @Autowired(required = false) + public void setServiceCreationPluginList(List<ServiceCreationPlugin> serviceCreationPluginList) { + this.serviceCreationPluginList = serviceCreationPluginList; + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/plugins/ServiceCreationPlugin.java b/catalog-be/src/main/java/org/openecomp/sdc/be/plugins/ServiceCreationPlugin.java new file mode 100644 index 0000000000..4981a33d26 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/plugins/ServiceCreationPlugin.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.plugins; + +import org.openecomp.sdc.be.model.Service; + +/** + * Plugin to the Service Component creation logic + */ +public interface ServiceCreationPlugin { + + /** + * This method is called before the creation of the Service. + * + * @param service the service that is being created + */ + void beforeCreate(final Service service); + + /** + * Defines the order of execution of the plugin. + * + * @return a order + */ + int getOrder(); + +} |