From 948114a77bcf55433191e31de8f0612f55b01612 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 27 Feb 2019 20:16:47 -0500 Subject: Add blueprint runtime validator Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh --- .../validator/ResourceDictionaryValidator.java | 60 --------- .../validator/ServiceTemplateValidator.java | 147 --------------------- 2 files changed, 207 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java deleted file mode 100644 index 57330d90..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java +++ /dev/null @@ -1,60 +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.validator; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; - -/** - * ResourceDictionaryValidator.java Purpose: Provide Validation Service for Model Type Resource - * Dictionary Validator - * - * @author Brinda Santh - * @version 1.0 - */ -public class ResourceDictionaryValidator { - - private ResourceDictionaryValidator() {} - - /** - * This is a validateResourceDictionary method - * - * @param resourceDictionary - * @return boolean - * - */ - public static boolean validateResourceDictionary(ResourceDictionary resourceDictionary) { - - Preconditions.checkNotNull(resourceDictionary,"ResourceDictionary Information is missing." ); - - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()), - "DataDictionary Alias Name Information is missing."); - Preconditions.checkNotNull( resourceDictionary.getDefinition(), - "DataDictionary Definition Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()), - "DataDictionary Description Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getTags()), - "DataDictionary Tags Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getUpdatedBy()), - "DataDictionary Updated By Information is missing."); - return true; - - } - -} 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 deleted file mode 100644 index 5d15e087..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.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.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator - * - * @author Brinda Santh - * @version 1.0 - */ - -public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { - - StringBuilder message = new StringBuilder(); - private Map metaData = new HashMap<>(); - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplateContent serviceTemplateContent - * @return boolean - * @throws BluePrintException BluePrintException - */ - public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { - if (StringUtils.isNotBlank(serviceTemplateContent)) { - ServiceTemplate serviceTemplate = - JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class); - return validateServiceTemplate(serviceTemplate); - } else { - throw new BluePrintException( - "Service Template Content is (" + serviceTemplateContent + ") not Defined."); - } - } - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplate serviceTemplate - * @return boolean - * @throws BluePrintException BluePrintException - */ - @SuppressWarnings("squid:S00112") - public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - Map properties = new HashMap<>(); - super.validateBlueprint(serviceTemplate, properties); - return true; - } - - /** - * This is a getMetaData to get the key information during the - * - * @return Map - */ - public Map getMetaData() { - return metaData; - } - - @Override - public void validateMetadata(@NotNull Map metaDataMap) throws BluePrintException { - - Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing."); - super.validateMetadata(metaDataMap); - - this.metaData.putAll(serviceTemplate.getMetadata()); - } - - - @Override - public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) - throws BluePrintException { - super.validateNodeTemplate(nodeTemplateName, nodeTemplate); - validateNodeTemplateCustom(nodeTemplateName, nodeTemplate); - - } - - @Deprecated() - private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) - throws BluePrintException { - String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom(); - - if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) { - List resourceAssignment = getResourceAssignments(nodeTemplate); - ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl(); - resourceAssignmentValidationService.validate(resourceAssignment); - } - } - - private List getResourceAssignments(@NotNull NodeTemplate nodeTemplate) { - - List 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.Companion.getJson(mappingObject); - Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent), - String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); - - resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class); - - Preconditions.checkNotNull(resourceAssignment, - String.format("Failed to get resource assignment info from the content (%s) ", mappingContent)); - } - } - } - return resourceAssignment; - } -} -- cgit 1.2.3-korg