Fixup multicloud log exceptions and error cases 55/74955/1
authorEric Multanen <eric.w.multanen@intel.com>
Thu, 20 Dec 2018 16:38:23 +0000 (08:38 -0800)
committerEric Multanen <eric.w.multanen@intel.com>
Thu, 20 Dec 2018 16:43:45 +0000 (08:43 -0800)
Fix log calls which would have an exception.
Throw and mso exception when call to multicloud
fails to create a stack.

Change-Id: Ib103c6f4420e444734bbb715699eb57ffc110925
Issue-ID: SO-1336
Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java

index 73e0da1..0e37ce3 100644 (file)
@@ -205,17 +205,24 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         createInfo.setName(stackName);
 
         MulticloudCreateResponse multicloudResponseBody = null;
-        if (response.getStatus() == Response.Status.CREATED.getStatusCode() && response.hasEntity()) {
+        if (response.hasEntity()) {
             multicloudResponseBody = getCreateBody((java.io.InputStream)response.getEntity());
+        }
+        if (response.getStatus() == Response.Status.CREATED.getStatusCode() && response.hasEntity()) {
             createInfo.setCanonicalName(stackName + "/" + multicloudResponseBody.getWorkloadId());
             if (logger.isDebugEnabled()) {
                 logger.debug("Multicloud Create Response Body: " + multicloudResponseBody);
             }
             return getStackStatus(cloudSiteId, tenantId, createInfo.getCanonicalName(), pollForCompletion, timeoutMinutes, backout);
         } else {
-            createInfo.setStatus(HeatStatus.FAILED);
-            createInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
-            return createInfo;
+            StringBuilder stackErrorStatusReason = new StringBuilder(response.getStatusInfo().getReasonPhrase());
+            if (null != multicloudResponseBody) {
+                stackErrorStatusReason.append(multicloudResponseBody.toString());
+            }
+            MsoOpenstackException me = new MsoOpenstackException(0, "", stackErrorStatusReason.toString());
+            me.addContext(CREATE_STACK);
+            alarmLogger.sendAlarm(HEAT_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage());
+            throw me;
         }
     }
 
@@ -383,7 +390,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                         if (pollTimeout <= 0) {
                             // Note that this should not occur, since there is a timeout specified
                             // in the Openstack (multicloud?) call.
-                            logger.error(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, instanceId, stackInfo.getStatus(), "", "", MsoLogger.ErrorCode.AvailabilityError, "Create stack timeout"));
+                            logger.error(String.format("%s %s %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_TIMEOUT.toString(), cloudSiteId, tenantId, instanceId, stackInfo.getStatus(), "", "", MsoLogger.ErrorCode.AvailabilityError, "Create stack timeout"));
                             createTimedOut = true;
                             break;
                         }
@@ -401,7 +408,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                     // Cannot query the stack status. Something is wrong.
                     // Try to roll back the stack
                     if (!backout) {
-                        logger.warn(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, stack deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Create Stack, stack deletion suppressed"));
+                        logger.warn(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack error, stack deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Create Stack, stack deletion suppressed"));
                     } else {
                         try {
                             logger.debug("Create Stack error - unable to query for stack status - attempting to delete stack: " + instanceId + " - This will likely fail and/or we won't be able to query to see if delete worked");
@@ -415,7 +422,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                                     logger.debug("Deleting " + instanceId + ", status: " + queryInfo.getStatus());
                                     if (HeatStatus.DELETING.equals(queryInfo.getStatus())) {
                                         if (deletePollTimeout <= 0) {
-                                            logger.error(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, instanceId,
+                                            logger.error(String.format("%s %s %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_TIMEOUT.toString(), cloudSiteId, tenantId, instanceId,
                                                     queryInfo.getStatus(), "", "", MsoLogger.ErrorCode.AvailabilityError,
                                                     "Rollback: DELETE stack timeout"));
                                             break;
@@ -433,12 +440,12 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                                     }
                                 } catch (Exception e3) {
                                     // Just log this one. We will report the original exception.
-                                    logger.error(String.format("%d %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back stack: " + e3, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back stack on error on query"));
+                                    logger.error(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack: Nested exception rolling back stack: " + e3, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back stack on error on query"));
                                 }
                             }
                         } catch (Exception e2) {
                             // Just log this one. We will report the original exception.
-                            logger.error(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back stack: " + e2, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back stack"));
+                            logger.error(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack: Nested exception rolling back stack: " + e2, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back stack"));
                         }
                     }
 
@@ -449,12 +456,12 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
             }
 
             if (!HeatStatus.CREATED.equals(stackInfo.getStatus())) {
-                logger.error(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack error:  Polling complete with non-success status: "
+                logger.error(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack error:  Polling complete with non-success status: "
                               + stackInfo.getStatus () + ", " + stackInfo.getStatusMessage(), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error"));
 
                 // Rollback the stack creation, since it is in an indeterminate state.
                 if (!backout) {
-                    logger.warn(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, stack deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error, stack deletion suppressed"));
+                    logger.warn(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack errored, stack deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error, stack deletion suppressed"));
                 }
                 else
                 {
@@ -469,7 +476,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                                 logger.debug("Deleting " + instanceId + ", status: " + queryInfo.getStatus());
                                 if (HeatStatus.DELETING.equals(queryInfo.getStatus())) {
                                     if (deletePollTimeout <= 0) {
-                                        logger.error(String.format("%d %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, instanceId,
+                                        logger.error(String.format("%s %s %s %s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_TIMEOUT.toString(), cloudSiteId, tenantId, instanceId,
                                                 queryInfo.getStatus(), "", "", MsoLogger.ErrorCode.AvailabilityError,
                                                 "Rollback: DELETE stack timeout"));
                                         break;
@@ -483,14 +490,14 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                                     continue;
                                 } else {
                                     //got a status other than DELETE_IN_PROGRESS or DELETE_COMPLETE - so break and evaluate
-                                    logger.warn(String.format("%d %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, stack deletion FAILED", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error, stack deletion FAILED"));
+                                    logger.warn(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack errored, stack deletion FAILED", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error, stack deletion FAILED"));
                                     logger.debug("Stack deletion FAILED on a rollback of a create - " + instanceId + ", status=" + queryInfo.getStatus() + ", reason=" + queryInfo.getStatusMessage());
                                     break;
                                 }
                             } catch (MsoException me2) {
                                 // Just log this one. We will report the original exception.
                                 logger.debug("Exception thrown trying to delete " + instanceId + " on a create->rollback: " + me2.getContextMessage(), me2);
-                                logger.warn(String.format("%d %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, then stack deletion FAILED - exception thrown", "", "", MsoLogger.ErrorCode.BusinessProcesssError, me2.getContextMessage()));
+                                logger.warn(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack errored, then stack deletion FAILED - exception thrown", "", "", MsoLogger.ErrorCode.BusinessProcesssError, me2.getContextMessage()));
                             }
                         }
                         StringBuilder errorContextMessage;
@@ -506,7 +513,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
                         }
                     } catch (MsoException e2) {
                         // shouldn't happen - but handle
-                        logger.error(String.format("%d %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back stack: " + e2, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Create Stack: rolling back stack"));
+                        logger.error(String.format("%s %s %s %s %d %s", MessageEnum.RA_CREATE_STACK_ERR.toString(), "Create Stack: Nested exception rolling back stack: " + e2, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Create Stack: rolling back stack"));
                     }
                 }
                 MsoOpenstackException me = new MsoOpenstackException(0, "", stackErrorStatusReason.toString());
@@ -613,8 +620,8 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         try {
             return JSON_MAPPER.readTree(directives);
         } catch (Exception e) {
-            logger.error(String.format("%d %s %s %s %d %s",
-                    MessageEnum.RA_CREATE_STACK_ERR,
+            logger.error(String.format("%s %s %s %s %d %s",
+                    MessageEnum.RA_CREATE_STACK_ERR.toString(),
                     "Create Stack: " + e, "", "",
                     MsoLogger.ErrorCode.BusinessProcesssError,
                     "Exception in Create Stack: Invalid JSON format of directives" + directives));