summaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-onappf/src/main/java')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterActivator.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterActivator.java)47
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterCommandLineArguments.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterCommandLineArguments.java)6
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterConstants.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterConstants.java)6
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterMain.java)20
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpStateChangeListener.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpStateChangeListener.java)4
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpStatusPublisher.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpStatusPublisher.java)15
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpUpdateListener.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpUpdateListener.java)4
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/exception/ApexStarterException.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/exception/ApexStarterException.java)2
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/exception/ApexStarterRunTimeException.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/exception/ApexStarterRunTimeException.java)2
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/engine/ApexEngineHandler.java)25
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpMessageHandler.java)20
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpStateChangeMessageHandler.java)31
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpUpdateMessageHandler.java)45
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ApexStarterParameterGroup.java)4
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ApexStarterParameterHandler.java)6
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/PdpStatusParameters.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/PdpStatusParameters.java)2
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/RestServerParameters.java52
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ToscaPolicyTypeIdentifierParameters.java (renamed from services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ToscaPolicyTypeIdentifierParameters.java)2
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterAafFilter.java39
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterRestServer.java150
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckProvider.java58
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckRestControllerV1.java86
22 files changed, 523 insertions, 103 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterActivator.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterActivator.java
index b33d792a0..e08b5b344 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterActivator.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterActivator.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
import java.util.List;
import java.util.Properties;
@@ -26,13 +26,14 @@ import java.util.Properties;
import lombok.Getter;
import lombok.Setter;
-import org.onap.policy.apex.starter.comm.PdpStateChangeListener;
-import org.onap.policy.apex.starter.comm.PdpStatusPublisher;
-import org.onap.policy.apex.starter.comm.PdpUpdateListener;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.exception.ApexStarterRunTimeException;
-import org.onap.policy.apex.starter.handler.PdpMessageHandler;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.comm.PdpStateChangeListener;
+import org.onap.policy.apex.services.onappf.comm.PdpStatusPublisher;
+import org.onap.policy.apex.services.onappf.comm.PdpUpdateListener;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException;
+import org.onap.policy.apex.services.onappf.handler.PdpMessageHandler;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.rest.ApexStarterRestServer;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -56,6 +57,7 @@ public class ApexStarterActivator {
private List<TopicSink> topicSinks;// topics to which apex-pdp sends pdp status
private List<TopicSource> topicSources; // topics to which apex-pdp listens to for messages from pap.
private static final String[] MSG_TYPE_NAMES = { "messageName" };
+
/**
* Listens for messages on the topic, decodes them into a message, and then dispatches them.
*/
@@ -66,10 +68,21 @@ public class ApexStarterActivator {
*/
private ServiceManager manager;
+ /**
+ * The ApexStarter REST API server.
+ */
+ private ApexStarterRestServer restServer;
+
@Getter
@Setter(lombok.AccessLevel.PRIVATE)
private volatile boolean alive = false;
+ /**
+ * Instantiate the activator for onappf PDP-A.
+ *
+ * @param apexStarterParameterGroup the parameters for the onappf PDP-A service
+ * @param topicProperties properties used to configure the topics
+ */
public ApexStarterActivator(final ApexStarterParameterGroup apexStarterParameterGroup,
final Properties topicProperties) {
@@ -118,7 +131,15 @@ public class ApexStarterActivator {
() -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name()))
.addAction("Message Dispatcher",
() -> registerMsgDispatcher(),
- () -> unregisterMsgDispatcher());
+ () -> unregisterMsgDispatcher())
+ .addAction("Create REST server",
+ () -> restServer =
+ new ApexStarterRestServer(apexStarterParameterGroup.getRestServerParameters()),
+ () -> restServer = null)
+ .addAction("Rest Server",
+ () -> restServer.start(),
+ () -> restServer.stop());
+
// @formatter:on
}
@@ -128,8 +149,6 @@ public class ApexStarterActivator {
private void stopAndRemovePdpStatusPublisher() {
final PdpStatusPublisher pdpStatusPublisher =
Registry.get(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER, PdpStatusPublisher.class);
- // send a final heartbeat with terminated status
- pdpStatusPublisher.send(new PdpMessageHandler().getTerminatedPdpStatus());
pdpStatusPublisher.terminate();
Registry.unregister(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER);
}
@@ -164,6 +183,10 @@ public class ApexStarterActivator {
throw new IllegalStateException("activator is not running");
}
try {
+ final PdpStatusPublisher pdpStatusPublisher =
+ Registry.get(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER, PdpStatusPublisher.class);
+ // send a final heartbeat with terminated status
+ pdpStatusPublisher.send(new PdpMessageHandler().getTerminatedPdpStatus());
manager.stop();
Registry.unregister(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR);
} catch (final ServiceManagerException exp) {
@@ -175,7 +198,7 @@ public class ApexStarterActivator {
/**
* Get the parameters used by the activator.
*
- * @return the parameters of the activator
+ * @return apexStarterParameterGroup the parameters of the activator
*/
public ApexStarterParameterGroup getParameterGroup() {
return apexStarterParameterGroup;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterCommandLineArguments.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterCommandLineArguments.java
index f1d082fcb..152182b52 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterCommandLineArguments.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterCommandLineArguments.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
import java.io.File;
import java.io.PrintWriter;
@@ -33,8 +33,8 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.chainsaw.Main;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.exception.ApexStarterRunTimeException;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException;
import org.onap.policy.common.utils.resources.ResourceUtils;
/**
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterConstants.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterConstants.java
index 6173872e0..2481f4ef7 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterConstants.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterConstants.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
/**
* Names of various items contained in the Registry.
@@ -31,4 +31,8 @@ public class ApexStarterConstants {
public static final String REG_PDP_STATUS_PUBLISHER = "object:pdp/status/publisher";
public static final String REG_APEX_PDP_TOPIC_SINKS = "object:apex/pdp/topic/sinks";
public static final String REG_APEX_ENGINE_HANDLER = "object:engine/apex/handler";
+
+ private ApexStarterConstants() {
+ super();
+ }
}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterMain.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java
index e4465ed92..4813eb356 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterMain.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/ApexStarterMain.java
@@ -18,15 +18,15 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Properties;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterHandler;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.common.utils.services.Registry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +38,8 @@ import org.slf4j.LoggerFactory;
*/
public class ApexStarterMain {
+ private static final String APEX_STARTER_FAIL_MSG = "start of services-onappf failed";
+
private static final Logger LOGGER = LoggerFactory.getLogger(ApexStarterMain.class);
private ApexStarterActivator activator;
@@ -48,7 +50,7 @@ public class ApexStarterMain {
*
* @param args the command line arguments
*/
- ApexStarterMain(final String[] args) {
+ public ApexStarterMain(final String[] args) {
LOGGER.info("In ApexStarter with parameters " + Arrays.toString(args));
// Check the arguments
@@ -63,7 +65,7 @@ public class ApexStarterMain {
// Validate that the arguments are sane
arguments.validate();
} catch (final ApexStarterException e) {
- LOGGER.error("start of ApexStarter failed", e);
+ LOGGER.error(APEX_STARTER_FAIL_MSG, e);
return;
}
@@ -71,7 +73,7 @@ public class ApexStarterMain {
try {
parameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
} catch (final Exception e) {
- LOGGER.error("start of ApexStarter failed", e);
+ LOGGER.error(APEX_STARTER_FAIL_MSG, e);
return;
}
@@ -83,7 +85,7 @@ public class ApexStarterMain {
topicProperties.load(stream);
}
} catch (final Exception e) {
- LOGGER.error("start of ApexStarter failed", e);
+ LOGGER.error(APEX_STARTER_FAIL_MSG, e);
return;
}
@@ -108,7 +110,7 @@ public class ApexStarterMain {
/**
* Get the parameters specified in JSON.
*
- * @return the parameters
+ * @return parameterGroup the parameters
*/
public ApexStarterParameterGroup getParameters() {
return parameterGroup;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpStateChangeListener.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpStateChangeListener.java
index 0bd0d935f..404749051 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpStateChangeListener.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpStateChangeListener.java
@@ -18,9 +18,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.comm;
+package org.onap.policy.apex.services.onappf.comm;
-import org.onap.policy.apex.starter.handler.PdpStateChangeMessageHandler;
+import org.onap.policy.apex.services.onappf.handler.PdpStateChangeMessageHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.listeners.ScoListener;
import org.onap.policy.common.utils.coder.StandardCoderObject;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpStatusPublisher.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpStatusPublisher.java
index 69c9dd18d..9a61084ca 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpStatusPublisher.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpStatusPublisher.java
@@ -18,13 +18,13 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.comm;
+package org.onap.policy.apex.services.onappf.comm;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
-import org.onap.policy.apex.starter.handler.PdpMessageHandler;
+import org.onap.policy.apex.services.onappf.handler.PdpMessageHandler;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -45,11 +45,10 @@ public class PdpStatusPublisher extends TimerTask {
private long interval;
/**
- * Constructor for instantiating PdpStatusPublisher
+ * Constructor for instantiating PdpStatusPublisher.
*
- * @param pdpStatus
- * @param topicSinks
- * @param apexStarterParameterGroup
+ * @param topicSinks the topic sinks
+ * @param interval time interval to send pdp status
*/
public PdpStatusPublisher(final List<TopicSink> topicSinks, final long interval) {
this.topicSinkClient = new TopicSinkClient(topicSinks.get(0));
@@ -76,7 +75,7 @@ public class PdpStatusPublisher extends TimerTask {
/**
* Get the current time interval used by the timer task.
*
- * @return interval
+ * @return interval the current time interval
*/
public long getInterval() {
return interval;
@@ -84,6 +83,8 @@ public class PdpStatusPublisher extends TimerTask {
/**
* Method to send pdp status message to pap on demand.
+ *
+ * @param pdpStatus the pdp status
*/
public void send(final PdpStatus pdpStatus) {
topicSinkClient.send(pdpStatus);
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpUpdateListener.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpUpdateListener.java
index 46ce30e57..5633d60fb 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/comm/PdpUpdateListener.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/comm/PdpUpdateListener.java
@@ -18,9 +18,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.comm;
+package org.onap.policy.apex.services.onappf.comm;
-import org.onap.policy.apex.starter.handler.PdpUpdateMessageHandler;
+import org.onap.policy.apex.services.onappf.handler.PdpUpdateMessageHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.listeners.ScoListener;
import org.onap.policy.common.utils.coder.StandardCoderObject;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/exception/ApexStarterException.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/exception/ApexStarterException.java
index 7062e377b..461d758c9 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/exception/ApexStarterException.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/exception/ApexStarterException.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.exception;
+package org.onap.policy.apex.services.onappf.exception;
/**
* This exception will be called if an error occurs in apex starter.
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/exception/ApexStarterRunTimeException.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/exception/ApexStarterRunTimeException.java
index f15b55d33..a1c970a56 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/exception/ApexStarterRunTimeException.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/exception/ApexStarterRunTimeException.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.exception;
+package org.onap.policy.apex.services.onappf.exception;
/**
* This runtime exception will be called if a runtime error occurs when using apex starter.
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/engine/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index e58b0db76..85d666c2b 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/engine/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.engine;
+package org.onap.policy.apex.services.onappf.handler;
import com.google.gson.JsonObject;
@@ -30,7 +30,7 @@ import java.nio.file.Path;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.slf4j.Logger;
@@ -49,9 +49,8 @@ public class ApexEngineHandler {
/**
* Constructs the object. Extracts the apex config and model files and instantiates the apex engine.
*
- * @param properties
- * @return ApexEngineHandler
- * @throws ApexStarterException
+ * @param properties the properties which contains the policies and configurations received from pap
+ * @throws ApexStarterException if the apex engine instantiation failed using the properties passed
*/
public ApexEngineHandler(final String properties) throws ApexStarterException {
@@ -70,17 +69,17 @@ public class ApexEngineHandler {
final String modelFilePath = createFile(policyModel, "modelFile");
final String apexConfigFilePath = createFile(apexConfig, "apexConfigFile");
- final String[] apexArgs = { "-rfr", "target/classes", "-c", apexConfigFilePath, "-m", modelFilePath };
+ final String[] apexArgs = { "-c", apexConfigFilePath, "-m", modelFilePath };
LOGGER.debug("Starting apex engine.");
apexMain = new ApexMain(apexArgs);
}
/**
- * Method to create the policy model file
+ * Method to create the policy model file.
*
- * @param policyModel
- * @param modelFilePath
- * @throws ApexStarterException
+ * @param fileContent the content of the file
+ * @param fileName the name of the file
+ * @throws ApexStarterException if the file creation failed
*/
private String createFile(final String fileContent, final String fileName) throws ApexStarterException {
try {
@@ -94,10 +93,16 @@ public class ApexEngineHandler {
}
}
+ /**
+ * Method to check whether the apex engine is running or not.
+ */
public boolean isApexEngineRunning() {
return null != apexMain;
}
+ /**
+ * Method to shut down the apex engine.
+ */
public void shutdown() throws ApexStarterException {
try {
LOGGER.debug("Shutting down apex engine.");
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
index be76938f3..b72ef805f 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
@@ -18,14 +18,14 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.handler;
+package org.onap.policy.apex.services.onappf.handler;
import java.util.ArrayList;
import java.util.List;
-import org.onap.policy.apex.starter.ApexStarterConstants;
-import org.onap.policy.apex.starter.parameters.PdpStatusParameters;
-import org.onap.policy.apex.starter.parameters.ToscaPolicyTypeIdentifierParameters;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.parameters.PdpStatusParameters;
+import org.onap.policy.apex.services.onappf.parameters.ToscaPolicyTypeIdentifierParameters;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -44,12 +44,12 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
public class PdpMessageHandler {
/**
- * Method to create PdpStatus message from the parameters which will be saved to the context
+ * Method to create PdpStatus message from the parameters which will be saved to the context.
*
* @param instanceId instance id of apex pdp
* @param pdpStatusParameters pdp status parameters read from the configuration file
*
- * @return PdpStatus the pdp status message
+ * @return pdpStatus the pdp status message
*/
public PdpStatus createPdpStatusFromParameters(final String instanceId,
final PdpStatusParameters pdpStatusParameters) {
@@ -66,8 +66,8 @@ public class PdpMessageHandler {
/**
* Method to get supported policy types from the parameters.
*
- * @param pdpStatusParameters
- * @return list of PolicyTypeIdent
+ * @param pdpStatusParameters pdp status parameters
+ * @return supportedPolicyTypes list of PolicyTypeIdent
*/
private List<ToscaPolicyTypeIdentifier> getSupportedPolicyTypesFromParameters(
final PdpStatusParameters pdpStatusParameters) {
@@ -104,9 +104,7 @@ public class PdpMessageHandler {
/**
* Method to get a final pdp status when the apex started is shutting down.
*
- * @param policies list of ToscaPolicy
- *
- * @return PdpStatus
+ * @return PdpStatus the pdp status message
*/
public PdpStatus getTerminatedPdpStatus() {
final PdpStatus pdpStatusInContext = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT, PdpStatus.class);
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpStateChangeMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
index 9f97fb24b..d2c7786ca 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpStateChangeMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
@@ -18,14 +18,13 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.handler;
+package org.onap.policy.apex.services.onappf.handler;
import java.util.List;
-import org.onap.policy.apex.starter.ApexStarterConstants;
-import org.onap.policy.apex.starter.comm.PdpStatusPublisher;
-import org.onap.policy.apex.starter.engine.ApexEngineHandler;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.comm.PdpStatusPublisher;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
@@ -33,6 +32,8 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This class supports the handling of pdp state change messages.
@@ -41,6 +42,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
*/
public class PdpStateChangeMessageHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PdpStateChangeMessageHandler.class);
+
/**
* Method which handles a pdp state change event from PAP.
*
@@ -73,10 +76,10 @@ public class PdpStateChangeMessageHandler {
/**
* Method to handle when the new state from pap is active.
*
- * @param pdpStateChangeMsg
- * @param pdpStatusContext
- * @param pdpMessageHandler
- * @return pdpResponseDetails
+ * @param pdpStateChangeMsg pdp state change message
+ * @param pdpStatusContext pdp status object in memory
+ * @param pdpMessageHandler the pdp message handler
+ * @return pdpResponseDetails pdp response
*/
private PdpResponseDetails handleActiveState(final PdpStateChange pdpStateChangeMsg,
final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
@@ -99,6 +102,7 @@ public class PdpStateChangeMessageHandler {
PdpResponseStatus.SUCCESS, "Apex engine started. State changed to active.");
pdpStatusContext.setState(PdpState.ACTIVE);
} catch (final ApexStarterException e) {
+ LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
@@ -110,10 +114,10 @@ public class PdpStateChangeMessageHandler {
/**
* Method to handle when the new state from pap is passive.
*
- * @param pdpStateChangeMsg
- * @param pdpStatusContext
- * @param pdpMessageHandler
- * @return pdpResponseDetails
+ * @param pdpStateChangeMsg pdp state change message
+ * @param pdpStatusContext pdp status object in memory
+ * @param pdpMessageHandler the pdp message handler
+ * @return pdpResponseDetails pdp response
*/
private PdpResponseDetails handlePassiveState(final PdpStateChange pdpStateChangeMsg,
final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
@@ -129,6 +133,7 @@ public class PdpStateChangeMessageHandler {
PdpResponseStatus.SUCCESS, "Apex pdp state changed from Active to Passive.");
pdpStatusContext.setState(PdpState.PASSIVE);
} catch (final Exception e) {
+ LOGGER.error("Stopping apex engine failed. State cannot be changed to Passive.", e);
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL,
"Stopping apex engine failed. State cannot be changed to Passive." + e.getMessage());
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
index 5198c229e..31963ddc0 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpUpdateMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
@@ -18,14 +18,13 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.handler;
+package org.onap.policy.apex.services.onappf.handler;
import java.util.List;
-import org.onap.policy.apex.starter.ApexStarterConstants;
-import org.onap.policy.apex.starter.comm.PdpStatusPublisher;
-import org.onap.policy.apex.starter.engine.ApexEngineHandler;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.comm.PdpStatusPublisher;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
@@ -33,6 +32,8 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This class supports the handling of pdp update messages.
@@ -41,6 +42,8 @@ import org.onap.policy.models.pdp.enums.PdpState;
*/
public class PdpUpdateMessageHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PdpUpdateMessageHandler.class);
+
/**
* Method which handles a pdp update event from PAP.
*
@@ -53,7 +56,7 @@ public class PdpUpdateMessageHandler {
if (pdpUpdateMsg.appliesTo(pdpStatusContext.getName(), pdpStatusContext.getPdpGroup(),
pdpStatusContext.getPdpSubgroup())) {
final PdpStatusPublisher pdpStatusPublisher = Registry.get(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER);
- if (checkIfAlreadyHandled(pdpUpdateMsg, pdpStatusContext, pdpStatusPublisher.getInterval())) {
+ if (checkIfAlreadyHandled(pdpUpdateMsg, pdpStatusContext)) {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already updated");
} else {
@@ -66,8 +69,7 @@ public class PdpUpdateMessageHandler {
pdpStatusContext
.setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
- pdpResponseDetails =
- startOrStopApexEngineBasedOnPolicies(pdpUpdateMsg, pdpMessageHandler, pdpStatusContext);
+ pdpResponseDetails = startOrStopApexEngineBasedOnPolicies(pdpUpdateMsg, pdpMessageHandler);
}
Registry.registerOrReplace(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies());
if (null == pdpResponseDetails) {
@@ -89,13 +91,13 @@ public class PdpUpdateMessageHandler {
* active, if PAP sends PdpUpdate with empty policies list, stop apex engine, or, if there is a change in policies,
* stop the current running policies and the deploy the new ones.
*
- * @param pdpUpdateMsg
- * @param pdpMessageHandler
- * @param pdpStatusContext
- * @return pdpResponseDetails
+ * @param pdpUpdateMsg the pdp update message from pap
+ * @param pdpMessageHandler pdp message handler
+ * @param pdpStatusContext the pdp status object in memory
+ * @return pdpResponseDetails the pdp response
*/
private PdpResponseDetails startOrStopApexEngineBasedOnPolicies(final PdpUpdate pdpUpdateMsg,
- final PdpMessageHandler pdpMessageHandler, final PdpStatus pdpStatusContext) {
+ final PdpMessageHandler pdpMessageHandler) {
PdpResponseDetails pdpResponseDetails = null;
if (pdpUpdateMsg.getPolicies().isEmpty()) {
final ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER);
@@ -103,6 +105,7 @@ public class PdpUpdateMessageHandler {
try {
apexEngineHandler.shutdown();
} catch (final ApexStarterException e) {
+ LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Pdp update failed as the policies couldn't be undeployed.");
}
@@ -119,6 +122,7 @@ public class PdpUpdateMessageHandler {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Apex engine started and policies are running.");
} catch (final ApexStarterException e) {
+ LOGGER.error("Apex engine service running failed. ", e);
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
@@ -127,26 +131,19 @@ public class PdpUpdateMessageHandler {
}
/**
- * Method checks of the Pdp update message is already handled by checking the values in the context.
+ * Method checks if the Pdp update message is already handled by checking the values in the context.
*
* @param pdpUpdateMsg pdp update message received from pap
* @param pdpStatusContext values saved in context memory
- * @param interval the current interval in which the pdp status publisher is sending the heartbeats
* @return boolean flag which tells if the information is same or not
*/
- private boolean checkIfAlreadyHandled(final PdpUpdate pdpUpdateMsg, final PdpStatus pdpStatusContext,
- final long interval) {
+ private boolean checkIfAlreadyHandled(final PdpUpdate pdpUpdateMsg, final PdpStatus pdpStatusContext) {
return null != pdpStatusContext.getPdpGroup()
&& pdpStatusContext.getPdpGroup().equals(pdpUpdateMsg.getPdpGroup())
&& null != pdpStatusContext.getPdpSubgroup()
&& pdpStatusContext.getPdpSubgroup().equals(pdpUpdateMsg.getPdpSubgroup())
- && null != pdpStatusContext.getPolicies()
- && new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies())
- .equals(pdpStatusContext.getPolicies())
- && (null == pdpUpdateMsg.getPdpHeartbeatIntervalMs()
- || (null != pdpUpdateMsg.getPdpHeartbeatIntervalMs()
- && pdpUpdateMsg.getPdpHeartbeatIntervalMs() > 0
- && interval == pdpUpdateMsg.getPdpHeartbeatIntervalMs()));
+ && null != pdpStatusContext.getPolicies() && new PdpMessageHandler()
+ .getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()).equals(pdpStatusContext.getPolicies());
}
/**
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ApexStarterParameterGroup.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java
index 68299480e..db51803be 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ApexStarterParameterGroup.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import lombok.Getter;
@@ -35,7 +35,7 @@ import org.onap.policy.common.parameters.annotations.NotNull;
@NotBlank
@Getter
public class ApexStarterParameterGroup extends ParameterGroupImpl {
-
+ private RestServerParameters restServerParameters;
private PdpStatusParameters pdpStatusParameters;
/**
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ApexStarterParameterHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java
index dae4b8334..ed7c00f10 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ApexStarterParameterHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java
@@ -18,12 +18,12 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import java.io.File;
-import org.onap.policy.apex.starter.ApexStarterCommandLineArguments;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/PdpStatusParameters.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/PdpStatusParameters.java
index fbc94193d..962a98e4c 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/PdpStatusParameters.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/PdpStatusParameters.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import java.util.List;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/RestServerParameters.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/RestServerParameters.java
new file mode 100644
index 000000000..fafca0c9e
--- /dev/null
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/RestServerParameters.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.services.onappf.parameters;
+
+import lombok.Getter;
+
+import org.onap.policy.common.parameters.ParameterGroupImpl;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+
+/**
+ * Class to hold all parameters needed for services-onappf rest server.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+@NotNull
+@NotBlank
+@Getter
+public class RestServerParameters extends ParameterGroupImpl {
+ private String host;
+
+ @Min(value = 1)
+ private int port;
+
+ private String userName;
+ private String password;
+ private boolean https;
+ private boolean aaf;
+
+ public RestServerParameters() {
+ super("RestServerParameters");
+ }
+}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ToscaPolicyTypeIdentifierParameters.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ToscaPolicyTypeIdentifierParameters.java
index 37e27492e..a08b9347c 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/starter/parameters/ToscaPolicyTypeIdentifierParameters.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ToscaPolicyTypeIdentifierParameters.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import lombok.EqualsAndHashCode;
import lombok.Getter;
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterAafFilter.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterAafFilter.java
new file mode 100644
index 000000000..2745a79f9
--- /dev/null
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterAafFilter.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.services.onappf.rest;
+
+import org.onap.policy.common.endpoints.http.server.aaf.AafGranularAuthFilter;
+
+/**
+ * Class to manage aaf filters for services-onappf component.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ApexStarterAafFilter extends AafGranularAuthFilter {
+
+ public static final String AAF_NODETYPE = "policy-apex-pdp";
+ public static final String AAF_ROOT_PERMISSION = DEFAULT_NAMESPACE + "." + AAF_NODETYPE;
+
+ @Override
+ public String getPermissionTypeRoot() {
+ return AAF_ROOT_PERMISSION;
+ }
+}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterRestServer.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterRestServer.java
new file mode 100644
index 000000000..02e1fcf70
--- /dev/null
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/ApexStarterRestServer.java
@@ -0,0 +1,150 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.services.onappf.rest;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.onap.policy.apex.services.onappf.parameters.RestServerParameters;
+import org.onap.policy.common.capabilities.Startable;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class to manage life cycle of services-onappf rest server.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ApexStarterRestServer implements Startable {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApexStarterRestServer.class);
+
+ private List<HttpServletServer> servers = new ArrayList<>();
+
+ private RestServerParameters restServerParameters;
+
+ /**
+ * Constructor for instantiating ApexStarterRestServer.
+ *
+ * @param restServerParameters the rest server parameters
+ */
+ public ApexStarterRestServer(final RestServerParameters restServerParameters) {
+ this.restServerParameters = restServerParameters;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public boolean start() {
+ try {
+ servers = HttpServletServer.factory.build(getServerProperties());
+ for (final HttpServletServer server : servers) {
+ if (server.isAaf()) {
+ server.addFilterClass(null, ApexStarterAafFilter.class.getCanonicalName());
+ }
+ server.start();
+ }
+ } catch (final Exception exp) {
+ LOGGER.error("Failed to start services-onappf http server", exp);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Creates the server properties object using restServerParameters.
+ *
+ * @return the properties object
+ */
+ private Properties getServerProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, restServerParameters.getName());
+
+ final String svcpfx =
+ PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + restServerParameters.getName();
+
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, restServerParameters.getHost());
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
+ Integer.toString(restServerParameters.getPort()));
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
+ HealthCheckRestControllerV1.class.getCanonicalName());
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "false");
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "true");
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX,
+ restServerParameters.getUserName());
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX,
+ restServerParameters.getPassword());
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX,
+ String.valueOf(restServerParameters.isHttps()));
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX,
+ String.valueOf(restServerParameters.isAaf()));
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
+ GsonMessageBodyHandler.class.getName());
+ return props;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public boolean stop() {
+ for (final HttpServletServer server : servers) {
+ try {
+ server.stop();
+ } catch (final Exception exp) {
+ LOGGER.error("Failed to stop services-onappf http server", exp);
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void shutdown() {
+ stop();
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public boolean isAlive() {
+ return !servers.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("ApexStarterRestServer [servers=");
+ builder.append(servers);
+ builder.append("]");
+ return builder.toString();
+ }
+}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckProvider.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckProvider.java
new file mode 100644
index 000000000..12a34ef57
--- /dev/null
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckProvider.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.services.onappf.rest;
+
+import org.onap.policy.apex.services.onappf.ApexStarterActivator;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.common.utils.services.Registry;
+
+/**
+ * Class to fetch health check of ApexStarter service.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+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.
+ *
+ * @return Report containing health check status
+ */
+ public HealthCheckReport performHealthCheck() {
+ final HealthCheckReport report = new HealthCheckReport();
+ report.setName(NAME);
+ 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);
+ return report;
+ }
+}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckRestControllerV1.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckRestControllerV1.java
new file mode 100644
index 000000000..53efa5940
--- /dev/null
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/rest/HealthCheckRestControllerV1.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.services.onappf.rest;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Authorization;
+import io.swagger.annotations.BasicAuthDefinition;
+import io.swagger.annotations.Info;
+import io.swagger.annotations.SecurityDefinition;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.annotations.Tag;
+
+import java.net.HttpURLConnection;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.onap.policy.common.endpoints.report.HealthCheckReport;
+
+/**
+ * Class to provide REST endpoints for services-onappf component health check.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+//@formatter:off
+@Path("/policy/apex-pdp/v1")
+@Api(value = "PDP-A API")
+@Produces(MediaType.APPLICATION_JSON)
+@SwaggerDefinition(
+ info = @Info(description =
+ "PDP-A is responsible for making policy decisions and for managing the administrative"
+ + " state of the PDPs as directed by PolicyAdministration", version = "v1.0",
+ title = "PDP-A"),
+ consumes = {MediaType.APPLICATION_JSON},
+ produces = {MediaType.APPLICATION_JSON},
+ schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
+ tags = {@Tag(name = "PDP-A", description = "PDP-A Operations")},
+ securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+//@formatter:on
+public class HealthCheckRestControllerV1 {
+
+ public static final String AUTHORIZATION_TYPE = "basicAuth";
+
+ public static final int AUTHENTICATION_ERROR_CODE = HttpURLConnection.HTTP_UNAUTHORIZED;
+ public static final int AUTHORIZATION_ERROR_CODE = HttpURLConnection.HTTP_FORBIDDEN;
+ public static final int SERVER_ERROR_CODE = HttpURLConnection.HTTP_INTERNAL_ERROR;
+
+ public static final String AUTHENTICATION_ERROR_MESSAGE = "Authentication Error";
+ public static final String AUTHORIZATION_ERROR_MESSAGE = "Authorization Error";
+ public static final String SERVER_ERROR_MESSAGE = "Internal Server Error";
+
+ @GET
+ @Path("healthcheck")
+ @ApiOperation(value = "Perform healthcheck", notes = "Returns healthy status of the PDP-A component",
+ response = HealthCheckReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
+ @ApiResponses(value = { @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) })
+ public Response healthcheck() {
+ return Response.status(Response.Status.OK).entity(new HealthCheckProvider().performHealthCheck()).build();
+ }
+}