diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2020-03-05 12:44:33 -0500 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2020-03-06 16:20:38 +0000 |
commit | ba03d679d75647a442febd68e2da2c4da773cb7e (patch) | |
tree | 8930f1449d15986b4fe53e1b55322147da369755 | |
parent | e223731767eb532108c1c2e09cd6cc3c12b77574 (diff) |
Removing legacy guard from policy/api
Renamed the guard policy types per this review:
https://gerrit.onap.org/r/c/policy/models/+/103127
Issue-ID: POLICY-2243
Change-Id: I35ef95756483c869d374f36d0a1dfe6b588444c7
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
21 files changed, 27 insertions, 1040 deletions
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 67ea856f..0fcf985d 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,11 +31,9 @@ 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; @@ -45,17 +43,13 @@ 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; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,268 +68,6 @@ public class LegacyApiRestController extends CommonRestController { private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class); /** - * Retrieves the latest version of a particular guard policy. - * - * @param policyId the ID of specified guard policy - * - * @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/latest") - @ApiOperation(value = "Retrieve the latest version of a particular guard policy", - 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")}) - 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) { - - try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) { - Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider.fetchGuardPolicy(policyId, null); - return makeOkResponse(requestId, policies); - } catch (PfModelException | PfModelRuntimeException pfme) { - LOGGER.debug( - "GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}" + "/versions/latest", - policyId, pfme); - return makeErrorResponse(requestId, pfme); - } - } - - /** - * Retrieves the specified version of a particular guard policy. - * - * @param policyId the ID of specified policy - * @param policyVersion the version of specified policy - * - * @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/{policyVersion}") - @ApiOperation(value = "Retrieve one version of a particular guard policy", - 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")}) - 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); - return makeOkResponse(requestId, policies); - } catch (PfModelException | PfModelRuntimeException pfme) { - LOGGER.debug("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}", - policyId, policyVersion, pfme); - return makeErrorResponse(requestId, pfme); - } - } - - /** - * Retrieves deployed versions of a particular guard policy in PDP groups. - * - * @param policyId the ID of specified policy - * - * @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") - @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")}) - 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) { - - try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) { - Map<Pair<String, String>, Map<String, LegacyGuardPolicyOutput>> deployedGuardPolicies = - guardPolicyProvider.fetchDeployedGuardPolicies(policyId); - return makeOkResponse(requestId, deployedGuardPolicies); - } catch (PfModelException | PfModelRuntimeException pfme) { - LOGGER.debug("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/" - + "policies/{}/versions/deployed", policyId, pfme); - return makeErrorResponse(requestId, pfme); - } - } - - /** - * Creates a new guard policy. - * - * @param body the body of policy - * - * @return the Response object containing the results of the API operation - */ - @POST - @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",}, - 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 = 406, message = "Not Acceptable Payload"), - @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)); - } - - try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) { - Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body); - return makeOkResponse(requestId, policy); - } catch (PfModelException | PfModelRuntimeException pfme) { - LOGGER.debug("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme); - return makeErrorResponse(requestId, pfme); - } - } - - /** - * Deletes the specified version of a particular guard policy. - * - * @param policyId the ID of specified policy - * @param policyVersion the version of specified policy - * - * @return the Response object containing the results of the API operation - */ - @DELETE - @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",}, - 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")}) - 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); - return makeOkResponse(requestId, policies); - } catch (PfModelException | PfModelRuntimeException pfme) { - LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}", - policyId, policyVersion, pfme); - return makeErrorResponse(requestId, pfme); - } - } - - /** * Retrieves the latest version of a particular operational policy. * * @param policyId the ID of specified operational policy diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java deleted file mode 100644 index 80c57d36..00000000 --- a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy API - * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.api.main.rest.provider; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; - -import javax.ws.rs.core.Response; - -import org.apache.commons.lang3.tuple.Pair; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; - -/** - * Class to provide all kinds of legacy guard policy operations. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -public class LegacyGuardPolicyProvider extends CommonModelProvider { - - private static final Map<String, PfConceptKey> GUARD_POLICY_TYPE_MAP = new LinkedHashMap<>(); - - static { - GUARD_POLICY_TYPE_MAP.put("guard.frequency.", - new PfConceptKey("onap.policies.controlloop.guard.FrequencyLimiter:1.0.0")); - GUARD_POLICY_TYPE_MAP.put("guard.minmax.", new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0")); - GUARD_POLICY_TYPE_MAP.put("guard.blacklist.", - new PfConceptKey("onap.policies.controlloop.guard.Blacklist:1.0.0")); - } - - /** - * Default constructor. - */ - public LegacyGuardPolicyProvider() throws PfModelException { - super(); - } - - /** - * Retrieves a list of guard policies matching specified ID and version. - * - * @param policyId the ID of policy - * @param policyVersion the version of policy - * - * @return the map of LegacyGuardPolicyOutput objects - */ - public Map<String, LegacyGuardPolicyOutput> fetchGuardPolicy(String policyId, String policyVersion) - throws PfModelException { - - return modelsProvider.getGuardPolicy(policyId, policyVersion); - } - - /** - * Retrieves a list of deployed guard policies in each pdp group. - * - * @param policyId the ID of the policy - * - * @return a list of deployed policies in each pdp group - * - * @throws PfModelException the PfModel parsing exception - */ - public Map<Pair<String, String>, Map<String, LegacyGuardPolicyOutput>> fetchDeployedGuardPolicies(String policyId) - throws PfModelException { - - return collectDeployedPolicies(policyId, getGuardPolicyType(policyId), modelsProvider::getGuardPolicy, - Map::putAll, new HashMap<>()); - } - - /** - * Creates a new guard policy. - * - * @param body the entity body of policy - * - * @return the map of LegacyGuardPolicyOutput objectst - */ - public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(LegacyGuardPolicyInput body) throws PfModelException { - - return modelsProvider.createGuardPolicy(body); - } - - /** - * Deletes the guard policies matching specified ID and version. - * - * @param policyId the ID of policy - * @param policyVersion the version of policy - * - * @return the map of LegacyGuardPolicyOutput objects - */ - public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(String policyId, String policyVersion) - throws PfModelException { - - return modelsProvider.deleteGuardPolicy(policyId, policyVersion); - } - - /** - * Retrieves guard policy type given guard policy ID. - * - * @param policyId the ID of guard policy - * - * @return the concept key of guard policy type - * - * @throws PfModelException the PfModel parsing exception - */ - private PfConceptKey getGuardPolicyType(String policyId) throws PfModelException { - - for (Entry<String, PfConceptKey> guardPolicyTypeEntry : GUARD_POLICY_TYPE_MAP.entrySet()) { - if (policyId.startsWith(guardPolicyTypeEntry.getKey())) { - return guardPolicyTypeEntry.getValue(); - } - } - throw new PfModelException(Response.Status.BAD_REQUEST, "No policy type defined for " + policyId); - } -}
\ No newline at end of file diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java index 7e3765d2..199b6bd6 100644 --- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java +++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java @@ -73,7 +73,7 @@ public class ApiDatabaseInitializer { ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); serviceTemplate.setDataTypes(new LinkedHashMap<String, ToscaDataType>()); serviceTemplate.setPolicyTypes(new LinkedHashMap<String, ToscaPolicyType>()); - serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0_0"); + serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_1_0"); ToscaServiceTemplate createdPolicyTypes = preloadServiceTemplate(serviceTemplate, apiParameterGroup.getPreloadPolicyTypes(), databaseProvider::createPolicyTypes); 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 95a20692..9474814d 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 @@ -69,7 +69,6 @@ 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.ToscaServiceTemplate; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; /** @@ -121,27 +120,10 @@ public class TestApiRestServer { + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/2.0.0"; private static final String POLICYTYPES_TCA_POLICIES_VCPE_LATEST = "policytypes/" + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/latest"; - private static final String POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED = "policytypes/" - + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/deployed"; private static final String POLICYTYPES_DROOLS_POLICIES_VCPE_VERSION = POLICYTYPES_DROOLS_VERSION + "/policies/" + OP_POLICY_NAME_VCPE + "/versions/1.0.0"; - private static final String GUARD_POLICIES = "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies"; - private static final String GUARD_POLICIES_VDNS_FL_LATEST = - "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout" - + "/versions/latest"; - private static final String GUARD_POLICIES_VDNS_FL_DEPLOYED = - "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout" - + "/versions/deployed"; - private static final String GUARD_POLICIES_VDNS_MINMAX_LATEST = - "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout" - + "/versions/latest"; - private static final String GUARD_POLICIES_VDNS_FL_VERSION = "policytypes/" - + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1"; - private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION = - "policytypes/" + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1"; - private static final String OPS_POLICIES = "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies"; private static final String OPS_POLICIES_VCPE_LATEST = @@ -192,9 +174,10 @@ public class TestApiRestServer { LEGACY_POLICYTYPE_OP_RESOURCE, TOSCA_POLICYTYPE_OP_RESOURCE, "policytypes/onap.policies.controlloop.operational.common.Drools.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.Common.yaml", + "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml", + "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml", + "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml", "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml", "policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml", "policytypes/onap.policies.optimization.resource.DistancePolicy.yaml", @@ -213,11 +196,6 @@ public class TestApiRestServer { private static final String TOSCA_POLICY_OP_DROOLS_VCPE_RESOURSE_YAML = "policies/vCPE.policy.operational.input.tosca.yaml"; - private static final String[] LEGACY_GUARD_POLICY_RESOURCE_NAMES = { - "policies/vDNS.policy.guard.frequency.input.json", - "policies/vDNS.policy.guard.minmax.input.json" - }; - private static final String[] LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES = { "policies/vCPE.policy.operational.legacy.input.json", "policies/vDNS.policy.operational.legacy.input.json", @@ -371,20 +349,6 @@ public class TestApiRestServer { } @Test - public void testCreateGuardPolicies() throws Exception { - for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) { - Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - } - - Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, APP_JSON); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - - rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - } - - @Test public void testCreateOperationalPolicies() throws Exception { for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) { Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName); @@ -740,41 +704,6 @@ public class TestApiRestServer { } @Test - public void testReadGuardPoliciesJson() throws Exception { - testReadGuardPolicies(APP_JSON); - } - - @Test - public void testReadGuardPoliciesYaml() throws Exception { - testReadGuardPolicies(APP_YAML); - } - - private void testReadGuardPolicies(String mediaType) throws Exception { - for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) { - Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName); - 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_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, mediaType); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - - rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - - rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - } - - @Test public void testReadOperationalPoliciesJson() throws Exception { testReadOperationalPolicies(APP_JSON); } @@ -820,49 +749,6 @@ public class TestApiRestServer { } @Test - public void testDeleteGuardPolicyJson() throws Exception { - testDeleteGuardPolicy(APP_JSON); - } - - @Test - public void testDeleteGuardPolicyYaml() throws Exception { - testDeleteGuardPolicy(APP_YAML); - } - - private void testDeleteGuardPolicy(String mediaType) throws Exception { - for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) { - Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - } - - Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - - rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - } - - @Test - public void testGetDeployedVersionsOfGuardPolicyJson() throws Exception { - testGetDeployedVersionsOfGuardPolicy(APP_JSON); - } - - @Test - public void testGetDeployedVersionsOfGuardPolicyYaml() throws Exception { - testGetDeployedVersionsOfGuardPolicy(APP_YAML); - } - - 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() throws Exception { testDeleteOperationalPolicy(APP_JSON); } @@ -962,27 +848,6 @@ public class TestApiRestServer { return invocationBuilder.post(entity); } - 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); - } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) { - mediaType = APP_YAML; - rawGuardPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName), - LegacyGuardPolicyInput.class); - } - - final Invocation.Builder invocationBuilder; - - invocationBuilder = sendHttpsRequest(endpoint, mediaType); - - Entity<LegacyGuardPolicyInput> entity = Entity.entity(rawGuardPolicy, mediaType); - return invocationBuilder.post(entity); - } - private Response createOperationalPolicy(String endpoint, String resourceName) throws Exception { String mediaType = APP_JSON; // default media type diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java deleted file mode 100644 index dfe29cfc..00000000 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java +++ /dev/null @@ -1,432 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy API - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.api.main.rest.provider; - -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -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.util.ArrayList; -import java.util.Base64; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.api.main.parameters.ApiParameterGroup; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.pdp.concepts.Pdp; -import org.onap.policy.models.pdp.concepts.PdpGroup; -import org.onap.policy.models.pdp.concepts.PdpGroupFilter; -import org.onap.policy.models.pdp.concepts.PdpSubGroup; -import org.onap.policy.models.pdp.enums.PdpHealthStatus; -import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.provider.PolicyModelsProvider; -import org.onap.policy.models.provider.PolicyModelsProviderFactory; -import org.onap.policy.models.provider.PolicyModelsProviderParameters; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; -import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; - -/** - * This class performs unit test of {@link LegacyGuardPolicyProvider}. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -public class TestLegacyGuardPolicyProvider { - - private static LegacyGuardPolicyProvider guardPolicyProvider; - private static PolicyTypeProvider policyTypeProvider; - private static PolicyModelsProviderParameters providerParams; - private static ApiParameterGroup apiParamGroup; - private static StandardCoder standardCoder; - private static StandardYamlCoder standardYamlCoder; - - private static final String POLICY_RESOURCE = "policies/vDNS.policy.guard.frequency.input.json"; - private static final String POLICY_RESOURCE_VER1 = "policies/vDNS.policy.guard.frequency.input.ver1.json"; - private static final String POLICY_RESOURCE_VER2 = "policies/vDNS.policy.guard.frequency.input.ver2.json"; - private static final String POLICY_RESOURCE_WITH_NO_VERSION = - "policies/vDNS.policy.guard.frequency.no.policyversion.json"; - private static final String POLICY_TYPE_RESOURCE = - "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml"; - private static final String POLICY_TYPE_ID = "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0"; - private static final String POLICY_TYPE_NAME = "onap.policies.controlloop.guard.FrequencyLimiter"; - private static final String POLICY_TYPE_VERSION = "1.0.0"; - private static final String POLICY_NAME = "guard.frequency.scaleout"; - private static final String POLICY_VERSION = "1"; - private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0"; - - /** - * Initializes parameters. - * - * @throws PfModelException the PfModel parsing exception - */ - @Before - public void setupParameters() throws PfModelException { - standardCoder = new StandardCoder(); - standardYamlCoder = new StandardYamlCoder(); - providerParams = new PolicyModelsProviderParameters(); - providerParams.setDatabaseDriver("org.h2.Driver"); - providerParams.setDatabaseUrl("jdbc:h2:mem:testdb"); - providerParams.setDatabaseUser("policy"); - providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); - providerParams.setPersistenceUnit("ToscaConceptTest"); - apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, - Collections.emptyList(), Collections.emptyList()); - ParameterService.register(apiParamGroup, true); - guardPolicyProvider = new LegacyGuardPolicyProvider(); - policyTypeProvider = new PolicyTypeProvider(); - } - - /** - * Closes up DB connections and deregisters API parameter group. - * - * @throws PfModelException the PfModel parsing exception - */ - @After - public void tearDown() throws PfModelException { - guardPolicyProvider.close(); - policyTypeProvider.close(); - ParameterService.deregister(apiParamGroup); - } - - @Test - public void testFetchGuardPolicy() { - - assertThatThrownBy(() -> { - guardPolicyProvider.fetchGuardPolicy("dummy", null); - }).hasMessage("no policy found for policy: dummy:null"); - - assertThatThrownBy(() -> { - guardPolicyProvider.fetchGuardPolicy("dummy", "dummy"); - }).hasMessageContaining("parameter \"version\": value \"dummy.0.0\", does not match regular expression"); - - assertThatCode(() -> { - ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder - .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); - policyTypeProvider.createPolicyType(policyTypeServiceTemplate); - - String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER1); - LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate); - assertNotNull(createdPolicy); - assertFalse(createdPolicy.isEmpty()); - - policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER2); - policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate); - assertNotNull(createdPolicy); - assertFalse(createdPolicy.isEmpty()); - - Map<String, LegacyGuardPolicyOutput> firstVersion = - guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1"); - assertNotNull(firstVersion); - assertEquals("1", - firstVersion.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString()); - - Map<String, LegacyGuardPolicyOutput> latestVersion = - guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", null); - assertNotNull(latestVersion); - assertEquals("2", - latestVersion.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString()); - }).doesNotThrowAnyException(); - - assertThatThrownBy(() -> { - guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1.0.0"); - }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression"); - - assertThatThrownBy(() -> { - guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "latest"); - }).hasMessageContaining("parameter \"version\": value \"latest.0.0\", does not match regular expression"); - - assertThatCode(() -> { - guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1"); - guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "2"); - policyTypeProvider.deletePolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"); - }).doesNotThrowAnyException(); - } - - @Test - public void testFetchDeployedGuardPolicies() { - - assertThatThrownBy(() -> { - guardPolicyProvider.fetchDeployedGuardPolicies("dummy"); - }).hasMessage("No policy type defined for dummy"); - - try (PolicyModelsProvider databaseProvider = - new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) { - assertEquals(0, databaseProvider.getPdpGroups("name").size()); - assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size()); - - assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>())); - assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>())); - - PdpGroup pdpGroup = new PdpGroup(); - pdpGroup.setName("group"); - pdpGroup.setVersion("1.2.3"); - pdpGroup.setPdpGroupState(PdpState.ACTIVE); - pdpGroup.setPdpSubgroups(new ArrayList<>()); - List<PdpGroup> groupList = new ArrayList<>(); - groupList.add(pdpGroup); - - PdpSubGroup pdpSubGroup = new PdpSubGroup(); - pdpSubGroup.setPdpType("type"); - pdpSubGroup.setDesiredInstanceCount(123); - pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>()); - pdpSubGroup.getSupportedPolicyTypes() - .add(new ToscaPolicyTypeIdentifier(POLICY_TYPE_NAME, POLICY_TYPE_VERSION)); - pdpGroup.getPdpSubgroups().add(pdpSubGroup); - - Pdp pdp = new Pdp(); - pdp.setInstanceId("type-0"); - pdp.setMessage("Hello"); - pdp.setPdpState(PdpState.ACTIVE); - pdp.setHealthy(PdpHealthStatus.UNKNOWN); - pdpSubGroup.setPdpInstances(new ArrayList<>()); - pdpSubGroup.getPdpInstances().add(pdp); - - // Create Pdp Groups - assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0) - .getDesiredInstanceCount()); - assertEquals(1, databaseProvider.getPdpGroups("group").size()); - - // Create Policy Type - assertThatCode(() -> { - ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder - .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); - policyTypeProvider.createPolicyType(policyTypeServiceTemplate); - }).doesNotThrowAnyException(); - - // Create Policy - assertThatCode(() -> { - String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput policyToCreate = - standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - Map<String, LegacyGuardPolicyOutput> policyCreated = - guardPolicyProvider.createGuardPolicy(policyToCreate); - assertFalse(policyCreated.isEmpty()); - }).doesNotThrowAnyException(); - - // Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true - assertThatThrownBy(() -> { - guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME); - }).hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID - + " deployed in any pdp group"); - - // Update pdpSubGroup - pdpSubGroup.setPolicies(new ArrayList<>()); - pdpSubGroup.getPolicies() - .add(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION + LEGACY_MINOR_PATCH_SUFFIX)); - assertEquals(1, - databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size()); - - // Test fetchDeployedPolicies - assertThatCode(() -> { - guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME); - }).doesNotThrowAnyException(); - - // Test validateDeleteEligibility exception path(!pdpGroups.isEmpty()) - assertThatThrownBy(() -> { - guardPolicyProvider.deleteGuardPolicy(POLICY_NAME, POLICY_VERSION); - }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type"); - } catch (Exception exc) { - fail("Test should not throw an exception"); - } - } - - @Test - public void testCreateGuardPolicy() throws Exception { - assertThatThrownBy(() -> { - String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - guardPolicyProvider.createGuardPolicy(policyToCreate); - }).hasMessageContaining( - "no policy types are defined on the service template for the policies in the topology template"); - - ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder - .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); - policyTypeProvider.createPolicyType(policyTypeServiceTemplate); - - String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate); - assertNotNull(createdPolicy); - assertFalse(createdPolicy.isEmpty()); - assertTrue(createdPolicy.containsKey("guard.frequency.scaleout")); - assertEquals("onap.policies.controlloop.guard.FrequencyLimiter", - createdPolicy.get("guard.frequency.scaleout").getType()); - assertEquals("1.0.0", createdPolicy.get("guard.frequency.scaleout").getVersion()); - - String defaultPolicyVersionString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_VERSION); - LegacyGuardPolicyInput defaultVersionPolicy = - standardCoder.decode(defaultPolicyVersionString, LegacyGuardPolicyInput.class); - createdPolicy = guardPolicyProvider.createGuardPolicy(defaultVersionPolicy); - assertEquals("1.0.0", createdPolicy.get("guard.frequency.scaleout.noversion").getVersion()); - - assertThatCode(() -> { - String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput duplicatePolicyToCreate = - standardCoder.decode(duplicatePolicyString, LegacyGuardPolicyInput.class); - guardPolicyProvider.createGuardPolicy(duplicatePolicyToCreate); - }).doesNotThrowAnyException(); - - assertThatThrownBy(() -> { - String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput duplicatePolicyToCreate = - standardCoder.decode(duplicatePolicyString, LegacyGuardPolicyInput.class); - duplicatePolicyToCreate.setContent(new LegacyGuardPolicyContent()); - guardPolicyProvider.createGuardPolicy(duplicatePolicyToCreate); - }).hasMessageContaining("INVALID:entity in incoming fragment does not equal existing entity"); - } - - @Test - public void testDeleteGuardPolicyException() { - String policyId = "guard.frequency.scaleout"; - String policyVersion = "1"; - String policyTypeVersion = "1.0.0"; - String policyTypeId = "onap.policies.controlloop.guard.FrequencyLimiter"; - String legacyMinorPatchSuffix = ".0.0"; - - try (PolicyModelsProvider databaseProvider = - new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) { - assertEquals(0, databaseProvider.getPdpGroups("name").size()); - assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size()); - - assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>())); - assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>())); - - PdpGroup pdpGroup = new PdpGroup(); - pdpGroup.setName("group"); - pdpGroup.setVersion("1.2.3"); - pdpGroup.setPdpGroupState(PdpState.ACTIVE); - pdpGroup.setPdpSubgroups(new ArrayList<>()); - List<PdpGroup> groupList = new ArrayList<>(); - groupList.add(pdpGroup); - - PdpSubGroup pdpSubGroup = new PdpSubGroup(); - pdpSubGroup.setPdpType("type"); - pdpSubGroup.setDesiredInstanceCount(123); - pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>()); - pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion)); - pdpGroup.getPdpSubgroups().add(pdpSubGroup); - - Pdp pdp = new Pdp(); - pdp.setInstanceId("type-0"); - pdp.setMessage("Hello"); - pdp.setPdpState(PdpState.ACTIVE); - pdp.setHealthy(PdpHealthStatus.UNKNOWN); - pdpSubGroup.setPdpInstances(new ArrayList<>()); - pdpSubGroup.getPdpInstances().add(pdp); - - // Create Pdp Groups - assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0) - .getDesiredInstanceCount()); - assertEquals(1, databaseProvider.getPdpGroups("group").size()); - - // Create Policy Type - assertThatCode(() -> { - ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder - .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); - policyTypeProvider.createPolicyType(policyTypeServiceTemplate); - }).doesNotThrowAnyException(); - - // Create Policy - assertThatCode(() -> { - String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput policyToCreate = - standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - Map<String, LegacyGuardPolicyOutput> createdPolicy = - guardPolicyProvider.createGuardPolicy(policyToCreate); - assertNotNull(createdPolicy); - assertFalse(createdPolicy.isEmpty()); - }).doesNotThrowAnyException(); - - // Update pdpSubGroup - pdpSubGroup.setPolicies(new ArrayList<>()); - pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion + legacyMinorPatchSuffix)); - assertEquals(1, - databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size()); - assertThatThrownBy(() -> { - guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1"); - }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type"); - } catch (Exception exc) { - fail("Test should not throw an exception"); - } - } - - @Test - public void testDeleteGuardPolicy() { - assertThatThrownBy(() -> { - guardPolicyProvider.deleteGuardPolicy("dummy", null); - }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$"); - - assertThatThrownBy(() -> { - guardPolicyProvider.deleteGuardPolicy("dummy", "1.0.0"); - }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression"); - - assertThatCode(() -> { - ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder - .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class); - policyTypeProvider.createPolicyType(policyTypeServiceTemplate); - - String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE); - LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class); - Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate); - assertNotNull(createdPolicy); - assertFalse(createdPolicy.isEmpty()); - - Map<String, LegacyGuardPolicyOutput> deletedPolicy = - guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1"); - assertNotNull(deletedPolicy); - assertFalse(deletedPolicy.isEmpty()); - assertTrue(deletedPolicy.containsKey("guard.frequency.scaleout")); - assertEquals("onap.policies.controlloop.guard.FrequencyLimiter", - deletedPolicy.get("guard.frequency.scaleout").getType()); - assertEquals("1", - deletedPolicy.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString()); - - }).doesNotThrowAnyException(); - - assertThatThrownBy(() -> { - guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1"); - }).hasMessage("no policy found for policy: guard.frequency.scaleout:1"); - - assertThatCode(() -> { - policyTypeProvider.deletePolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"); - }).doesNotThrowAnyException(); - } -} diff --git a/main/src/test/resources/parameters/ApiConfigParameters_Https.json b/main/src/test/resources/parameters/ApiConfigParameters_Https.json index c5562432..e9c387db 100644 --- a/main/src/test/resources/parameters/ApiConfigParameters_Https.json +++ b/main/src/test/resources/parameters/ApiConfigParameters_Https.json @@ -31,9 +31,10 @@ "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.Common.yaml", + "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml", + "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml", + "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml", "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml", "policytypes/onap.policies.controlloop.Operational.yaml", "policytypes/onap.policies.Naming.yaml", diff --git a/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml b/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml index a946ba4e..e87e353d 100644 --- a/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml +++ b/main/src/test/resources/policies/vCPE.policies.optimization.input.tosca.v2.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 topology_template: policies: - diff --git a/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json b/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json index 4eb84aa5..a9407955 100644 --- a/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json +++ b/main/src/test/resources/policies/vCPE.policy.bad.policytypeid.json @@ -1,5 +1,5 @@ { - "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", "topology_template": { "policies": [ { diff --git a/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json b/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json index 23195a97..c0286822 100644 --- a/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json +++ b/main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json @@ -1,5 +1,5 @@ { - "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", "topology_template": { "policies": [ { diff --git a/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json b/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json index cc7e4ee4..cda5dce6 100644 --- a/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json +++ b/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json @@ -1,5 +1,5 @@ { - "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", "topology_template": { "policies": [ { diff --git a/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml index 459dcf7d..dc1991e8 100644 --- a/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml +++ b/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 topology_template: policies: - diff --git a/main/src/test/resources/policies/vCPE.policy.no.policyversion.json b/main/src/test/resources/policies/vCPE.policy.no.policyversion.json index b70d5965..1faa3aad 100644 --- a/main/src/test/resources/policies/vCPE.policy.no.policyversion.json +++ b/main/src/test/resources/policies/vCPE.policy.no.policyversion.json @@ -1,5 +1,5 @@ { - "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", "topology_template": { "policies": [ { diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json deleted file mode 100644 index 6dc54cb8..00000000 --- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "policy-id" : "guard.frequency.scaleout", - "policy-version" : "1", - "content" : { - "actor": "SO", - "recipe": "scaleOut", - "targets": ".*", - "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3", - "limit": "1", - "timeWindow": "10", - "timeUnits": "minute", - "guardActiveStart": "00:00:01-05:00", - "guardActiveEnd": "23:59:59-05:00" - } -} diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json deleted file mode 100644 index a8c325fb..00000000 --- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "policy-id" : "guard.frequency.scaleout", - "policy-version" : "2", - "content" : { - "actor": "SO", - "recipe": "scaleOut", - "targets": ".*", - "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3", - "limit": "1", - "timeWindow": "10", - "timeUnits": "minute", - "guardActiveStart": "00:00:01-05:00", - "guardActiveEnd": "23:59:59-05:00" - } -} diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json deleted file mode 100644 index 518f09e8..00000000 --- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "policy-id" : "guard.frequency.scaleout.noversion", - "content" : { - "actor": "SO", - "recipe": "VF Module Create", - "targets": ".*", - "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3", - "limit": "1", - "timeWindow": "10", - "timeUnits": "minute", - "guardActiveStart": "00:00:01-05:00", - "guardActiveEnd": "23:59:59-05:00" - } -} diff --git a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml index 208c656f..03ad85f7 100644 --- a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml +++ b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 topology_template: policies: - onap.scaleout.tca: diff --git a/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml index d76dc53e..780b4321 100644 --- a/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml +++ b/main/src/test/resources/policies/vFirewall.policy.monitoring.input.tosca.v2.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 topology_template: policies: - diff --git a/main/src/test/resources/policytypes/onap.policies.Test.yaml b/main/src/test/resources/policytypes/onap.policies.Test.yaml index c8850a13..a029ca8f 100644 --- a/main/src/test/resources/policytypes/onap.policies.Test.yaml +++ b/main/src/test/resources/policytypes/onap.policies.Test.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 policy_types: onap.policies.Test: derived_from: tosca.policies.Root diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml index cab66238..7e6b2698 100644 --- a/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml +++ b/main/src/test/resources/policytypes/onap.policies.optimization.Resource.no.version.yaml @@ -1,4 +1,4 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 +tosca_definitions_version: tosca_simple_yaml_1_1_0 policy_types: onap.policies.optimization.Resource: derived_from: onap.policies.Optimization diff --git a/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json b/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json index 95cf0d5e..042fb9d5 100644 --- a/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json +++ b/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json @@ -32,9 +32,10 @@ "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.Common.yaml", + "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml", + "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml", + "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml", "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml", "policytypes/onap.policies.controlloop.Operational.yaml", "policytypes/onap.policies.Naming.yaml", diff --git a/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json b/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json index 95cf0d5e..042fb9d5 100644 --- a/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json +++ b/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json @@ -32,9 +32,10 @@ "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.Common.yaml", + "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml", + "policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml", + "policytypes/onap.policies.controlloop.guard.common.MinMax.yaml", "policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml", "policytypes/onap.policies.controlloop.Operational.yaml", "policytypes/onap.policies.Naming.yaml", |