summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java828
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java37
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java37
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java37
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java136
5 files changed, 576 insertions, 499 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
index 60ccba0f..7661c273 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,16 +37,21 @@ import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
+
import java.util.UUID;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
+
import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
import org.onap.policy.api.main.rest.provider.PolicyProvider;
import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
@@ -69,19 +75,20 @@ import org.slf4j.LoggerFactory;
@Api(value = "Policy Design API")
@Produces({"application/json", "application/yaml"})
@Consumes({"application/json", "application/yaml"})
-@SwaggerDefinition(info = @Info(
+@SwaggerDefinition(
+ info = @Info(
description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
- + " policy types, policy type implementation and policies which can be recognized"
- + " and executable by incorporated policy engines. It is an"
- + " independent component running rest service that takes all policy design API calls"
- + " from clients and then assign them to different API working functions. Besides"
- + " that, API is also exposed for clients to retrieve healthcheck status of this API"
- + " rest service and the statistics report including the counters of API invocation.",
+ + " policy types, policy type implementation and policies which can be recognized"
+ + " and executable by incorporated policy engines. It is an"
+ + " independent component running rest service that takes all policy design API calls"
+ + " from clients and then assign them to different API working functions. Besides"
+ + " that, API is also exposed for clients to retrieve healthcheck status of this API"
+ + " rest service and the statistics report including the counters of API invocation.",
version = "1.0.0", title = "Policy Design",
extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
@ExtensionProperty(name = "component", value = "Policy Framework")})}),
- schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
- securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
+ schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
+ securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
public class ApiRestController extends CommonRestController {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);
@@ -94,30 +101,29 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/healthcheck")
@ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
- response = HealthCheckReport.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ response = HealthCheckReport.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 500, message = "Internal Server Error")})
- public Response getHealthCheck(
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ public Response
+ getHealthCheck(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());
@@ -131,31 +137,30 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/statistics")
@ApiOperation(value = "Retrieve current statistics",
- notes = "Returns current statistics including the counters of API invocation",
- response = StatisticsReport.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Returns current statistics including the counters of API invocation",
+ response = StatisticsReport.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response
- getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
@@ -170,31 +175,30 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/policytypes")
@ApiOperation(value = "Retrieve existing policy types",
- notes = "Returns a list of existing policy types stored in Policy Framework",
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Returns a list of existing policy types stored in Policy Framework",
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 500, message = "Internal Server Error")})
- public Response getAllPolicyTypes(
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ public Response
+ getAllPolicyTypes(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
@@ -217,33 +221,32 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/policytypes/{policyTypeId}")
@ApiOperation(value = "Retrieve all available versions of a policy type",
- notes = "Returns a list of all available versions for the specified policy type",
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Returns a list of all available versions for the specified policy type",
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response getAllVersionsOfPolicyType(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
@@ -267,33 +270,32 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/policytypes/{policyTypeId}/versions/{versionId}")
@ApiOperation(value = "Retrieve one particular version of a policy type",
- notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response getSpecificVersionOfPolicyType(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
@@ -316,32 +318,31 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/policytypes/{policyTypeId}/versions/latest")
@ApiOperation(value = "Retrieve latest version of a policy type",
- notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response getLatestVersionOfPolicyType(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
@@ -364,41 +365,32 @@ public class ApiRestController extends CommonRestController {
@POST
@Path("/policytypes")
@ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
- authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version",
- response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose",
- response = UUID.class)
- },
- extensions = {
- @Extension(name = "interface info", properties = {
- @ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")
- })
- })
- @ApiResponses(value = {
- @ApiResponse(code = 400, message = "Invalid Body"),
- @ApiResponse(code = 401, message = "Authentication Error"),
- @ApiResponse(code = 403, message = "Authorization Error"),
- @ApiResponse(code = 406, message = "Not Acceptable Payload"),
- @ApiResponse(code = 500, message = "Internal Server Error")
- })
+ authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 406, message = "Not Acceptable Payload"),
+ @ApiResponse(code = 500, message = "Internal Server Error")})
public Response createPolicyType(
- @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
@@ -426,37 +418,36 @@ public class ApiRestController extends CommonRestController {
@DELETE
@Path("/policytypes/{policyTypeId}/versions/{versionId}")
@ApiOperation(value = "Delete one version of a policy type",
- notes = "Rule 1: pre-defined policy types cannot be deleted;"
- + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
- + "The parameterizing TOSCA policies must be deleted first;",
- authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Rule 1: pre-defined policy types cannot be deleted;"
+ + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
+ + "The parameterizing TOSCA policies must be deleted first;",
+ authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response deleteSpecificVersionOfPolicyType(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
@@ -475,42 +466,52 @@ public class ApiRestController extends CommonRestController {
*
* @return the Response object containing the results of the API operation
*/
+ // @formatter:off
@GET
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
- @ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version",
- notes = "Returns a list of all versions of specified policy created for the specified policy type version",
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
- @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiOperation(
+ value = "Retrieve all versions of a policy created for a particular policy type version",
+ notes = "Returns a list of all versions of specified policy created for the specified policy type version",
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy,"},
+ extensions = {
+ @Extension(name = "interface info", properties = {
+ @ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
- @ApiResponse(code = 500, message = "Internal Server Error")})
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
public Response getAllPolicies(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
- required = true) String policyTypeVersion,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ + " REFERENCED for fully referenced policies") PolicyFetchMode mode
+ ) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
- policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null);
+ policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
@@ -519,6 +520,7 @@ public class ApiRestController extends CommonRestController {
return makeErrorResponse(requestId, pfme);
}
}
+ // @formatter:on
/**
* Retrieves all versions of a particular policy.
@@ -529,43 +531,50 @@ public class ApiRestController extends CommonRestController {
*
* @return the Response object containing the results of the API operation
*/
+ // @formatter:off
@GET
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
@ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
- notes = "Returns a list of all version details of the specified policy",
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
- @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
+ notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
+ extensions = {
+ @Extension(name = "interface info", properties = {
+ @ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
- @ApiResponse(code = 500, message = "Internal Server Error")})
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
public Response getAllVersionsOfPolicy(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
- required = true) String policyTypeVersion,
- @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
-
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ + " REFERENCED for fully referenced policies") PolicyFetchMode mode
+ ) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
- policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null);
+ policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
@@ -574,6 +583,7 @@ public class ApiRestController extends CommonRestController {
return makeErrorResponse(requestId, pfme);
}
}
+ // @formatter:on
/**
* Retrieves the specified version of a particular policy.
@@ -585,53 +595,62 @@ public class ApiRestController extends CommonRestController {
*
* @return the Response object containing the results of the API operation
*/
+ // @formatter:off
@GET
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
@ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
- notes = "Returns a particular version of specified policy created for the specified policy type version",
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
- @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
+ notes = "Returns a particular version of specified policy created for the specified policy type version",
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
+ extensions = {
+ @Extension(name = "interface info", properties = {
+ @ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+ })
+ }
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
- @ApiResponse(code = 500, message = "Internal Server Error")})
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
public Response getSpecificVersionOfPolicy(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
- required = true) String policyTypeVersion,
- @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
- @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
-
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ + " REFERENCED for fully referenced policies") PolicyFetchMode mode
+ ) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
- policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
+ policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
- policyId, policyVersion, pfme);
+ policyId, policyVersion, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
}
+ // @formatter:on
/**
* Retrieves the latest version of a particular policy.
@@ -645,44 +664,45 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
@ApiOperation(value = "Retrieve the latest version of a particular policy",
- notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response getLatestVersionOfPolicy(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
- required = true) String policyTypeVersion,
- @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), "
+ + "REFERENCED for fully referenced policies") PolicyFetchMode mode) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
- policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId);
+ policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,
- policyId, pfme);
+ policyId, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -700,50 +720,40 @@ public class ApiRestController extends CommonRestController {
@POST
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
@ApiOperation(value = "Create a new policy for a policy type version",
- notes = "Client should provide TOSCA body of the new policy",
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version",
- response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose",
- response = UUID.class)
- },
- extensions = {
- @Extension(name = "interface info", properties = {
- @ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")
- })
- })
- @ApiResponses(value = {
- @ApiResponse(code = 400, message = "Invalid Body"),
- @ApiResponse(code = 401, message = "Authentication Error"),
- @ApiResponse(code = 403, message = "Authorization Error"),
- @ApiResponse(code = 404, message = "Resource Not Found"),
- @ApiResponse(code = 406, message = "Not Acceptable Payload"),
- @ApiResponse(code = 500, message = "Internal Server Error")
- })
+ notes = "Client should provide TOSCA body of the new policy",
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 404, message = "Resource Not Found"),
+ @ApiResponse(code = 406, message = "Not Acceptable Payload"),
+ @ApiResponse(code = 500, message = "Internal Server Error")})
public Response createPolicy(
- @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
- required = true) String policyTypeVersion,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
- @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
- "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
+ "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
}
try (PolicyProvider policyProvider = new PolicyProvider()) {
@@ -767,43 +777,33 @@ public class ApiRestController extends CommonRestController {
@POST
@Path("/policies")
@ApiOperation(value = "Create one or more new policies",
- notes = "Client should provide TOSCA body of the new polic(ies)",
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version",
- response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose",
- response = UUID.class)
- },
- extensions = {
- @Extension(name = "interface info", properties = {
- @ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "El Alto")
- })
- })
- @ApiResponses(value = {
- @ApiResponse(code = 400, message = "Invalid Body"),
- @ApiResponse(code = 401, message = "Authentication Error"),
- @ApiResponse(code = 403, message = "Authorization Error"),
- @ApiResponse(code = 404, message = "Resource Not Found"),
- @ApiResponse(code = 406, message = "Not Acceptable Payload"),
- @ApiResponse(code = 500, message = "Internal Server Error")
- })
+ notes = "Client should provide TOSCA body of the new polic(ies)",
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "El Alto")})})
+ @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 404, message = "Resource Not Found"),
+ @ApiResponse(code = 406, message = "Not Acceptable Payload"),
+ @ApiResponse(code = 500, message = "Internal Server Error")})
public Response createPolicies(
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
- @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
@@ -833,46 +833,44 @@ public class ApiRestController extends CommonRestController {
@DELETE
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
@ApiOperation(value = "Delete a particular version of a policy",
- notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
- authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
- response = ToscaServiceTemplate.class,
- responseHeaders = {
- @ResponseHeader(name = "X-MinorVersion",
- description = "Used to request or communicate a MINOR version back from the client"
- + " to the server, and from the server back to the client",
- response = String.class),
- @ResponseHeader(name = "X-PatchVersion",
- 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",
- response = String.class),
- @ResponseHeader(name = "X-LatestVersion",
- description = "Used only to communicate an API's latest version", response = String.class),
- @ResponseHeader(name = "X-ONAP-RequestID",
- description = "Used to track REST transactions for logging purpose", response = UUID.class)},
- extensions = {@Extension(name = "interface info",
- properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
- @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
+ notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ 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",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose", response = UUID.class)},
+ extensions = {
+ @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
@ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
@ApiResponse(code = 500, message = "Internal Server Error")})
public Response deleteSpecificVersionOfPolicy(
- @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
- required = true) String policyTypeVersion,
- @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
- @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
- @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
- policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
+ policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
- policyId, policyVersion, pfme);
+ policyId, policyVersion, pfme);
return makeErrorResponse(requestId, pfme);
}
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java b/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java
new file mode 100644
index 00000000..99678b84
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.api.main.rest;
+
+public enum PolicyFetchMode {
+ BARE,
+ REFERENCED;
+
+ /**
+ * Convert a string to this ENUM.
+ *
+ * @param modeString the incoming string value
+ * @return the enum value of the string
+ */
+ public static PolicyFetchMode fromString(final String modeString) {
+ String modeStringUpper = modeString.toUpperCase();
+ return valueOf(modeStringUpper);
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
index 35d0e805..4ba3322d 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
@@ -23,6 +23,7 @@
package org.onap.policy.api.main.rest.provider;
+import org.onap.policy.api.main.rest.PolicyFetchMode;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -48,15 +49,16 @@ public class PolicyProvider extends CommonModelProvider {
* @param policyTypeVersion the version of policy type
* @param policyId the ID of policy
* @param policyVersion the version of policy
+ * @param mode the fetch mode for policies
*
* @return the ToscaServiceTemplate object
*
* @throws PfModelException the PfModel parsing exception
*/
- public ToscaServiceTemplate fetchPolicies(String policyTypeId, String policyTypeVersion, String policyId,
- String policyVersion) throws PfModelException {
+ public ToscaServiceTemplate fetchPolicies(final String policyTypeId, final String policyTypeVersion,
+ final String policyId, final String policyVersion, final PolicyFetchMode mode) throws PfModelException {
- return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
+ return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
}
/**
@@ -65,15 +67,15 @@ public class PolicyProvider extends CommonModelProvider {
* @param policyTypeId the ID of policy type
* @param policyTypeVersion the version of policy type
* @param policyId the ID of the policy
- *
+ * @param mode the fetch mode for policies
* @return the ToscaServiceTemplate object
*
* @throws PfModelException the PfModel parsing exception
*/
- public ToscaServiceTemplate fetchLatestPolicies(String policyTypeId, String policyTypeVersion, String policyId)
- throws PfModelException {
+ public ToscaServiceTemplate fetchLatestPolicies(final String policyTypeId, final String policyTypeVersion,
+ final String policyId, final PolicyFetchMode mode) throws PfModelException {
- return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION);
+ return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION, mode);
}
/**
@@ -88,7 +90,7 @@ public class PolicyProvider extends CommonModelProvider {
* @throws PfModelException the PfModel parsing exception
*/
public ToscaServiceTemplate createPolicy(String policyTypeId, String policyTypeVersion, ToscaServiceTemplate body)
- throws PfModelException {
+ throws PfModelException {
return modelsProvider.createPolicies(body);
}
@@ -119,7 +121,7 @@ public class PolicyProvider extends CommonModelProvider {
* @throws PfModelException the PfModel parsing exception
*/
public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion, String policyId,
- String policyVersion) throws PfModelException {
+ String policyVersion) throws PfModelException {
return modelsProvider.deletePolicy(policyId, policyVersion);
}
@@ -131,16 +133,25 @@ public class PolicyProvider extends CommonModelProvider {
* @param policyTypeVersion the version of the policy type
* @param policyName the name of the policy
* @param policyVersion the version of the policy
+ * @param mode the fetch mode for policies
*
* @return the TOSCA service template containing the specified version of the policy
*
* @throws PfModelException the PfModel parsing exception
*/
- private ToscaServiceTemplate getFilteredPolicies(String policyTypeName, String policyTypeVersion, String policyName,
- String policyVersion) throws PfModelException {
+ private ToscaServiceTemplate getFilteredPolicies(final String policyTypeName, final String policyTypeVersion,
+ final String policyName, final String policyVersion, final PolicyFetchMode mode) throws PfModelException {
ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder().name(policyName).version(policyVersion)
- .type(policyTypeName).typeVersion(policyTypeVersion).build();
- return modelsProvider.getFilteredPolicies(policyFilter);
+ .type(policyTypeName).typeVersion(policyTypeVersion).build();
+
+ ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicies(policyFilter);
+
+ if (mode == null || PolicyFetchMode.BARE.equals(mode)) {
+ serviceTemplate.setPolicyTypes(null);
+ serviceTemplate.setDataTypes(null);
+ }
+
+ return serviceTemplate;
}
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index 21bd5cda..1b1ed3cf 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -26,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -586,13 +587,17 @@ public class TestApiRestServer {
+ "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0", APP_JSON);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/"
+ + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0?mode=referenced", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
ToscaServiceTemplate namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size());
assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/"
- + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/latest", APP_JSON);
+ + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/latest?mode=referenced", APP_JSON);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
@@ -600,13 +605,41 @@ public class TestApiRestServer {
assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size());
assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
- rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/policies", APP_JSON);
+ rawResponse =
+ readResource("policytypes/onap.policies.Naming/versions/1.0.0/policies?mode=referenced", APP_JSON);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size());
assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
+
+ rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/"
+ + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+
+ assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertNull(namingServiceTemplate.getPolicyTypes());
+ assertNull(namingServiceTemplate.getDataTypes());
+
+ rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/"
+ + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/latest", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertNull(namingServiceTemplate.getPolicyTypes());
+ assertNull(namingServiceTemplate.getDataTypes());
+
+ rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/policies", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertNull(namingServiceTemplate.getPolicyTypes());
+ assertNull(namingServiceTemplate.getDataTypes());
}
@Test
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
index f458013d..63542420 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
@@ -34,6 +34,7 @@ import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -75,18 +76,18 @@ public class TestPolicyProvider {
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_ID = "policies/vCPE.policy.bad.policytypeid.json";
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_VERSION =
- "policies/vCPE.policy.bad.policytypeversion.json";
+ "policies/vCPE.policy.bad.policytypeversion.json";
private static final String POLICY_RESOURCE_WITH_NO_POLICY_VERSION = "policies/vCPE.policy.no.policyversion.json";
private static final String POLICY_RESOURCE_WITH_DIFFERENT_FIELDS =
- "policies/vCPE.policy.different.policy.fields.json";
+ "policies/vCPE.policy.different.policy.fields.json";
private static final String MULTIPLE_POLICIES_RESOURCE = "policies/vCPE.policies.optimization.input.tosca.json";
public static final String POLICY_TYPE_RESOURCE_OPERATIONAL =
- "policytypes/onap.policies.controlloop.Operational.yaml";
+ "policytypes/onap.policies.controlloop.Operational.yaml";
public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON =
- "policytypes/onap.policies.controlloop.operational.Common.yaml";
+ "policytypes/onap.policies.controlloop.operational.Common.yaml";
public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS =
- "policytypes/onap.policies.controlloop.operational.common.Drools.yaml";
+ "policytypes/onap.policies.controlloop.operational.common.Drools.yaml";
private static final String POLICY_RESOURCE_OPERATIONAL = "policies/vCPE.policy.operational.input.tosca.json";
public static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
@@ -106,8 +107,8 @@ public class TestPolicyProvider {
providerParams.setDatabaseUser("policy");
providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
providerParams.setPersistenceUnit("ToscaConceptTest");
- apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams,
- Collections.emptyList(), Collections.emptyList());
+ apiParamGroup =
+ new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList(), Collections.emptyList());
ParameterService.register(apiParamGroup, true);
policyTypeProvider = new PolicyTypeProvider();
policyProvider = new PolicyProvider();
@@ -130,15 +131,15 @@ public class TestPolicyProvider {
public void testFetchPolicies() {
assertThatThrownBy(() -> {
- policyProvider.fetchPolicies("dummy", "1.0.0", null, null);
+ policyProvider.fetchPolicies("dummy", "1.0.0", null, null, null);
}).hasMessage("service template not found in database");
assertThatThrownBy(() -> {
- policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", null);
+ policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", null, null);
}).hasMessage("service template not found in database");
assertThatThrownBy(() -> {
- policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0");
+ policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0", null);
}).hasMessage("service template not found in database");
}
@@ -146,7 +147,7 @@ public class TestPolicyProvider {
public void testFetchLatestPolicies() {
assertThatThrownBy(() -> {
- policyProvider.fetchLatestPolicies("dummy", "dummy", "dummy");
+ policyProvider.fetchLatestPolicies("dummy", "dummy", "dummy", null);
}).hasMessage("service template not found in database");
}
@@ -158,7 +159,7 @@ public class TestPolicyProvider {
String policyTypeId = "onap.policies.monitoring.cdap.tca.hi.lo.app";
try (PolicyModelsProvider databaseProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) {
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) {
assertEquals(0, databaseProvider.getPdpGroups("name").size());
assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
@@ -189,14 +190,14 @@ public class TestPolicyProvider {
pdpSubGroup.getPdpInstances().add(pdp);
// Create Pdp Groups
- assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
- .getDesiredInstanceCount());
+ assertEquals(123,
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
assertEquals(1, databaseProvider.getPdpGroups("group").size());
// Create Policy Type
assertThatCode(() -> {
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -204,9 +205,9 @@ public class TestPolicyProvider {
assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
ToscaServiceTemplate policyServiceTemplate =
- standardCoder.decode(policyString, ToscaServiceTemplate.class);
+ standardCoder.decode(policyString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate =
- policyProvider.createPolicy(policyTypeId, policyTypeVersion, policyServiceTemplate);
+ policyProvider.createPolicy(policyTypeId, policyTypeVersion, policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
@@ -214,12 +215,12 @@ public class TestPolicyProvider {
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion));
assertEquals(1,
- databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
+ databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
// Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
assertThatThrownBy(() -> {
policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
- "1.0.0");
+ "1.0.0");
}).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
} catch (Exception exc) {
fail("Test should not throw an exception");
@@ -234,7 +235,7 @@ public class TestPolicyProvider {
}).hasMessage("topology template not specified on service template");
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertThatCode(() -> policyTypeProvider.createPolicyType(policyTypeServiceTemplate)).doesNotThrowAnyException();
@@ -242,63 +243,63 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_BAD_POLICYTYPE_ID);
ToscaServiceTemplate badPolicyServiceTemplate =
- standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
+ standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- badPolicyServiceTemplate);
+ badPolicyServiceTemplate);
}).hasMessageContaining(
- "policy type onap.policies.monitoring.cdap.tca.hi.lo.appxxx:0.0.0 referenced in policy not found");
+ "policy type onap.policies.monitoring.cdap.tca.hi.lo.appxxx:0.0.0 referenced in policy not found");
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_BAD_POLICYTYPE_VERSION);
ToscaServiceTemplate badPolicyServiceTemplate =
- standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
+ standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- badPolicyServiceTemplate);
+ badPolicyServiceTemplate);
}).hasMessageContaining(
- "policy type onap.policies.monitoring.cdap.tca.hi.lo.app:2.0.0 referenced in policy not found");
+ "policy type onap.policies.monitoring.cdap.tca.hi.lo.app:2.0.0 referenced in policy not found");
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_POLICY_VERSION);
ToscaServiceTemplate badPolicyServiceTemplate =
- standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
+ standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- badPolicyServiceTemplate);
+ badPolicyServiceTemplate);
}).hasMessageContaining("key version is a null version");
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
- ToscaServiceTemplate serviceTemplate = policyProvider
- .createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
+ ToscaServiceTemplate serviceTemplate =
+ policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_DIFFERENT_FIELDS);
ToscaServiceTemplate badPolicyServiceTemplate =
- standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
+ standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- badPolicyServiceTemplate);
+ badPolicyServiceTemplate);
}).hasMessageContaining("entity in incoming fragment does not equal existing entity");
}
@Test
public void testCreateOperationalDroolsPolicy() throws CoderException, PfModelException {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS), ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_DROOLS), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_OPERATIONAL);
ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate =
- policyProvider.createPolicy(POLICY_TYPE_OPERATIONAL_DROOLS, "1.0.0", policyServiceTemplate);
+ policyProvider.createPolicy(POLICY_TYPE_OPERATIONAL_DROOLS, "1.0.0", policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}
@@ -308,74 +309,71 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
ToscaServiceTemplate multiPoliciesServiceTemplate =
- standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
+ standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
policyProvider.createPolicies(multiPoliciesServiceTemplate);
}).hasMessageContaining(
- "no policy types are defined on the service template for the policies in the topology template");
+ "no policy types are defined on the service template for the policies in the topology template");
// Create required policy types
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.Optimization.yaml"),
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardYamlCoder.decode(ResourceUtils.getResourceAsString("policytypes/onap.policies.Optimization.yaml"),
ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.Resource.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.Resource.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils
- .getResourceAsString("policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils
- .getResourceAsString("policytypes/onap.policies.optimization.resource.DistancePolicy.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.DistancePolicy.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.Vim_fit.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.Vim_fit.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.HpaPolicy.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.HpaPolicy.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.VnfPolicy.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.VnfPolicy.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.Service.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.Service.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils
- .getResourceAsString("policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.service.QueryPolicy.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.service.QueryPolicy.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"),
- ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
// Create multiple policies in one call
String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
ToscaServiceTemplate multiPoliciesServiceTemplate =
- standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
+ standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
assertThatCode(() -> {
policyProvider.createPolicies(multiPoliciesServiceTemplate);
@@ -392,7 +390,7 @@ public class TestPolicyProvider {
assertThatCode(() -> {
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -400,19 +398,19 @@ public class TestPolicyProvider {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyProvider
- .createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
+ .createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
assertThatCode(() -> {
ToscaServiceTemplate serviceTemplate = policyProvider
- .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
+ .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
assertThatThrownBy(() -> {
policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
- "1.0.0");
+ "1.0.0");
}).hasMessageContaining("no policies found");
}
}