aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-24 15:05:04 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-24 15:05:04 +0000
commit43aaa62cdf9a7dadfb6d688f1fe83c5bd355a86d (patch)
tree4958fd36b50129329aba24327c2af875b65050ff /models-tosca/src/main/java/org/onap
parent09c388b5c9781383a0577bf8c2f574f806abe85c (diff)
parent001fe2af138c08755f68025eeffd8c7a25cc8e5c (diff)
Merge "Remove legacy operational policy from models"
Diffstat (limited to 'models-tosca/src/main/java/org/onap')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java47
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java128
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java214
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.java3
4 files changed, 2 insertions, 390 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java
deleted file mode 100644
index a87fab1e0..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.legacy.concepts;
-
-import com.google.gson.annotations.SerializedName;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-/**
- * Definition of a legacy operational policy stored as a TOSCA policy.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-@Data
-public class LegacyOperationalPolicy {
-
- @ApiModelProperty(name = "policy-id")
- @SerializedName("policy-id")
- private String policyId;
-
- @ApiModelProperty(name = "policy-version")
- @SerializedName("policy-version")
- private String policyVersion;
-
- private String content;
- private String controllerName;
-
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java
deleted file mode 100644
index ffa6f8b27..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.legacy.mapping;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.ws.rs.core.Response;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
-import org.onap.policy.models.tosca.simple.mapping.JpaToscaServiceTemplateMapper;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class maps a legacy operational policy to and from a TOSCA service template.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class LegacyOperationalPolicyMapper
- implements JpaToscaServiceTemplateMapper<LegacyOperationalPolicy, LegacyOperationalPolicy> {
-
- // Property name for the operational policy content
- private static final String CONTENT_PROPERTY = "content";
- private static final String CONTROLLER_PROPERTY = "controllerName";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapper.class);
-
- private static final PfConceptKey LEGACY_OPERATIONAL_TYPE =
- new PfConceptKey("onap.policies.controlloop.Operational", "1.0.0");
-
- @Override
- public JpaToscaServiceTemplate toToscaServiceTemplate(final LegacyOperationalPolicy legacyOperationalPolicy) {
- String incomingVersion = legacyOperationalPolicy.getPolicyVersion();
- if (incomingVersion == null) {
- incomingVersion = "1";
- }
-
- PfConceptKey policyKey = new PfConceptKey(legacyOperationalPolicy.getPolicyId(), incomingVersion + ".0.0");
-
- final JpaToscaPolicy toscaPolicy = new JpaToscaPolicy(policyKey);
-
- toscaPolicy.setType(LEGACY_OPERATIONAL_TYPE);
-
- final Map<String, String> propertyMap = new HashMap<>();
- toscaPolicy.setProperties(propertyMap);
- toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent());
- if (legacyOperationalPolicy.getControllerName() != null) {
- toscaPolicy.getProperties().put(CONTROLLER_PROPERTY, legacyOperationalPolicy.getControllerName());
- }
-
- final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_1_0");
-
- serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
-
- serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy);
-
- return serviceTemplate;
- }
-
- @Override
- public LegacyOperationalPolicy fromToscaServiceTemplate(final JpaToscaServiceTemplate serviceTemplate) {
- ToscaUtils.assertPoliciesExist(serviceTemplate);
-
- if (serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size() > 1) {
- String errorMessage = "more than one policy found in service template";
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- // Get the policy
- final JpaToscaPolicy toscaPolicy =
- serviceTemplate.getTopologyTemplate().getPolicies().getAll(null).iterator().next();
-
- final LegacyOperationalPolicy legacyOperationalPolicy = new LegacyOperationalPolicy();
- legacyOperationalPolicy.setPolicyId(toscaPolicy.getKey().getName());
- legacyOperationalPolicy.setPolicyVersion(Integer.toString(toscaPolicy.getKey().getMajorVersion()));
-
- if (toscaPolicy.getProperties() == null) {
- String errorMessage = "no properties defined on TOSCA policy";
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY);
-
- if (content == null) {
- String errorMessage = "property \"content\" not defined on TOSCA policy";
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- legacyOperationalPolicy.setContent(content);
-
- String controllerName = toscaPolicy.getProperties().get(CONTROLLER_PROPERTY);
- if (controllerName != null) {
- legacyOperationalPolicy.setControllerName(controllerName);
- }
-
- return legacyOperationalPolicy;
- }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java
deleted file mode 100644
index 4d03f0560..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.legacy.provider;
-
-import java.util.Map;
-import javax.ws.rs.core.Response;
-import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.dao.PfDao;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class provides the provision of information on TOSCA concepts in the database to callers in legacy formats.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class LegacyProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(LegacyProvider.class);
-
- public static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
-
- // Recurring constants
- private static final String NO_POLICY_FOUND_FOR_POLICY = "no policy found for policy: ";
-
- /**
- * Get legacy operational policy.
- *
- * @param dao the DAO to use to access the database
- * @param policyId ID of the policy.
- * @param policyVersion version of the policy.
- * @return the policies found
- * @throws PfModelException on errors getting policies
- */
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId,
- final String policyVersion) throws PfModelException {
-
- LOGGER.debug("->getOperationalPolicy: policyId={}, policyVersion={}", policyId, policyVersion);
-
- LegacyOperationalPolicy legacyOperationalPolicy =
- new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(getLegacyPolicy(dao, policyId, policyVersion));
-
- LOGGER.debug("<-getOperationalPolicy: policyId={}, policyVersion={}, legacyOperationalPolicy={}", policyId,
- policyVersion, legacyOperationalPolicy);
- return legacyOperationalPolicy;
- }
-
- /**
- * Create legacy operational policy.
- *
- * @param dao the DAO to use to access the database
- * @param legacyOperationalPolicy the definition of the policy to be created.
- * @return the created policy
- * @throws PfModelException on errors creating policies
- */
- public LegacyOperationalPolicy createOperationalPolicy(@NonNull final PfDao dao,
- @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
-
- LOGGER.debug("->createOperationalPolicy: legacyOperationalPolicy={}", legacyOperationalPolicy);
-
- JpaToscaServiceTemplate legacyOperationalServiceTemplate =
- new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy);
-
- new SimpleToscaProvider().createPolicies(dao, legacyOperationalServiceTemplate);
-
- LegacyOperationalPolicy createdLegacyOperationalPolicy =
- new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(legacyOperationalServiceTemplate);
-
- LOGGER.debug("<-createOperationalPolicy: createdLegacyOperationalPolicy={}", createdLegacyOperationalPolicy);
- return createdLegacyOperationalPolicy;
- }
-
- /**
- * Update legacy operational policy.
- *
- * @param dao the DAO to use to access the database
- * @param legacyOperationalPolicy the definition of the policy to be updated
- * @return the updated policy
- * @throws PfModelException on errors updating policies
- */
- public LegacyOperationalPolicy updateOperationalPolicy(@NonNull final PfDao dao,
- @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
-
- LOGGER.debug("->updateOperationalPolicy: legacyOperationalPolicy={}", legacyOperationalPolicy);
- JpaToscaServiceTemplate incomingServiceTemplate =
- new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy);
- JpaToscaServiceTemplate outgoingingServiceTemplate =
- new SimpleToscaProvider().updatePolicies(dao, incomingServiceTemplate);
-
- LegacyOperationalPolicy updatedLegacyOperationalPolicy =
- new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate);
-
- LOGGER.debug("<-updateOperationalPolicy: updatedLegacyOperationalPolicy={}", updatedLegacyOperationalPolicy);
- return updatedLegacyOperationalPolicy;
- }
-
- /**
- * Delete legacy operational policy.
- *
- * @param dao the DAO to use to access the database
- * @param policyId ID of the policy.
- * @param policyVersion version of the policy.
- * @return the deleted policy
- * @throws PfModelException on errors deleting policies
- */
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId,
- @NonNull final String policyVersion) throws PfModelException {
-
- LOGGER.debug("->deleteOperationalPolicy: policyId={}, policyVersion={}", policyId, policyVersion);
-
- JpaToscaServiceTemplate deleteServiceTemplate = new SimpleToscaProvider().deletePolicy(dao,
- new PfConceptKey(policyId, policyVersion + LEGACY_MINOR_PATCH_SUFFIX));
- LegacyOperationalPolicy legacyOperationalPolicy =
- new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(deleteServiceTemplate);
-
- LOGGER.debug("<-deleteOperationalPolicy: policyId={}, policyVersion={}, legacyOperationalPolicy={}", policyId,
- policyVersion, legacyOperationalPolicy);
- return legacyOperationalPolicy;
- }
-
- /**
- * Get the JPA Policy for a policy ID and version.
- *
- * @param dao The DAO to search
- * @param policyId the policy ID to search for
- * @param policyVersion the policy version to search for
- * @return the JPA policy found
- * @throws PfModelException if a policy is not found
- */
- private JpaToscaServiceTemplate getLegacyPolicy(final PfDao dao, final String policyId, final String policyVersion)
- throws PfModelException {
- JpaToscaServiceTemplate foundPolicyServiceTemplate = null;
- if (policyVersion == null) {
- foundPolicyServiceTemplate = getLatestPolicy(dao, policyId);
- } else {
- foundPolicyServiceTemplate =
- new SimpleToscaProvider().getPolicies(dao, policyId, policyVersion + LEGACY_MINOR_PATCH_SUFFIX);
- }
-
- if (foundPolicyServiceTemplate == null) {
- String errorMessage = NO_POLICY_FOUND_FOR_POLICY + policyId + ':' + policyVersion;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
-
- return foundPolicyServiceTemplate;
- }
-
- /**
- * Get the latest policy for a policy ID.
- *
- * @param dao The DAO to read from
- * @param policyId the ID of the policy
- * @return the policy
- * @throws PfModelException on exceptions getting the policies
- */
- private JpaToscaServiceTemplate getLatestPolicy(final PfDao dao, final String policyId) throws PfModelException {
- // Get all the policies in the database and check the policy ID against the policies returned
- JpaToscaServiceTemplate serviceTemplate = new SimpleToscaProvider().getPolicies(dao, policyId, null);
-
- if (!ToscaUtils.doPoliciesExist(serviceTemplate)) {
- return null;
- }
-
- // Find the latest policy that matches the ID
- final Map<PfConceptKey, JpaToscaPolicy> policyMap =
- serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap();
- PfConceptKey newestPolicyKey = null;
-
- for (JpaToscaPolicy policy : policyMap.values()) {
- if (!policyId.equals(policy.getKey().getName())) {
- continue;
- }
-
- // We found a matching policy
- if (newestPolicyKey == null || policy.getKey().isNewerThan(newestPolicyKey)) {
- // First policy found
- newestPolicyKey = policy.getKey();
- }
- }
-
- final PfConceptKey newestPolicyFinalKey = newestPolicyKey;
- policyMap.keySet().removeIf(key -> !key.equals(newestPolicyFinalKey));
-
- return serviceTemplate;
- }
-}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.java
index e7a4056f7..91292f4f0 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +24,7 @@ package org.onap.policy.models.tosca.simple.mapping;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
- * This interface is used to map legacy and proprietary policies into and out of TOSCA service templates.
+ * This interface is used to map proprietary policies into and out of TOSCA service templates.
*
* @author Liam Fallon (liam.fallon@est.tech)
* @param <I> the type for the incoming policy definition