exception handling
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / client / cds / AbstractCDSProcessingBBUtils.java
index 6bfa675..5498b5b 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOu
 import org.onap.so.client.PreconditionFailedException;
 import org.onap.so.client.RestPropertiesLoader;
 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.BadResponseException;
 import org.onap.so.client.exception.ExceptionBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,6 +59,12 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener {
     private static final String FAILED = "Failed";
     private static final String PROCESSING = "Processing";
 
+    /**
+     * indicate exception thrown.
+     */
+    private static final String EXCEPTION = "Exception";
+
+
     private final AtomicReference<String> cdsResponse = new AtomicReference<>();
 
     @Autowired
@@ -132,7 +139,15 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener {
             }
 
             if (cdsResponse != null) {
-                execution.setVariable("CDSStatus", cdsResponse.get());
+                String cdsResponseStatus = cdsResponse.get();
+                execution.setVariable("CDSStatus", cdsResponseStatus);
+
+                /**
+                 * throw CDS failed exception.
+                 */
+                if (cdsResponseStatus != SUCCESS) {
+                    throw new BadResponseException("CDS call failed with status: " + cdsResponseStatus);
+                }
             }
 
         } catch (Exception ex) {
@@ -177,6 +192,7 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener {
     public void onError(Throwable t) {
         Status status = Status.fromThrowable(t);
         logger.error("Failed processing blueprint {}", status, t);
+        cdsResponse.set(EXCEPTION);
     }
 
 }