From b87e0242ce1a957740ee988bec3b82e3628adbed Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 17 Dec 2020 12:10:21 +0000 Subject: Add Service Template TOSCA handling Today we can only handle a single service template in the database. We should be able to handle multiple service templates and assign arbitrary policy types and policies to maned and versioned service templates. This review brings in the Java API in models provider for handling service templates in this way and uses a simplistic single-teplate implementation in models-tosca, that will work but still only handles a single service template under the hood. Issue-ID: POLICY-2900 Change-Id: Ia02dea8abe44b7f407e685090a4b8e0360889653 Signed-off-by: liamfallon --- .../models/provider/PolicyModelsProvider.java | 57 +++++++++++++++++++++- .../impl/DatabasePolicyModelsProviderImpl.java | 38 +++++++++++++++ .../impl/DummyPolicyModelsProviderImpl.java | 32 ++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) (limited to 'models-provider/src/main/java') diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java index f2f7318e8..1e8fd24ff 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java @@ -35,6 +35,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; /** * This interface describes the operations that are provided to users and components for reading objects from and @@ -53,6 +54,58 @@ public interface PolicyModelsProvider extends AutoCloseable { @Override public void close() throws PfModelException; + /** + * Get service templates. + * + * @param name the name of the topology template to get, set to null to get all service templates + * @param version the version of the service template to get, set to null to get all service templates + * @return the topology templates found + * @throws PfModelException on errors getting service templates + */ + public List getServiceTemplateList(final String name, final String version) + throws PfModelException; + + /** + * Get filtered service templates. + * + * @param filter the filter for the service templates to get + * @return the service templates found + * @throws PfModelException on errors getting service templates + */ + public List getFilteredServiceTemplateList(@NonNull final ToscaServiceTemplateFilter filter) + throws PfModelException; + + /** + * Create service template. + * + * @param serviceTemplate the service template to be created + * @return the created service template + * @throws PfModelException on errors creating the service template + */ + public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException; + + /** + * Update service template. + * + * @param serviceTemplate the service template to be updated + * @return the updated service template + * @throws PfModelException on errors updating the service template + */ + public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException; + + /** + * Delete service template. + * + * @param name the name of the service template to delete. + * @param version the version of the service template to delete. + * @return the TOSCA service template that was deleted + * @throws PfModelException on errors deleting policy types + */ + public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version) + throws PfModelException; + /** * Get policy types. * @@ -104,7 +157,7 @@ public interface PolicyModelsProvider extends AutoCloseable { throws PfModelException; /** - * Create policy types. + * Update policy types. * * @param serviceTemplate the service template containing the definition of the policy types to be modified * @return the TOSCA service template containing the modified policy types @@ -119,7 +172,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @param name the name of the policy type to delete. * @param version the version of the policy type to delete. * @return the TOSCA service template containing the policy type that was deleted - * @throws PfModelException on errors deleting policy types + * @throws PfModelException on errors deleting the policy type */ public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version) throws PfModelException; diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java index e27b9a43c..29b2d70b0 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java @@ -50,6 +50,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,6 +131,43 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { parameters.getPersistenceUnit()); } + @Override + public List getServiceTemplateList(final String name, final String version) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().getServiceTemplateList(pfDao, name, version); + } + + + @Override + public List getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().getFilteredServiceTemplateList(pfDao, filter); + } + + @Override + public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().createServiceTemplate(pfDao, serviceTemplate); + } + + @Override + public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().updateServiceTemplate(pfDao, serviceTemplate); + } + + @Override + public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version) + throws PfModelException { + assertInitialized(); + + return new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, name, version); + } + @Override public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException { assertInitialized(); diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java index 16f5a2b74..1d892272c 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.ws.rs.core.Response; +import lombok.NonNull; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; @@ -42,6 +43,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter; /** * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. @@ -69,6 +71,36 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { // Not required on the dummy provider } + + @Override + public List getServiceTemplateList(String name, String version) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) + throws PfModelException { + return new ArrayList<>(); + } + + @Override + public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version) + throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json"); + } + @Override public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); -- cgit 1.2.3-korg