diff options
author | Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com> | 2018-08-30 14:17:06 +0000 |
---|---|---|
committer | Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com> | 2018-08-30 14:17:06 +0000 |
commit | 905d8bf666e0667774bebccfabce65e3497e9c32 (patch) | |
tree | f9140a5b81ed876ead24759902ca7422eade2603 /ms/controllerblueprints/modules/service/src/main/java | |
parent | 254217ffff5edea9069f96b992a5939b3745d376 (diff) |
Controller Blueprints Microservice
Add Resource Seuencing validation and Optimise resource assignment validation logics
Change-Id: I6f31ca5dbeb6f6aa89959b7d96fbfad25468b3a4
Issue-ID: CCSDK-416
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/main/java')
4 files changed, 98 insertions, 39 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index f52137191..9c1a045cd 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
@@ -290,31 +291,29 @@ public class ConfigModelCreateService { * @return ConfigModel
* @throws BluePrintException BluePrintException
*/
- public ConfigModel publishConfigModel(Long id) throws BluePrintException {
+ public ConfigModel publishConfigModel(@NotNull Long id) throws BluePrintException {
ConfigModel dbConfigModel = null;
- if (id != null) {
- Optional<ConfigModel> dbConfigModelOptional = configModelRepository.findById(id);
- if (dbConfigModelOptional.isPresent()) {
- dbConfigModel = dbConfigModelOptional.get();
- List<ConfigModelContent> configModelContents = dbConfigModel.getConfigModelContents();
- if (configModelContents != null && !configModelContents.isEmpty()) {
- for (ConfigModelContent configModelContent : configModelContents) {
- if (configModelContent.getContentType()
- .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) {
- ServiceTemplate serviceTemplate = JacksonUtils
- .readValue(configModelContent.getContent(), ServiceTemplate.class);
- if (serviceTemplate != null) {
- validateServiceTemplate(serviceTemplate);
- }
+ Optional<ConfigModel> dbConfigModelOptional = configModelRepository.findById(id);
+ if (dbConfigModelOptional.isPresent()) {
+ dbConfigModel = dbConfigModelOptional.get();
+ List<ConfigModelContent> configModelContents = dbConfigModel.getConfigModelContents();
+ if (configModelContents != null && !configModelContents.isEmpty()) {
+ for (ConfigModelContent configModelContent : configModelContents) {
+ if (configModelContent.getContentType()
+ .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) {
+ ServiceTemplate serviceTemplate = JacksonUtils
+ .readValue(configModelContent.getContent(), ServiceTemplate.class);
+ if (serviceTemplate != null) {
+ validateServiceTemplate(serviceTemplate);
}
}
}
- dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y);
- configModelRepository.save(dbConfigModel);
- log.info("Config model ({}) published successfully.", id);
-
}
-
+ dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y);
+ configModelRepository.save(dbConfigModel);
+ log.info("Config model ({}) published successfully.", id);
+ } else {
+ throw new BluePrintException(String.format("Couldn't get Config model for id :(%s)", id));
}
return dbConfigModel;
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java new file mode 100644 index 000000000..1228e2eeb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java @@ -0,0 +1,29 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService;
+import org.springframework.stereotype.Service;
+/**
+ * ResourceAssignmentValidationService.
+ *
+ * @author Brinda Santh
+ */
+@Service
+public class ResourceAssignmentValidationService extends ResourceAssignmentValidationDefaultService {
+
+}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 70cee3c9e..3e3c8e286 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent;
import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse;
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;
@@ -45,21 +44,24 @@ public class ServiceTemplateService { private ConfigModelCreateService configModelCreateService;
private BluePrintEnhancerService bluePrintEnhancerService;
+ private ResourceAssignmentValidationService resourceAssignmentValidationService;
/**
* This is a SchemaGeneratorService constructor
*
- * @param dataDictionaryRepository dataDictionaryRepository
- * @param configModelCreateService configModelCreateService
- * @param bluePrintEnhancerService bluePrintEnhancerService
+ * @param dataDictionaryRepository dataDictionaryRepository
+ * @param configModelCreateService configModelCreateService
+ * @param bluePrintEnhancerService bluePrintEnhancerService
+ * @param resourceAssignmentValidationService resourceAssignmentValidationService
*/
public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository,
ConfigModelCreateService configModelCreateService,
- BluePrintEnhancerService bluePrintEnhancerService) {
+ BluePrintEnhancerService bluePrintEnhancerService,
+ ResourceAssignmentValidationService resourceAssignmentValidationService) {
this.dataDictionaryRepository = dataDictionaryRepository;
this.configModelCreateService = configModelCreateService;
this.bluePrintEnhancerService = bluePrintEnhancerService;
-
+ this.resourceAssignmentValidationService = resourceAssignmentValidationService;
}
/**
@@ -105,13 +107,7 @@ public class ServiceTemplateService { */
public List<ResourceAssignment> validateResourceAssignments(List<ResourceAssignment> resourceAssignments)
throws BluePrintException {
- try {
- ResourceAssignmentValidator resourceAssignmentValidator =
- new ResourceAssignmentValidator(resourceAssignments);
- resourceAssignmentValidator.validateResourceAssignment();
- } catch (BluePrintException e) {
- throw new BluePrintException(e.getMessage(), e);
- }
+ resourceAssignmentValidationService.validate(resourceAssignments);
return resourceAssignments;
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java index 848a32f5b..42adf1a3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java @@ -17,16 +17,23 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator;
import com.google.common.base.Preconditions;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
+import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment;
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -62,7 +69,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /**
* This is a validateServiceTemplate
*
- * @param serviceTemplate
+ * @param serviceTemplate serviceTemplate
* @return boolean
* @throws BluePrintException BluePrintException
*/
@@ -76,7 +83,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /**
* This is a getMetaData to get the key information during the
*
- * @return Map<String, String>
+ * @return Map<String , String>
*/
public Map<String, String> getMetaData() {
return metaData;
@@ -104,9 +111,37 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
throws BluePrintException {
String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();
- if ("tosca.nodes.Artifact".equals(derivedFrom)) {
- ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate);
- resourceAssignmentValidator.validateResourceAssignment();
+
+ if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) {
+ List<ResourceAssignment> resourceAssignment = getResourceAssignments(nodeTemplate);
+ ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationDefaultService();
+ resourceAssignmentValidationService.validate(resourceAssignment);
+ }
+ }
+
+ private List<ResourceAssignment> getResourceAssignments(@NotNull NodeTemplate nodeTemplate) {
+
+ List<ResourceAssignment> resourceAssignment = null;
+
+ if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {
+
+ CapabilityAssignment capabilityAssignment =
+ nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
+ if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {
+ Object mappingObject =
+ capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
+ if (mappingObject != null) {
+ String mappingContent = JacksonUtils.getJson(mappingObject);
+ Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent),
+ String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));
+
+ resourceAssignment = JacksonUtils.getListFromJson(mappingContent, ResourceAssignment.class);
+
+ Preconditions.checkNotNull(resourceAssignment,
+ String.format("Failed to get resource assignment info from the content (%s) ", mappingContent));
+ }
+ }
}
+ return resourceAssignment;
}
}
|