Fixed sonar issues - NovaServerResourceValidator 73/26773/2
authormojahidi <mojahidul.islam@amdocs.com>
Fri, 22 Dec 2017 05:33:21 +0000 (11:03 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Sun, 24 Dec 2017 14:43:46 +0000 (14:43 +0000)
Fixed all sonar issues

Change-Id: I4ee3a6fdc33a3874ce36d32296ab508ee7089468
Issue-ID: SDC-343
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java

index 33d20d5..7d8ab25 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.sdc.validation.impl.validators.heatresource;
 
 import org.apache.commons.collections4.MapUtils;
@@ -20,21 +36,19 @@ import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
 
 import java.util.Map;
 
-/**
- * Created by TALIO on 2/22/2017.
- */
 public class NovaServerResourceValidator implements ResourceValidator {
-  private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+  private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
   private static final ErrorMessageCode ERROR_CODE_HNS1 = new ErrorMessageCode("HNS1");
   private static final ErrorMessageCode ERROR_CODE_HNS2 = new ErrorMessageCode("HNS2");
 
+  @Override
   public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
                        GlobalValidationContext globalContext, ValidationContext validationContext) {
 
     HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext)
             validationContext;
-    validateNovaServerResourceType
-            (fileName, resourceEntry, heatResourceValidationContext, globalContext);
+    validateNovaServerResourceType (fileName,
+            resourceEntry, heatResourceValidationContext, globalContext );
   }
 
   private static void validateNovaServerResourceType(String fileName,
@@ -42,14 +56,13 @@ public class NovaServerResourceValidator implements ResourceValidator {
                                                      HeatResourceValidationContext heatResourceValidationContext,
                                                      GlobalValidationContext globalContext) {
 
-    mdcDataDebugMessage.debugEntryMessage("file", fileName);
+    MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
 
     validateAssignedValueForImageOrFlavorFromNova(fileName, resourceEntry, globalContext);
-    validateAllServerGroupsPointedByServerExistAndDefined
-            (fileName, resourceEntry,
-                    heatResourceValidationContext.getHeatOrchestrationTemplate(), globalContext);
+    validateAllServerGroupsPointedByServerExistAndDefined (fileName,
+            resourceEntry, heatResourceValidationContext.getHeatOrchestrationTemplate(), globalContext );
 
-    mdcDataDebugMessage.debugExitMessage("file", fileName);
+    MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
 
   }
 
@@ -59,7 +72,7 @@ public class NovaServerResourceValidator implements ResourceValidator {
                                                                     GlobalValidationContext
                                                                             globalContext) {
 
-    mdcDataDebugMessage.debugEntryMessage("file", fileName);
+    MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
 
     Resource resource = resourceEntry.getValue();
     Map<String, Object> propertiesMap = resource.getProperties();
@@ -72,7 +85,7 @@ public class NovaServerResourceValidator implements ResourceValidator {
               LoggerErrorDescription.MISSING_NOVA_PROPERTIES);
     }
 
-    mdcDataDebugMessage.debugExitMessage("file", fileName);
+    MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
   }
 
   @SuppressWarnings("unchecked")
@@ -81,7 +94,7 @@ public class NovaServerResourceValidator implements ResourceValidator {
                                                                             HeatOrchestrationTemplate heatOrchestrationTemplate,
                                                                             GlobalValidationContext globalContext) {
 
-    mdcDataDebugMessage.debugEntryMessage("file", fileName);
+    MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
 
     Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
     Map<String, Object> resourceProperties = resourceEntry.getValue().getProperties();
@@ -93,6 +106,14 @@ public class NovaServerResourceValidator implements ResourceValidator {
       return;
     }
 
+    validateServerGroupValue(fileName, resourceEntry, globalContext, resourcesMap, schedulerHintsMap);
+
+    MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
+  }
+
+  private static void validateServerGroupValue(String fileName, Map.Entry<String,
+                  Resource> resourceEntry, GlobalValidationContext globalContext,
+                  Map<String, Resource> resourcesMap, Map<String, Object> schedulerHintsMap) {
     if (schedulerHintsMap != null) {
       for (Object serverGroupValue : schedulerHintsMap.values()) {
         if (!(serverGroupValue instanceof Map)) {
@@ -115,8 +136,6 @@ public class NovaServerResourceValidator implements ResourceValidator {
         }
       }
     }
-
-    mdcDataDebugMessage.debugExitMessage("file", fileName);
   }
 
 }