From 5eebfaa6ac0d4cb4fdf20d19ead7cd0303fc6f29 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Sep 2018 00:20:34 +0000 Subject: Controller Blueprints Microservice Add resource assignment enhancement and validation to blueprint validation and enhancement. Change-Id: I547760012e7014cfbb7a1e3a1d8ffb77edc9b6a2 Issue-ID: CCSDK-562 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 23 +++-- .../service/BluePrintRepoDBService.java | 97 ----------------- .../service/ResourceDefinitionRepoDBService.java | 115 +++++++++++++++++++++ 3 files changed, 129 insertions(+), 106 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java/org') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java index 8e98f947..ef3b4a48 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java @@ -25,12 +25,13 @@ import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.*; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -48,14 +49,18 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); + private ResourceAssignmentEnhancerService resourceAssignmentEnhancerService; + private Map recipeDataTypes = new HashMap<>(); - public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) { - super(bluePrintEnhancerRepoDBService); + public BluePrintEnhancerService(ResourceDefinitionRepoService resourceDefinitionRepoService, + ResourceAssignmentEnhancerService resourceAssignmentEnhancerService) { + super(resourceDefinitionRepoService); + this.resourceAssignmentEnhancerService = resourceAssignmentEnhancerService; } @Override - public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException{ + public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException { super.enrichTopologyTemplate(serviceTemplate); // Update the Recipe Inputs and DataTypes @@ -101,7 +106,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { // Modified for ONAP converted Object to JsonNode JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES); - log.info("Processing Receipe Names : {} ", recipeNames); + log.info("Processing Recipe Names : {} ", recipeNames); if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) { @@ -159,6 +164,9 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); + // Enhance Resource Assignment + resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); + dataTypeProperties = new HashMap<>(); for (ResourceAssignment resourceAssignment : resourceAssignments) { @@ -167,9 +175,6 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { && resourceAssignment.getProperty() != null && StringUtils.isNotBlank(resourceAssignment.getName())) { - // Enrich the Property Definition - super.enrichPropertyDefinition(resourceAssignment.getName(), resourceAssignment.getProperty()); - dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty()); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java deleted file mode 100644 index 5510e480..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.onap.ccsdk.apps.controllerblueprints.service; - -import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.*; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -import java.util.Optional; - -/** - * BluePrintRepoDBService - * - * @author Brinda Santh - */ -@Service -@SuppressWarnings("unused") -public class BluePrintRepoDBService implements BluePrintRepoService { - - private ModelTypeRepository modelTypeRepository; - @SuppressWarnings("unused") - public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { - this.modelTypeRepository = modelTypeRepository; - } - - @Override - public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { - return getModelType(nodeTypeName, NodeType.class); - } - - @Override - public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { - return getModelType(dataTypeName, DataType.class); - } - - @Override - public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { - return getModelType(artifactTypeName, ArtifactType.class); - } - - @Override - public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { - return getModelType(relationshipTypeName, RelationshipType.class); - } - - @Override - public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { - return getModelType(capabilityDefinitionName, CapabilityDefinition.class); - } - - private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing"); - - return getModelDefinition(modelName).map(modelDefinition -> { - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(modelDefinition, valueClass); - } - ); - } - - private Mono getModelDefinition(String modelName) throws BluePrintException { - JsonNode modelDefinition; - Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); - if (modelTypeDb.isPresent()) { - modelDefinition = modelTypeDb.get().getDefinition(); - } else { - throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); - } - return Mono.just(modelDefinition); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java new file mode 100644 index 00000000..16cc8415 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java @@ -0,0 +1,115 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.onap.ccsdk.apps.controllerblueprints.service; + +import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.*; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.Optional; + +/** + * ResourceDefinitionRepoDBService + * + * @author Brinda Santh + */ +@Service +@SuppressWarnings("unused") +public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoService { + + private ModelTypeRepository modelTypeRepository; + private ResourceDictionaryRepository resourceDictionaryRepository; + + @SuppressWarnings("unused") + public ResourceDefinitionRepoDBService(ModelTypeRepository modelTypeRepository, + ResourceDictionaryRepository resourceDictionaryRepository) { + this.modelTypeRepository = modelTypeRepository; + this.resourceDictionaryRepository = resourceDictionaryRepository; + } + + @Override + public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { + return getModelType(nodeTypeName, NodeType.class); + } + + @Override + public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { + return getModelType(dataTypeName, DataType.class); + } + + @Override + public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { + return getModelType(artifactTypeName, ArtifactType.class); + } + + @Override + public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { + return getModelType(relationshipTypeName, RelationshipType.class); + } + + @Override + public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { + return getModelType(capabilityDefinitionName, CapabilityDefinition.class); + } + + @NotNull + @Override + public Mono getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException{ + Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); + if(dbResourceDictionary.isPresent()){ + return Mono.just(dbResourceDictionary.get().getDefinition()); + }else{ + throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); + } + } + + private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing"); + + return getModelDefinition(modelName).map(modelDefinition -> { + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)); + return JacksonUtils.readValue(modelDefinition, valueClass); + } + ); + } + + private Mono getModelDefinition(String modelName) throws BluePrintException { + JsonNode modelDefinition; + Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); + if (modelTypeDb.isPresent()) { + modelDefinition = modelTypeDb.get().getDefinition(); + } else { + throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); + } + return Mono.just(modelDefinition); + } +} -- cgit 1.2.3-korg