summaryrefslogtreecommitdiffstats
path: root/main/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-03-12 11:53:22 -0400
committerJim Hahn <jrh3@att.com>2019-03-13 16:26:27 -0400
commit4a3cfdff6285a516f1e05d4cebd748ea623177e5 (patch)
tree326e5d97e6e731d93ef355cc441295a9cf67ba16 /main/src/main
parentd8e7fa11c3bab410f41a4161f9f736eab5b2e3ec (diff)
Add PDP Group Deploy and Delete REST API stubs
Note: this will not build until the models-pap code has been added. Added PDP group Delete methods, with and without version. Added checks for OK status codes. Added topic configuration. Still does not have the "simplified" PDP Group deploy/undeploy. Still won't build without "Move PDP Group classes to concepts subdirectory". Will add junit tests for code changes in another review. Updated comments about unlocking after updates. Made ServiceManager final. Included topic start/stop actions. Fixed parameter comment. Removed unneeded parameters from json files. Fixed argument test in shell script. Updated licenses. Change-Id: I6176d51918ae758e04fb68562dc9ca70534137d4 Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpClient.java101
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpClientException.java49
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java70
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/RestServerParameters.java141
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java61
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java4
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java132
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java58
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java88
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java57
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/Main.java18
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java61
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java54
13 files changed, 532 insertions, 362 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpClient.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpClient.java
deleted file mode 100644
index 7919912a..00000000
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpClient.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP PAP
- * ================================================================================
- * Copyright (C) 2019 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.
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pap.main.comm;
-
-import java.util.List;
-import lombok.Getter;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Client for communication with PDPs.
- */
-public class PdpClient {
- private static final Logger logger = LoggerFactory.getLogger(PdpClient.class);
-
- /**
- * Coder used to encode messages being sent to PDPs.
- */
- private static final Coder CODER = new StandardCoder();
-
- /**
- * Topic to which messages are published.
- */
- @Getter
- private final String topic;
-
- /**
- * Where messages are published.
- */
- private final TopicSink sink;
-
- /**
- * Constructs the object.
- *
- * @param topic topic to which messages should be published
- * @throws PdpClientException if the topic does not exist
- */
- public PdpClient(String topic) throws PdpClientException {
- this.topic = topic;
-
- List<TopicSink> lst = getTopicSinks(topic);
- if (lst.isEmpty()) {
- throw new PdpClientException("no sinks for topic: " + topic);
- }
-
- this.sink = lst.get(0);
- }
-
- /**
- * Sends a message to the PDPs via the topic, after encoding the message as json.
- *
- * @param message message to be encoded and sent
- * @return {@code true} if the message was successfully sent/enqueued, {@code false}
- * otherwise
- */
- public boolean send(Object message) {
- try {
- String json = CODER.encode(message);
- return sink.send(json);
-
- } catch (RuntimeException | CoderException e) {
- logger.warn("send to {} failed because of {}", topic, e.getMessage(), e);
- return false;
- }
- }
-
- // the remaining methods are wrappers that can be overridden by junit tests
-
- /**
- * Gets the sinks for a given topic.
- *
- * @param topic the topic of interest
- * @return the sinks for the topic
- */
- protected List<TopicSink> getTopicSinks(String topic) {
- return TopicEndpoint.manager.getTopicSinks(topic);
- }
-}
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpClientException.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpClientException.java
deleted file mode 100644
index 547812f2..00000000
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpClientException.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP PAP
- * ================================================================================
- * Copyright (C) 2019 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.
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pap.main.comm;
-
-/**
- * Exception thrown by PDP client classes.
- */
-public class PdpClientException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public PdpClientException() {
- super();
- }
-
- public PdpClientException(String message) {
- super(message);
- }
-
- public PdpClientException(Throwable cause) {
- super(cause);
- }
-
- public PdpClientException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public PdpClientException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-
-}
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
index 09f87049..dce21f98 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,77 +21,28 @@
package org.onap.policy.pap.main.parameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import lombok.Getter;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* Class to hold all parameters needed for pap component.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-public class PapParameterGroup implements ParameterGroup {
- private String name;
+@NotNull
+@NotBlank
+@Getter
+public class PapParameterGroup extends ParameterGroupImpl {
private RestServerParameters restServerParameters;
/**
* Create the pap parameter group.
*
* @param name the parameter group name
- * @param restServerParameters the rest server parameters
*/
- public PapParameterGroup(final String name, final RestServerParameters restServerParameters) {
- this.name = name;
- this.restServerParameters = restServerParameters;
- }
-
- /**
- * Return the name of this parameter group instance.
- *
- * @return name the parameter group name
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Set the name of this parameter group instance.
- *
- * @param name the parameter group name
- */
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Return the restServerParameters of this parameter group instance.
- *
- * @return the restServerParameters
- */
- public RestServerParameters getRestServerParameters() {
- return restServerParameters;
- }
-
- /**
- * Validate the parameter group.
- *
- * @return the result of the validation
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
- if (!ParameterValidationUtils.validateStringParameter(name)) {
- validationResult.setResult("name", ValidationStatus.INVALID, "must be a non-blank string");
- }
- if (restServerParameters == null) {
- validationResult.setResult("restServerParameters", ValidationStatus.INVALID,
- "must have restServerParameters to configure pap rest server");
- } else {
- validationResult.setResult("restServerParameters", restServerParameters.validate());
- }
- return validationResult;
+ public PapParameterGroup(final String name) {
+ super(name);
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/RestServerParameters.java b/main/src/main/java/org/onap/policy/pap/main/parameters/RestServerParameters.java
index 6b1e3f82..99b346e1 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/RestServerParameters.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/RestServerParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,144 +21,32 @@
package org.onap.policy.pap.main.parameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+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 pap rest server.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-public class RestServerParameters implements ParameterGroup {
- private String name;
+@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;
- /**
- * Constructor for instantiating RestServerParameters.
- *
- * @param host the host name
- * @param port the port
- * @param userName the user name
- * @param password the password
- * @param https the https flag
- * @param aaf the aaf flag
- */
- public RestServerParameters(final String host, final int port, final String userName, final String password,
- final boolean https, final boolean aaf) {
- super();
- this.host = host;
- this.port = port;
- this.userName = userName;
- this.password = password;
- this.https = https;
- this.aaf = aaf;
- }
-
- /**
- * Return the name of this RestServerParameters instance.
- *
- * @return name the name of this RestServerParameters
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Return the host of this RestServerParameters instance.
- *
- * @return the host
- */
- public String getHost() {
- return host;
- }
-
- /**
- * Return the port of this RestServerParameters instance.
- *
- * @return the port
- */
- public int getPort() {
- return port;
- }
-
- /**
- * Return the user name of this RestServerParameters instance.
- *
- * @return the userName
- */
- public String getUserName() {
- return userName;
- }
-
- /**
- * Return the password of this RestServerParameters instance.
- *
- * @return the password
- */
- public String getPassword() {
- return password;
- }
-
- /**
- * Return the https flag of this RestServerParameters instance.
- *
- * @return the https flag
- */
- public boolean isHttps() {
- return https;
- }
-
- /**
- * Return the aaf flag of this RestServerParameters instance.
- *
- * @return the aaf flag
- */
- public boolean isAaf() {
- return aaf;
- }
-
- /**
- * Set the name of this RestServerParameters instance.
- *
- * @param name the name to set
- */
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Validate the rest server parameters.
- *
- * @return the result of the validation
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
- if (!ParameterValidationUtils.validateStringParameter(host)) {
- validationResult.setResult("host", ValidationStatus.INVALID,
- "must be a non-blank string containing hostname/ipaddress of the pap rest server");
- }
- if (!ParameterValidationUtils.validateStringParameter(userName)) {
- validationResult.setResult("userName", ValidationStatus.INVALID,
- "must be a non-blank string containing userName for pap rest server credentials");
- }
- if (!ParameterValidationUtils.validateStringParameter(password)) {
- validationResult.setResult("password", ValidationStatus.INVALID,
- "must be a non-blank string containing password for pap rest server credentials");
- }
- if (!ParameterValidationUtils.validateIntParameter(port)) {
- validationResult.setResult("port", ValidationStatus.INVALID,
- "must be a positive integer containing port of the pap rest server");
- }
- return validationResult;
+ public RestServerParameters() {
+ super("RestServerParameters");
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java
index bd182239..fb5d2d89 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019 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.
@@ -28,15 +28,18 @@ import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import java.net.HttpURLConnection;
+import java.util.UUID;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.ResponseBuilder;
/**
* Version v1 common superclass to provide REST endpoints for PAP component.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
+// @formatter:off
@Path("/policy/pap/v1")
@Api(value = "Policy Administration (PAP) API")
@Produces(MediaType.APPLICATION_JSON)
@@ -48,12 +51,36 @@ import javax.ws.rs.core.MediaType;
+ " ensuring that policies are available to users, that policies are executing correctly,"
+ " and that the state and status of policies is monitored", version = "v1.0",
title = "Policy Administration"),
- consumes = {MediaType.APPLICATION_JSON}, produces = {MediaType.APPLICATION_JSON},
+ consumes = {MediaType.APPLICATION_JSON},
+ produces = {MediaType.APPLICATION_JSON},
schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
tags = {@Tag(name = "policy-administration", description = "Policy Administration Service Operations")},
- securityDefinition = @SecurityDefinition(
- basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+ securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+// @formatter:on
public class PapRestControllerV1 {
+ public static final String EXTENSION_NAME = "interface info";
+
+ public static final String API_VERSION_NAME = "api-version";
+ public static final String API_VERSION = "1.0.0";
+
+ public static final String LAST_MOD_NAME = "last-mod-release";
+ public static final String LAST_MOD_RELEASE = "Dublin";
+
+ public static final String VERSION_MINOR_NAME = "X-MinorVersion";
+ public static final String VERSION_MINOR_DESCRIPTION =
+ "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client";
+
+ public static final String VERSION_PATCH_NAME = "X-PatchVersion";
+ public static final String VERSION_PATCH_DESCRIPTION = "Used only to communicate a PATCH version in a response for"
+ + " troubleshooting purposes only, and will not be provided by" + " the client on request";
+
+ public static final String VERSION_LATEST_NAME = "X-LatestVersion";
+ public static final String VERSION_LATEST_DESCRIPTION = "Used only to communicate an API's latest version";
+
+ public static final String REQUEST_ID_NAME = "X-ONAP-RequestID";
+ public static final String REQUEST_ID_HDR_DESCRIPTION = "Used to track REST transactions for logging purpose";
+ public static final String REQUEST_ID_PARAM_DESCRIPTION = "RequestID for http transaction";
public static final String AUTHORIZATION_TYPE = "basicAuth";
@@ -64,4 +91,30 @@ public class PapRestControllerV1 {
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";
+
+ /**
+ * Adds version headers to the response.
+ *
+ * @param respBuilder response builder
+ * @return the response builder, with version headers
+ */
+ public ResponseBuilder addVersionControlHeaders(ResponseBuilder respBuilder) {
+ return respBuilder.header(VERSION_MINOR_NAME, "0").header(VERSION_PATCH_NAME, "0").header(VERSION_LATEST_NAME,
+ "1.0.0");
+ }
+
+ /**
+ * Adds logging headers to the response.
+ *
+ * @param respBuilder response builder
+ * @return the response builder, with version logging
+ */
+ public ResponseBuilder addLoggingHeaders(ResponseBuilder respBuilder, UUID requestId) {
+ if (requestId == null) {
+ // Generate a random uuid if client does not embed requestId in rest request
+ return respBuilder.header(REQUEST_ID_NAME, UUID.randomUUID());
+ }
+
+ return respBuilder.header(REQUEST_ID_NAME, requestId);
+ }
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
index 6064a14f..582c10d2 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
@@ -92,7 +92,9 @@ public class PapRestServer implements Startable {
Integer.toString(restServerParameters.getPort()));
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
String.join(",", HealthCheckRestControllerV1.class.getCanonicalName(),
- StatisticsRestControllerV1.class.getCanonicalName()));
+ StatisticsRestControllerV1.class.getCanonicalName(),
+ PdpGroupDeployControllerV1.class.getCanonicalName(),
+ PdpGroupDeleteControllerV1.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,
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java
new file mode 100644
index 00000000..46982183
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java
@@ -0,0 +1,132 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP PAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Authorization;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.ResponseHeader;
+import java.util.UUID;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+
+/**
+ * Class to provide REST end points for PAP component to delete a PDP group.
+ */
+public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
+
+ private final PdpGroupDeleteProvider provider = new PdpGroupDeleteProvider();
+
+ /**
+ * Deletes a PDP group.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param groupName name of the PDP group to be deleted
+ * @return a response
+ */
+ // @formatter:off
+ @DELETE
+ @Path("pdps/groups/{name}")
+ @ApiOperation(value = "Delete PDP Group",
+ notes = "Deletes a PDP Group, returning optional error details",
+ response = PdpGroupDeleteResponse.class,
+ tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+ @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)})
+ // @formatter:on
+
+ public Response deleteGroup(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "PDP Group Name", required = true) @PathParam("name") String groupName) {
+
+ Pair<Status, PdpGroupDeleteResponse> pair = provider.delete(groupName, null);
+
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+
+ /**
+ * Deletes a PDP group.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param groupName name of the PDP group to be deleted
+ * @param version version to be deleted
+ * @return a response
+ */
+ // @formatter:off
+ @DELETE
+ @Path("pdps/groups/{name}/versions/{version}")
+ @ApiOperation(value = "Delete version of a PDP Group",
+ notes = "Deletes a version of PDP Group, returning optional error details",
+ response = PdpGroupDeleteResponse.class,
+ tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+ @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)})
+ // @formatter:on
+
+ public Response deleteGroupVersion(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "PDP Group Name", required = true) @PathParam("name") String groupName,
+ @ApiParam(value = "PDP Group Version", required = true) @PathParam("version") String version) {
+
+ Pair<Status, PdpGroupDeleteResponse> pair = provider.delete(groupName, version);
+
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java
new file mode 100644
index 00000000..e40b053c
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP PAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+
+/**
+ * Provider for PAP component to delete PDP groups.
+ */
+public class PdpGroupDeleteProvider {
+
+ /**
+ * Deletes a PDP group.
+ *
+ * @param groupName name of the PDP group to be deleted
+ * @param version group version to delete; may be {@code null} if the group has only
+ * one version
+ * @return a pair containing the status and the response
+ */
+ public Pair<Response.Status, PdpGroupDeleteResponse> delete(String groupName, String version) {
+
+ /*
+ * TODO Lock for updates - return error if already locked.
+ */
+
+ /*
+ * TODO Make updates - sending initial messages to PDPs and arranging for
+ * listeners to complete the deletion actions (in the background). The final step
+ * for the listener is to unlock.
+ */
+
+ /*
+ * TODO Return error if unable to send updates to all PDPs.
+ */
+
+ return Pair.of(Response.Status.OK, new PdpGroupDeleteResponse());
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
new file mode 100644
index 00000000..228d97c9
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
@@ -0,0 +1,88 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP PAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Authorization;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.ResponseHeader;
+import java.util.UUID;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.models.pap.concepts.PdpGroup;
+import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+
+/**
+ * Class to provide REST end points for PAP component to deploy a PDP group.
+ */
+public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
+
+ private final PdpGroupDeployProvider provider = new PdpGroupDeployProvider();
+
+ /**
+ * Deploys or updates a PDP group.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param group PDP group configuration
+ * @return a response
+ */
+ // @formatter:off
+ @POST
+ @Path("pdps")
+ @ApiOperation(value = "Deploy or update PDP Group",
+ notes = "Deploys or updates a PDP Group, returning optional error details",
+ response = PdpGroupDeployResponse.class,
+ tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+ @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)})
+ // @formatter:on
+
+ public Response deploy(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "PDP Group Configuration", required = true) PdpGroup group) {
+
+ Pair<Status, PdpGroupDeployResponse> pair = provider.deploy(group);
+
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
new file mode 100644
index 00000000..da3b2ded
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP PAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.models.pap.concepts.PdpGroup;
+import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+
+/**
+ * Provider for PAP component to deploy PDP groups.
+ */
+public class PdpGroupDeployProvider {
+
+ /**
+ * Deploys or updates a PDP group.
+ *
+ * @param group PDP group configuration
+ * @return a pair containing the status and the response
+ */
+ public Pair<Response.Status, PdpGroupDeployResponse> deploy(PdpGroup group) {
+
+ /*
+ * TODO Lock for updates - return error if already locked.
+ */
+
+ /*
+ * TODO Make updates - sending initial messages to PDPs and arranging for
+ * listeners to complete the deployment actions (in the background). The final
+ * step for the listener is to unlock.
+ */
+
+ /*
+ * TODO Return error if unable to send updates to all PDPs.
+ */
+
+ return Pair.of(Response.Status.OK, new PdpGroupDeployResponse());
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java b/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java
index cbe4dcc9..223e322e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java
@@ -21,8 +21,9 @@
package org.onap.policy.pap.main.startstop;
+import java.io.FileInputStream;
import java.util.Arrays;
-
+import java.util.Properties;
import org.onap.policy.pap.main.PolicyPapException;
import org.onap.policy.pap.main.parameters.PapParameterGroup;
import org.onap.policy.pap.main.parameters.PapParameterHandler;
@@ -74,9 +75,20 @@ public class Main {
return;
}
+ // Read the properties
+ Properties props = new Properties();
+ try {
+ String propFile = arguments.getFullPropertyFilePath();
+ try (FileInputStream stream = new FileInputStream(propFile)) {
+ props.load(stream);
+ }
+ } catch (final Exception e) {
+ LOGGER.error("start of policy pap service failed", e);
+ return;
+ }
+
// Now, create the activator for the policy pap service
- activator = new PapActivator(parameterGroup);
- PapActivator.setCurrent(activator);
+ activator = new PapActivator(parameterGroup, props);
// Start the activator
try {
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
index 687c5fb0..3334d81a 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
@@ -21,9 +21,13 @@
package org.onap.policy.pap.main.startstop;
+import java.util.Properties;
import lombok.Getter;
import lombok.Setter;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.services.ServiceManager;
+import org.onap.policy.common.utils.services.ServiceManagerException;
import org.onap.policy.pap.main.PolicyPapException;
import org.onap.policy.pap.main.parameters.PapParameterGroup;
import org.onap.policy.pap.main.rest.PapRestServer;
@@ -31,8 +35,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * This class wraps a distributor so that it can be activated as a complete service together with all its pap and
- * forwarding handlers.
+ * This class wraps a distributor so that it can be activated as a complete service
+ * together with all its pap and forwarding handlers.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
@@ -43,12 +47,15 @@ public class PapActivator {
private final PapParameterGroup papParameterGroup;
/**
- * The current activator. This is initialized to a dummy instance used until the real
- * one has been configured.
+ * The current activator.
*/
@Getter
- @Setter
- private static volatile PapActivator current = new PapActivator(null);
+ private static volatile PapActivator current = null;
+
+ /**
+ * Used to stop the services.
+ */
+ private final ServiceManager manager;
@Getter
@Setter(lombok.AccessLevel.PRIVATE)
@@ -60,9 +67,31 @@ public class PapActivator {
* Instantiate the activator for policy pap as a complete service.
*
* @param papParameterGroup the parameters for the pap service
+ * @param topicProperties properties used to configure the topics
*/
- public PapActivator(final PapParameterGroup papParameterGroup) {
+ public PapActivator(final PapParameterGroup papParameterGroup, Properties topicProperties) {
+ TopicEndpoint.manager.addTopicSinks(topicProperties);
+ TopicEndpoint.manager.addTopicSources(topicProperties);
+
this.papParameterGroup = papParameterGroup;
+
+ // @formatter:off
+ this.manager = new ServiceManager()
+ .addAction("topics",
+ () -> TopicEndpoint.manager.start(),
+ () -> TopicEndpoint.manager.shutdown())
+ .addAction("register parameters",
+ () -> registerToParameterService(papParameterGroup),
+ () -> deregisterToParameterService(papParameterGroup))
+ .addAction("REST server",
+ () -> startPapRestServer(),
+ () -> restServer.stop())
+ .addAction("set alive",
+ () -> setAlive(true),
+ () -> setAlive(false));
+ // @formatter:on
+
+ current = this;
}
/**
@@ -77,12 +106,10 @@ public class PapActivator {
try {
LOGGER.debug("Policy pap starting as a service . . .");
- startPapRestServer();
- registerToParameterService(papParameterGroup);
- setAlive(true);
+ manager.start();
LOGGER.debug("Policy pap started as a service");
- } catch (final Exception exp) {
- LOGGER.error("Policy pap service startup failed", exp);
+ } catch (final ServiceManagerException exp) {
+ LOGGER.error("Policy pap service startup failed");
throw new PolicyPapException(exp.getMessage(), exp);
}
}
@@ -98,13 +125,9 @@ public class PapActivator {
}
try {
- deregisterToParameterService(papParameterGroup);
- setAlive(false);
-
- // Stop the pap rest server
- restServer.stop();
- } catch (final Exception exp) {
- LOGGER.error("Policy pap service termination failed", exp);
+ manager.stop();
+ } catch (final ServiceManagerException exp) {
+ LOGGER.error("Policy pap service termination failed");
throw new PolicyPapException(exp.getMessage(), exp);
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java
index 4b8bc348..b0bbfd8a 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +49,7 @@ public class PapCommandLineArguments {
private final Options options;
private String configurationFilePath = null;
+ private String propertyFilePath = null;
/**
* Construct the options for the CLI editor.
@@ -76,6 +78,15 @@ public class PapCommandLineArguments {
.required(false)
.type(String.class)
.build());
+ options.addOption(Option.builder("p")
+ .longOpt("property-file")
+ .desc("the full path to the topic property file to use, "
+ + "the property file contains the policy pap topic properties")
+ .hasArg()
+ .argName("PROP_FILE")
+ .required(false)
+ .type(String.class)
+ .build());
//@formatter:on
}
@@ -106,6 +117,7 @@ public class PapCommandLineArguments {
public String parse(final String[] args) throws PolicyPapException {
// Clear all our arguments
setConfigurationFilePath(null);
+ setPropertyFilePath(null);
CommandLine commandLine = null;
try {
@@ -137,6 +149,10 @@ public class PapCommandLineArguments {
setConfigurationFilePath(commandLine.getOptionValue('c'));
}
+ if (commandLine.hasOption('p')) {
+ setPropertyFilePath(commandLine.getOptionValue('p'));
+ }
+
return null;
}
@@ -147,6 +163,7 @@ public class PapCommandLineArguments {
*/
public void validate() throws PolicyPapException {
validateReadableFile("policy pap configuration", configurationFilePath);
+ validateReadableFile("policy pap properties", propertyFilePath);
}
/**
@@ -213,6 +230,43 @@ public class PapCommandLineArguments {
}
/**
+ * Gets the property file path.
+ *
+ * @return the property file path
+ */
+ public String getPropertyFilePath() {
+ return propertyFilePath;
+ }
+
+ /**
+ * Gets the full expanded property file path.
+ *
+ * @return the property file path
+ */
+ public String getFullPropertyFilePath() {
+ return ResourceUtils.getFilePath4Resource(getPropertyFilePath());
+ }
+
+ /**
+ * Sets the property file path.
+ *
+ * @param propertyFilePath the property file path
+ */
+ public void setPropertyFilePath(final String propertyFilePath) {
+ this.propertyFilePath = propertyFilePath;
+
+ }
+
+ /**
+ * Check set property file path.
+ *
+ * @return true, if check set property file path
+ */
+ public boolean checkSetPropertyFilePath() {
+ return propertyFilePath != null && propertyFilePath.length() > 0;
+ }
+
+ /**
* Validate readable file.
*
* @param fileTag the file tag