Refactor PAP REST controller 34/79734/2
authorJim Hahn <jrh3@att.com>
Tue, 5 Mar 2019 20:15:28 +0000 (15:15 -0500)
committerJim Hahn <jrh3@att.com>
Tue, 5 Mar 2019 21:04:00 +0000 (21:04 +0000)
Split health check and statistics REST controllers out of the
PAP REST controller and made PAP REST controller into a superclass.

Change-Id: I6f492c9fd5d058d81143ed34d70760dbd05a5770
Issue-ID: POLICY-1542
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/pap/main/rest/PapRestController.java [deleted file]
main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java [new file with mode: 0644]

diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java
new file mode 100644 (file)
index 0000000..bf36a1a
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * ============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.
+ * 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.pap.main.rest;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Authorization;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.endpoints.report.HealthCheckReport;
+
+/**
+ * Class to provide REST endpoints for PAP component health check.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class HealthCheckRestControllerV1 extends PapRestControllerV1 {
+
+    @GET
+    @Path("healthcheck")
+    @ApiOperation(value = "Perform healthcheck",
+                    notes = "Returns healthy status of the Policy Administration 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();
+    }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestController.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestController.java
deleted file mode 100644 (file)
index 8d153f3..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * ============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.pap.main.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 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 PAP component.
- *
- * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
- */
-@Path("/policy/pap/v1")
-@Api(value = "Policy Administration (PAP) API")
-@Produces(MediaType.APPLICATION_JSON)
-@SwaggerDefinition(info = @Info(
-        description = "Policy Administration is responsible for the deployment life cycle of policies as well as "
-                + "interworking with the mechanisms required to orchestrate the nodes and containers on which "
-                + "policies run. It is also responsible for the administration of policies at run time;"
-                + " 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 },
-        schemes = { SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS },
-        tags = { @Tag(name = "policy-administration", description = "Policy Administration Service Operations") },
-        securityDefinition = @SecurityDefinition(basicAuthDefinitions = { @BasicAuthDefinition(key = "basicAuth") }))
-public class PapRestController {
-
-    @GET
-    @Path("healthcheck")
-    @ApiOperation(value = "Perform healthcheck",
-            notes = "Returns healthy status of the Policy Administration component", response = HealthCheckReport.class,
-            authorizations = @Authorization(value = "basicAuth"))
-    @ApiResponses(value = { @ApiResponse(code = 401, message = "Authentication Error"),
-        @ApiResponse(code = 403, message = "Authorization Error"),
-        @ApiResponse(code = 500, message = "Internal Server Error") })
-    public Response healthcheck() {
-        return Response.status(Response.Status.OK).entity(new HealthCheckProvider().performHealthCheck()).build();
-    }
-
-    @GET
-    @Path("statistics")
-    @ApiOperation(value = "Fetch current statistics",
-            notes = "Returns current statistics of the Policy Administration component",
-            response = StatisticsReport.class, authorizations = @Authorization(value = "basicAuth"))
-    @ApiResponses(value = { @ApiResponse(code = 401, message = "Authentication Error"),
-        @ApiResponse(code = 403, message = "Authorization Error"),
-        @ApiResponse(code = 500, message = "Internal Server Error") })
-    public Response statistics() {
-        return Response.status(Response.Status.OK).entity(new StatisticsProvider().fetchCurrentStatistics()).build();
-    }
-}
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
new file mode 100644 (file)
index 0000000..bd18223
--- /dev/null
@@ -0,0 +1,67 @@
+/*-
+ * ============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.
+ * 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.pap.main.rest;
+
+import io.swagger.annotations.Api;
+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.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Version v1 common superclass to provide REST endpoints for PAP component.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Path("/policy/pap/v1")
+@Api(value = "Policy Administration (PAP) API")
+@Produces(MediaType.APPLICATION_JSON)
+@SwaggerDefinition(
+    info = @Info(description =
+                    "Policy Administration is responsible for the deployment life cycle of policies as well as "
+                    + "interworking with the mechanisms required to orchestrate the nodes and containers on which "
+                    + "policies run. It is also responsible for the administration of policies at run time;"
+                    + " 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},
+    schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
+    tags = {@Tag(name = "policy-administration", description = "Policy Administration Service Operations")},
+    securityDefinition = @SecurityDefinition(
+                    basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+public class PapRestControllerV1 {
+
+    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";
+}
index c6a5e30..6064a14 100644 (file)
@@ -91,7 +91,8 @@ public class PapRestServer implements Startable {
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
                         Integer.toString(restServerParameters.getPort()));
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
-                        PapRestController.class.getCanonicalName());
+                        String.join(",", HealthCheckRestControllerV1.class.getCanonicalName(),
+                                        StatisticsRestControllerV1.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/StatisticsRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java
new file mode 100644 (file)
index 0000000..e864586
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============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.
+ * 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.pap.main.rest;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Authorization;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+/**
+ * Class to provide REST endpoints for PAP component statistics.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class StatisticsRestControllerV1 extends PapRestControllerV1 {
+
+    @GET
+    @Path("statistics")
+    @ApiOperation(value = "Fetch current statistics",
+                    notes = "Returns current statistics of the Policy Administration component",
+                    response = StatisticsReport.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 statistics() {
+        return Response.status(Response.Status.OK).entity(new StatisticsProvider().fetchCurrentStatistics()).build();
+    }
+}