2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service.validator;
\r
19 import com.google.common.base.Preconditions;
\r
20 import org.apache.commons.lang3.StringUtils;
\r
21 import org.jetbrains.annotations.NotNull;
\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;
\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
\r
28 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator;
\r
30 import java.util.HashMap;
\r
31 import java.util.Map;
\r
34 * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator
\r
36 * @author Brinda Santh
\r
40 public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
\r
42 StringBuilder message = new StringBuilder();
\r
43 private Map<String, String> metaData = new HashMap();
\r
46 * This is a validateServiceTemplate
\r
48 * @param serviceTemplateContent
\r
50 * @throws BluePrintException
\r
52 public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException {
\r
53 if (StringUtils.isNotBlank(serviceTemplateContent)) {
\r
54 ServiceTemplate serviceTemplate =
\r
55 JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class);
\r
56 return validateServiceTemplate(serviceTemplate);
\r
58 throw new BluePrintException(
\r
59 "Service Template Content is (" + serviceTemplateContent + ") not Defined.");
\r
64 * This is a validateServiceTemplate
\r
66 * @param serviceTemplate
\r
68 * @throws BluePrintException
\r
70 @SuppressWarnings("squid:S00112")
\r
71 public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {
\r
72 Map<String, Object> properties = new HashMap<>();
\r
73 super.validateBlueprint(serviceTemplate, properties);
\r
78 * This is a getMetaData to get the key information during the
\r
80 * @return Map<String ,
\r
83 public Map<String, String> getMetaData() {
\r
88 public void validateMetadata(@NotNull Map<String, String> metaDataMap) throws BluePrintException {
\r
90 Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing.");
\r
92 this.metaData.putAll(serviceTemplate.getMetadata());
\r
94 String author = serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR);
\r
95 String serviceTemplateName =
\r
96 serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME);
\r
97 String serviceTemplateVersion =
\r
98 serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION);
\r
100 Preconditions.checkArgument(StringUtils.isNotBlank(author), "Template Metadata (author) Information is missing.");
\r
101 Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateName), "Template Metadata (service-template-name) Information is missing.");
\r
102 Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateVersion), "Template Metadata (service-template-version) Information is missing.");
\r
107 public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
\r
108 throws BluePrintException {
\r
109 super.validateNodeTemplate(nodeTemplateName, nodeTemplate);
\r
110 validateNodeTemplateCustom(nodeTemplateName, nodeTemplate);
\r
115 private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
\r
116 throws BluePrintException {
\r
117 String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();
\r
118 if ("tosca.nodes.Artifact".equals(derivedFrom)) {
\r
119 ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate);
\r
120 resourceAssignmentValidator.validateResourceAssignment();
\r