Repair healthcheck 71/95371/2
authorsebdet <sebastien.determe@intl.att.com>
Tue, 10 Sep 2019 13:57:10 +0000 (15:57 +0200)
committersebdet <sebastien.determe@intl.att.com>
Tue, 10 Sep 2019 14:50:30 +0000 (16:50 +0200)
HealthCheck was always returning 200 even if the db was not up and
running

Issue-ID: CLAMP-494
Change-Id: I85aa427a212c6cde568d3863d1ab1a1a11c71f16
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
docs/swagger/swagger.json
docs/swagger/swagger.pdf
src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java
src/main/java/org/onap/clamp/loop/LoopController.java
src/main/resources/META-INF/resources/swagger.html
src/main/resources/clds/camel/rest/clamp-api-v2.xml
src/main/resources/clds/camel/rest/clds-services.xml
src/test/java/org/onap/clamp/clds/it/CldsHealthcheckServiceItCase.java

index 0bd2b07..80ffc2a 100644 (file)
@@ -4,7 +4,7 @@
     "version" : "4.1.2-SNAPSHOT",
     "title" : "Clamp Rest API"
   },
-  "host" : "localhost:40147",
+  "host" : "localhost:36829",
   "basePath" : "/restservices/clds/",
   "schemes" : [ "http" ],
   "paths" : {
         "asString" : {
           "type" : "string"
         },
-        "asBoolean" : {
-          "type" : "boolean"
-        },
         "asNumber" : {
           "$ref" : "#/definitions/Number"
         },
+        "asBoolean" : {
+          "type" : "boolean"
+        },
         "asDouble" : {
           "type" : "number",
           "format" : "double"
         "asJsonPrimitive" : {
           "$ref" : "#/definitions/JsonPrimitive"
         },
-        "jsonObject" : {
+        "jsonPrimitive" : {
           "type" : "boolean"
         },
-        "jsonNull" : {
-          "type" : "boolean"
+        "asJsonArray" : {
+          "$ref" : "#/definitions/JsonArray"
         },
-        "jsonArray" : {
+        "jsonObject" : {
           "type" : "boolean"
         },
-        "jsonPrimitive" : {
+        "jsonNull" : {
           "type" : "boolean"
         },
-        "asJsonArray" : {
-          "$ref" : "#/definitions/JsonArray"
-        },
         "asJsonNull" : {
           "$ref" : "#/definitions/JsonNull"
+        },
+        "jsonArray" : {
+          "type" : "boolean"
         }
       },
       "x-className" : {
         "asString" : {
           "type" : "string"
         },
-        "asBoolean" : {
-          "type" : "boolean"
-        },
         "asNumber" : {
           "$ref" : "#/definitions/Number"
         },
+        "asBoolean" : {
+          "type" : "boolean"
+        },
         "asDouble" : {
           "type" : "number",
           "format" : "double"
         "asJsonPrimitive" : {
           "$ref" : "#/definitions/JsonPrimitive"
         },
-        "jsonObject" : {
+        "jsonPrimitive" : {
           "type" : "boolean"
         },
-        "jsonNull" : {
-          "type" : "boolean"
+        "asJsonArray" : {
+          "$ref" : "#/definitions/JsonArray"
         },
-        "jsonArray" : {
+        "jsonObject" : {
           "type" : "boolean"
         },
-        "jsonPrimitive" : {
+        "jsonNull" : {
           "type" : "boolean"
         },
-        "asJsonArray" : {
-          "$ref" : "#/definitions/JsonArray"
-        },
         "asJsonNull" : {
           "$ref" : "#/definitions/JsonNull"
+        },
+        "jsonArray" : {
+          "type" : "boolean"
         }
       }
     },
         "asString" : {
           "type" : "string"
         },
-        "jsonObject" : {
+        "jsonPrimitive" : {
           "type" : "boolean"
         },
-        "jsonNull" : {
-          "type" : "boolean"
+        "asJsonArray" : {
+          "$ref" : "#/definitions/JsonArray"
         },
-        "jsonArray" : {
+        "jsonObject" : {
           "type" : "boolean"
         },
-        "asBoolean" : {
-          "type" : "boolean"
+        "asNumber" : {
+          "$ref" : "#/definitions/Number"
         },
-        "jsonPrimitive" : {
+        "jsonNull" : {
           "type" : "boolean"
         },
-        "asJsonArray" : {
-          "$ref" : "#/definitions/JsonArray"
-        },
         "asJsonNull" : {
           "$ref" : "#/definitions/JsonNull"
         },
-        "asNumber" : {
-          "$ref" : "#/definitions/Number"
+        "jsonArray" : {
+          "type" : "boolean"
+        },
+        "asBoolean" : {
+          "type" : "boolean"
         },
         "asDouble" : {
           "type" : "number",
         "asString" : {
           "type" : "string"
         },
-        "jsonObject" : {
+        "jsonPrimitive" : {
           "type" : "boolean"
         },
-        "jsonNull" : {
-          "type" : "boolean"
+        "asJsonArray" : {
+          "$ref" : "#/definitions/JsonArray"
         },
-        "jsonArray" : {
+        "jsonObject" : {
           "type" : "boolean"
         },
-        "asBoolean" : {
-          "type" : "boolean"
+        "asNumber" : {
+          "$ref" : "#/definitions/Number"
         },
-        "jsonPrimitive" : {
+        "jsonNull" : {
           "type" : "boolean"
         },
-        "asJsonArray" : {
-          "$ref" : "#/definitions/JsonArray"
-        },
         "asJsonNull" : {
           "$ref" : "#/definitions/JsonNull"
         },
-        "asNumber" : {
-          "$ref" : "#/definitions/Number"
+        "jsonArray" : {
+          "type" : "boolean"
+        },
+        "asBoolean" : {
+          "type" : "boolean"
         },
         "asDouble" : {
           "type" : "number",
index 967dc9a..9ae7d6e 100644 (file)
@@ -4,8 +4,8 @@
 << /Title (Clamp Rest API)
 /Creator (Asciidoctor PDF 1.5.0.alpha.10, based on Prawn 1.3.0)
 /Producer (Asciidoctor PDF 1.5.0.alpha.10, based on Prawn 1.3.0)
-/CreationDate (D:20190909171618+02'00')
-/ModDate (D:20190909171618+02'00')
+/CreationDate (D:20190910155046+02'00')
+/ModDate (D:20190910155046+02'00')
 >>
 endobj
 2 0 obj
@@ -3407,7 +3407,7 @@ ET
 BT
 71.30850000000001 592.176 Td
 /F1.0 10.5 Tf
-<203a206c6f63616c686f73743a3430313437> Tj
+<203a206c6f63616c686f73743a3336383239> Tj
 ET
 
 0.000 0.000 0.000 SCN
index f167916..39c12c8 100644 (file)
@@ -34,7 +34,6 @@ import org.onap.clamp.loop.LoopController;
 import org.slf4j.event.Level;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 
 /**
@@ -54,36 +53,28 @@ public class CldsHealthcheckService {
      *
      * @return CldsHealthCheck class containing healthcheck info
      */
-    public ResponseEntity<CldsHealthCheck> gethealthcheck() {
+    public CldsHealthCheck gethealthcheck() {
         CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
         Date startTime = new Date();
         LoggingUtils util = new LoggingUtils(logger);
         LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
         LoggingUtils.setTimeContext(startTime, new Date());
-        boolean healthcheckFailed = false;
         try {
             loopController.getLoopNames();
             cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
             cldsHealthCheck.setHealthCheckStatus("UP");
             cldsHealthCheck.setDescription("OK");
             LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
+            util.exiting("200", "Healthcheck success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
         } catch (Exception e) {
-            healthcheckFailed = true;
             logger.error("CLAMP application Heath check failed", e);
             LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
             cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
             cldsHealthCheck.setHealthCheckStatus("DOWN");
             cldsHealthCheck.setDescription("NOT-OK");
-        }
-        // audit log
-        LoggingUtils.setTimeContext(startTime, new Date());
-        if (healthcheckFailed) {
             util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "Healthcheck failed", Level.INFO,
                     ONAPLogConstants.ResponseStatus.ERROR);
-            return new ResponseEntity<>(cldsHealthCheck, HttpStatus.INTERNAL_SERVER_ERROR);
-        } else {
-            util.exiting("200", "Healthcheck failed", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
-            return new ResponseEntity<>(cldsHealthCheck, HttpStatus.OK);
         }
+        return cldsHealthCheck;
     }
 }
\ No newline at end of file
index 7d41e48..72726fa 100644 (file)
@@ -61,40 +61,35 @@ public class LoopController {
     /**
      * Update the Operational Policy properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param operationalPoliciesJson
-     *        The new Operational Policy properties
+     * @param loopName                The loop name
+     * @param operationalPoliciesJson The new Operational Policy properties
      * @return The updated loop
      */
     public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
         List<OperationalPolicy> operationalPolicies = JsonUtils.GSON.fromJson(operationalPoliciesJson,
-            OPERATIONAL_POLICY_TYPE);
+                OPERATIONAL_POLICY_TYPE);
         return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
     }
 
     /**
-     * Update the whole array of MicroService policies properties
+     * Update the whole array of MicroService policies properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param microServicePoliciesJson
-     *        The array of all MicroService policies properties
+     * @param loopName                 The loop name
+     * @param microServicePoliciesJson The array of all MicroService policies
+     *                                 properties
      * @return The updated loop
      */
     public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
         List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON.fromJson(microServicePoliciesJson,
-            MICROSERVICE_POLICY_TYPE);
+                MICROSERVICE_POLICY_TYPE);
         return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
     }
 
     /**
-     * Update the global properties
+     * Update the global properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param globalProperties
-     *        The updated global properties
+     * @param loopName         The loop name
+     * @param globalProperties The updated global properties
      * @return The updated loop
      */
     public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties) {
@@ -102,12 +97,10 @@ public class LoopController {
     }
 
     /**
-     * Update one MicroService policy properties
+     * Update one MicroService policy properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param newMicroservicePolicy
-     *        The new MicroService policy properties
+     * @param loopName              The loop name
+     * @param newMicroservicePolicy The new MicroService policy properties
      * @return The updated MicroService policy
      */
     public MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) {
@@ -115,13 +108,12 @@ public class LoopController {
     }
 
     /**
-     * Get the SVG representation of the loop
+     * Get the SVG representation of the loop.
      *
-     * @param loopName
-     *        The loop name
+     * @param loopName The loop name
      * @return The SVG representation
      */
-    public String getSVGRepresentation(String loopName) {
+    public String getSvgRepresentation(String loopName) {
         Loop loop = loopService.getLoop(loopName);
         return loop != null ? loop.getSvgRepresentation() : null;
     }
index d2ec966..d3b38b6 100644 (file)
@@ -588,7 +588,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
 <div class="sect2">
 <h3 id="_uri_scheme"><a class="anchor" href="#_uri_scheme"></a><a class="link" href="#_uri_scheme">1.2. URI scheme</a></h3>
 <div class="paragraph">
-<p><em>Host</em> : localhost:40147<br>
+<p><em>Host</em> : localhost:36829<br>
 <em>BasePath</em> : /restservices/clds/<br>
 <em>Schemes</em> : HTTP</p>
 </div>
index 6ee44ca..cf99625 100644 (file)
@@ -68,7 +68,7 @@
                                        <to
                                                uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')" />
                                        <to
-                                               uri="bean:org.onap.clamp.loop.LoopController?method=getSVGRepresentation(${header.loopName})" />
+                                               uri="bean:org.onap.clamp.loop.LoopController?method=getSvgRepresentation(${header.loopName})" />
                                        <to
                                                uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
                                        <doCatch>
index b3061dc..dd3a4bf 100644 (file)
@@ -1,19 +1,29 @@
 <rests xmlns="http://camel.apache.org/schema/spring">
-       <rest >
-               <get uri="/v1/clds/cldsInfo"
-                       outType="org.onap.clamp.clds.model.CldsInfo"
+       <rest>
+               <get uri="/v1/clds/cldsInfo" outType="org.onap.clamp.clds.model.CldsInfo"
                        produces="application/json">
                        <to
                                uri="bean:org.onap.clamp.clds.service.CldsService?method=getCldsInfo()" />
                </get>
-               <get uri="/v1/healthcheck" produces="application/json">
-                       <to
-                               uri="bean:org.onap.clamp.clds.service.CldsHealthcheckService?method=gethealthcheck()" />
+               <get uri="/v1/healthcheck" produces="application/json"
+                       outType="org.onap.clamp.clds.model.CldsHealthCheck">
+                       <route>
+                               <setBody>
+                                       <method ref="org.onap.clamp.clds.service.CldsHealthcheckService"
+                                               method="gethealthcheck()" />
+                               </setBody>
+                               <when>
+                                       <simple> ${body} == 'NOT-OK'</simple>
+                                       <setHeader headerName="CamelHttpResponseCode">
+                                               <constant>404</constant>
+                                       </setHeader>
+                                       <log loggingLevel="ERROR" message="HealthCheck failed" />
+                               </when>
+                       </route>
                </get>
 
                <get uri="/v1/user/getUser" produces="text/plain">
-                       <to
-                               uri="bean:org.onap.clamp.clds.service.UserService?method=getUser()" />
+                       <to uri="bean:org.onap.clamp.clds.service.UserService?method=getUser()" />
                </get>
        </rest>
 </rests>
index 1dbea37..587b7c9 100644 (file)
@@ -32,7 +32,6 @@ import org.onap.clamp.clds.service.CldsHealthcheckService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.http.ResponseEntity;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 /**
@@ -47,8 +46,7 @@ public class CldsHealthcheckServiceItCase {
 
     @Test
     public void testGetHealthCheck() {
-        ResponseEntity response = cldsHealthcheckService.gethealthcheck();
-        CldsHealthCheck cldsHealthCheck = (CldsHealthCheck) response.getBody();
+        CldsHealthCheck cldsHealthCheck = cldsHealthcheckService.gethealthcheck();
         assertNotNull(cldsHealthCheck);
         assertEquals("UP", cldsHealthCheck.getHealthCheckStatus());
         assertEquals("CLDS-APP", cldsHealthCheck.getHealthCheckComponent());