Use unique name in apex-pdp messages 42/122342/1
authorJim Hahn <jrh3@att.com>
Mon, 28 Jun 2021 20:01:47 +0000 (16:01 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 28 Jun 2021 20:11:55 +0000 (16:11 -0400)
Used name generator for apex-pdp instance id.

Issue-ID: POLICY-3410
Change-Id: Ifcb216d45fba7d6b10043f39fcb299daffe86b69
Signed-off-by: Jim Hahn <jrh3@att.com>
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterActivator.java
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckProvider.java
services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java

index b9424c2..abd8d44 100644 (file)
@@ -80,6 +80,9 @@ public class ApexStarterActivator {
     @Getter
     private List<ToscaConceptIdentifier> supportedPolicyTypes;
 
+    @Getter
+    private final String instanceId;
+
     /**
      * Instantiate the activator for onappf PDP-A.
      *
@@ -93,7 +96,7 @@ public class ApexStarterActivator {
         topicSources = TopicEndpointManager.getManager()
                         .addTopicSources(apexStarterParameterGroup.getTopicParameterGroup().getTopicSources());
 
-        final String instanceId = NetworkUtil.getHostname();
+        instanceId = NetworkUtil.genUniqueName("apex");
         LOGGER.debug("ApexStarterActivator initializing with instance id: {}", instanceId);
         try {
             this.apexStarterParameterGroup = apexStarterParameterGroup;
index 12a34ef..1c6b887 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,7 +36,6 @@ public class HealthCheckProvider {
     private static final String NOT_ALIVE = "not alive";
     private static final String ALIVE = "alive";
     private static final String URL = "self";
-    private static final String NAME = "Policy PDP-A";
 
     /**
      * Performs the health check of PAP service.
@@ -43,13 +43,13 @@ public class HealthCheckProvider {
      * @return Report containing health check status
      */
     public HealthCheckReport performHealthCheck() {
+        final ApexStarterActivator activator =
+                        Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class);
+        final boolean alive = activator.isAlive();
+
         final HealthCheckReport report = new HealthCheckReport();
-        report.setName(NAME);
+        report.setName(activator.getInstanceId());
         report.setUrl(URL);
-
-        final boolean alive =
-                Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class).isAlive();
-
         report.setHealthy(alive);
         report.setCode(alive ? 200 : 500);
         report.setMessage(alive ? ALIVE : NOT_ALIVE);
index 2831340..65d901d 100644 (file)
@@ -71,7 +71,6 @@ public class CommonApexStarterRestServer {
     public static final String NOT_ALIVE = "not alive";
     public static final String ALIVE = "alive";
     public static final String SELF = "self";
-    public static final String NAME = "Policy PDP-A";
     public static final String ENDPOINT_PREFIX = "policy/apex-pdp/v1/";
 
     private static int port;
index 100db5d..7ccfe85 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
 
 package org.onap.policy.apex.services.onappf.rest;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 
 import javax.ws.rs.client.Invocation;
@@ -44,15 +46,15 @@ public class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer
     public void testHealthCheckSuccess() throws Exception {
         final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
-        validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
+        validateHealthCheckReport(SELF, true, 200, ALIVE, report);
 
         // verify it fails when no authorization info is included
         checkUnauthRequest(HEALTHCHECK_ENDPOINT, req -> req.get());
     }
 
-    private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
+    private void validateHealthCheckReport(final String url, final boolean healthy, final int code,
             final String message, final HealthCheckReport report) {
-        assertEquals(name, report.getName());
+        assertThat(report.getName()).isNotBlank();
         assertEquals(url, report.getUrl());
         assertEquals(healthy, report.isHealthy());
         assertEquals(code, report.getCode());