aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-03-07 17:56:39 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-07 17:56:39 +0000
commitf46ea4332fd4924c89879214b2577564168d7b46 (patch)
tree5a43f2f9fc90dd6c81375ef57033ebe001747b96 /main/src
parentf626b9f2f27f713f00d60a6f36974b2632da83be (diff)
parent851984a0701f59aa0a97546862bdbe1ffb39c666 (diff)
Merge "Add code to follow ONAP API CVS guidelines"
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java554
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java4
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java4
3 files changed, 481 insertions, 81 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 f13e8f74..d3ff0465 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
@@ -30,13 +30,17 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.BasicAuthDefinition;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
+import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
-import io.swagger.annotations.Tag;
+import java.util.UUID;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -44,15 +48,16 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
import org.onap.policy.api.main.rest.provider.PolicyProvider;
import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
import org.onap.policy.api.main.rest.provider.StatisticsProvider;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
-import org.onap.policy.model.tosca.ToscaPolicy;
-import org.onap.policy.model.tosca.ToscaPolicyList;
-import org.onap.policy.model.tosca.ToscaPolicyType;
-import org.onap.policy.model.tosca.ToscaPolicyTypeList;
+import org.onap.policy.models.tosca.ToscaPolicy;
+import org.onap.policy.models.tosca.ToscaPolicyList;
+import org.onap.policy.models.tosca.ToscaPolicyType;
+import org.onap.policy.models.tosca.ToscaPolicyTypeList;
/**
* Class to provide REST API services.
@@ -63,16 +68,21 @@ import org.onap.policy.model.tosca.ToscaPolicyTypeList;
@Consumes(MediaType.APPLICATION_JSON)
@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 XACML, Drools and APEX. It is a"
- + "standalone 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 = "v1.0", title = "Policy Design"),
- consumes = { MediaType.APPLICATION_JSON }, produces = { MediaType.APPLICATION_JSON },
+ + " 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 },
- tags = { @Tag(name = "policy-api", description = "Policy API Service Operations") },
securityDefinition = @SecurityDefinition(basicAuthDefinitions = { @BasicAuthDefinition(key = "basicAuth") }))
public class ApiRestController {
@@ -86,15 +96,40 @@ public class ApiRestController {
@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", })
+ 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() {
- return Response.status(Response.Status.OK).entity(new HealthCheckProvider().performHealthCheck()).build();
+ public Response getHealthCheck(
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new HealthCheckProvider().performHealthCheck()).build();
}
/**
@@ -107,15 +142,40 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve current statistics",
notes = "Returns current statistics including the counters of API invocation",
response = StatisticsReport.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ description = "Used only to communicate a PATCH version in a response for"
+ + " troubleshooting purposes only, and will not be provided by"
+ + " the client on request",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion",
+ description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose",
+ response = UUID.class)
+ },
authorizations = @Authorization(value = "basicAuth"),
- tags = { "Statistics", })
+ 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() {
- return Response.status(Response.Status.OK).entity(new StatisticsProvider().fetchCurrentStatistics()).build();
+ public Response getStatistics(
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new StatisticsProvider().fetchCurrentStatistics()).build();
}
/**
@@ -128,15 +188,39 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve existing policy types",
notes = "Returns a list of existing policy types stored in Policy Framework",
response = ToscaPolicyTypeList.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", })
+ 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() {
- return Response.status(Response.Status.OK)
+ public Response getAllPolicyTypes(
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyTypeProvider().fetchPolicyTypes(null, null)).build();
}
@@ -152,8 +236,31 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve all available versions of a policy type",
notes = "Returns a list of all available versions for the specified policy type",
response = ToscaPolicyTypeList.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", })
+ 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"),
@@ -161,8 +268,9 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response getAllVersionsOfPolicyType(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, null)).build();
}
@@ -179,8 +287,31 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve one particular version of a policy type",
notes = "Returns a particular version for the specified policy type",
response = ToscaPolicyTypeList.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", })
+ 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"),
@@ -188,9 +319,10 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response getSpecificVersionOfPolicyType(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("versionId") @ApiParam("ID of version") String versionId) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, versionId)).build();
}
@@ -206,15 +338,42 @@ public class ApiRestController {
@ApiOperation(value = "Create a new policy type",
notes = "Client should provide TOSCA body of the new policy type",
authorizations = @Authorization(value = "basicAuth"),
- tags = { "PolicyType", })
+ 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 = 201, message = "Resource successfully created",
+ 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)
+ }),
@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(ToscaPolicyType body) {
- return Response.status(Response.Status.OK).entity(new PolicyTypeProvider().createPolicyType(body)).build();
+ public Response createPolicyType(
+ @ApiParam(value = "Entity body of policy type", required = true) ToscaPolicyType body,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new PolicyTypeProvider().createPolicyType(body)).build();
}
/**
@@ -231,8 +390,32 @@ public class ApiRestController {
+ "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", })
+ 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 = 204, message = "Resources successfully deleted, no content returned",
+ 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)
+ }),
@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@@ -240,8 +423,9 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response deleteAllVersionsOfPolicyType(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, null)).build();
}
@@ -260,8 +444,32 @@ public class ApiRestController {
+ "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", })
+ 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 = 204, message = "Resource successfully deleted, no content returned",
+ 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)
+ }),
@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@@ -269,9 +477,10 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response deleteSpecificVersionOfPolicyType(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("versionId") @ApiParam("ID of version") String versionId) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, versionId)).build();
}
@@ -288,8 +497,31 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version",
notes = "Returns a list of all versions of specified policy created for the specified policy type version",
response = ToscaPolicyList.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", })
+ 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"),
@@ -297,9 +529,11 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response getAllPolicies(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, null, null)).build();
}
@@ -317,8 +551,31 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
notes = "Returns a list of all version details of the specified policy",
response = ToscaPolicyList.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", })
+ 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"),
@@ -326,10 +583,12 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response getAllVersionsOfPolicy(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
- @PathParam("policyId") @ApiParam("ID of policy") String policyId) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
}
@@ -348,8 +607,31 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
notes = "Returns a particular version of specified policy created for the specified policy type version",
response = ToscaPolicyList.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", })
+ 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"),
@@ -357,11 +639,13 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response getSpecificVersionOfPolicy(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
- @PathParam("policyId") @ApiParam("ID of policy") String policyId,
- @PathParam("policyVersion") @ApiParam("ID of policy version") String policyVersion) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion,
policyId, policyVersion)).build();
}
@@ -380,8 +664,31 @@ public class ApiRestController {
@ApiOperation(value = "Retrieve either latest or deployed version of a particular policy depending on query param",
notes = "Returns either latest or deployed version of specified policy depending on query param",
response = ToscaPolicyList.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", })
+ 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"),
@@ -389,11 +696,14 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response getEitherLatestOrDeployedVersionOfPolicy(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
- @PathParam("policyId") @ApiParam("ID of policy") String policyId,
- @QueryParam("type") @ApiParam("Type of version that can only be 'latest' or 'deployed'") String type) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @QueryParam("type")
+ @ApiParam(value = "Version that can only be 'latest' or 'deployed'", required = true) String type,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, type)).build();
}
@@ -411,8 +721,32 @@ public class ApiRestController {
@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", })
+ 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 = 201, message = "Resource successfully created",
+ 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)
+ }),
@ApiResponse(code = 400, message = "Invalid Body"),
@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@@ -420,10 +754,12 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response createPolicy(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
- ToscaPolicy body) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
+ @ApiParam(value = "Entity body of policy", required = true) ToscaPolicy body) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().createPolicy(policyTypeId, policyTypeVersion, body)).build();
}
@@ -441,8 +777,32 @@ public class ApiRestController {
@ApiOperation(value = "Delete all versions of a policy",
notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
authorizations = @Authorization(value = "basicAuth"),
- tags = { "Policy", })
+ 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 = 204, message = "Resources successfully deleted, no content returned",
+ 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)
+ }),
@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@@ -450,10 +810,12 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response deleteAllVersionsOfPolicy(
- @PathParam("policyTypeId") @ApiParam("ID of policy type") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
- @PathParam("policyId") @ApiParam("ID of policy") String policyId) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
}
@@ -472,8 +834,32 @@ public class ApiRestController {
@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", })
+ 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 = 204, message = "Resource successfully deleted, no content returned",
+ 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)
+ }),
@ApiResponse(code = 401, message = "Authentication Error"),
@ApiResponse(code = 403, message = "Authorization Error"),
@ApiResponse(code = 404, message = "Resource Not Found"),
@@ -481,12 +867,26 @@ public class ApiRestController {
@ApiResponse(code = 500, message = "Internal Server Error")
})
public Response deleteSpecificVersionOfPolicy(
- @PathParam("policyTypeId") @ApiParam("PolicyType ID") String policyTypeId,
- @PathParam("policyTypeVersion") @ApiParam("ID of policy type version") String policyTypeVersion,
- @PathParam("policyId") @ApiParam("ID of policy") String policyId,
- @PathParam("policyVersion") @ApiParam("ID of policy version") String policyVersion) {
- return Response.status(Response.Status.OK)
+ @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
+ @PathParam("policyTypeVersion")
+ @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
+ @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+ @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion,
policyId, policyVersion)).build();
}
+
+ private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
+ return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
+ }
+
+ private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
+ if (requestId == null) {
+ // Generate a random uuid if client does not embed requestId in rest request
+ return rb.header("X-ONAP-RequestID", UUID.randomUUID());
+ }
+ return rb.header("X-ONAP-RequestID", requestId);
+ }
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
index 3a8c238b..c02ce6c7 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
@@ -22,8 +22,8 @@
package org.onap.policy.api.main.rest.provider;
-import org.onap.policy.model.tosca.ToscaPolicy;
-import org.onap.policy.model.tosca.ToscaPolicyList;
+import org.onap.policy.models.tosca.ToscaPolicy;
+import org.onap.policy.models.tosca.ToscaPolicyList;
/**
* Class to provide all kinds of policy operations.
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
index 6443d496..67c4237c 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
@@ -22,8 +22,8 @@
package org.onap.policy.api.main.rest.provider;
-import org.onap.policy.model.tosca.ToscaPolicyType;
-import org.onap.policy.model.tosca.ToscaPolicyTypeList;
+import org.onap.policy.models.tosca.ToscaPolicyType;
+import org.onap.policy.models.tosca.ToscaPolicyTypeList;
/**
* Class to provide all kinds of policy type operations.