Changed Code and DGs to return detailed response. 73/58773/3
authorShailendra Borale <sb8915@att.com>
Thu, 2 Aug 2018 20:00:22 +0000 (16:00 -0400)
committerTakamune Cho <tc012c@att.com>
Fri, 3 Aug 2018 20:01:09 +0000 (20:01 +0000)
Added comment and used String instead of Integer.toString

Change-Id: I07a0a7752b225fbf50d761b489b9320b47fcc71d
Issue-ID: APPC-1013
Signed-off-by: sb8915 <sb8915@att.com>
appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java
appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/impl/TestAnsibleAdapterImpl.java
appc-directed-graph/appc-dgraph/provider/src/main/resources/json/APPC/APPC_DGOrchestrator.json
appc-directed-graph/appc-dgraph/provider/src/main/resources/json/APPC/APPC_Generic_AnsibleDG.json
appc-directed-graph/appc-dgraph/provider/src/main/resources/json/APPC/APPC_ansible-adapter-1.0.json

index b9cdbc6..ae0b859 100644 (file)
@@ -77,6 +77,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
     private static final String RESULT_CODE_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.result.code";
     private static final String MESSAGE_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.message";
     private static final String RESULTS_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.results";
+    private static final String OUTPUT_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.output";
     private static final String ID_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.Id";
     private static final String LOG_ATTRIBUTE_NAME = "org.onap.appc.adapter.ansible.log";
 
@@ -317,6 +318,7 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
         int code = -1;
         String message = StringUtils.EMPTY;
         String results = StringUtils.EMPTY;
+        String output = StringUtils.EMPTY;
 
         try {
             // Try to retrieve the test results (modify the URL for that)
@@ -324,13 +326,14 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
             code = testResult.getStatusCode();
             message = testResult.getStatusMessage();
 
-            if (code == 200) {
+            if (code == 200 || code == 400 || "FINISHED".equalsIgnoreCase(message)) {
                 logger.info("Parsing response from Server = " + message);
                 // Valid HTTP. process the Ansible message
                 testResult = messageProcessor.parseGetResponse(message);
                 code = testResult.getStatusCode();
                 message = testResult.getStatusMessage();
                 results = testResult.getResults();
+                output = testResult.getOutput();
             }
 
             logger.info("Request response = " + message);
@@ -350,13 +353,16 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
             logger.info(String.format("Ansible Request  %s finished with Result %s, Message = %s", params.get("Id"),
                     OUTCOME_FAILURE, message));
             ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results);
+            ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output);
             doFailure(ctx, code, message);
             return;
         }
 
-        ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, Integer.toString(code));
+        // In case of 200,400,FINISHED return 400
+        ctx.setAttribute(RESULT_CODE_ATTRIBUTE_NAME, "400");
         ctx.setAttribute(MESSAGE_ATTRIBUTE_NAME, message);
         ctx.setAttribute(RESULTS_ATTRIBUTE_NAME, results);
+        ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output);
         ctx.setStatus(OUTCOME_SUCCESS);
     }
 
index 7898260..7ba34e9 100644 (file)
@@ -150,7 +150,7 @@ public class TestAnsibleAdapterImpl {
         when(messageProcessor.reqUriResult(params)).thenReturn(agentUrl);
         when(messageProcessor.parseGetResponse(anyString())).thenReturn(result);
         spyAdapter.reqExecResult(params, svcContext);
-        assertEquals(SUCCESS, svcContext.getAttribute(RESULT_CODE_ATTRIBUTE_NAME));
+        assertEquals("400", svcContext.getAttribute(RESULT_CODE_ATTRIBUTE_NAME));
     }
 
     /**
index 7a22ddf..6354ffa 100644 (file)
         "id": "ca5807aa.f436",
         "type": "set",
         "name": "set error-code 401 and message",
-        "xml": "<set>\n<parameter name='error-code' value='401' />\n<parameter name='error-message' value=\"`$tmp.flowControl.status-message`\" />\n<parameter name='output-payload' value=\"\" />\n",
+        "xml": "<set>\n<parameter name='error-code' value='401' />\n<parameter name='error-message' value=\"`$tmp.flowControl.status-message`\" />\n<parameter name='output-payload' value='`$output-payload`' />\n",
         "comments": "",
         "x": 2459.99755859375,
         "y": 347.3666076660156,
         "z": "5f45af23.e79db",
         "wires": []
     }
-]
\ No newline at end of file
+]
index 05e733f..b3069cd 100644 (file)
         "id": "fb756701.8cc94",\r
         "type": "returnFailure",\r
         "name": "return failure",\r
-        "xml": "<return status=\"failure\">\n<parameter name='error-code' value=\"401\" />\n<parameter name='error-message' value='`$org.onap.appc.adapter.ansible.message`'/>",\r
+        "xml": "<return status=\"failure\">\n<parameter name='error-code' value=\"401\" />\n<parameter name='error-message' value='`$org.onap.appc.adapter.ansible.message`'/>\n<parameter name='output-payload' value='`$org.onap.appc.adapter.ansible.output`'/>",\r
         "comments": "",\r
         "x": 1050.9717254638672,\r
         "y": 762.2043304443359,\r
         "id": "5ce0b58c.6872f4",\r
         "type": "set",\r
         "name": "set payloadResponse",\r
-        "xml": "<set>\n<parameter name='error-code' value='400' />\n<parameter name='error-message' value='`$org.onap.appc.adapter.ansible.message`'/>\n<parameter name='output-payload' value='`$org.onap.appc.adapter.ansible.results`'/>",\r
+        "xml": "<set>\n<parameter name='error-code' value='400' />\n<parameter name='error-message' value='`$org.onap.appc.adapter.ansible.message`'/>\n<parameter name='output-payload' value='`$org.onap.appc.adapter.ansible.output`'/>",\r
         "comments": "",\r
         "x": 837,\r
         "y": 971,\r
         "z": "23466936.d3b346",\r
         "wires": []\r
     }\r
-]
\ No newline at end of file
+]
index 9586002..ec7151a 100644 (file)
@@ -37,7 +37,7 @@
         "id": "53079a4f.559f84",\r
         "type": "returnFailure",\r
         "name": "return failure",\r
-        "xml": "<return status='failure'>\n<parameter name='error-code' value='200' />\n<parameter name='error-message' value='`$org.onap.appc.adapter.ansible.message`' />\n<parameter name='output.status.results' value='`$org.onap.appc.adapter.ansible.results`' />\n",\r
+        "xml": "<return status='failure'>\n<parameter name='error-code' value='200' />\n<parameter name='error-message' value='`$org.onap.appc.adapter.ansible.message`' />\n<parameter name='output.status.results' value='`$org.onap.appc.adapter.ansible.results`' />\n<parameter name='output.status.outputdata' value= '`$org.onap.appc.adapter.ansible.output`/>\n",\r
         "comments": "",\r
         "x": 1218.6999816894531,\r
         "y": 669.8833348751068,\r