From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../validation/datatypes/AttHeatResourceTypes.java | 53 +++++++++++++++++++ .../datatypes/AttLoggerErrorDescription.java | 9 ++++ .../datatypes/AttLoggerTargetServiceName.java | 9 ++++ .../datatypes/AttValetGroupTypeValues.java | 53 +++++++++++++++++++ .../AttValetGroupAssignmentResourceValidator.java | 60 ++++++++++++++++++++++ .../com/att/sdc/validation/messages/Messages.java | 20 ++++++++ .../src/main/resources/config-merge-validaton.json | 18 +++++++ 7 files changed, 222 insertions(+) create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttHeatResourceTypes.java create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerErrorDescription.java create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerTargetServiceName.java create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttValetGroupTypeValues.java create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/impl/validators/AttValetGroupAssignmentResourceValidator.java create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/messages/Messages.java create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/resources/config-merge-validaton.json (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttHeatResourceTypes.java b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttHeatResourceTypes.java new file mode 100644 index 0000000000..427fc9c84a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttHeatResourceTypes.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.att.sdc.validation.datatypes; + +import java.util.HashMap; +import java.util.Map; + +public enum AttHeatResourceTypes { + ATT_VALET_GROUP_ASSIGNMENT("ATT::Valet::GroupAssignment"); + + private static Map stringToAttRsourceMap; + + static { + stringToAttRsourceMap = new HashMap<>(); + + for (AttHeatResourceTypes attHeatResourceType : AttHeatResourceTypes.values()) { + stringToAttRsourceMap.put(attHeatResourceType.type, attHeatResourceType); + } + } + + private String type; + + + AttHeatResourceTypes(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public static AttHeatResourceTypes findByResourceType(String type) { + return stringToAttRsourceMap.get(type); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerErrorDescription.java b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerErrorDescription.java new file mode 100644 index 0000000000..c4f1d0a4b4 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerErrorDescription.java @@ -0,0 +1,9 @@ +package com.att.sdc.validation.datatypes; + +/** + * Created by TALIO on 5/21/2017. + */ +public class AttLoggerErrorDescription { + + public static final String ATT_VALET_IN_USE = "ATT Valet group type is in use"; +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerTargetServiceName.java b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerTargetServiceName.java new file mode 100644 index 0000000000..111a9873fc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttLoggerTargetServiceName.java @@ -0,0 +1,9 @@ +package com.att.sdc.validation.datatypes; + +/** + * Created by TALIO on 5/21/2017. + */ +public class AttLoggerTargetServiceName { + + public static final String VALIDATE_ATT_VALET_TYPE = "Validate OPENECOMP Valet Group Resosurce Type"; +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttValetGroupTypeValues.java b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttValetGroupTypeValues.java new file mode 100644 index 0000000000..08647b18af --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/datatypes/AttValetGroupTypeValues.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.att.sdc.validation.datatypes; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public enum AttValetGroupTypeValues { + EXCLUSIVITY("exclusivity"), + AFFINITY("affinity"), + DIVERSITY("diversity"); + + private static List groupTypeAsStrings; + + static { + groupTypeAsStrings = new ArrayList<>(); + for (AttValetGroupTypeValues attGroupTypeValue : AttValetGroupTypeValues.values()) { + groupTypeAsStrings.add(attGroupTypeValue.groupTypeValue); + } + } + + private String groupTypeValue; + + AttValetGroupTypeValues(String groupTypeValue) { + this.groupTypeValue = groupTypeValue; + } + + public static boolean isGroupTypeValid(Object groupType) { + if (groupType instanceof Map) { + return true; + } + return groupTypeAsStrings.contains(groupType); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/impl/validators/AttValetGroupAssignmentResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/impl/validators/AttValetGroupAssignmentResourceValidator.java new file mode 100644 index 0000000000..30b65f4b3e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/impl/validators/AttValetGroupAssignmentResourceValidator.java @@ -0,0 +1,60 @@ +package com.att.sdc.validation.impl.validators; + +import com.att.sdc.validation.datatypes.AttLoggerErrorDescription; +import com.att.sdc.validation.datatypes.AttLoggerTargetServiceName; +import com.att.sdc.validation.datatypes.AttValetGroupTypeValues; +import com.att.sdc.validation.messages.Messages; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; +import org.openecomp.core.validation.types.GlobalValidationContext; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.validation.ResourceValidator; +import org.openecomp.sdc.validation.ValidationContext; + +import java.util.Map; +import java.util.Objects; + +/** + * Created by TALIO on 2/26/2017. + */ +public class AttValetGroupAssignmentResourceValidator implements ResourceValidator { + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + @Override + public void validate(String fileName, Map.Entry resourceEntry, + GlobalValidationContext globalContext, ValidationContext validationContext) { + mdcDataDebugMessage.debugEntryMessage("file", fileName); + + Resource resource = resourceEntry.getValue(); + + Map propertiesMap = resource.getProperties(); + if (MapUtils.isEmpty(propertiesMap)) { + return; + } + + Object groupTypeValue = propertiesMap.get("group_type"); + if (Objects.isNull(groupTypeValue)) { + return; + } + + validateGroupTypeValue(fileName, resourceEntry.getKey(), groupTypeValue, globalContext); + mdcDataDebugMessage.debugExitMessage("file", fileName); + } + + private static void validateGroupTypeValue(String fileName, String resourceId, + Object groupTypeValue, + GlobalValidationContext globalContext) { + mdcDataDebugMessage.debugEntryMessage("file", fileName); + + if (!AttValetGroupTypeValues.isGroupTypeValid(groupTypeValue)) { + globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters(Messages.UNEXPECTED_GROUP_TYPE_ATT_VALET.getErrorMessage(), + resourceId), AttLoggerTargetServiceName.VALIDATE_ATT_VALET_TYPE, + AttLoggerErrorDescription.ATT_VALET_IN_USE); + } + + mdcDataDebugMessage.debugExitMessage("file", fileName); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/messages/Messages.java b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/messages/Messages.java new file mode 100644 index 0000000000..0b3274edf0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/java/com/att/sdc/validation/messages/Messages.java @@ -0,0 +1,20 @@ +package com.att.sdc.validation.messages; + +/** + * Created by TALIO on 5/17/2017. + */ +public enum Messages { + + UNEXPECTED_GROUP_TYPE_ATT_VALET( + "Unexpected group_type for ATT::Valet::GroupAssignment, Resource ID [%s]"); + + private String errorMessage; + + Messages(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorMessage() { + return errorMessage; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/resources/config-merge-validaton.json b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/resources/config-merge-validaton.json new file mode 100644 index 0000000000..179f13c344 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/att-sdc-validation-impl/src/main/resources/config-merge-validaton.json @@ -0,0 +1,18 @@ +{ + "validatorImplementations": { + "resourceHeatValidator": { + "properties": { + "resourceBaseValidator": { + "ATT::Valet::GroupAssignment": { + "enable": true, + "implementationClass": "com.att.sdc.validation.impl.validators.AttValetGroupAssignmentResourceValidator" + } + } + } + } + }, + "_config": { + "namespace": "validation", + "mergeStrategy": "merge" + } +} \ No newline at end of file -- cgit 1.2.3-korg