summaryrefslogtreecommitdiffstats
path: root/client/client-full/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'client/client-full/src/main/java/org/onap')
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java84
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java207
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterException.java49
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java116
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java115
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java211
-rw-r--r--client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/package-info.java27
7 files changed, 809 insertions, 0 deletions
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java
new file mode 100644
index 000000000..3a38dc082
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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.client.full.rest;
+
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.onap.policy.apex.model.utilities.Assertions;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class is used to launch the services. It creates a Grizzly embedded web server and runs the services.
+ */
+public class ApexServicesRest {
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(ApexServicesRest.class);
+
+ // The HTTP server exposing JAX-RS resources defined in this application.
+ private HttpServer server;
+
+ /**
+ * Starts the HTTP server for the Apex services client on the default base URI and with the default REST packages
+ */
+ public ApexServicesRest() {
+ this(new ApexServicesRestParameters());
+ }
+
+ /**
+ * Starts the HTTP server for the Apex services client
+ *
+ * @param parameters: The Apex parameters to use to start the server
+ */
+ public ApexServicesRest(final ApexServicesRestParameters parameters) {
+ Assertions.argumentNotNull(parameters, "parameters may not be null");
+
+ logger.debug("Apex services RESTful client starting . . .");
+
+ // Create a resource configuration that scans for JAX-RS resources and providers
+ // in org.onap.policy.apex.client.full.rest package
+ final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages());
+
+ // Add MultiPartFeature class for jersey-media-multipart
+ rc.register(MultiPartFeature.class);
+
+ // create and start a new instance of grizzly http server
+ // exposing the Jersey application at BASE_URI
+ server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc);
+
+ // Add static content
+ server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
+ ApexServicesRest.class.getClassLoader(), "/webapp/"), parameters.getStaticPath());
+
+ logger.debug("Apex services RESTful client started");
+ }
+
+ /**
+ * Shut down the web server
+ */
+ public void shutdown() {
+ logger.debug("Apex services RESTful client shutting down . . .");
+ server.shutdown();
+ logger.debug("Apex services RESTful client shut down");
+ }
+}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java
new file mode 100644
index 000000000..a9e5db9d0
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java
@@ -0,0 +1,207 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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.client.full.rest;
+
+import java.io.PrintStream;
+
+/**
+ * This class is the main class that is used to launch the Apex editor from the command line.
+ *
+ */
+public class ApexServicesRestMain {
+ /**
+ * The Enum EditorState holds the current state of the editor.
+ */
+ // Editor state
+ public enum EditorState {
+ /** The editor is stopped. */
+ STOPPED,
+ /** The editor is ready to run. */
+ READY,
+ /** The editor is getting ready to run. */
+ INITIALIZING,
+ /** The editor is running. */
+ RUNNING
+ };
+
+ private static final int EDITOR_RNNING_CHECK_TIMEOUT = 1000;
+
+ private EditorState state = EditorState.STOPPED;
+
+ // The Apex editor this class is running
+ private ApexServicesRest apexServices = null;
+
+ // The parameters for the editor
+ private ApexServicesRestParameters parameters = null;
+
+ // Output and error streams for messages
+ private final PrintStream outStream;
+
+ /**
+ * Main method, main entry point for command.
+ *
+ * @param args The command line arguments for the editor
+ */
+ public static void main(final String[] args) {
+ try {
+ final ApexServicesRestMain editorMain = new ApexServicesRestMain(args, System.out);
+ editorMain.init();
+ } catch (final Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Constructor, kicks off the editor.
+ *
+ * @param args The command line arguments for the editor
+ * @param outStream The stream for output messages
+ */
+ public ApexServicesRestMain(final String[] args, final PrintStream outStream) {
+ // Save the streams for output and error
+ this.outStream = outStream;
+
+ // Editor parameter parsing
+ final ApexServicesRestParameterParser parser = new ApexServicesRestParameterParser();
+
+ try {
+ // Get and check the parameters
+ parameters = parser.parse(args);
+ } catch (final ApexServicesRestParameterException e) {
+ throw new ApexServicesRestParameterException(
+ "Apex Editor REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n'
+ + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
+ }
+
+ if (parameters.isHelpSet()) {
+ throw new ApexServicesRestParameterException(parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
+ }
+
+ // Validate the parameters
+ final String validationMessage = parameters.validate();
+ if (validationMessage.length() > 0) {
+ throw new ApexServicesRestParameterException(
+ "Apex Editor REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage
+ + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()));
+ }
+
+ state = EditorState.READY;
+ }
+
+ /**
+ * Initialize the Apex editor.
+ */
+ public void init() {
+ outStream.println("Apex Editor REST endpoint (" + this.toString() + ") starting at "
+ + parameters.getBaseURI().toString() + " . . .");
+
+ try {
+ state = EditorState.INITIALIZING;
+
+ // Start the editor
+ apexServices = new ApexServicesRest(parameters);
+
+ // Add a shutdown hook to shut down the editor when the process is exiting
+ Runtime.getRuntime().addShutdownHook(new Thread(new ApexServicesRestShutdownHook()));
+
+ state = EditorState.RUNNING;
+
+ if (parameters.getTimeToLive() == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE) {
+ outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started at "
+ + parameters.getBaseURI().toString());
+ } else {
+ outStream.println("Apex Editor REST endpoint (" + this.toString() + ") started");
+ }
+
+ // Find out how long is left to wait
+ long timeRemaining = parameters.getTimeToLive();
+ while (timeRemaining == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE || timeRemaining > 0) {
+ // decrement the time to live in the non-infinity case
+ if (timeRemaining > 0) {
+ timeRemaining--;
+ }
+
+ // Wait for a second
+ Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT);
+ }
+ } catch (final Exception e) {
+ outStream.println(
+ "Apex Editor REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage());
+ } finally {
+ if (apexServices != null) {
+ apexServices.shutdown();
+ apexServices = null;
+ }
+ state = EditorState.STOPPED;
+ }
+ }
+
+ /**
+ * Get the editor state.
+ *
+ * @return the state
+ */
+ public EditorState getState() {
+ return state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder ret = new StringBuilder();
+ ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=")
+ .append(this.getState());
+ return ret.toString();
+ }
+
+ /**
+ * Explicitly shut down the editor.
+ */
+ public void shutdown() {
+ if (apexServices != null) {
+ outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shutting down");
+ apexServices.shutdown();
+ }
+ state = EditorState.STOPPED;
+ outStream.println("Apex Editor REST endpoint (" + this.toString() + ") shut down");
+ }
+
+ /**
+ * This class is a shutdown hook for the Apex editor command.
+ */
+ private class ApexServicesRestShutdownHook implements Runnable {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ if (apexServices != null) {
+ apexServices.shutdown();
+ }
+ }
+ }
+}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterException.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterException.java
new file mode 100644
index 000000000..8b966b13f
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterException.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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.client.full.rest;
+
+/**
+ * A run time exception used to report parsing and parameter input errors.
+ *
+ * User: ewatkmi Date: 31 Jul 2017
+ */
+public class ApexServicesRestParameterException extends IllegalArgumentException {
+ private static final long serialVersionUID = 6520231162404452427L;
+
+ /**
+ * Create an ApexServicesRestParameterException with a message
+ *
+ * @param message the message
+ */
+ public ApexServicesRestParameterException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Create an ApexServicesRestParameterException with a message and an exception.
+ *
+ * @param message the message
+ * @param throwable The exception that caused the exception
+ */
+ public ApexServicesRestParameterException(final String message, final Throwable throwable) {
+ super(message, throwable);
+ }
+}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java
new file mode 100644
index 000000000..28b0d4cf4
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameterParser.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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.client.full.rest;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Arrays;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+/**
+ * This class reads and handles command line parameters to the Apex RESTful services
+ *
+ * User: ewatkmi Date: 31 Jul 2017
+ */
+public class ApexServicesRestParameterParser {
+ // Apache Commons CLI options
+ Options options;
+
+ /**
+ * Construct the options for the CLI RESTful services
+ */
+ public ApexServicesRestParameterParser() {
+ options = new Options();
+ options.addOption("h", "help", false, "outputs the usage of this command");
+ options.addOption(Option.builder("p").longOpt("port").desc("port to use for the Apex Services REST calls")
+ .hasArg().argName("PORT").required(false).type(Number.class).build());
+ options.addOption(Option.builder("t").longOpt("time-to-live")
+ .desc("the amount of time in seconds that the server will run for before terminating").hasArg()
+ .argName("TIME_TO_LIVE").required(false).type(Number.class).build());
+ }
+
+ /**
+ * Parse the command line options.
+ *
+ * @param args the arguments
+ * @return parsed parameters
+ */
+ public ApexServicesRestParameters parse(final String[] args) {
+ CommandLine commandLine = null;
+ try {
+ commandLine = new DefaultParser().parse(options, args);
+ } catch (final ParseException e) {
+ throw new ApexServicesRestParameterException(
+ "invalid command line arguments specified : " + e.getMessage());
+ }
+
+ final ApexServicesRestParameters parameters = new ApexServicesRestParameters();
+ final String[] remainingArgs = commandLine.getArgs();
+
+ if (commandLine.getArgs().length > 0) {
+ throw new ApexServicesRestParameterException(
+ "too many command line arguments specified : " + Arrays.toString(remainingArgs));
+ }
+
+ if (commandLine.hasOption('h')) {
+ parameters.setHelp(true);
+ }
+ try {
+ if (commandLine.hasOption('p')) {
+ parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
+ }
+ } catch (final ParseException e) {
+ throw new ApexServicesRestParameterException("error parsing argument \"port\" :" + e.getMessage(), e);
+ }
+ try {
+ if (commandLine.hasOption('t')) {
+ parameters.setTimeToLive(((Number) commandLine.getParsedOptionValue("time-to-live")).longValue());
+ }
+ } catch (final ParseException e) {
+ throw new ApexServicesRestParameterException("error parsing argument \"time-to-live\" :" + e.getMessage(),
+ e);
+ }
+
+ return parameters;
+ }
+
+ /**
+ * Get help information.
+ *
+ * @param mainClassName the main class name for the help output
+ * @return help string
+ */
+ public String getHelp(final String mainClassName) {
+ final StringWriter stringWriter = new StringWriter();
+ final PrintWriter stringPrintWriter = new PrintWriter(stringWriter);
+
+ final HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.printHelp(stringPrintWriter, 120, mainClassName + " [options...] ", "", options, 0, 0, "");
+
+ return stringWriter.toString();
+ }
+}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java
new file mode 100644
index 000000000..17f0eac60
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestParameters.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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.client.full.rest;
+
+import java.net.URI;
+
+/**
+ * This class reads and handles command line parameters to the Apex RESTful services
+ *
+ * User: ewatkmi Date: 31 Jul 2017
+ */
+public class ApexServicesRestParameters {
+ public static final int DEFAULT_REST_PORT = 18989;
+ public static final int INFINITY_TIME_TO_LIVE = -1;
+
+ // Base URI the HTTP server will listen on
+ private static final String DEFAULT_SERVER_URI_ROOT = "http://localhost:";
+ private static final String DEFAULT_REST_PATH = "/apexservices/";
+ private static final String DEFAULT_STATIC_PATH = "/";
+
+ // Package that will field REST requests
+ public static final String[] DEFAULT_PACKAGES = new String[] { "org.onap.policy.apex.client.deployment.rest",
+ "org.onap.policy.apex.client.editor.rest", "org.onap.policy.apex.client.monitoring.rest" };
+
+ // The services parameters
+ private boolean helpSet = false;
+ private int restPort = DEFAULT_REST_PORT;
+ private long timeToLive = INFINITY_TIME_TO_LIVE;
+
+ public String validate() {
+ String validationMessage = "";
+ validationMessage += validatePort();
+ validationMessage += validateTimeToLive();
+
+ return validationMessage;
+ }
+
+ public URI getBaseURI() {
+ return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH);
+ }
+
+ public String[] getRESTPackages() {
+ return DEFAULT_PACKAGES;
+ }
+
+ public String getStaticPath() {
+ return DEFAULT_STATIC_PATH;
+ }
+
+ private String validatePort() {
+ if (restPort < 1024 || restPort > 65535) {
+ return "port must be greater than 1023 and less than 65536\n";
+ } else {
+ return "";
+ }
+ }
+
+ private String validateTimeToLive() {
+ if (timeToLive < -1) {
+ return "time to live must be greater than -1 (set to -1 to wait forever)\n";
+ } else {
+ return "";
+ }
+ }
+
+ public boolean isHelpSet() {
+ return helpSet;
+ }
+
+ public void setHelp(final boolean helpSet) {
+ this.helpSet = helpSet;
+ }
+
+ public int getRESTPort() {
+ return restPort;
+ }
+
+ public void setRESTPort(final int restPort) {
+ this.restPort = restPort;
+ }
+
+ public long getTimeToLive() {
+ return timeToLive;
+ }
+
+ public void setTimeToLive(final long timeToLive) {
+ this.timeToLive = timeToLive;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder ret = new StringBuilder();
+ ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=")
+ .append(this.getTimeToLive()).append("sec");
+ return ret.toString();
+ }
+}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java
new file mode 100644
index 000000000..3384a17f8
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java
@@ -0,0 +1,211 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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.client.full.rest;
+
+import java.util.Map;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class ParameterCheck is used to check parameters passed to the servlet.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public final class ParameterCheck {
+ private static final int MAX_PORT = 65535;
+
+ /**
+ * private constructor to prevent subclassing of this utility class.
+ */
+ private ParameterCheck() {}
+
+ /**
+ * The Enum StartStop is used to hold .
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+ public enum StartStop {
+ /** Start of an Apex engine has been ordered. */
+ START,
+ /** Stop of an Apex engine has been ordered. */
+ STOP
+ };
+
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ParameterCheck.class);
+
+ private static final String HOSTNAME_PAR = "hostname";
+ private static final String PORT_PAR = "port";
+ private static final String AXARTIFACTKEY_PAR = "AxArtifactKey";
+
+ /**
+ * Gets the host name.
+ *
+ * @param parameterMap the parameter map
+ * @return the host name
+ */
+ public static String getHostName(final Map<String, String[]> parameterMap) {
+ if (!parameterMap.containsKey(HOSTNAME_PAR)) {
+ LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found");
+ return null;
+ }
+
+ final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR);
+
+ if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) {
+ LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found");
+ return null;
+ }
+
+ return hostNameValue[0];
+ }
+
+ /**
+ * Gets the port.
+ *
+ * @param parameterMap the parameter map
+ * @return the port
+ */
+ public static int getPort(final Map<String, String[]> parameterMap) {
+ if (!parameterMap.containsKey(PORT_PAR)) {
+ LOGGER.warn("parameter \"" + PORT_PAR + "\" not found");
+ return -1;
+ }
+
+ final String[] portValue = parameterMap.get(PORT_PAR);
+
+ if (portValue.length == 0 || portValue[0].trim().length() == 0) {
+ LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found");
+ return -1;
+ }
+
+ int port = -1;
+ try {
+ port = Integer.parseInt(portValue[0]);
+ } catch (final Exception e) {
+ LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e);
+ return -1;
+ }
+
+ if (port <= 0 || port > MAX_PORT) {
+ LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR
+ + "\" not a valid port between 0 and 65535");
+ return -1;
+ }
+
+ return port;
+ }
+
+ /**
+ * Gets the engine key.
+ *
+ * @param parameterMap the parameter map
+ * @return the engine key
+ */
+ public static AxArtifactKey getEngineKey(final Map<String, String[]> parameterMap) {
+ String artifactKeyParameter = null;
+ for (final String parameter : parameterMap.keySet()) {
+ // Check for an AxArtifactKey parameter
+ if (parameter.startsWith(AXARTIFACTKEY_PAR)) {
+ artifactKeyParameter = parameter;
+ break;
+ }
+ }
+ if (artifactKeyParameter == null) {
+ LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found");
+ return null;
+ }
+
+ final String[] axArtifactKeyArray = artifactKeyParameter.split("#");
+
+ if (axArtifactKeyArray.length != 2) {
+ LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid");
+ return null;
+ }
+
+ return new AxArtifactKey(axArtifactKeyArray[1]);
+ }
+
+ /**
+ * Gets the start stop.
+ *
+ * @param parameterMap the parameter map
+ * @param engineKey the engine key
+ * @return the start stop
+ */
+ public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap,
+ final AxArtifactKey engineKey) {
+ final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getID();
+ if (!parameterMap.containsKey(startStopPar)) {
+ LOGGER.warn("parameter \"" + startStopPar + "\" not found");
+ return null;
+ }
+
+ final String[] startStopValue = parameterMap.get(startStopPar);
+
+ if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) {
+ LOGGER.warn("value of parameter \"" + startStopPar + "\" not found");
+ return null;
+ }
+
+ ParameterCheck.StartStop startStop;
+ if (startStopValue[0].equalsIgnoreCase("start")) {
+ startStop = ParameterCheck.StartStop.START;
+ } else if (startStopValue[0].equalsIgnoreCase("stop")) {
+ startStop = ParameterCheck.StartStop.STOP;
+ } else {
+ LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar
+ + "\" not \"start\" or \"stop\"");
+ return null;
+ }
+
+ return startStop;
+ }
+
+ /**
+ * Find and return a long value with the given name.
+ *
+ * @param parameterMap The parameter map containing the value
+ * @param longName The name of the long parameter
+ * @return The long value
+ */
+ public static long getLong(final Map<String, String[]> parameterMap, final String longName) {
+ if (!parameterMap.containsKey(longName)) {
+ LOGGER.warn("parameter \"" + longName + "\" not found");
+ return -1;
+ }
+
+ final String[] longValue = parameterMap.get(longName);
+
+ if (longValue.length == 0 || longValue[0].trim().length() == 0) {
+ LOGGER.warn("value of parameter \"" + longName + "\" not found");
+ return -1;
+ }
+
+ try {
+ return Long.parseLong(longValue[0]);
+ } catch (final Exception e) {
+ LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e);
+ return -1;
+ }
+ }
+}
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/package-info.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/package-info.java
new file mode 100644
index 000000000..de6130363
--- /dev/null
+++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/package-info.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * 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=========================================================
+ */
+
+/**
+ * Implements the RESTful client with full functionality.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+package org.onap.policy.apex.client.full.rest;