summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java970
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java574
-rw-r--r--main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java23
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java29
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java1439
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java7
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java7
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java12
-rw-r--r--main/src/test/resources/logback-test.xml53
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters.json44
10 files changed, 1154 insertions, 2004 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 67baa8a4..6d6b4d14 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
@@ -36,9 +36,11 @@ import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
+
import java.util.List;
import java.util.Map;
import java.util.UUID;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -48,6 +50,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
+
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
import org.onap.policy.api.main.rest.provider.PolicyProvider;
@@ -75,22 +78,17 @@ import org.slf4j.LoggerFactory;
@Consumes({"application/json", "application/yaml"})
@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.",
- 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") }))
+ + " 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")}))
public class ApiRestController extends CommonRestController {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);
@@ -102,39 +100,29 @@ public class ApiRestController extends CommonRestController {
*/
@GET
@Path("/healthcheck")
- @ApiOperation(value = "Perform a system healthcheck",
- notes = "Returns healthy status of the Policy API component",
+ @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")
- })
- })
- @ApiResponses(value = {
- @ApiResponse(code = 401, message = "Authentication Error"),
- @ApiResponse(code = 403, message = "Authorization Error"),
- @ApiResponse(code = 500, message = "Internal Server Error")
- })
+ @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) {
@@ -153,37 +141,28 @@ public class ApiRestController extends CommonRestController {
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) {
+ @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) {
updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
@@ -201,35 +180,26 @@ public class ApiRestController extends CommonRestController {
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")
- })
+ @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) {
@@ -238,7 +208,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes", pfme);
+ LOGGER.debug("GET /policytypes", pfme);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -257,36 +227,27 @@ public class ApiRestController extends CommonRestController {
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")
- })
+ @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) {
@@ -296,7 +257,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}", policyTypeId, pfme);
+ LOGGER.debug("GET /policytypes/{}", policyTypeId, pfme);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -313,39 +274,29 @@ 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,
+ 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")
- })
+ @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,
@@ -356,7 +307,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
+ LOGGER.debug("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -372,39 +323,29 @@ 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,
+ 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")
- })
+ @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) {
@@ -414,7 +355,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
+ LOGGER.debug("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -429,40 +370,30 @@ 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", },
+ @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 = 500, message = "Internal Server Error")
- })
+ @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 = 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) {
@@ -476,7 +407,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("POST /policytypes", pfme);
+ LOGGER.debug("POST /policytypes", pfme);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);
return makeErrorResponse(requestId, pfme);
}
@@ -494,41 +425,32 @@ public class ApiRestController extends CommonRestController {
@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", },
+ + "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")
- })
+ @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,
@@ -538,7 +460,7 @@ public class ApiRestController extends CommonRestController {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
+ LOGGER.debug("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -557,40 +479,31 @@ public class ApiRestController extends CommonRestController {
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")
- })
+ @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 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,
+ @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
+ required = true) String policyTypeVersion,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
@@ -599,7 +512,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
+ LOGGER.debug("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -620,51 +533,41 @@ public class ApiRestController extends CommonRestController {
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")
- })
+ @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 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("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) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
- ToscaServiceTemplate serviceTemplate = policyProvider
- .fetchPolicies(policyTypeId, policyTypeVersion, policyId, null);
+ ToscaServiceTemplate serviceTemplate =
+ policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId,
- pfme);
+ LOGGER.debug("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -686,52 +589,43 @@ public class ApiRestController extends CommonRestController {
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")
- })
+ @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 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("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
- .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
+ ToscaServiceTemplate serviceTemplate =
+ policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId,
- policyTypeVersion, policyId, policyVersion, pfme);
+ LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
+ policyId, policyVersion, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -749,43 +643,33 @@ 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,
+ 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")
- })
+ @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("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) {
@@ -795,8 +679,8 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId,
- policyTypeVersion, policyId, pfme);
+ LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,
+ policyId, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
}
@@ -814,53 +698,44 @@ public class ApiRestController extends CommonRestController {
@GET
@Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/deployed")
@ApiOperation(value = "Retrieve deployed versions of a particular policy in pdp groups",
- notes = "Returns deployed versions of specified policy in pdp groups",
- response = ToscaPolicy.class, responseContainer = "List",
+ notes = "Returns deployed versions of specified policy in pdp groups", response = ToscaPolicy.class,
+ responseContainer = "List",
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")
- })
+ @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 getDeployedVersionsOfPolicy(
@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("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) {
try (PolicyProvider policyProvider = new PolicyProvider()) {
- Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicies = policyProvider
- .fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
+ Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicies =
+ policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, deployedPolicies);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/{}/versions/{}/policies/{}/versions/deployed", policyTypeId,
+ LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/deployed", policyTypeId,
policyTypeVersion, policyId, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
return makeErrorResponse(requestId, pfme);
@@ -880,59 +755,48 @@ public class ApiRestController extends CommonRestController {
@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", },
+ 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 = 500, message = "Internal Server Error")
- })
+ @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 = 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,
+ @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()) {
- ToscaServiceTemplate serviceTemplate = policyProvider
- .createPolicy(policyTypeId, policyTypeVersion, body);
+ ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
+ LOGGER.debug("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
return makeErrorResponse(requestId, pfme);
}
@@ -949,39 +813,30 @@ public class ApiRestController extends CommonRestController {
@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", },
+ 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 = 500, message = "Internal Server Error")
- })
+ @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 = 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) {
@@ -995,7 +850,7 @@ public class ApiRestController extends CommonRestController {
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("POST /policies", pfme);
+ LOGGER.debug("POST /policies", pfme);
updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
return makeErrorResponse(requestId, pfme);
}
@@ -1015,68 +870,63 @@ public class ApiRestController extends CommonRestController {
@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", },
+ 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")
- })
+ @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("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);
+ ToscaServiceTemplate serviceTemplate =
+ policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId,
- policyTypeVersion, policyId, policyVersion, pfme);
+ LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
+ policyId, policyVersion, pfme);
return makeErrorResponse(requestId, pfme);
}
}
private enum Target {
- POLICY, POLICY_TYPE, OTHER
+ POLICY,
+ POLICY_TYPE,
+ OTHER
}
private enum Result {
- SUCCESS, FAILURE
+ SUCCESS,
+ FAILURE
}
private enum HttpMethod {
- POST, GET
+ POST,
+ GET
}
private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
index 6a4e39d3..1c2e8d8d 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
@@ -31,9 +31,11 @@ import io.swagger.annotations.Authorization;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
+
import java.util.List;
import java.util.Map;
import java.util.UUID;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -43,6 +45,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
+
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
@@ -83,36 +86,27 @@ public class LegacyApiRestController extends CommonRestController {
notes = "Returns the latest version of the specified guard policy",
response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
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 = { "Legacy Guard 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")
- })
+ @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 = {"Legacy Guard 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 getLatestVersionOfGuardPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
@@ -121,8 +115,9 @@ public class LegacyApiRestController extends CommonRestController {
Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider.fetchGuardPolicy(policyId, null);
return makeOkResponse(requestId, policies);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}"
- + "/versions/latest", policyId, pfme);
+ LOGGER.debug(
+ "GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}" + "/versions/latest",
+ policyId, pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -141,47 +136,38 @@ public class LegacyApiRestController extends CommonRestController {
notes = "Returns a particular version of a specified guard policy",
response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
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 = { "Legacy Guard 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")
- })
+ @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 = {"Legacy Guard 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 getSpecificVersionOfGuardPolicy(
@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 (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
- Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
- .fetchGuardPolicy(policyId, policyVersion);
+ Map<String, LegacyGuardPolicyOutput> policies =
+ guardPolicyProvider.fetchGuardPolicy(policyId, policyVersion);
return makeOkResponse(requestId, policies);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
+ LOGGER.debug("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
policyId, policyVersion, pfme);
return makeErrorResponse(requestId, pfme);
}
@@ -195,42 +181,32 @@ public class LegacyApiRestController extends CommonRestController {
* @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
- + "policies/{policyId}/versions/deployed")
+ @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/" + "policies/{policyId}/versions/deployed")
@ApiOperation(value = "Retrieve deployed versions of a particular guard policy in pdp groups",
notes = "Returns deployed versions of a specified guard policy in pdp groups",
response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
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 = { "Legacy Guard 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")
- })
+ @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 = {"Legacy Guard 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 getDeployedVersionsOfGuardPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
@@ -240,8 +216,8 @@ public class LegacyApiRestController extends CommonRestController {
guardPolicyProvider.fetchDeployedGuardPolicies(policyId);
return makeOkResponse(requestId, deployedGuardPolicies);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
- + "policies/{}/versions/deployed", policyId, pfme);
+ LOGGER.debug("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
+ + "policies/{}/versions/deployed", policyId, pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -257,52 +233,43 @@ public class LegacyApiRestController extends CommonRestController {
@Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies")
@ApiOperation(value = "Create a new guard policy",
notes = "Client should provide entity body of the new guard policy",
- authorizations = @Authorization(value = "basicAuth"),
- tags = { "Legacy Guard Policy", },
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
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 = 500, message = "Internal Server Error")
- })
+ @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 = 500, message = "Internal Server Error")})
public Response createGuardPolicy(
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
@ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
- "/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", toJson(body));
+ "/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", toJson(body));
}
try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
return makeOkResponse(requestId, policy);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
+ LOGGER.debug("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -319,50 +286,41 @@ public class LegacyApiRestController extends CommonRestController {
@Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
@ApiOperation(value = "Delete a particular version of a guard policy",
notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
- authorizations = @Authorization(value = "basicAuth"),
- tags = { "Legacy Guard Policy", },
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
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")
- })
+ @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 deleteSpecificVersionOfGuardPolicy(
@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 (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
- Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
- .deleteGuardPolicy(policyId, policyVersion);
+ Map<String, LegacyGuardPolicyOutput> policies =
+ guardPolicyProvider.deleteGuardPolicy(policyId, policyVersion);
return makeOkResponse(requestId, policies);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
+ LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
policyId, policyVersion, pfme);
return makeErrorResponse(requestId, pfme);
}
@@ -381,36 +339,27 @@ public class LegacyApiRestController extends CommonRestController {
notes = "Returns the latest version of the specified operational policy",
response = LegacyOperationalPolicy.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 = { "Legacy Operational 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")
- })
+ @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 = {"Legacy Operational 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 getLatestVersionOfOperationalPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
@@ -419,8 +368,8 @@ public class LegacyApiRestController extends CommonRestController {
LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, null);
return makeOkResponse(requestId, policy);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
- + "/versions/latest", policyId, pfme);
+ LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
+ + "/versions/latest", policyId, pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -435,41 +384,32 @@ public class LegacyApiRestController extends CommonRestController {
*/
@GET
@Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/{policyId}/versions/{policyVersion}")
+ + "policies/{policyId}/versions/{policyVersion}")
@ApiOperation(value = "Retrieve one version of a particular operational policy",
notes = "Returns a particular version of a specified operational policy",
response = LegacyOperationalPolicy.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 = { "Legacy Operational 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")
- })
+ @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 = {"Legacy Operational 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 getSpecificVersionOfOperationalPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
@@ -479,8 +419,8 @@ public class LegacyApiRestController extends CommonRestController {
LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, policyVersion);
return makeOkResponse(requestId, policy);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/{}/versions/{}", policyId, policyVersion, pfme);
+ LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+ + "policies/{}/versions/{}", policyId, policyVersion, pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -494,41 +434,32 @@ public class LegacyApiRestController extends CommonRestController {
*/
@GET
@Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/{policyId}/versions/deployed")
+ + "policies/{policyId}/versions/deployed")
@ApiOperation(value = "Retrieve deployed versions of a particular operational policy in pdp groups",
notes = "Returns deployed versions of a specified operational policy in pdp groups",
response = LegacyOperationalPolicy.class, responseContainer = "List",
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 = { "Legacy Operational 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")
- })
+ @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 = {"Legacy Operational 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 getDeployedVersionsOfOperationalPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
@@ -538,8 +469,8 @@ public class LegacyApiRestController extends CommonRestController {
operationalPolicyProvider.fetchDeployedOperationalPolicies(policyId);
return makeOkResponse(requestId, deployedOperationalPolicies);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/{}/versions/deployed", policyId, pfme);
+ LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+ + "policies/{}/versions/deployed", policyId, pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -555,52 +486,43 @@ public class LegacyApiRestController extends CommonRestController {
@Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
@ApiOperation(value = "Create a new operational policy",
notes = "Client should provide entity body of the new operational policy",
- authorizations = @Authorization(value = "basicAuth"),
- tags = { "Legacy Operational Policy", },
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
response = LegacyOperationalPolicy.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 = 500, message = "Internal Server Error")
- })
+ @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 = 500, message = "Internal Server Error")})
public Response createOperationalPolicy(
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
@ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
- "/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", toJson(body));
+ "/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", toJson(body));
}
try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
return makeOkResponse(requestId, policy);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
+ LOGGER.debug("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
return makeErrorResponse(requestId, pfme);
}
}
@@ -615,54 +537,44 @@ public class LegacyApiRestController extends CommonRestController {
*/
@DELETE
@Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/{policyId}/versions/{policyVersion}")
+ + "policies/{policyId}/versions/{policyVersion}")
@ApiOperation(value = "Delete a particular version of a specified operational policy",
notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
- authorizations = @Authorization(value = "basicAuth"),
- tags = { "Legacy Operational Policy", },
+ authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
response = LegacyOperationalPolicy.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")
- })
+ @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 deleteSpecificVersionOfOperationalPolicy(
@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 (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
- LegacyOperationalPolicy policy = operationalPolicyProvider
- .deleteOperationalPolicy(policyId, policyVersion);
+ LegacyOperationalPolicy policy = operationalPolicyProvider.deleteOperationalPolicy(policyId, policyVersion);
return makeOkResponse(requestId, policy);
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
- + "policies/{}/versions/{}", policyId, policyVersion, pfme);
+ LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+ + "policies/{}/versions/{}", policyId, policyVersion, pfme);
return makeErrorResponse(requestId, pfme);
}
}
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java
index 41e4e43a..d50ff40b 100644
--- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java
+++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiActivator.java
@@ -34,8 +34,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * This class wraps a distributor so that it can be activated as a complete service together with all its api
- * and forwarding handlers.
+ * This class wraps a distributor so that it can be activated as a complete service together with all its api and
+ * forwarding handlers.
*/
public class ApiActivator {
@@ -77,11 +77,9 @@ public class ApiActivator {
private void startApiRestServer() throws PolicyApiException {
apiParameterGroup.getRestServerParameters().setName(apiParameterGroup.getName());
restServer = new RestServer(apiParameterGroup.getRestServerParameters(), AafApiFilter.class,
- LegacyApiRestController.class,
- ApiRestController.class);
+ LegacyApiRestController.class, ApiRestController.class);
if (!restServer.start()) {
- throw new PolicyApiException(
- "Failed to start api rest server. Check log for more details...");
+ throw new PolicyApiException("Failed to start api rest server. Check log for more details...");
}
}
@@ -93,10 +91,15 @@ public class ApiActivator {
public void terminate() throws PolicyApiException {
try {
deregisterToParameterService(apiParameterGroup);
- ApiActivator.setAlive(false);
+
+ if (ApiActivator.isAlive()) {
+ ApiActivator.setAlive(false);
+ }
// Stop the api rest server
- restServer.stop();
+ if (restServer.isAlive()) {
+ restServer.stop();
+ }
} catch (final Exception exp) {
throw new PolicyApiException("Policy api service termination failed", exp);
}
@@ -126,7 +129,9 @@ public class ApiActivator {
* @param apiParameterGroup the api parameter group
*/
public void deregisterToParameterService(final ApiParameterGroup apiParameterGroup) {
- ParameterService.deregister(apiParameterGroup.getName());
+ if (ParameterService.contains(apiParameterGroup.getName())) {
+ ParameterService.deregister(apiParameterGroup.getName());
+ }
}
/**
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java
index 480a5d8a..9cc09f60 100644
--- a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+
import org.junit.Test;
import org.onap.policy.api.main.exception.PolicyApiException;
import org.onap.policy.api.main.startstop.ApiCommandLineArguments;
@@ -39,7 +40,7 @@ import org.onap.policy.api.main.startstop.ApiCommandLineArguments;
public class TestApiParameterHandler {
@Test
public void testParameterHandlerNoParameterFile() throws PolicyApiException {
- final String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" };
+ final String[] noArgumentString = {"-c", "parameters/NoParameterFile.json"};
final ApiCommandLineArguments noArguments = new ApiCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -53,7 +54,7 @@ public class TestApiParameterHandler {
@Test
public void testParameterHandlerEmptyParameters() throws PolicyApiException {
- final String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" };
+ final String[] emptyArgumentString = {"-c", "parameters/EmptyParameters.json"};
final ApiCommandLineArguments emptyArguments = new ApiCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
@@ -67,7 +68,7 @@ public class TestApiParameterHandler {
@Test
public void testParameterHandlerBadParameters() throws PolicyApiException {
- final String[] badArgumentString = { "-c", "parameters/BadParameters.json" };
+ final String[] badArgumentString = {"-c", "parameters/BadParameters.json"};
final ApiCommandLineArguments badArguments = new ApiCommandLineArguments();
badArguments.parse(badArgumentString);
@@ -83,7 +84,7 @@ public class TestApiParameterHandler {
@Test
public void testParameterHandlerInvalidParameters() throws PolicyApiException {
- final String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" };
+ final String[] invalidArgumentString = {"-c", "parameters/InvalidParameters.json"};
final ApiCommandLineArguments invalidArguments = new ApiCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
@@ -99,7 +100,7 @@ public class TestApiParameterHandler {
@Test
public void testParameterHandlerNoParameters() throws PolicyApiException {
- final String[] noArgumentString = { "-c", "parameters/NoParameters.json" };
+ final String[] noArgumentString = {"-c", "parameters/NoParameters.json"};
final ApiCommandLineArguments noArguments = new ApiCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -117,7 +118,7 @@ public class TestApiParameterHandler {
@Test
public void testParameterHandlerMinumumParameters() throws PolicyApiException {
- final String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" };
+ final String[] minArgumentString = {"-c", "parameters/MinimumParameters.json"};
final ApiCommandLineArguments minArguments = new ApiCommandLineArguments();
minArguments.parse(minArgumentString);
final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(minArguments);
@@ -126,7 +127,7 @@ public class TestApiParameterHandler {
@Test
public void testApiParameterGroup() throws PolicyApiException {
- final String[] apiConfigParameters = { "-c", "parameters/ApiConfigParameters.json" };
+ final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_Https.json"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
arguments.parse(apiConfigParameters);
final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(arguments);
@@ -136,7 +137,7 @@ public class TestApiParameterHandler {
@Test
public void testApiParameterGroup_InvalidName() throws PolicyApiException {
- final String[] apiConfigParameters = { "-c", "parameters/ApiConfigParameters_InvalidName.json" };
+ final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
arguments.parse(apiConfigParameters);
@@ -150,10 +151,8 @@ public class TestApiParameterHandler {
}
@Test
- public void testApiParameterGroup_InvalidRestServerParameters()
- throws PolicyApiException, IOException {
- final String[] apiConfigParameters =
- { "-c", "parameters/ApiConfigParameters_InvalidRestServerParameters.json" };
+ public void testApiParameterGroup_InvalidRestServerParameters() throws PolicyApiException, IOException {
+ final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidRestServerParameters.json"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
arguments.parse(apiConfigParameters);
@@ -170,7 +169,7 @@ public class TestApiParameterHandler {
@Test
public void testApiVersion() throws PolicyApiException {
- final String[] apiConfigParameters = { "-v" };
+ final String[] apiConfigParameters = {"-v"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
final String version = arguments.parse(apiConfigParameters);
assertTrue(version.startsWith("ONAP Policy Framework Api Service"));
@@ -178,7 +177,7 @@ public class TestApiParameterHandler {
@Test
public void testApiHelp() throws PolicyApiException {
- final String[] apiConfigParameters = { "-h" };
+ final String[] apiConfigParameters = {"-h"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
final String help = arguments.parse(apiConfigParameters);
assertTrue(help.startsWith("usage:"));
@@ -186,7 +185,7 @@ public class TestApiParameterHandler {
@Test
public void testApiInvalidOption() throws PolicyApiException {
- final String[] apiConfigParameters = { "-d" };
+ final String[] apiConfigParameters = {"-d"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
try {
arguments.parse(apiConfigParameters);
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 3636d625..abc87383 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,39 +26,36 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.security.SecureRandom;
-import java.security.cert.X509Certificate;
import java.util.Base64;
import java.util.Collections;
import java.util.Properties;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
-import org.glassfish.jersey.client.ClientConfig;
+
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.api.main.exception.PolicyApiException;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.api.main.parameters.CommonTestData;
import org.onap.policy.api.main.rest.provider.PolicyProvider;
import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
import org.onap.policy.api.main.startstop.Main;
-import org.onap.policy.common.endpoints.http.server.RestServer;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
-import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.parameters.ParameterService;
@@ -66,14 +63,14 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Class to perform unit test of {@link ApiRestServer}.
@@ -81,9 +78,6 @@ import org.slf4j.LoggerFactory;
* @author Chenfei Gao (cgao@research.att.com)
*/
public class TestApiRestServer {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(TestApiRestServer.class);
- private static final String NOT_ALIVE = "not alive";
private static final String ALIVE = "alive";
private static final String SELF = NetworkUtil.getHostname();
private static final String NAME = "Policy API";
@@ -155,15 +149,9 @@ public class TestApiRestServer {
private static final String POLICIES = "policies";
private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
- private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
- private Main main;
- private RestServer restServer;
- private StandardCoder standardCoder = new StandardCoder();
- private StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
- private int port;
// @formatter:off
- private String[] toscaPolicyResourceNames = {
+ private static final String[] TOSCA_POLICY_RESOURCE_NAMES = {
"policies/vCPE.policy.monitoring.input.tosca.json",
"policies/vCPE.policy.monitoring.input.tosca.yaml",
"policies/vDNS.policy.monitoring.input.tosca.json",
@@ -172,12 +160,12 @@ public class TestApiRestServer {
"policies/vFirewall.policy.monitoring.input.tosca.yaml"
};
- private String[] toscaPoliciesResourceNames = {
+ private static final String[] TOSCA_POLICIES_RESOURCE_NAMES = {
"policies/vCPE.policies.optimization.input.tosca.json",
"policies/vCPE.policies.optimization.input.tosca.yaml"
};
- private String[] toscaPolicyTypeResourceNames = {
+ private static final String[] TOSCA_PPOLICYTYPE_RESOURCE_NAMES = {
"policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
"policytypes/onap.policies.Optimization.yaml",
@@ -197,12 +185,12 @@ public class TestApiRestServer {
"policytypes/onap.policies.optimization.resource.VnfPolicy.yaml"
};
- private String[] legacyGuardPolicyResourceNames = {
+ private static final String[] LEGACY_GUARD_POLICY_RESOURCE_NAMES = {
"policies/vDNS.policy.guard.frequency.input.json",
"policies/vDNS.policy.guard.minmax.input.json"
};
- private String[] legacyOperationalPolicyResourceNames = {
+ private static final String[] LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES = {
"policies/vCPE.policy.operational.input.json",
"policies/vDNS.policy.operational.input.json",
"policies/vFirewall.policy.operational.input.json"
@@ -215,14 +203,20 @@ public class TestApiRestServer {
// @formatter:on
+ private static final StandardCoder standardCoder = new StandardCoder();
+
+ private static int apiPort;
+ private static Main apiMain;
+
+ private static StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
+
/**
* Initializes parameters.
*
* @throws PfModelException the PfModel parsing exception
*/
- private void setupParameters() throws PfModelException {
-
- standardCoder = new StandardCoder();
+ @BeforeClass
+ public static void setupParameters() throws PfModelException {
providerParams = new PolicyModelsProviderParameters();
providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
@@ -231,1345 +225,728 @@ public class TestApiRestServer {
providerParams.setPersistenceUnit("ToscaConceptTest");
apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList());
ParameterService.register(apiParamGroup, true);
+
policyTypeProvider = new PolicyTypeProvider();
policyProvider = new PolicyProvider();
}
/**
- * Method for cleanup after each test.
+ * Set up test environemnt.
+ *
+ * @throws Exception on test setup exceptions
*/
- @After
- public void teardown() throws Exception {
- if (policyTypeProvider != null) {
- policyTypeProvider.close();
- }
- if (policyProvider != null) {
- policyProvider.close();
- }
- if (main != null) {
- stopApiService(main);
- } else if (restServer != null) {
- restServer.stop();
- }
- }
-
- @Test
- public void testApiStatisticsConstructorIsPrivate() {
+ @BeforeClass
+ public static void beforeStartApiService() throws Exception {
+ apiPort = NetworkUtil.allocPort();
- try {
- final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
- assertTrue(Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- } catch (final Exception exp) {
- assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
- }
- }
-
- @Test
- public void testCreatePolicyTypes() {
- try {
- main = startApiService(true);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ final String[] apiConfigParameters = new String[2];
+ final Properties systemProps = System.getProperties();
+ systemProps.put("javax.net.ssl.keyStore", KEYSTORE);
+ systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
+ System.setProperties(systemProps);
+ new CommonTestData().makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
+ "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json", apiPort);
+ apiConfigParameters[0] = "-c";
+ apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json";
+ apiMain = new Main(apiConfigParameters);
}
- @Test
- public void testCreatePolicies() {
- try {
- main = startApiService(true);
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ /**
+ * Method for cleanup after each test.
+ */
+ @AfterClass
+ public static void teardown() throws Exception {
+ policyTypeProvider.close();
+ policyProvider.close();
- @Test
- public void testCreatePoliciesPersistent() throws Exception {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
+ if (apiMain != null) {
+ apiMain.shutdown();
}
}
- @Test
- public void testSimpleCreatePolicies() throws Exception {
- main = startApiService(true);
- for (String resrcName : toscaPoliciesResourceNames) {
- Response rawResponse = createResource(POLICIES, resrcName, true);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type onap.policies.optimization.resource.AffinityPolicy:1.0.0 for "
- + "policy OSDF_CASABLANCA.Affinity_Default:1.0.0 does not exist", error.getErrorMessage());
- }
- }
+ /**
+ * Clear the database before each test.
+ *
+ * @throws Exception on clearing exceptions
+ */
+ @Before
+ public void beforeClearDatabase() throws Exception {
+ Response rawResponse = readResource(POLICYTYPES, APP_JSON);
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- @Test
- public void testSimpleCreatePoliciesPersistent() throws Exception {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : toscaPoliciesResourceNames) {
- Response rawResponse = createResource(POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
- }
- }
+ for (ToscaEntityKey policyTypeKey : response.getPolicyTypesAsMap().keySet()) {
+ String getPoliciesPath =
+ "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion() + "/policies";
- @Test
- public void testCreateGuardPolicies() {
- try {
- main = startApiService(true);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ Response rawPolicyResponse = readResource(getPoliciesPath, APP_JSON);
+ if (Response.Status.OK.getStatusCode() == rawPolicyResponse.getStatus()) {
+ ToscaServiceTemplate policyResponse = rawPolicyResponse.readEntity(ToscaServiceTemplate.class);
- @Test
- public void testCreateGuardPoliciesPersistent() {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ for (ToscaEntityKey policyKey : policyResponse.getToscaTopologyTemplate().getPoliciesAsMap().keySet()) {
+ String deletePolicyPath =
+ "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion()
+ + "/policies/" + policyKey.getName() + "/versions/" + policyKey.getVersion();
+ deleteResource(deletePolicyPath, APP_JSON);
+ }
}
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
- @Test
- public void testCreateOperationalPolicies() {
- try {
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
+ String deletePolicyTypePath =
+ "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion();
+ deleteResource(deletePolicyTypePath, APP_JSON);
}
}
@Test
- public void testCreateOperationalPoliciesPersistent() {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ public void testApiStatisticsConstructorIsPrivate() {
- @Test
- public void testHttpsCreatePolicyTypes() {
try {
- main = startApiService(false);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, false);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
+ assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+ constructor.setAccessible(true);
+ constructor.newInstance();
- @Test
- public void testHttpsCreatePolicies() {
- try {
- main = startApiService(false);
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, false);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
+ } catch (final Exception exp) {
+ assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
}
}
@Test
- public void testHttpsCreatePoliciesPersistent() throws Exception {
- setupParameters(); // setup DB
- main = startApiService(false);
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, false);
+ public void testCreatePolicyTypes() throws Exception {
+ for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertNotNull(response);
- assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
+ assertFalse(response.getPolicyTypes().isEmpty());
}
- }
- @Test
- public void testHttpsSimpleCreatePolicies() throws Exception {
- main = startApiService(false);
- for (String resrcName : toscaPoliciesResourceNames) {
- Response rawResponse = createResource(POLICIES, resrcName, false);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type onap.policies.optimization.resource.AffinityPolicy:1.0.0 for "
- + "policy OSDF_CASABLANCA.Affinity_Default:1.0.0 does not exist", error.getErrorMessage());
- }
+ // Send a policy type with a null value to trigger an error
+ Response rawResponse = readResource(POLICYTYPES, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ String firstPolicyType = response.getPolicyTypes().keySet().iterator().next();
+ response.getPolicyTypes().put(firstPolicyType, null);
+ Response rawResponse2 = createResource(POLICYTYPES, standardCoder.encode(response));
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
+ ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
+ assertEquals("no policy types specified on service template", errorResponse.getErrorMessage());
}
@Test
- public void testHttpsSimpleCreatePoliciesPersistent() throws Exception {
- setupParameters(); // setup DB
- main = startApiService(false);
- for (String resrcName : toscaPoliciesResourceNames) {
- Response rawResponse = createResource(POLICIES, resrcName, false);
+ public void testCreatePolicies() throws Exception {
+ createPolicyTypes();
+
+ for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
}
- }
- @Test
- public void testHttpsCreateGuardPolicies() {
- try {
- main = startApiService(false);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, false);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ new File("src/test/resources/policies/BadTestPolicy.yaml").deleteOnExit();
- @Test
- public void testHttpsCreateOperationalPolicies() {
- try {
- main = startApiService(false);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, false);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- }
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ // Send a policy with no policy type trigger an error
+ String toscaPolicy = ResourceUtils
+ .getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]);
- @Test
- public void testHealthCheckSuccessJson() {
- testHealthCheckSuccess(APP_JSON);
- }
+ toscaPolicy = toscaPolicy.replaceAll("onap.policies.monitoring.cdap.tca.hi.lo.app", "");
+ TextFileUtils.putStringAsTextFile(toscaPolicy, "src/test/resources/policies/BadTestPolicy.yaml");
- @Test
- public void testHealthCheckSuccessYaml() {
- testHealthCheckSuccess(APP_YAML);
+ Response rawResponse2 =
+ createResource(POLICYTYPES_TCA_POLICIES, "src/test/resources/policies/BadTestPolicy.yaml");
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
+ ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
+ assertEquals("policy type id does not match", errorResponse.getErrorMessage());
}
+ @Test
+ public void testSimpleCreatePolicies() throws Exception {
+ testCreatePolicyTypes();
-
- private void testHealthCheckSuccess(String mediaType) {
-
- try {
- main = startApiService(true);
- final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT, mediaType);
- final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
- } catch (final Exception exp) {
- LOGGER.error("testHealthCheckSuccess failed", exp);
- fail("Test should not throw an exception");
+ for (String resrcName : TOSCA_POLICIES_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
- }
- @Test
- public void testHealthCheckFailureJson() {
- testHealthCheckFailure(APP_JSON);
- }
+ new File("src/test/resources/policies/BadTestPolicy.yaml").deleteOnExit();
- @Test
- public void testHealthCheckFailureYaml() {
- testHealthCheckFailure(APP_YAML);
- }
+ // Send a policy with no policy type trigger an error
+ String toscaPolicy = ResourceUtils
+ .getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]);
- private void testHealthCheckFailure(String mediaType) {
- try {
- port = NetworkUtil.allocPort();
- final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
- restServerParams.setName(CommonTestData.API_GROUP_NAME);
- restServer = new RestServer(restServerParams, null, ApiRestController.class);
-
- restServer.start();
- final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT, mediaType);
- final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(NAME, SELF, false, 500, NOT_ALIVE, report);
- assertTrue(restServer.isAlive());
- assertTrue(restServer.toString().startsWith("RestServer [servers="));
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ toscaPolicy = toscaPolicy.replaceAll("onap.policies.monitoring.cdap.tca.hi.lo.app", "");
+ TextFileUtils.putStringAsTextFile(toscaPolicy, "src/test/resources/policies/BadTestPolicy.yaml");
- @Test
- public void testHttpsHealthCheckSuccessJson() {
- testHttpsHealthCheckSuccess(APP_JSON);
+ Response rawResponse2 = createResource(POLICIES, "src/test/resources/policies/BadTestPolicy.yaml");
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
+ ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
+ assertEquals("policy type NULL:0.0.0 for policy onap.restart.tca:1.0.0 does not exist",
+ errorResponse.getErrorMessage());
}
@Test
- public void testHttpsHealthCheckSuccessYaml() {
- testHttpsHealthCheckSuccess(APP_YAML);
- }
+ public void testCreateGuardPolicies() throws Exception {
+ createPolicyTypes();
- private void testHttpsHealthCheckSuccess(String mediaType) {
- try {
- main = startApiService(false);
- final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT, mediaType);
- final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
- } catch (Exception exp) {
- fail("Test should not throw an exception");
+ for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
}
@Test
- public void testApiStatistics_200_Json() {
- testApiStatistics_200(APP_JSON);
- }
-
- @Test
- public void testApiStatistics_200_Yaml() {
- testApiStatistics_200(APP_YAML);
- }
+ public void testCreateOperationalPolicies() throws Exception {
+ createPolicyTypes();
- private void testApiStatistics_200(String mediaType) {
- try {
- main = startApiService(true);
- Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT, mediaType);
- StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- updateApiStatistics();
- invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT, mediaType);
- report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- ApiStatisticsManager.resetAllStatistics();
- } catch (Exception exp) {
- fail("Test should not throw an exception");
+ for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
}
@Test
- public void testHttpsApiStatisticsJson() {
- testHttpsApiStatistics(APP_JSON);
+ public void testHealthCheckSuccessJson() throws Exception {
+ testHealthCheckSuccess(APP_JSON);
}
@Test
- public void testHttpsApiStatisticsYaml() {
- testHttpsApiStatistics(APP_YAML);
+ public void testHealthCheckSuccessYaml() throws Exception {
+ testHealthCheckSuccess(APP_YAML);
}
- private void testHttpsApiStatistics(String mediaType) {
- try {
- main = startApiService(false);
- final Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType);
- final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testHealthCheckSuccess(String mediaType) throws Exception {
+ final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT, mediaType);
+ final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
+ validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
}
@Test
- public void testApiStatistics_500_Json() {
- testApiStatistics_500(APP_JSON);
+ public void testApiStatistics_200_Json() throws Exception {
+ testApiStatistics_200(APP_JSON);
}
@Test
- public void testApiStatistics_500_Yaml() {
- testApiStatistics_500(APP_YAML);
+ public void testApiStatistics_200_Yaml() throws Exception {
+ testApiStatistics_200(APP_YAML);
}
-
- private void testApiStatistics_500(String mediaType) {
- try {
- port = NetworkUtil.allocPort();
- final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
- restServerParams.setName(CommonTestData.API_GROUP_NAME);
- restServer = new RestServer(restServerParams, null, ApiRestController.class);
-
- restServer.start();
- final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT, mediaType);
- final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 500);
- ApiStatisticsManager.resetAllStatistics();
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testApiStatistics_200(String mediaType) throws Exception {
+ Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType);
+ StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
+ validateStatisticsReport(report, 200);
+ updateApiStatistics();
+ invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType);
+ report = invocationBuilder.get(StatisticsReport.class);
+ validateStatisticsReport(report, 200);
+ ApiStatisticsManager.resetAllStatistics();
}
-
@Test
- public void testReadPolicyTypesJson() {
+ public void testReadPolicyTypesJson() throws Exception {
testReadPolicyTypes(APP_JSON);
}
@Test
- public void testReadPolicyTypesYaml() {
+ public void testReadPolicyTypesYaml() throws Exception {
testReadPolicyTypes(APP_YAML);
}
- private void testReadPolicyTypes(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertTrue(response.getPolicyTypes().isEmpty());
-
- rawResponse = readResource(POLICYTYPES_TCA, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:null does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_TCA_VERSION, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_TCA_LATEST, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:null does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_COLLECTOR, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID "
- + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID "
- + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:1.0.0 does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID "
- + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
- error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ private void testReadPolicyTypes(String mediaType) throws Exception {
+ createPolicyTypes();
- @Test
- public void testReadPreloadPolicyTypesPersistentJson() throws Exception {
- setupParameters();
- main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES, true, APP_JSON);
+ Response rawResponse = readResource(POLICYTYPES, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertEquals(28, response.getPolicyTypes().size());
- }
+ assertFalse(response.getPolicyTypes().isEmpty());
- @Test
- public void testReadPreloadPolicyTypesPersistentYaml() throws Exception {
- setupParameters();
- main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES, true, APP_YAML);
+ rawResponse = readResource(POLICYTYPES_TCA, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertEquals(28, response.getPolicyTypes().size());
- }
-
- @Test
- public void testReadPolicyTypesPersistentJson() {
- testReadPolicyTypesPersistent(APP_JSON);
- }
-
- @Test
- public void testReadPolicyTypesPersistentYaml() {
- testReadPolicyTypesPersistent(APP_YAML);
- }
- private void testReadPolicyTypesPersistent(String mediaType) {
- try {
- setupParameters();
- main = startApiService(true);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
-
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- Response rawResponse = readResource(POLICYTYPES_TCA, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = readResource(POLICYTYPES_TCA_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
-
- rawResponse = readResource(POLICYTYPES_TCA_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
-
- rawResponse = readResource(POLICYTYPES_COLLECTOR, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_COLLECTOR, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testDeletePolicyTypeJson() {
+ public void testDeletePolicyTypeJson() throws Exception {
testDeletePolicyType(APP_JSON);
}
@Test
- public void testDeletePolicyTypeYaml() {
+ public void testDeletePolicyTypeYaml() throws Exception {
testDeletePolicyType(APP_YAML);
}
- private void testDeletePolicyType(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
-
- rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID "
- + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:1.0.0 does not exist",
- error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testDeletePolicyTypePersistentJson() {
- testDeletePolicyTypePersistent(APP_JSON);
- }
+ private void testDeletePolicyType(String mediaType) throws Exception {
+ createPolicyTypes();
- @Test
- public void testDeletePolicyTypePersistentYaml() {
- testDeletePolicyTypePersistent(APP_YAML);
- }
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- private void testDeletePolicyTypePersistent(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);// create policy types
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
+ rawResponse = readResource(POLICYTYPES_TCA_VERSION, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- @Test
- public void testReadPoliciesJson() {
- testReadPolicies(APP_JSON);
- }
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- @Test
- public void testReadPoliciesYaml() {
- testReadPolicies(APP_YAML);
- }
+ rawResponse = readResource(POLICYTYPES_COLLECTOR, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- private void testReadPolicies(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID null:null and "
- + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:null and "
- + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:1.0.0 and "
- + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
-
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:null and "
- + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type with ID "
+ + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
+ errorResponse.getErrorMessage());
}
@Test
- public void testReadPoliciesPersistentJson() {
- testReadPoliciesPersistent(APP_JSON);
+ public void testReadPoliciesJson() throws Exception {
+ testReadPolicies(APP_JSON);
}
@Test
- public void testReadPoliciesPersistentYaml() {
- testReadPoliciesPersistent(APP_YAML);
+ public void testReadPoliciesYaml() throws Exception {
+ testReadPolicies(APP_YAML);
}
- private void testReadPoliciesPersistent(String mediaType) {
- try {
- setupParameters();
- main = startApiService(true);
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
-
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
+ private void testReadPolicies(String mediaType) throws Exception {
+ testCreatePolicies();
- Response rawResponse;
- rawResponse = readResource(POLICYTYPES_TCA, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testDeletePoliciesJson() {
+ public void testDeletePoliciesJson() throws Exception {
testDeletePolicies(APP_JSON);
}
@Test
- public void testDeletePoliciesYaml() {
+ public void testDeletePoliciesYaml() throws Exception {
testDeletePolicies(APP_YAML);
}
- private void testDeletePolicies(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:1.0.0 and "
- + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testDeletePolicies(String mediaType) throws Exception {
+ createPolicyTypes();
+
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "policy with ID onap.restart.tca:1.0.0 and "
+ + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ error.getErrorMessage());
}
@Test
- public void testDeletePolicyVersionJson() {
+ public void testDeletePolicyVersionJson() throws Exception {
testDeletePolicyVersion(APP_JSON);
}
@Test
- public void testDeletePolicyVersionYaml() {
+ public void testDeletePolicyVersionYaml() throws Exception {
testDeletePolicyVersion(APP_YAML);
}
- private void testDeletePolicyVersion(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);// create policy types
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, true, mediaType);
+ private void testDeletePolicyVersion(String mediaType) throws Exception {
+ for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
}
- }
+ for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- @Test
- public void testGetAllVersionOfPolicyJson() {
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "policy with ID onap.restart.tca:1.0.0 and type "
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ errorResponse.getErrorMessage());
+
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "policy with ID onap.restart.tca:null and type "
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ errorResponse.getErrorMessage());
+
+ rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "policy with ID onap.restart.tca:null and type "
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ errorResponse.getErrorMessage());
+ }
+
+ @Test
+ public void testGetAllVersionOfPolicyJson() throws Exception {
testGetAllVersionOfPolicy(APP_JSON);
}
@Test
- public void testGetAllVersionOfPolicyYaml() {
+ public void testGetAllVersionOfPolicyYaml() throws Exception {
testGetAllVersionOfPolicy(APP_YAML);
}
- private void testGetAllVersionOfPolicy(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);// create policy types
- for (String resrcName : toscaPolicyTypeResourceNames) {
- Response rawResponse = createResource(POLICYTYPES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
- assertNotNull(response);
- assertFalse(response.getPolicyTypes().isEmpty());
- }
- for (String resrcName : toscaPolicyResourceNames) {
- Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, true, mediaType);
+ private void testGetAllVersionOfPolicy(String mediaType) throws Exception {
+ for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
}
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
-
@Test
- public void testReadGuardPoliciesJson() {
+ public void testReadGuardPoliciesJson() throws Exception {
testReadGuardPolicies(APP_JSON);
}
@Test
- public void testReadGuardPoliciesYaml() {
+ public void testReadGuardPoliciesYaml() throws Exception {
testReadGuardPolicies(APP_YAML);
}
- private void testReadGuardPolicies(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: guard.frequency.scaleout:null", error.getErrorMessage());
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: guard.frequency.scaleout:1", error.getErrorMessage());
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: guard.minmax.scaleout:null", error.getErrorMessage());
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: guard.minmax.scaleout:1", error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testReadGuardPoliciesPersistentJson() {
- testReadGuardPoliciesPersistent(APP_JSON);
- }
-
- @Test
- public void testReadGuardPoliciesPersistentYaml() {
- testReadGuardPoliciesPersistent(APP_YAML);
- }
-
- private void testReadGuardPoliciesPersistent(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
+ private void testReadGuardPolicies(String mediaType) throws Exception {
+ createGuardPolicies();
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
-
- rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
-
@Test
- public void testReadOperationalPoliciesJson() {
+ public void testReadOperationalPoliciesJson() throws Exception {
testReadOperationalPolicies(APP_JSON);
}
@Test
- public void testReadOperationalPoliciesYaml() {
+ public void testReadOperationalPoliciesYaml() throws Exception {
testReadOperationalPolicies(APP_YAML);
}
- private void testReadOperationalPolicies(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.restart:null", error.getErrorMessage());
-
- rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
-
- rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.scaleout:null", error.getErrorMessage());
-
- rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.scaleout:1", error.getErrorMessage());
-
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.modifyconfig:null", error.getErrorMessage());
-
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.modifyconfig:1", error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testReadOperationalPoliciesPersistentJson() {
- testReadOperationalPoliciesPersistent(APP_JSON);
- }
-
- @Test
- public void testReadOperationalPoliciesPersistentYaml() {
- testReadOperationalPoliciesPersistent(APP_YAML);
- }
-
- private void testReadOperationalPoliciesPersistent(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
-
- rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
-
- rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ private void testReadOperationalPolicies(String mediaType) throws Exception {
+ createOperationalPolicies();
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testDeleteGuardPolicyJson() {
+ public void testDeleteGuardPolicyJson() throws Exception {
testDeleteGuardPolicy(APP_JSON);
}
@Test
- public void testDeleteGuardPolicyYaml() {
+ public void testDeleteGuardPolicyYaml() throws Exception {
testDeleteGuardPolicy(APP_YAML);
}
- private void testDeleteGuardPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: guard.frequency.scaleout:1", error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testDeleteGuardPolicyPersistentJson() {
- testDeleteGuardPolicyPersistent(APP_JSON);
- }
+ private void testDeleteGuardPolicy(String mediaType) throws Exception {
+ createGuardPolicies();
- @Test
- public void testDeleteGuardPolicyPersistentYaml() {
- testDeleteGuardPolicyPersistent(APP_YAML);
- }
-
- private void testDeleteGuardPolicyPersistent(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);
-
- for (String resrcName : legacyGuardPolicyResourceNames) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
-
- Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
- public void testGetDeployedVersionsOfGuardPolicyJson() {
+ public void testGetDeployedVersionsOfGuardPolicyJson() throws Exception {
testGetDeployedVersionsOfGuardPolicy(APP_JSON);
}
@Test
- public void testGetDeployedVersionsOfGuardPolicyYaml() {
+ public void testGetDeployedVersionsOfGuardPolicyYaml() throws Exception {
testGetDeployedVersionsOfGuardPolicy(APP_YAML);
}
- private void testGetDeployedVersionsOfGuardPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testGetDeployedVersionsOfGuardPolicy(String mediaType) throws Exception {
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_DEPLOYED, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "could not find policy with ID guard.frequency.scaleout and type "
+ + "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0 deployed in any pdp group",
+ errorResponse.getErrorMessage());
}
@Test
- public void testDeleteOperationalPolicyJson() {
+ public void testDeleteOperationalPolicyJson() throws Exception {
testDeleteOperationalPolicy(APP_JSON);
}
@Test
- public void testDeleteOperationalPolicyYaml() {
+ public void testDeleteOperationalPolicyYaml() throws Exception {
testDeleteOperationalPolicy(APP_YAML);
}
- private void testDeleteOperationalPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
- }
-
- @Test
- public void testDeleteOperationalPolicyPersistentJson() {
- testDeleteOperationalPolicyPersistent(APP_JSON);
- }
+ private void testDeleteOperationalPolicy(String mediaType) throws Exception {
+ createPolicyTypes();
- @Test
- public void testDeleteOperationalPolicyPersistentYaml() {
- testDeleteOperationalPolicyPersistent(APP_YAML);
- }
-
- private void testDeleteOperationalPolicyPersistent(String mediaType) {
- try {
- setupParameters(); // setup DB
- main = startApiService(true);
- for (String resrcName : legacyOperationalPolicyResourceNames) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, mediaType);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
}
-
@Test
- public void testGetDeployedVersionsOfPolicyJson() {
+ public void testGetDeployedVersionsOfPolicyJson() throws Exception {
testGetDeployedVersionsOfPolicy(APP_JSON);
}
@Test
- public void testGetDeployedVersionsOfPolicyYaml() {
+ public void testGetDeployedVersionsOfPolicyYaml() throws Exception {
testGetDeployedVersionsOfPolicy(APP_YAML);
}
- private void testGetDeployedVersionsOfPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testGetDeployedVersionsOfPolicy(String mediaType) throws Exception {
+ Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "could not find policy with ID onap.restart.tca and type "
+ + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 deployed in any pdp group",
+ errorResponse.getErrorMessage());
}
@Test
- public void testGetLatestVersionOfOperationalPolicyJson() {
+ public void testGetLatestVersionOfOperationalPolicyJson() throws Exception {
testGetLatestVersionOfOperationalPolicy(APP_JSON);
}
@Test
- public void testGetLatestVersionOfOperationalPolicyYaml() {
+ public void testGetLatestVersionOfOperationalPolicyYaml() throws Exception {
testGetLatestVersionOfOperationalPolicy(APP_YAML);
}
- private void testGetLatestVersionOfOperationalPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testGetLatestVersionOfOperationalPolicy(String mediaType) throws Exception {
+ Response rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, mediaType);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy: operational.scaleout:null", errorResponse.getErrorMessage());
}
@Test
- public void testGetSpecificVersionOfOperationalPolicyJson() {
+ public void testGetSpecificVersionOfOperationalPolicyJson() throws Exception {
testGetSpecificVersionOfOperationalPolicy(APP_JSON);
}
@Test
- public void testGetSpecificVersionOfOperationalPolicyYaml() {
+ public void testGetSpecificVersionOfOperationalPolicyYaml() throws Exception {
testGetSpecificVersionOfOperationalPolicy(APP_YAML);
}
- private void testGetSpecificVersionOfOperationalPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testGetSpecificVersionOfOperationalPolicy(String mediaType) throws Exception {
+ Response rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, mediaType);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy: operational.scaleout:1", errorResponse.getErrorMessage());
}
@Test
- public void testGetDeployedVersionsOfOperationalPolicyJson() {
+ public void testGetDeployedVersionsOfOperationalPolicyJson() throws Exception {
testGetDeployedVersionsOfOperationalPolicy(APP_JSON);
}
@Test
- public void testGetDeployedVersionsOfOperationalPolicyYaml() {
+ public void testGetDeployedVersionsOfOperationalPolicyYaml() throws Exception {
testGetDeployedVersionsOfOperationalPolicy(APP_YAML);
}
- private void testGetDeployedVersionsOfOperationalPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, true, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ private void testGetDeployedVersionsOfOperationalPolicy(String mediaType) throws Exception {
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, mediaType);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals(
+ "could not find policy with ID operational.restart and type "
+ + "onap.policies.controlloop.Operational:1.0.0 deployed in any pdp group",
+ errorResponse.getErrorMessage());
}
@Test
- public void testDeleteSpecificVersionOfOperationalPolicyJson() {
- testDeleteSpecificVersionOfOperationalPolicy(APP_JSON);
- }
+ public void testDeleteSpecificVersionOfOperationalPolicy() throws Exception {
+ createOperationalPolicies();
- @Test
- public void testDeleteSpecificVersionOfOperationalPolicyYaml() {
- testDeleteSpecificVersionOfOperationalPolicy(APP_YAML);
- }
+ Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- private void testDeleteSpecificVersionOfOperationalPolicy(String mediaType) {
- try {
- main = startApiService(true);
- Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, true, mediaType);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
- } catch (Exception exp) {
- fail("Test should not throw an exception");
- }
+ rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_YAML);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("no policy found for policy: operational.scaleout:1", errorResponse.getErrorMessage());
}
- private Response createResource(String endpoint, String resourceName, boolean http)
- throws Exception {
+ private Response createResource(String endpoint, String resourceName) throws Exception {
String mediaType = APP_JSON; // default media type
ToscaServiceTemplate rawServiceTemplate = new ToscaServiceTemplate();
if (resourceName.endsWith(".json")) {
- rawServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
+ rawServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
} else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
mediaType = APP_YAML;
- rawServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
+ rawServiceTemplate = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
+ ToscaServiceTemplate.class);
}
final Invocation.Builder invocationBuilder;
- if (http) {
- invocationBuilder = sendHttpRequest(endpoint, mediaType);
- } else {
- invocationBuilder = sendHttpsRequest(endpoint, mediaType);
- }
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
return invocationBuilder.post(entity);
}
- private Response createGuardPolicy(String endpoint, String resourceName, boolean http)
- throws Exception {
+ private Response createGuardPolicy(String endpoint, String resourceName) throws Exception {
String mediaType = APP_JSON; // default media type
LegacyGuardPolicyInput rawGuardPolicy = new LegacyGuardPolicyInput();
if (resourceName.endsWith(".json")) {
- rawGuardPolicy = standardCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
+ rawGuardPolicy =
+ standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
} else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
mediaType = APP_YAML;
- rawGuardPolicy = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), LegacyGuardPolicyInput.class);
+ rawGuardPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
+ LegacyGuardPolicyInput.class);
}
final Invocation.Builder invocationBuilder;
- if (http) {
- invocationBuilder = sendHttpRequest(endpoint, mediaType);
- } else {
- invocationBuilder = sendHttpsRequest(endpoint, mediaType);
- }
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, mediaType);
return invocationBuilder.post(entity);
}
- private Response createOperationalPolicy(String endpoint, String resourceName, boolean http)
- throws Exception {
+ private Response createOperationalPolicy(String endpoint, String resourceName) throws Exception {
String mediaType = APP_JSON; // default media type
LegacyOperationalPolicy rawOpsPolicy = new LegacyOperationalPolicy();
if (resourceName.endsWith(".json")) {
- rawOpsPolicy = standardCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
+ rawOpsPolicy = standardCoder.decode(ResourceUtils.getResourceAsString(resourceName),
+ LegacyOperationalPolicy.class);
} else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) {
mediaType = APP_YAML;
- rawOpsPolicy = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class);
+ rawOpsPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName),
+ LegacyOperationalPolicy.class);
}
final Invocation.Builder invocationBuilder;
- if (http) {
- invocationBuilder = sendHttpRequest(endpoint, mediaType);
- } else {
- invocationBuilder = sendHttpsRequest(endpoint, mediaType);
- }
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
Entity<LegacyOperationalPolicy> entity = Entity.entity(rawOpsPolicy, mediaType);
return invocationBuilder.post(entity);
}
- private Response readResource(String endpoint, boolean http, String mediaType) throws Exception {
+ private Response readResource(String endpoint, String mediaType) throws Exception {
final Invocation.Builder invocationBuilder;
- if (http) {
- invocationBuilder = sendHttpRequest(endpoint, mediaType);
- } else {
- invocationBuilder = sendHttpsRequest(endpoint, mediaType);
- }
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
return invocationBuilder.get();
}
- private Response deleteResource(String endpoint, boolean http, String mediaType) throws Exception {
+ private Response deleteResource(String endpoint, String mediaType) throws Exception {
final Invocation.Builder invocationBuilder;
- if (http) {
- invocationBuilder = sendHttpRequest(endpoint, mediaType);
- } else {
- invocationBuilder = sendHttpsRequest(endpoint, mediaType);
- }
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType);
return invocationBuilder.delete();
}
- private Main startApiService(final boolean http) throws Exception {
- port = NetworkUtil.allocPort();
-
- final String[] apiConfigParameters = new String[2];
- if (http) {
- COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters.json",
- "src/test/resources/parameters/ApiConfigParametersXXX.json", port);
- apiConfigParameters[0] = "-c";
- apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParametersXXX.json";
- } else {
- final Properties systemProps = System.getProperties();
- systemProps.put("javax.net.ssl.keyStore", KEYSTORE);
- systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
- System.setProperties(systemProps);
- COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
- "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json", port);
- apiConfigParameters[0] = "-c";
- apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json";
+ private void createPolicyTypes() throws Exception {
+ for (String resrcName : TOSCA_PPOLICYTYPE_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
- return new Main(apiConfigParameters);
- }
-
- private void stopApiService(final Main main) throws PolicyApiException {
-
- main.shutdown();
}
- private Invocation.Builder sendHttpRequest(final String endpoint, String mediaType) throws Exception {
-
- final ClientConfig clientConfig = new ClientConfig();
-
- final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
- clientConfig.register(feature);
-
- final Client client = ClientBuilder.newClient(clientConfig);
+ private void createGuardPolicies() throws Exception {
+ createPolicyTypes();
- client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
- if (APP_JSON.equalsIgnoreCase(mediaType)) {
- client.register(GsonMessageBodyHandler.class);
- } else if (APP_YAML.equalsIgnoreCase(mediaType)) {
- client.register(YamlMessageBodyHandler.class);
+ for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
+ }
- final WebTarget webTarget = client.target("http://localhost:" + port + "/policy/api/v1/" + endpoint);
-
- final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
+ private void createOperationalPolicies() throws Exception {
+ createPolicyTypes();
- if (!NetworkUtil.isTcpPortOpen("localhost", port, 60, 1000L)) {
- throw new IllegalStateException("cannot connect to port " + port);
+ for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
- return invocationBuilder;
}
private Invocation.Builder sendHttpsRequest(final String endpoint, String mediaType) throws Exception {
- final TrustManager[] noopTrustManager = new TrustManager[] { new X509TrustManager() {
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return new X509Certificate[0];
- }
-
- @Override
- public void checkClientTrusted(final java.security.cert.X509Certificate[] certs, final String authType) {}
-
- @Override
- public void checkServerTrusted(final java.security.cert.X509Certificate[] certs, final String authType) {}
- } };
+ final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager();
final SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, noopTrustManager, new SecureRandom());
@@ -1586,12 +963,12 @@ public class TestApiRestServer {
client.register(YamlMessageBodyHandler.class);
}
- final WebTarget webTarget = client.target("https://localhost:" + port + "/policy/api/v1/" + endpoint);
+ final WebTarget webTarget = client.target("https://localhost:" + apiPort + "/policy/api/v1/" + endpoint);
final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
- if (!NetworkUtil.isTcpPortOpen("localhost", port, 60, 1000L)) {
- throw new IllegalStateException("cannot connect to port " + port);
+ if (!NetworkUtil.isTcpPortOpen("localhost", apiPort, 60, 1000L)) {
+ throw new IllegalStateException("cannot connect to port " + apiPort);
}
return invocationBuilder;
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
index 3b6fad5a..62bd0c37 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
@@ -43,14 +43,13 @@ public class TestCommonRestController {
public void testAddLoggingHeaders() {
UUID requestId = UUID.randomUUID();
ResponseBuilder rb =
- crc.addLoggingHeaders(
- crc.addVersionControlHeaders(Response.status(Response.Status.OK)), requestId);
+ crc.addLoggingHeaders(crc.addVersionControlHeaders(Response.status(Response.Status.OK)), requestId);
assertTrue(rb.equals(rb.header("X-ONAP-RequestID", requestId)));
}
/*
- * Tests null response for null object
- */
+ * Tests null response for null object
+ */
@Test
public void testToJsonNull() {
assertNull(crc.toJson(null));
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
index c34a4aa3..3e482a62 100644
--- a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
@@ -30,7 +30,6 @@ import org.onap.policy.api.main.parameters.ApiParameterHandler;
import org.onap.policy.api.main.parameters.CommonTestData;
import org.onap.policy.common.utils.network.NetworkUtil;
-
/**
* Class to perform unit test of ApiActivator.
*
@@ -40,9 +39,9 @@ public class TestApiActivator {
@Test
public void testApiActivator() throws Exception {
- COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters.json",
- "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
- final String[] apiConfigParameters = { "-c", "src/test/resources/parameters/ApiConfigParametersXXX.json" };
+ COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
+ "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
+ final String[] apiConfigParameters = {"-c", "src/test/resources/parameters/ApiConfigParametersXXX.json"};
final ApiCommandLineArguments arguments = new ApiCommandLineArguments(apiConfigParameters);
final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(arguments);
final ApiActivator activator = new ApiActivator(parGroup);
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java
index b97b0ccc..60222f6d 100644
--- a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java
@@ -38,9 +38,9 @@ public class TestMain {
@Test
public void testMain() throws Exception {
- COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters.json",
- "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
- final String[] apiConfigParameters = { "-c", "src/test/resources/parameters/ApiConfigParametersXXX.json" };
+ COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
+ "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
+ final String[] apiConfigParameters = {"-c", "src/test/resources/parameters/ApiConfigParametersXXX.json"};
final Main main = new Main(apiConfigParameters);
assertTrue(main.getParameters().isValid());
assertEquals(CommonTestData.API_GROUP_NAME, main.getParameters().getName());
@@ -56,20 +56,20 @@ public class TestMain {
@Test
public void testMain_InvalidArguments() {
- final String[] apiConfigParameters = { "parameters/ApiConfigParameters.json" };
+ final String[] apiConfigParameters = {"parameters/ApiConfigParameters.json"};
final Main main = new Main(apiConfigParameters);
assertTrue(main.getParameters() == null);
}
@Test
public void testMain_Help() {
- final String[] apiConfigParameters = { "-h" };
+ final String[] apiConfigParameters = {"-h"};
assertThatCode(() -> Main.main(apiConfigParameters)).doesNotThrowAnyException();
}
@Test
public void testMain_InvalidParameters() {
- final String[] apiConfigParameters = { "-c", "parameters/ApiConfigParameters_InvalidName.json" };
+ final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"};
final Main main = new Main(apiConfigParameters);
assertTrue(main.getParameters() == null);
}
diff --git a/main/src/test/resources/logback-test.xml b/main/src/test/resources/logback-test.xml
new file mode 100644
index 00000000..88187371
--- /dev/null
+++ b/main/src/test/resources/logback-test.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ ================================================================================
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<configuration>
+
+ <contextName>policy-api</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+
+ <!-- USE FOR STD OUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <logger name="org.onap.policy.api" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap.policy.common.gson.GsonMessageBodyHandler" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.eclipse.jetty.server.RequestLog" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+</configuration>
diff --git a/main/src/test/resources/parameters/ApiConfigParameters.json b/main/src/test/resources/parameters/ApiConfigParameters.json
deleted file mode 100644
index f7c992bf..00000000
--- a/main/src/test/resources/parameters/ApiConfigParameters.json
+++ /dev/null
@@ -1,44 +0,0 @@
-{
- "name":"ApiGroup",
- "restServerParameters":{
- "host":"0.0.0.0",
- "port":6969,
- "userName":"healthcheck",
- "password":"zb!XztG34"
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.h2.Driver",
- "databaseUrl": "jdbc:h2:mem:testdb",
- "databaseUser": "policy",
- "databasePassword": "UDAxaWNZ",
- "persistenceUnit": "ToscaConceptTest"
- },
- "preloadPolicyTypes": [
- "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
- "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
- "policytypes/onap.policies.Optimization.yaml",
- "policytypes/onap.policies.optimization.Resource.yaml",
- "policytypes/onap.policies.optimization.Service.yaml",
- "policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml",
- "policytypes/onap.policies.optimization.resource.DistancePolicy.yaml",
- "policytypes/onap.policies.optimization.resource.HpaPolicy.yaml",
- "policytypes/onap.policies.optimization.resource.OptimizationPolicy.yaml",
- "policytypes/onap.policies.optimization.resource.PciPolicy.yaml",
- "policytypes/onap.policies.optimization.service.QueryPolicy.yaml",
- "policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml",
- "policytypes/onap.policies.optimization.resource.Vim_fit.yaml",
- "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml",
- "policytypes/onap.policies.controlloop.guard.Blacklist.yaml",
- "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml",
- "policytypes/onap.policies.controlloop.guard.MinMax.yaml",
- "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml",
- "policytypes/onap.policies.controlloop.Operational.yaml",
- "policytypes/onap.policies.Naming.yaml",
- "policytypes/onap.policies.drools.Controller.yaml",
- "policytypes/onap.policies.native.Drools.yaml",
- "policytypes/onap.policies.native.Xacml.yaml",
- "policytypes/onap.policies.native.Apex.yaml"
- ]
-}