Sonar Fix - Removed unnecessary cast to Date
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / main / java / org / onap / appc / adapter / iaas / provider / operation / impl / StopServer.java
index 10236a8..d502a79 100644 (file)
@@ -2,9 +2,11 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (c) 2019 IBM
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,6 +51,7 @@ import java.util.Map;
 import org.slf4j.MDC;
 import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.STOP_SERVICE;
 import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
 
 public class StopServer extends ProviderServerOperation {
 
@@ -78,12 +81,23 @@ public class StopServer extends ProviderServerOperation {
             String identStr = (ident == null) ? null : ident.toString();
             Context context = null;
             ctx.setAttribute("STOP_STATUS", "ERROR");
+            // Is the skip Hypervisor check attribute populated?
+            String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+            if (skipHypervisorCheck == null && ctx != null) {
+                skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+            }
             try {
                 context = getContext(rc, vm_url, identStr);
                 if (context != null) {
                     rc.reset();
                     server = lookupServer(rc, context, vm.getServerId());
                     logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
+                    // Always perform Hypervisor check
+                    // unless the skip is set to true
+                    if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
+                        // Check of the Hypervisor for the VM Server is UP and reachable
+                        checkHypervisor(server);
+                    }
                     String msg;
                     /*
                      * We determine what to do based on the current state of the server
@@ -183,8 +197,9 @@ public class StopServer extends ProviderServerOperation {
         logOperation(Msg.STOPPING_SERVER, params, context);
         return stopServer(params, context);
     }
+
     private void setTimeForMetricsLogger() {
-        String timestamp = LoggingUtils.generateTimestampStr(((Date) new Date()).toInstant());
+        String timestamp = LoggingUtils.generateTimestampStr((new Date()).toInstant());
         MDC.put(LoggingConstants.MDCKeys.BEGIN_TIMESTAMP, timestamp);
         MDC.put(LoggingConstants.MDCKeys.END_TIMESTAMP, timestamp);
         MDC.put(LoggingConstants.MDCKeys.ELAPSED_TIME, "0");