return getKey().getId();
}
+ /**
+ * Gets the name of this concept.
+ *
+ * @return the name of this concept
+ */
+ public String getName() {
+ return getKey().getName();
+ }
+
+ /**
+ * Gets the version of this concept.
+ *
+ * @return the version of this concept
+ */
+ public String getVersion() {
+ return getKey().getVersion();
+ }
+
/**
* Checks if this key matches the given key ID.
*
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.base;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Data;
+import lombok.NonNull;
+
+/**
+ * Filter class for searches for {@link ToscaPolicy} instances. If any fields are null, they are ignored.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Builder
+@Data
+public class PfConceptFilter implements PfObjectFilter<PfConcept> {
+ public static final String LATEST_VERSION = "LATEST";
+
+ // Exact expression
+ private String name;
+
+ // Exact match, set to LATEST_VERSION to get the latest version
+ private String version;
+
+ // version prefix
+ private String versionPrefix;
+
+ @Override
+ public List<PfConcept> filter(@NonNull final List<PfConcept> originalList) {
+
+ // @formatter:off
+ List<PfConcept> returnList = originalList.stream()
+ .filter(filterStringPred(name, PfConcept::getName))
+ .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), PfConcept::getVersion))
+ .filter(filterPrefixPred(versionPrefix, PfConcept::getVersion))
+ .collect(Collectors.toList());
+ // @formatter:off
+
+ if (LATEST_VERSION.equals(version)) {
+ return this.latestVersionFilter(returnList);
+ }
+ else {
+ return returnList;
+ }
+ }
+}
{
"onap.vfirewall.tca":
{
- "type": "onap.policy.monitoring.cdap.tca.hi.lo.app",
+ "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
"version": "1.0.0",
"metadata":
{
policies:
-
onap.vfirewall.tca:
- type: onap.policy.monitoring.cdap.tca.hi.lo.app
+ type: onap.policies.monitoring.cdap.tca.hi.lo.app
version: 1.0.0
metadata:
policy-id: onap.vfirewall.tca
--- /dev/null
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+ - onap.policies.controlloop.Operational:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ description: Operational Policy for Control Loops
\ No newline at end of file
--- /dev/null
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+ - onap.policies.controlloop.Guard:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ description: Guard Policies for Control Loop Operational Policies
+ - onap.policies.controlloop.guard.Blacklist:
+ derived_from: onap.policies.controlloop.Guard
+ version: 1.0.0
+ description: Supports blacklist of VNF's from performing control loop actions on.
+ properties:
+ blacklist_policy:
+ type: map
+ description:
+ entry_schema:
+ type: onap.datatypes.guard.Blacklist
+data_types:
+ - onap.datatypes.guard.Blacklist:
+ derived_from: tosca.datatypes.Root
+ properties:
+ actor:
+ type: string
+ description: Specifies the Actor
+ required: true
+ recipe:
+ type: string
+ description: Specified the Recipe
+ required: true
+ time_range:
+ type: tosca.datatypes.TimeInterval
+ description: An optional range of time during the day the blacklist is valid for.
+ required: false
+ controlLoopName:
+ type: string
+ description: An optional specific control loop to apply this guard to.
+ required: false
+ blacklist:
+ type: list
+ description: List of VNF's
+ required: true
\ No newline at end of file
--- /dev/null
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+ - onap.policies.controlloop.Guard:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ description: Guard Policies for Control Loop Operational Policies
+ - onap.policies.controlloop.guard.FrequencyLimiter:
+ derived_from: onap.policies.controlloop.Guard
+ version: 1.0.0
+ description: Supports limiting the frequency of actions being taken by a Actor.
+ properties:
+ frequency_policy:
+ type: map
+ description:
+ entry_schema:
+ type: onap.datatypes.guard.FrequencyLimiter
+data_types:
+ - onap.datatypes.guard.FrequencyLimiter:
+ derived_from: tosca.datatypes.Root
+ properties:
+ actor:
+ type: string
+ description: Specifies the Actor
+ required: true
+ recipe:
+ type: string
+ description: Specified the Recipe
+ required: true
+ time_window:
+ type: scalar-unit.time
+ description: The time window to count the actions against.
+ required: true
+ limit:
+ type: integer
+ description: The limit
+ required: true
+ constraints:
+ - greater_than: 0
+ time_range:
+ type: tosca.datatypes.TimeInterval
+ description: An optional range of time during the day the frequency is valid for.
+ required: false
+ controlLoopName:
+ type: string
+ description: An optional specific control loop to apply this guard to.
+ required: false
+ target:
+ type: string
+ description: An optional specific VNF to apply this guard to.
+ required: false
\ No newline at end of file
--- /dev/null
+policy_types:
+ - onap.policies.controlloop.Guard:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ description: Guard Policies for Control Loop Operational Policies
+ - onap.policies.controlloop.guard.MinMax:
+ derived_from: onap.policies.controlloop.Guard
+ version: 1.0.0
+ description: Supports Min/Max number of VF Modules
+ properties:
+ minmax_policy:
+ type: map
+ description:
+ entry_schema:
+ type: onap.datatypes.guard.MinMax
+data_types:
+ - onap.datatypes.guard.MinMax:
+ derived_from: tosca.datatypes.Root
+ properties:
+ actor:
+ type: string
+ description: Specifies the Actor
+ required: true
+ recipe:
+ type: string
+ description: Specified the Recipe
+ required: true
+ time_range:
+ type: tosca.datatypes.TimeInterval
+ description: An optional range of time during the day the Min/Max limit is valid for.
+ required: false
+ controlLoopName:
+ type: string
+ description: An optional specific control loop to apply this guard to.
+ required: false
+ min_vf_module_instances:
+ type: integer
+ required: true
+ description: The minimum instances of this VF-Module
+
+ max_vf_module_instances:
+ type: integer
+ required: false
+ description: The maximum instances of this VF-Module
\ No newline at end of file
derived_from: tosca.policies.Root
description: a base policy type for all policies that governs monitoring provisioning
-
- onap.policy.monitoring.cdap.tca.hi.lo.app:
+ onap.policies.monitoring.cdap.tca.hi.lo.app:
derived_from: onap.policies.Monitoring
version: 1.0.0
properties:
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
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.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
/**
* Test persistence of monitoring policies to and from the database.
* Initialize provider.
*
* @throws PfModelException on exceptions in the tests
+ * @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException {
+ public void setupParameters() throws PfModelException, CoderException {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
parameters.setPersistenceUnit("ToscaConceptTest");
databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ createPolicyTypes();
}
/**
// All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters
assertEquals(policyOutputString.replaceAll("\\s+", ""), actualRetrievedJson.replaceAll("\\s+", ""));
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.MinMax.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+ }
}
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
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.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
/**
* Test persistence of monitoring policies to and from the database.
* Initialize provider.
*
* @throws PfModelException on exceptions in the tests
+ * @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException {
+ public void setupParameters() throws PfModelException, CoderException {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
parameters.setPersistenceUnit("ToscaConceptTest");
databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ createPolicyTypes();
}
/**
actualRetrievedJson.replaceAll("\\s+", "").replaceAll("u0027", "_-_-_-_").replaceAll("\\\\_-_-_-_",
"'"));
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+ }
}
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
* Initialize provider.
*
* @throws PfModelException on exceptions in the tests
+ * @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException {
+ public void setupParameters() throws PfModelException, CoderException {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
parameters.setPersistenceUnit("ToscaConceptTest");
databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ createPolicyTypes();
}
/**
}
}
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+ }
}
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
* Initialize provider.
*
* @throws PfModelException on exceptions in the tests
+ * @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException {
+ public void setupParameters() throws PfModelException, CoderException {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
parameters.setPersistenceUnit("ToscaConceptTest");
databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ createPolicyTypes();
}
/**
assertEquals(incomingPolicy.getType(), databasePolicy.getType());
}
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+ }
}
"policytypes/onap.policies.optimization.SubscriberPolicy.yaml",
"policytypes/onap.policies.optimization.Vim_fit.yaml",
"policytypes/onap.policies.optimization.VnfPolicy.yaml",
- "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml"
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"
};
// @formatter:on
package org.onap.policy.models.tosca.simple.provider;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.ws.rs.core.Response;
+
import lombok.NonNull;
import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptFilter;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
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.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.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.
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class SimpleToscaProvider {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class);
+
/**
* Get policy types.
*
ToscaUtils.assertPoliciesExist(serviceTemplate);
for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) {
+ verifyPolicyTypeForPolicy(dao, policy);
+
dao.create(policy);
}
return conceptMap;
}
+
+ /**
+ * Verify the policy type for a policy exists.
+ *
+ * @param dao the DAO to use to access policy types in the database
+ * @param policy the policy to check the policy type for
+ */
+ private void verifyPolicyTypeForPolicy(final PfDao dao, final JpaToscaPolicy policy) {
+ PfConceptKey policyTypeKey = policy.getType();
+
+ JpaToscaPolicyType policyType = null;
+
+ if (PfKey.NULL_KEY_VERSION.equals(policyTypeKey.getVersion())) {
+ policyType = getLatestPolicyTypeVersion(dao, policyTypeKey.getName());
+ } else {
+ policyType = dao.get(JpaToscaPolicyType.class, policyTypeKey);
+ }
+
+ if (policyType == null) {
+ String errorMessage =
+ "policy type " + policyTypeKey.getId() + " for policy " + policy.getId() + " does not exist";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+ }
+
+ /**
+ * Get the latest version of the policy type for the given policy type name.
+ *
+ * @param dao the DAO to use to access policy types in the database
+ * @param policyTypeName the name of the policy type
+ * @return the latest policy type
+ */
+ private JpaToscaPolicyType getLatestPolicyTypeVersion(final PfDao dao, final String policyTypeName) {
+ // Policy type version is not specified, get the latest version from the database
+ List<JpaToscaPolicyType> jpaPolicyTypeList =
+ dao.getFiltered(JpaToscaPolicyType.class, policyTypeName, null);
+
+ if (jpaPolicyTypeList.isEmpty()) {
+ return null;
+ }
+
+ // Create a filter to get the latest version of the policy type
+ PfConceptFilter pfConceptFilter = PfConceptFilter.builder().version(PfConceptFilter.LATEST_VERSION).build();
+
+ // FIlter the returned policy type list
+ List<PfConcept> policyTypeKeyList = new ArrayList<>(jpaPolicyTypeList);
+ List<PfConcept> filterdPolicyTypeList = pfConceptFilter.filter(policyTypeKeyList);
+
+ // We should have one and only one returned entry
+ if (filterdPolicyTypeList.size() != 1 ) {
+ String errorMessage =
+ "search for lates policy type " + policyTypeName + " returned more than one entry";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+
+ return (JpaToscaPolicyType) filterdPolicyTypeList.get(0);
+ }
}
/**
* Private constructor to prevent subclassing.
*/
- private ToscaUtils() {
- }
+ private ToscaUtils() {}
/**
* Check if policy types have been specified is initialized.
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
}
-
-
}
filter = ToscaPolicyFilter.builder().type("onap.policies.monitoring.cdap.tca.hi.lo.app").build();
filteredList = filter.filter(policyList);
- assertEquals(2, filteredList.size());
+ assertEquals(3, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.NonOperational").build();
filteredList = filter.filter(policyList);
"policytypes/onap.policies.optimization.SubscriberPolicy.yaml",
"policytypes/onap.policies.optimization.Vim_fit.yaml",
"policytypes/onap.policies.optimization.VnfPolicy.yaml",
- "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml"
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"
};
// @formatter:on
List<ToscaPolicyType> filteredList = filter.filter(typeList);
assertEquals(2, filteredList.size());
- filter = ToscaPolicyTypeFilter.builder().name("onap.policy.monitoring.cdap.tca.hi.lo.app").build();
+ filter = ToscaPolicyTypeFilter.builder().name("onap.policies.monitoring.cdap.tca.hi.lo.app").build();
filteredList = filter.filter(typeList);
assertEquals(1, filteredList.size());
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
+import org.yaml.snakeyaml.Yaml;
/**
* Test of the {@link AuthorativeToscaProvider} class.
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
- daoParameters.setJdbcProperties(jdbcProperties );
+ daoParameters.setJdbcProperties(jdbcProperties);
pfDao = new PfDaoFactory().createPfDao(daoParameters);
pfDao.init(daoParameters);
new AuthorativeToscaProvider().getPolicyList(null, null, null);
}).hasMessage("dao is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
}).hasMessage("filter is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
new AuthorativeToscaProvider().createPolicies(pfDao, null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
}
-
@Test
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(pfDao, null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
}).hasMessage("version is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
}).hasMessage("An incoming list of concepts must have at least one entry");
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+ }
}
try {
Yaml yaml = new Yaml();
String inputYaml = ResourceUtils.getResourceAsString(
- "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml");
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
Object yamlObject = yaml.load(inputYaml);
String yamlAsJsonString = standardCoder.encode(yamlObject);
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
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;
+import org.yaml.snakeyaml.Yaml;
/**
* Test the {@link LegacyProvider} class for legacy guard policies.
new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
new LegacyProvider().createGuardPolicy(pfDao, null);
}).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
}
-
@Test
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput());
}).hasMessage("policy type for guard policy \"null\" unknown");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
new LegacyProvider().deleteGuardPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
}).hasMessage("no policy found for policy ID: guard.frequency.scaleout");
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml()
+ .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.Blacklist.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+ }
}
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.yaml.snakeyaml.Yaml;
/**
* Test the {@link LegacyProvider} class for legacy operational policies.
new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
new LegacyProvider().createOperationalPolicy(pfDao, null);
}).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
}
-
@Test
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(pfDao, new LegacyOperationalPolicy());
}).hasMessage("no policy found for policy ID: null");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
assertEquals("Some New Content", gotUpdatedLop.getContent());
}
-
@Test
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, "");
+
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, null);
}).hasMessage("policyId is marked @NonNull but is null");
-
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
}).hasMessage("no policy found for policy ID: operational.restart");
+ }
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
}
}
assertEquals(tdtClone0, tp);
assertFalse(new JpaToscaPolicy().validate(new PfValidationResult()).isValid());
- System.err.println(tp.validate(new PfValidationResult()));
assertTrue(tp.validate(new PfValidationResult()).isValid());
tp.getProperties().put(null, null);
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.dao.impl.DefaultPfDao;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
+import org.yaml.snakeyaml.Yaml;
/**
* Test the {@link SimpleToscaProvider} class.
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
new SimpleToscaProvider().deletePolicy(pfDao, null);
}).hasMessage("policyKey is marked @NonNull but is null");
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+ }
}
JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject();
assertNotNull(policy.get("onap.vfirewall.tca"));
JsonObject policyVal = policy.get("onap.vfirewall.tca").getAsJsonObject();
- assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
assertEquals("1.0.0", policyVal.get("version").getAsString());
assertEquals("onap.vfirewall.tca", policyVal.get("metadata").getAsJsonObject().get("policy-id")
.getAsString());
private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class);
- private static final String MONITORING_TCA_YAML = "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml";
+ private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
private static final String MONITORING_COLLECTORS_YAML =
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
firstPolicyType.getValue().getDescription());
Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
- assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
assertEquals("1.0.0", secondPolicyType.getKey().getVersion());
assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
- assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
assertEquals("1.0.0", property.getKey().getParentKeyVersion());
assertEquals("tca_policy", property.getKey().getLocalName());
assertEquals("map", property.getType().getName());