summaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-15 17:03:34 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2022-11-18 08:57:36 +0000
commita2e99e7df02837d8270228c330bed4915043b996 (patch)
tree2864318cdd99e18fd1cbb2322318b3e89fe7454c /runtime-acm
parent5f72a385593d3ca906c8f3a6c382db213fce206c (diff)
Link the existing CommissioningController with the generated code
Link the existing CommissioningController endpoint implementation code with the generated code in Acm. Issue-ID: POLICY-4454 Change-Id: Ie10296b6af8c8bfdbfa7f54714b22ca4804a2eef Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java267
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java73
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java287
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java12
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java14
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java14
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java16
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java33
-rw-r--r--runtime-acm/src/main/resources/application.yaml2
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java109
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java118
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java238
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java16
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java16
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java16
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java10
16 files changed, 412 insertions, 829 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
index 55d7b0c13..c2564887c 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
@@ -21,30 +21,23 @@
package org.onap.policy.clamp.acm.runtime.commissioning;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import java.util.UUID;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -56,51 +49,33 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class CommissioningProvider {
public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
- private static final String HYPHEN = "-";
- private final ServiceTemplateProvider serviceTemplateProvider;
+ private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionProvider acProvider;
- private static final Coder CODER = new StandardCoder();
private final ParticipantProvider participantProvider;
private final SupervisionHandler supervisionHandler;
/**
* Create a commissioning provider.
*
- * @param serviceTemplateProvider the ServiceTemplate Provider
+ * @param acDefinitionProvider the ServiceTemplate Provider
* @param acProvider the AutomationComposition Provider
* @param supervisionHandler the Supervision Handler
* @param participantProvider the Participant Provider
*/
- public CommissioningProvider(ServiceTemplateProvider serviceTemplateProvider,
+ public CommissioningProvider(AcDefinitionProvider acDefinitionProvider,
AutomationCompositionProvider acProvider, SupervisionHandler supervisionHandler,
ParticipantProvider participantProvider) {
- this.serviceTemplateProvider = serviceTemplateProvider;
+ this.acDefinitionProvider = acDefinitionProvider;
this.acProvider = acProvider;
this.supervisionHandler = supervisionHandler;
this.participantProvider = participantProvider;
}
- /**
- * Create automation compositions from a service template.
- *
- * @param serviceTemplate the service template
- * @return the result of the commissioning operation
- * @throws PfModelException on creation errors
- */
- public CommissioningResponse createAutomationCompositionDefinitions(ToscaServiceTemplate serviceTemplate)
- throws PfModelException {
-
- if (verifyIfInstancePropertiesExists()) {
- throw new PfModelException(Status.BAD_REQUEST,
- "Delete instances, to commission automation composition definitions");
- }
- serviceTemplate = serviceTemplateProvider.createServiceTemplate(serviceTemplate);
- List<Participant> participantList = participantProvider.getParticipants();
- if (!participantList.isEmpty()) {
- supervisionHandler.handleSendCommissionMessage(serviceTemplate.getName(), serviceTemplate.getVersion());
- }
+ private CommissioningResponse createCommissioningResponse(UUID compositionId,
+ ToscaServiceTemplate serviceTemplate) {
var response = new CommissioningResponse();
+ response.setCompositionId(compositionId);
// @formatter:off
response.setAffectedAutomationCompositionDefinitions(
serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
@@ -114,201 +89,117 @@ public class CommissioningProvider {
}
/**
- * Delete the automation composition definition with the given name and version.
+ * Create automation compositions from a service template.
*
- * @param name the name of the automation composition definition to delete
- * @param version the version of the automation composition to delete
- * @return the result of the deletion
- * @throws PfModelException on deletion errors
+ * @param serviceTemplate the service template
+ * @return the result of the commissioning operation
*/
- public CommissioningResponse deleteAutomationCompositionDefinition(String name, String version)
- throws PfModelException {
+ public CommissioningResponse createAutomationCompositionDefinitions(ToscaServiceTemplate serviceTemplate) {
- if (verifyIfInstancePropertiesExists()) {
- throw new PfModelException(Status.BAD_REQUEST,
+ if (verifyIfDefinitionExists()) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
"Delete instances, to commission automation composition definitions");
}
- List<Participant> participantList = participantProvider.getParticipants();
+ var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate);
+ serviceTemplate = acmDefinition.getServiceTemplate();
+ var participantList = participantProvider.getParticipants();
if (!participantList.isEmpty()) {
- supervisionHandler.handleSendDeCommissionMessage();
+ supervisionHandler.handleSendCommissionMessage(serviceTemplate.getName(), serviceTemplate.getVersion());
}
- serviceTemplateProvider.deleteServiceTemplate(name, version);
- var response = new CommissioningResponse();
- response.setAffectedAutomationCompositionDefinitions(List.of(new ToscaConceptIdentifier(name, version)));
-
- return response;
+ return createCommissioningResponse(acmDefinition.getCompositionId(), serviceTemplate);
}
/**
- * Get automation composition node templates.
+ * Update Composition Definition.
*
- * @param acName the name of the automation composition, null for all
- * @param acVersion the version of the automation composition, null for all
- * @return list of automation composition node templates
- * @throws PfModelException on errors getting automation composition definitions
+ * @param compositionId The UUID of the automation composition definition to update
+ * @param serviceTemplate the service template
+ * @return the result of the commissioning operation
*/
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getAutomationCompositionDefinitions(String acName, String acVersion)
- throws PfModelException {
+ public CommissioningResponse updateCompositionDefinition(UUID compositionId, ToscaServiceTemplate serviceTemplate) {
+
+ var automationCompositions = acProvider.getAutomationCompositions();
+ var result = new BeanValidationResult("AutomationCompositions", automationCompositions);
+ for (var automationComposition : automationCompositions) {
+ if (!AutomationCompositionState.UNINITIALISED.equals(automationComposition.getState())) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
+ "There is an Automation Composition instantioation with state in "
+ + automationComposition.getState());
+ }
+ result.addResult(AcmUtils.validateAutomationComposition(automationComposition, serviceTemplate));
+ }
+ if (!result.isValid()) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, "Service template non valid: " + result.getMessage());
+ }
- // @formatter:off
- ToscaTypedEntityFilter<ToscaNodeTemplate> nodeTemplateFilter = ToscaTypedEntityFilter
- .<ToscaNodeTemplate>builder()
- .name(acName)
- .version(acVersion)
- .type(AUTOMATION_COMPOSITION_NODE_TYPE)
- .build();
- // @formatter:on
+ acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate);
- return acProvider.getFilteredNodeTemplates(nodeTemplateFilter);
+ return createCommissioningResponse(compositionId, serviceTemplate);
}
/**
- * Get the automation composition elements from a automation composition node template.
+ * Delete the automation composition definition with the given name and version.
*
- * @param automationCompositionNodeTemplate the automation composition node template
- * @return a list of the automation composition element node templates in a automation composition node template
- * @throws PfModelException on errors get automation composition element node templates
+ * @param compositionId The UUID of the automation composition definition to delete
+ * @return the result of the deletion
*/
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getAutomationCompositionElementDefinitions(
- ToscaNodeTemplate automationCompositionNodeTemplate) throws PfModelException {
- if (!AUTOMATION_COMPOSITION_NODE_TYPE.equals(automationCompositionNodeTemplate.getType())) {
- return Collections.emptyList();
- }
+ public CommissioningResponse deleteAutomationCompositionDefinition(UUID compositionId) {
- if (MapUtils.isEmpty(automationCompositionNodeTemplate.getProperties())) {
- return Collections.emptyList();
+ if (verifyIfInstanceExists()) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
+ "Delete instances, to commission automation composition definitions");
}
-
- @SuppressWarnings("unchecked")
- List<Map<String, String>> automationCompositionElements =
- (List<Map<String, String>>) automationCompositionNodeTemplate.getProperties().get("elements");
-
- if (CollectionUtils.isEmpty(automationCompositionElements)) {
- return Collections.emptyList();
+ List<Participant> participantList = participantProvider.getParticipants();
+ if (!participantList.isEmpty()) {
+ supervisionHandler.handleSendDeCommissionMessage();
}
-
- List<ToscaNodeTemplate> automationCompositionElementList = new ArrayList<>();
- // @formatter:off
- automationCompositionElementList.addAll(
- automationCompositionElements
- .stream()
- .map(elementMap -> acProvider.getNodeTemplates(elementMap.get("name"),
- elementMap.get("version")))
- .flatMap(List::stream)
- .collect(Collectors.toList())
- );
- // @formatter:on
-
- return automationCompositionElementList;
+ var serviceTemplate = acDefinitionProvider.deleteAcDefintion(compositionId);
+ return createCommissioningResponse(compositionId, serviceTemplate);
}
/**
- * Get the requested automation composition definitions.
+ * Get automation composition definition.
*
- * @param name the name of the definition to get, null for all definitions
- * @param version the version of the definition to get, null for all definitions
- * @return the automation composition definitions
+ * @param acName the name of the automation composition, null for all
+ * @param acVersion the version of the automation composition, null for all
+ * @return automation composition definition
* @throws PfModelException on errors getting automation composition definitions
*/
@Transactional(readOnly = true)
- public ToscaServiceTemplate getToscaServiceTemplate(String name, String version) throws PfModelException {
- return serviceTemplateProvider.getToscaServiceTemplate(name, version);
- }
+ public ToscaServiceTemplates getAutomationCompositionDefinitions(String acName, String acVersion) {
- /**
- * Get All the requested automation composition definitions.
- *
- * @return the automation composition definitions
- * @throws PfModelException on errors getting automation composition definitions
- */
- @Transactional(readOnly = true)
- public List<ToscaServiceTemplate> getAllToscaServiceTemplate() throws PfModelException {
- return serviceTemplateProvider.getAllServiceTemplates();
+ var result = new ToscaServiceTemplates();
+ result.setServiceTemplates(acDefinitionProvider.getServiceTemplateList(acName, acVersion));
+ return result;
}
/**
- * Get the tosca service template with only required sections.
+ * Get automation composition definition.
*
- * @param name the name of the template to get, null for all definitions
- * @param version the version of the template to get, null for all definitions
- * @param instanceName automation composition name
- * @return the tosca service template
- * @throws PfModelException on errors getting tosca service template
+ * @param compositionId the compositionId
+ * @return automation composition definition
*/
@Transactional(readOnly = true)
- public String getToscaServiceTemplateReduced(
- final String name, final String version, final String instanceName)
- throws PfModelException {
-
- var serviceTemplateList = serviceTemplateProvider.getServiceTemplateList(name, version);
-
- List<ToscaServiceTemplate> filteredServiceTemplateList =
- filterToscaNodeTemplateInstance(serviceTemplateList, instanceName);
-
- if (filteredServiceTemplateList.isEmpty()) {
- throw new PfModelException(Status.BAD_REQUEST, "Invalid Service Template");
- }
-
- ToscaServiceTemplate fullTemplate = filteredServiceTemplateList.get(0);
-
- var template = new HashMap<String, Object>();
- template.put("tosca_definitions_version", fullTemplate.getToscaDefinitionsVersion());
- template.put("data_types", fullTemplate.getDataTypes());
- template.put("policy_types", fullTemplate.getPolicyTypes());
- template.put("node_types", fullTemplate.getNodeTypes());
- template.put("topology_template", fullTemplate.getToscaTopologyTemplate());
-
- try {
- return CODER.encode(template);
+ public ToscaServiceTemplate getAutomationCompositionDefinitions(UUID compositionId) {
- } catch (CoderException e) {
- throw new PfModelException(Status.BAD_REQUEST, "Converion to Json Schema failed", e);
- }
+ return acDefinitionProvider.getAcDefinition(compositionId);
}
/**
- * Filters service templates if is not an instantiation type.
+ * Validates to see if there is any instance saved.
*
- * @param serviceTemplates tosca service template
- * @param instanceName automation composition name
- * @return List of tosca service templates
+ * @return true if exists instance
*/
- private List<ToscaServiceTemplate> filterToscaNodeTemplateInstance(
- List<ToscaServiceTemplate> serviceTemplates, String instanceName) {
-
- List<ToscaServiceTemplate> toscaServiceTemplates = new ArrayList<>();
-
- serviceTemplates.forEach(serviceTemplate -> {
-
- Map<String, ToscaNodeTemplate> toscaNodeTemplates = new HashMap<>();
-
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> {
- if (StringUtils.isNotEmpty(instanceName) && nodeTemplate.getName().contains(instanceName)) {
- toscaNodeTemplates.put(key, nodeTemplate);
- } else if (!nodeTemplate.getName().contains(HYPHEN)) {
- toscaNodeTemplates.put(key, nodeTemplate);
- }
- });
-
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().clear();
- serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(toscaNodeTemplates);
-
- toscaServiceTemplates.add(serviceTemplate);
- });
-
- return toscaServiceTemplates;
+ private boolean verifyIfInstanceExists() {
+ return !acProvider.getAutomationCompositions().isEmpty();
}
/**
- * Validates to see if there is any instance properties saved.
+ * Validates to see if there is any instance saved.
*
- * @return true if exists instance properties
+ * @return true if exists instance
*/
- private boolean verifyIfInstancePropertiesExists() {
- return acProvider.getAllNodeTemplates().stream()
- .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(HYPHEN));
-
+ private boolean verifyIfDefinitionExists() {
+ return !acDefinitionProvider.getAllServiceTemplates().isEmpty();
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 18fd1f938..df1f0ead4 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,30 +25,27 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
-import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
-import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
-import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -62,9 +59,9 @@ public class AutomationCompositionInstantiationProvider {
private static final String AUTOMATION_COMPOSITION_NODE_ELEMENT_TYPE = "AutomationCompositionElement";
private final AutomationCompositionProvider automationCompositionProvider;
- private final CommissioningProvider commissioningProvider;
private final SupervisionHandler supervisionHandler;
private final ParticipantProvider participantProvider;
+ private final AcDefinitionProvider acDefinitionProvider;
private static final String ENTRY = "entry ";
/**
@@ -126,67 +123,25 @@ public class AutomationCompositionInstantiationProvider {
* @return the result of validation
* @throws PfModelException if automationCompositions is not valid
*/
- private BeanValidationResult validateAutomationCompositions(AutomationCompositions automationCompositions)
- throws PfModelException {
+ private BeanValidationResult validateAutomationCompositions(AutomationCompositions automationCompositions) {
var result = new BeanValidationResult("AutomationCompositions", automationCompositions);
+ var serviceTemplates = acDefinitionProvider.getAllServiceTemplates();
+ if (serviceTemplates.isEmpty()) {
+ result.addResult(new ObjectValidationResult("ServiceTemplate", "", ValidationStatus.INVALID,
+ "Commissioned automation composition definition not found"));
+ return result;
+ }
- for (AutomationComposition automationComposition : automationCompositions.getAutomationCompositionList()) {
- var subResult = new BeanValidationResult(ENTRY + automationComposition.getDefinition().getName(),
- automationComposition);
-
- List<ToscaNodeTemplate> toscaNodeTemplates = commissioningProvider.getAutomationCompositionDefinitions(
- automationComposition.getDefinition().getName(), automationComposition.getDefinition().getVersion());
-
- if (toscaNodeTemplates.isEmpty()) {
- subResult.addResult(
- new ObjectValidationResult("AutomationComposition", automationComposition.getDefinition().getName(),
- ValidationStatus.INVALID, "Commissioned automation composition definition not found"));
- } else if (toscaNodeTemplates.size() > 1) {
- subResult.addResult(
- new ObjectValidationResult("AutomationComposition", automationComposition.getDefinition().getName(),
- ValidationStatus.INVALID, "Commissioned automation composition definition not valid"));
- } else {
-
- List<ToscaNodeTemplate> acElementDefinitions =
- commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplates.get(0));
-
- // @formatter:off
- Map<String, ToscaConceptIdentifier> definitions = acElementDefinitions
- .stream()
- .map(nodeTemplate -> nodeTemplate.getKey().asIdentifier())
- .collect(Collectors.toMap(ToscaConceptIdentifier::getName, UnaryOperator.identity()));
- // @formatter:on
+ var serviceTemplate = acDefinitionProvider.getAllServiceTemplates().get(0);
- for (AutomationCompositionElement element : automationComposition.getElements().values()) {
- subResult.addResult(validateDefinition(definitions, element.getDefinition()));
- }
- }
- result.addResult(subResult);
+ for (var automationComposition : automationCompositions.getAutomationCompositionList()) {
+ result.addResult(AcmUtils.validateAutomationComposition(automationComposition, serviceTemplate));
}
return result;
}
/**
- * Validate ToscaConceptIdentifier, checking if exist in ToscaConceptIdentifiers map.
- *
- * @param definitions map of all ToscaConceptIdentifiers
- * @param definition ToscaConceptIdentifier to validate
- * @return the validation result
- */
- private ValidationResult validateDefinition(Map<String, ToscaConceptIdentifier> definitions,
- ToscaConceptIdentifier definition) {
- var result = new BeanValidationResult(ENTRY + definition.getName(), definition);
- ToscaConceptIdentifier identifier = definitions.get(definition.getName());
- if (identifier == null) {
- result.setResult(ValidationStatus.INVALID, "Not found");
- } else if (!identifier.equals(definition)) {
- result.setResult(ValidationStatus.INVALID, "Version not matching");
- }
- return (result.isClean() ? null : result);
- }
-
- /**
* Delete the automation composition with the given name and version.
*
* @param name the name of the automation composition to delete
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java
index fef1e6de9..5a24db9af 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java
@@ -20,28 +20,23 @@
package org.onap.policy.clamp.acm.runtime.main.rest;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-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 io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
@@ -52,262 +47,118 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequiredArgsConstructor
-public class CommissioningController extends AbstractRestController {
-
- private static final String TAGS = "Clamp Automation Composition Commissioning API";
+public class CommissioningController extends AbstractRestController implements AutomationCompositionDefinitionApi {
private final CommissioningProvider provider;
/**
* Creates a automation composition definition.
*
- * @param requestId request ID used in ONAP logging
* @param body the body of automation composition following TOSCA definition
+ * @param requestId request ID used in ONAP logging
* @return a response
- * @throws PfModelException on errors creating a automation composition definition
*/
+ @Override
// @formatter:off
@PostMapping(value = "/commission",
consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(
- value = "Commissions automation composition definitions",
- notes = "Commissions automation composition definitions, returning commissioned definition IDs",
- response = CommissioningResponse.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_LATEST_NAME,
- description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)
- },
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
// @formatter:on
- public ResponseEntity<CommissioningResponse> create(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(
- value = "Entity Body of Automation Composition",
- required = true) @RequestBody ToscaServiceTemplate body)
- throws PfModelException {
+ public ResponseEntity<CommissioningResponse> createCompositionDefinitions(
+ @Parameter(
+ description = "Entity Body of Automation Composition",
+ required = true) @RequestBody ToscaServiceTemplate body,
+ @RequestHeader(name = REQUEST_ID_NAME, required = false) @Parameter(
+ description = REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- return ResponseEntity.ok().body(provider.createAutomationCompositionDefinitions(body));
+ var response = provider.createAutomationCompositionDefinitions(body);
+ return ResponseEntity.created(createUri("/commission/" + response.getCompositionId())).body(response);
}
/**
* Deletes a automation composition definition.
*
* @param requestId request ID used in ONAP logging
- * @param name the name of the automation composition definition to delete
- * @param version the version of the automation composition definition to delete
+ * @param compositionId The UUID of the automation composition definition to delete
* @return a response
- * @throws PfModelException on errors deleting a automation composition definition
*/
+ @Override
// @formatter:off
- @DeleteMapping(value = "/commission",
+ @DeleteMapping(value = "/commission/{compositionId}",
produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Delete a commissioned automation composition",
- notes = "Deletes a Commissioned Automation Composition, returning optional error details",
- response = CommissioningResponse.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME,
- description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_PATCH_NAME,
- description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = VERSION_LATEST_NAME,
- description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(
- name = REQUEST_ID_NAME,
- description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
// @formatter:on
- public ResponseEntity<CommissioningResponse> delete(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition definition name", required = true) @RequestParam(
- value = "name") String name,
- @ApiParam(
- value = "Automation composition definition version",
- required = true) @RequestParam("version") String version)
- throws PfModelException {
+ public ResponseEntity<CommissioningResponse> deleteCompositionDefinition(
+ @Parameter(
+ in = ParameterIn.PATH,
+ description = "The UUID of the automation composition definition to delete",
+ required = true) @PathVariable("compositionId") UUID compositionId,
+ @RequestHeader(name = REQUEST_ID_NAME, required = false) @Parameter(
+ description = REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- return ResponseEntity.ok().body(provider.deleteAutomationCompositionDefinition(name, version));
+ return ResponseEntity.ok().body(provider.deleteAutomationCompositionDefinition(compositionId));
}
/**
* Queries details of all or specific automation composition definitions.
*
- * @param requestId request ID used in ONAP logging
* @param name the name of the automation composition definition to get, null for all definitions
* @param version the version of the automation composition definition to get, null for all definitions
+ * @param requestId request ID used in ONAP logging
* @return the automation composition definitions
* @throws PfModelException on errors getting details of all or specific automation composition definitions
*/
+ @Override
// @formatter:off
@GetMapping(value = "/commission",
produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Query details of the requested commissioned automation composition definitions",
- notes = "Queries details of the requested commissioned automation composition definitions, "
- + "returning all automation composition details",
- response = ToscaNodeTemplate.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
// @formatter:on
- public ResponseEntity<List<ToscaNodeTemplate>> query(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Automation composition definition name", required = false) @RequestParam(
- value = "name",
- required = false) String name,
- @ApiParam(value = "Automation composition definition version", required = false) @RequestParam(
- value = "version",
- required = false) String version)
- throws PfModelException {
+ public ResponseEntity<ToscaServiceTemplates> queryCompositionDefinitions(
+
+ @Parameter(description = "Automation composition definition name", required = false) @RequestParam(
+ value = "name",
+ required = false) String name,
+ @Parameter(description = "Automation composition definition version", required = false) @RequestParam(
+ value = "version",
+ required = false) String version,
+ @RequestHeader(name = REQUEST_ID_NAME, required = false) @Parameter(
+ description = REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
return ResponseEntity.ok().body(provider.getAutomationCompositionDefinitions(name, version));
}
- /**
- * Retrieves the Tosca Service Template.
- *
- * @param requestId request ID used in ONAP logging
- * @param name the name of the tosca service template to retrieve
- * @param version the version of the tosca service template to get
- * @return the specified tosca service template
- * @throws PfModelException on errors getting the Tosca Service Template
- */
// @formatter:off
- @GetMapping(value = "/commission/toscaservicetemplate",
+ @Override
+ @GetMapping(value = "/commission/{compositionId}",
produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
- @ApiOperation(value = "Query details of the requested tosca service templates",
- notes = "Queries details of the requested commissioned tosca service template, "
- + "returning all tosca service template details",
- response = ToscaServiceTemplate.class,
- tags = {TAGS},
- authorizations = @Authorization(value = AUTHORIZATION_TYPE),
- responseHeaders = {
- @ResponseHeader(
- name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
- response = String.class),
- @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
- response = UUID.class)},
- extensions = {
- @Extension
- (
- name = EXTENSION_NAME,
- properties = {
- @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
- @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
- }
- )
- }
- )
- @ApiResponses(
- value = {
- @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
- }
- )
// @formatter:on
- public ResponseEntity<String> queryToscaServiceTemplate(
- @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Tosca service template name", required = false) @RequestParam(
- value = "name",
- required = false) String name,
- @ApiParam(value = "Tosca service template version", required = false) @RequestParam(
- value = "version",
- required = false) String version,
- @ApiParam(value = "Automation composition name", required = false) @RequestParam(
- value = "instanceName",
- required = false) String instanceName)
- throws PfModelException {
+ public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition(
+ @Parameter(
+ in = ParameterIn.PATH,
+ description = "The UUID of the automation composition definition to get",
+ required = true) @PathVariable("compositionId") UUID compositionId,
+ @RequestHeader(name = REQUEST_ID_NAME, required = false) @Parameter(
+ description = REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
+
+ return ResponseEntity.ok().body(provider.getAutomationCompositionDefinitions(compositionId));
+ }
- return ResponseEntity.ok().body(provider.getToscaServiceTemplateReduced(name, version, instanceName));
+ // @formatter:off
+ @Override
+ @PutMapping(value = "/commission/{compositionId}",
+ consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML},
+ produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
+ // @formatter:on
+ public ResponseEntity<CommissioningResponse> updateCompositionDefinition(
+ @Parameter(
+ in = ParameterIn.PATH,
+ description = "The UUID of the automation composition definition to update",
+ required = true) @PathVariable("compositionId") UUID compositionId,
+ @Parameter(
+ in = ParameterIn.DEFAULT,
+ description = "Serialised instance of.",
+ required = true) @RequestBody ToscaServiceTemplate body,
+ @RequestHeader(name = REQUEST_ID_NAME, required = false) @Parameter(
+ description = REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
+ return ResponseEntity.ok().body(provider.updateCompositionDefinition(compositionId, body));
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java
index 575111612..61522dd66 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/AbstractRestController.java
@@ -27,7 +27,11 @@ import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URISyntaxException;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.springframework.web.bind.annotation.RequestMapping;
/**
@@ -89,4 +93,12 @@ public abstract class AbstractRestController {
*/
protected AbstractRestController() {
}
+
+ protected URI createUri(String str) {
+ try {
+ return new URI(str);
+ } catch (URISyntaxException e) {
+ throw new AutomationCompositionRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
+ }
+ }
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
index 219383ac5..479d6cf6a 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
@@ -49,13 +48,11 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -81,7 +78,7 @@ public class SupervisionHandler {
private final AutomationCompositionProvider automationCompositionProvider;
private final ParticipantProvider participantProvider;
- private final ServiceTemplateProvider serviceTemplateProvider;
+ private final AcDefinitionProvider acDefinitionProvider;
// Publishers for participant communication
private final AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher;
@@ -448,12 +445,7 @@ public class SupervisionHandler {
}
private int getFirstStartPhase(AutomationComposition automationComposition) {
- ToscaServiceTemplate toscaServiceTemplate = null;
- try {
- toscaServiceTemplate = serviceTemplateProvider.getAllServiceTemplates().get(0);
- } catch (PfModelException e) {
- throw new PfModelRuntimeException(Status.BAD_REQUEST, "Canont load ToscaServiceTemplate from DB", e);
- }
+ var toscaServiceTemplate = acDefinitionProvider.getAllServiceTemplates().get(0);
return ParticipantUtils.getFirstStartPhase(automationComposition, toscaServiceTemplate);
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
index ce7195d93..5f3bfb281 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -36,9 +36,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -62,7 +62,7 @@ public class SupervisionScanner {
private final Map<ToscaConceptIdentifier, Integer> phaseMap = new HashMap<>();
private final AutomationCompositionProvider automationCompositionProvider;
- private final ServiceTemplateProvider serviceTemplateProvider;
+ private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
private final AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher;
private final ParticipantProvider participantProvider;
@@ -73,7 +73,7 @@ public class SupervisionScanner {
* Constructor for instantiating SupervisionScanner.
*
* @param automationCompositionProvider the provider to use to read automation compositions from the database
- * @param serviceTemplateProvider the Policy Models Provider
+ * @param acDefinitionProvider the Policy Models Provider
* @param automationCompositionStateChangePublisher the AutomationComposition StateChange Publisher
* @param automationCompositionUpdatePublisher the AutomationCompositionUpdate Publisher
* @param participantProvider the Participant Provider
@@ -82,13 +82,13 @@ public class SupervisionScanner {
* @param acRuntimeParameterGroup the parameters for the automation composition runtime
*/
public SupervisionScanner(final AutomationCompositionProvider automationCompositionProvider,
- ServiceTemplateProvider serviceTemplateProvider,
+ AcDefinitionProvider acDefinitionProvider,
final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher,
ParticipantProvider participantProvider, ParticipantStatusReqPublisher participantStatusReqPublisher,
ParticipantUpdatePublisher participantUpdatePublisher, final AcRuntimeParameterGroup acRuntimeParameterGroup) {
this.automationCompositionProvider = automationCompositionProvider;
- this.serviceTemplateProvider = serviceTemplateProvider;
+ this.acDefinitionProvider = acDefinitionProvider;
this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher;
this.automationCompositionUpdatePublisher = automationCompositionUpdatePublisher;
this.participantProvider = participantProvider;
@@ -130,7 +130,7 @@ public class SupervisionScanner {
}
try {
- var list = serviceTemplateProvider.getAllServiceTemplates();
+ var list = acDefinitionProvider.getAllServiceTemplates();
if (list != null && !list.isEmpty()) {
ToscaServiceTemplate toscaServiceTemplate = list.get(0);
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java
index 56da7e5a4..9beef51bb 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java
@@ -32,10 +32,8 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -48,7 +46,7 @@ import org.springframework.stereotype.Component;
public class AutomationCompositionUpdatePublisher extends AbstractParticipantPublisher<AutomationCompositionUpdate> {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionUpdatePublisher.class);
- private final ServiceTemplateProvider serviceTemplateProvider;
+ private final AcDefinitionProvider acDefinitionProvider;
/**
* Send AutomationCompositionUpdate to Participant.
@@ -75,17 +73,11 @@ public class AutomationCompositionUpdatePublisher extends AbstractParticipantPub
automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getKey().asIdentifier());
automationCompositionUpdateMsg.setMessageId(UUID.randomUUID());
automationCompositionUpdateMsg.setTimestamp(Instant.now());
- ToscaServiceTemplate toscaServiceTemplate;
- try {
- toscaServiceTemplate = serviceTemplateProvider.getAllServiceTemplates().get(0);
- } catch (PfModelException pfme) {
- LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
- return;
- }
+ var toscaServiceTemplate = acDefinitionProvider.getAllServiceTemplates().get(0);
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (AutomationCompositionElement element : automationComposition.getElements().values()) {
- AcmUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate);
+ AcmUtils.setAcPolicyInfo(element, toscaServiceTemplate);
AcmUtils.prepareParticipantUpdate(element, participantUpdates);
}
automationCompositionUpdateMsg.setParticipantUpdatesList(participantUpdates);
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java
index 27e8156b0..fa5e423d7 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java
@@ -26,17 +26,13 @@ import io.micrometer.core.annotation.Timed;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -50,7 +46,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
- private final ServiceTemplateProvider serviceTemplateProvider;
+ private final AcDefinitionProvider acDefinitionProvider;
/**
* Send ParticipantUpdate to all Participants.
@@ -80,31 +76,22 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
message.setParticipantId(participantId);
message.setTimestamp(Instant.now());
- ToscaServiceTemplate toscaServiceTemplate = null;
- Map<String, ToscaNodeType> commonPropertiesMap = null;
- try {
- var list = serviceTemplateProvider.getServiceTemplateList(name, version);
- if (!list.isEmpty()) {
- toscaServiceTemplate = list.get(0);
- commonPropertiesMap =
- serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, toscaServiceTemplate);
- } else {
- LOGGER.warn("No tosca service template found, cannot send participantupdate {} {}", name, version);
- return false;
- }
- } catch (PfModelException pfme) {
- LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
+ var list = acDefinitionProvider.getServiceTemplateList(name, version);
+ if (list.isEmpty()) {
+ LOGGER.warn("No tosca service template found, cannot send participantupdate {} {}", name, version);
return false;
}
+ var toscaServiceTemplate = list.get(0);
+ var commonPropertiesMap = AcmUtils.getCommonOrInstancePropertiesFromNodeTypes(true, toscaServiceTemplate);
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
for (var toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(),
toscaServiceTemplate)) {
AcmUtils.prepareParticipantDefinitionUpdate(
- ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()),
- toscaInputEntry.getKey(), toscaInputEntry.getValue(),
- participantDefinitionUpdates, commonPropertiesMap);
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()),
+ toscaInputEntry.getKey(), toscaInputEntry.getValue(), participantDefinitionUpdates,
+ commonPropertiesMap);
}
}
diff --git a/runtime-acm/src/main/resources/application.yaml b/runtime-acm/src/main/resources/application.yaml
index 6dbaa3a11..df1310d0a 100644
--- a/runtime-acm/src/main/resources/application.yaml
+++ b/runtime-acm/src/main/resources/application.yaml
@@ -3,7 +3,7 @@ spring:
user:
name: runtimeUser
password: zb!XztG34
- http:
+ mvc:
converters:
preferred-json-mapper: gson
datasource:
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index 4058c68b6..dabb05347 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -22,7 +22,6 @@
package org.onap.policy.clamp.acm.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -30,23 +29,18 @@ import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVIC
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class CommissioningProviderTest {
- private static final Coder CODER = new StandardCoder();
-
/**
* Test the fetching of automation composition definitions (ToscaServiceTemplates).
*
@@ -56,18 +50,17 @@ class CommissioningProviderTest {
void testGetAutomationCompositionDefinitions() throws Exception {
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
- List<ToscaNodeTemplate> listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
+ var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
+ assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
- when(acProvider.getFilteredNodeTemplates(any()))
- .thenReturn(List.of(new ToscaNodeTemplate(), new ToscaNodeTemplate()));
- listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
+ when(acDefinitionProvider.getServiceTemplateList(null, null))
+ .thenReturn(List.of(new ToscaServiceTemplate()));
+ serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
+ assertThat(serviceTemplates.getServiceTemplates()).hasSize(1);
}
/**
@@ -77,29 +70,21 @@ class CommissioningProviderTest {
*/
@Test
void testCreateAutomationCompositionDefinitions() throws Exception {
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
- var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
-
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
-
- List<ToscaNodeTemplate> listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
-
- ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setServiceTemplate(serviceTemplate);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition);
// Response should return the number of node templates present in the service template
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
List<ToscaConceptIdentifier> affectedDefinitions = provider
.createAutomationCompositionDefinitions(serviceTemplate).getAffectedAutomationCompositionDefinitions();
+ verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
assertThat(affectedDefinitions).hasSize(13);
-
- when(acProvider.getFilteredNodeTemplates(any()))
- .thenReturn(List.of(new ToscaNodeTemplate(), new ToscaNodeTemplate()));
-
- listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
}
/**
@@ -108,56 +93,18 @@ class CommissioningProviderTest {
*
*/
@Test
- void testGetToscaServiceTemplate() throws Exception {
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
+ void testGetToscaServiceTemplateList() throws Exception {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
+ var provider =
+ new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
- when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
-
- provider.createAutomationCompositionDefinitions(serviceTemplate);
- verify(serviceTemplateProvider).createServiceTemplate(serviceTemplate);
-
- when(serviceTemplateProvider.getToscaServiceTemplate(null, null)).thenReturn(serviceTemplate);
+ when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
- ToscaServiceTemplate returnedServiceTemplate = provider.getToscaServiceTemplate(null, null);
+ var returnedServiceTemplate = provider.getAutomationCompositionDefinitions(null, null);
assertThat(returnedServiceTemplate).isNotNull();
-
- Map<String, ToscaNodeTemplate> nodeTemplates =
- returnedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
-
- assertThat(nodeTemplates).hasSize(7);
- }
-
- /**
- * Test the fetching of a reduced ToscaServiceTemplate with only some of the objects from the full template.
- * The reduced template does not contain: DataTypesAsMap or PolicyTypesAsMap.
- *
- */
- @Test
- void testGetToscaServiceTemplateReduced() throws Exception {
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
- var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
-
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
- ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
- when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
-
- provider.createAutomationCompositionDefinitions(serviceTemplate);
-
- when(serviceTemplateProvider.getServiceTemplateList(any(), any()))
- .thenReturn(List.of(Objects.requireNonNull(serviceTemplate)));
-
- String returnedServiceTemplate = provider
- .getToscaServiceTemplateReduced(null, null, null);
- assertThat(returnedServiceTemplate).isNotNull();
- ToscaServiceTemplate parsedServiceTemplate = CODER.decode(returnedServiceTemplate, ToscaServiceTemplate.class);
-
- assertThat(parsedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()).hasSize(7);
+ assertThat(returnedServiceTemplate.getServiceTemplates()).isNotEmpty();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index f34e5eff0..0ded4ec0f 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -27,9 +27,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
-import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
+import java.util.HashMap;
import java.util.List;
+import java.util.UUID;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
@@ -43,7 +44,9 @@ import org.junit.jupiter.api.parallel.ExecutionMode;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -60,10 +63,10 @@ class CommissioningControllerTest extends CommonRestController {
private static final String COMMISSIONING_ENDPOINT = "commission";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
- private static ToscaServiceTemplate commonPropertiesServiceTemplate = new ToscaServiceTemplate();
+ private UUID compositionId;
@Autowired
- private ServiceTemplateProvider serviceTemplateProvider;
+ private AcDefinitionProvider acDefinitionProvider;
@LocalServerPort
private int randomServerPort;
@@ -74,7 +77,6 @@ class CommissioningControllerTest extends CommonRestController {
@BeforeAll
public static void setUpBeforeClass() {
serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- commonPropertiesServiceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
}
@BeforeEach
@@ -103,48 +105,16 @@ class CommissioningControllerTest extends CommonRestController {
}
@Test
- void testUnauthorizedQueryElements() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/elements");
- }
-
- @Test
void testUnauthorizedDelete() {
assertUnauthorizedDelete(COMMISSIONING_ENDPOINT);
}
@Test
- void testUnauthorizedQueryToscaServiceTemplate() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
- }
-
- @Test
- void testUnauthorizedQueryToscaServiceTemplateSchema() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/toscaServiceTemplateSchema");
- }
-
- @Test
- void testUnauthorizedQueryToscaServiceCommonOrInstanceProperties() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/getCommonOrInstanceProperties");
- }
-
- @Test
- void testQueryToscaServiceTemplate() throws Exception {
- createFullEntryInDbWithCommonProps();
-
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- ToscaServiceTemplate template = rawresp.readEntity(ToscaServiceTemplate.class);
- assertNotNull(template);
- assertThat(template.getNodeTypes()).hasSize(7);
- }
-
- @Test
void testCreateBadRequest() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json("NotToscaServiceTempalte"));
- assertThat(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).isEqualTo(resp.getStatus());
+ assertThat(Response.Status.BAD_REQUEST.getStatusCode()).isEqualTo(resp.getStatus());
CommissioningResponse commissioningResponse = resp.readEntity(CommissioningResponse.class);
assertThat(commissioningResponse.getErrorDetails()).isNotNull();
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).isNull();
@@ -154,9 +124,41 @@ class CommissioningControllerTest extends CommonRestController {
void testCreate() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ assertEquals(Response.Status.CREATED.getStatusCode(), resp.getStatus());
CommissioningResponse commissioningResponse = resp.readEntity(CommissioningResponse.class);
+ compositionId = commissioningResponse.getCompositionId();
+ assertNotNull(commissioningResponse);
+ assertNull(commissioningResponse.getErrorDetails());
+ // Response should return the number of node templates present in the service template
+ assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).hasSize(13);
+ for (String nodeTemplateName : serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().keySet()) {
+ assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
+ .anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
+ }
+ }
+ @Test
+ void testUpdate() {
+ var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
+ var resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.CREATED.getStatusCode(), resp.getStatus());
+ var commissioningResponse = resp.readEntity(CommissioningResponse.class);
+ compositionId = commissioningResponse.getCompositionId();
+
+ var toscaDataType = new ToscaDataType();
+ toscaDataType.setName("org.onap.datatypes.policy.clamp.Configuration");
+ toscaDataType.setDerivedFrom("tosca.datatypes.Root");
+ toscaDataType.setProperties(new HashMap<>());
+ var toscaProperty = new ToscaProperty();
+ toscaProperty.setName("configurationEntityId");
+ toscaProperty.setType("onap.datatypes.ToscaConceptIdentifier");
+ toscaDataType.getProperties().put(toscaProperty.getName(), toscaProperty);
+
+ serviceTemplate.getDataTypes().put(toscaDataType.getName(), toscaDataType);
+ invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
+ resp = invocationBuilder.put(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ commissioningResponse = resp.readEntity(CommissioningResponse.class);
assertNotNull(commissioningResponse);
assertNull(commissioningResponse.getErrorDetails());
// Response should return the number of node templates present in the service template
@@ -165,6 +167,12 @@ class CommissioningControllerTest extends CommonRestController {
assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
.anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
}
+
+ invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
+ resp = invocationBuilder.buildGet().invoke();
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ var entity = resp.readEntity(ToscaServiceTemplate.class);
+ assertThat(entity.getDataTypes()).containsKey(toscaDataType.getName());
}
@Test
@@ -174,8 +182,8 @@ class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name=noResultWithThisName");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List<?> entityList = rawresp.readEntity(List.class);
- assertThat(entityList).isEmpty();
+ var entityList = rawresp.readEntity(ToscaServiceTemplate.class);
+ assertThat(entityList.getNodeTypes()).isNull();
}
@Test
@@ -185,50 +193,44 @@ class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List<?> entityList = rawresp.readEntity(List.class);
+ var entityList = rawresp.readEntity(ToscaServiceTemplate.class);
assertNotNull(entityList);
- assertThat(entityList).hasSize(2);
}
@Test
void testDeleteBadRequest() throws Exception {
createEntryInDB();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
+ Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + UUID.randomUUID());
// Call delete with no info
Response resp = invocationBuilder.delete();
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
}
@Test
void testDelete() throws Exception {
- var serviceTemplateCreated = createEntryInDB();
+ createEntryInDB();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name="
- + serviceTemplateCreated.getName() + "&version=" + serviceTemplateCreated.getVersion());
+ Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
// Call delete with no info
Response resp = invocationBuilder.delete();
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- List<ToscaServiceTemplate> templatesInDB = serviceTemplateProvider.getAllServiceTemplates();
+ List<ToscaServiceTemplate> templatesInDB = acDefinitionProvider.getAllServiceTemplates();
assertThat(templatesInDB).isEmpty();
}
- private synchronized ToscaServiceTemplate createEntryInDB() throws Exception {
+ private synchronized void createEntryInDB() throws Exception {
deleteEntryInDB();
- return serviceTemplateProvider.createServiceTemplate(serviceTemplate);
+ var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate);
+ compositionId = acmDefinition.getCompositionId();
}
// Delete entries from the DB after relevant tests
private synchronized void deleteEntryInDB() throws Exception {
- var list = serviceTemplateProvider.getAllServiceTemplates();
+ var list = acDefinitionProvider.getAllServiceTemplates();
if (!list.isEmpty()) {
- serviceTemplateProvider.deleteServiceTemplate(list.get(0).getName(), list.get(0).getVersion());
+ acDefinitionProvider.deleteAcDefintion(compositionId);
}
}
-
- private synchronized void createFullEntryInDbWithCommonProps() throws Exception {
- deleteEntryInDB();
- serviceTemplateProvider.createServiceTemplate(commonPropertiesServiceTemplate);
- }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 016ec6c5e..040fabe27 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -23,16 +23,16 @@ package org.onap.policy.clamp.acm.runtime.instantiation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import java.util.List;
import java.util.Optional;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
@@ -41,9 +41,12 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* Class to perform unit test of {@link AutomationCompositionInstantiationProvider}}.
@@ -51,34 +54,40 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
*/
class AutomationCompositionInstantiationProviderTest {
private static final String AC_INSTANTIATION_CREATE_JSON =
- "src/test/resources/rest/acm/AutomationCompositions.json";
+ "src/test/resources/rest/acm/AutomationCompositions.json";
private static final String AC_INSTANTIATION_UPDATE_JSON =
- "src/test/resources/rest/acm/AutomationCompositionsUpdate.json";
+ "src/test/resources/rest/acm/AutomationCompositionsUpdate.json";
private static final String AC_INSTANTIATION_CHANGE_STATE_JSON = "src/test/resources/rest/acm/PassiveCommand.json";
private static final String AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON =
- "src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json";
+ "src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json";
private static final String AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON =
- "src/test/resources/rest/acm/AutomationCompositionsNotFound.json";
+ "src/test/resources/rest/acm/AutomationCompositionsNotFound.json";
private static final String AUTOMATION_COMPOSITION_NOT_FOUND = "Automation composition not found";
private static final String DELETE_BAD_REQUEST = "Automation composition state is still %s";
private static final String ORDERED_STATE_INVALID = "ordered state invalid or not specified on command";
private static final String AC_ELEMENT_NAME_NOT_FOUND =
- "\"AutomationCompositions\" INVALID, item has status INVALID\n"
- + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
- + "INVALID, item has status INVALID\n"
- + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
- + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
- + "INVALID, item has status INVALID\n"
- + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n";
+ "\"AutomationCompositions\" INVALID, item has status INVALID\n"
+ + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
+ + "INVALID, item has status INVALID\n"
+ + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
+ + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
+ + "INVALID, item has status INVALID\n"
+ + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n";
private static final String AC_DEFINITION_NOT_FOUND =
- "\"AutomationCompositions\" INVALID, item has status INVALID\n"
- + " {2}\"entry org.onap.domain.PMSHAutomationCompositionDefinition\" INVALID, item has status INVALID\n"
- + " {4}item \"AutomationComposition\" value \"org.onap.domain.PMSHAutomationCompositionDefinition\""
- + " INVALID, Commissioned automation composition definition not found\n"
- + " {2}\"entry org.onap.domain.PMSHAutomationCompositionDefinition\" INVALID, item has status INVALID\n"
- + " {4}item \"AutomationComposition\" value \"org.onap.domain.PMSHAutomationCompositionDefinition\""
- + " INVALID, Commissioned automation composition definition not found\n";
+ "\"AutomationCompositions\" INVALID, item has status INVALID\n"
+ + " item \"ServiceTemplate\" value \"\" INVALID,"
+ + " Commissioned automation composition definition not found\n";
+
+ private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+
+ @BeforeAll
+ public static void setUpBeforeClass() {
+ serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var jpa =
+ ProviderUtils.getJpaAndValidate(serviceTemplate, JpaToscaServiceTemplate::new, "toscaServiceTemplate");
+ serviceTemplate = jpa.toAuthorative();
+ }
@Test
void testInstantiationCrud() throws Exception {
@@ -86,51 +95,32 @@ class AutomationCompositionInstantiationProviderTest {
var participants = CommonTestData.createParticipants();
when(participantProvider.getParticipants()).thenReturn(participants);
- var commissioningProvider = mock(CommissioningProvider.class);
- var toscaNodeTemplate1 = new ToscaNodeTemplate();
- toscaNodeTemplate1.setName("org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement");
- toscaNodeTemplate1.setVersion("1.2.3");
- when(commissioningProvider.getAutomationCompositionDefinitions(anyString(), anyString()))
- .thenReturn(List.of(toscaNodeTemplate1));
-
- var toscaNodeTemplate2 = new ToscaNodeTemplate();
- toscaNodeTemplate2.setName("org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement");
- toscaNodeTemplate2.setVersion("1.2.3");
- var toscaNodeTemplate3 = new ToscaNodeTemplate();
- toscaNodeTemplate3.setName("org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement");
- toscaNodeTemplate3.setVersion("1.2.3");
- var toscaNodeTemplate4 = new ToscaNodeTemplate();
- toscaNodeTemplate4.setName("org.onap.domain.pmsh.PMSH_DCAEMicroservice");
- toscaNodeTemplate4.setVersion("1.2.3");
-
- when(commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplate1))
- .thenReturn(List.of(toscaNodeTemplate1, toscaNodeTemplate2, toscaNodeTemplate3, toscaNodeTemplate4));
-
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates()).thenReturn(List.of(serviceTemplate));
var supervisionHandler = mock(SupervisionHandler.class);
var acProvider = mock(AutomationCompositionProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
- AutomationCompositions automationCompositionsCreate =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- InstantiationResponse instantiationResponse =
- instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
+ var automationCompositionsCreate =
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ var instantiationResponse = instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionsCreate);
verify(acProvider).saveAutomationCompositions(automationCompositionsCreate.getAutomationCompositionList());
for (var automationComposition : automationCompositionsCreate.getAutomationCompositionList()) {
when(acProvider.getAutomationCompositions(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(List.of(automationComposition));
+ automationComposition.getVersion())).thenReturn(List.of(automationComposition));
- AutomationCompositions automationCompositionsGet = instantiationProvider
- .getAutomationCompositions(automationComposition.getName(), automationComposition.getVersion());
+ var automationCompositionsGet = instantiationProvider
+ .getAutomationCompositions(automationComposition.getName(), automationComposition.getVersion());
assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
assertThat(automationComposition)
- .isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
+ .isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
}
- AutomationCompositions automationCompositionsUpdate =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ var automationCompositionsUpdate =
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
instantiationResponse = instantiationProvider.updateAutomationCompositions(automationCompositionsUpdate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionsUpdate);
@@ -139,33 +129,33 @@ class AutomationCompositionInstantiationProviderTest {
for (var automationComposition : automationCompositionsUpdate.getAutomationCompositionList()) {
when(acProvider.findAutomationComposition(automationComposition.getKey().asIdentifier()))
- .thenReturn(Optional.of(automationComposition));
+ .thenReturn(Optional.of(automationComposition));
when(acProvider.findAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
+ automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
when(acProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(automationComposition);
+ automationComposition.getVersion())).thenReturn(automationComposition);
}
- InstantiationCommand instantiationCommand =
- InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
+ var instantiationCommand =
+ InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
instantiationResponse = instantiationProvider.issueAutomationCompositionCommand(instantiationCommand);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, instantiationCommand);
verify(supervisionHandler)
- .triggerAutomationCompositionSupervision(instantiationCommand.getAutomationCompositionIdentifierList());
+ .triggerAutomationCompositionSupervision(instantiationCommand.getAutomationCompositionIdentifierList());
// in order to delete a automationComposition the state must be UNINITIALISED
automationCompositionsCreate.getAutomationCompositionList()
- .forEach(ac -> ac.setState(AutomationCompositionState.UNINITIALISED));
+ .forEach(ac -> ac.setState(AutomationCompositionState.UNINITIALISED));
instantiationProvider.updateAutomationCompositions(automationCompositionsCreate);
for (AutomationComposition automationComposition : automationCompositionsCreate
- .getAutomationCompositionList()) {
+ .getAutomationCompositionList()) {
instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion());
+ automationComposition.getVersion());
verify(acProvider).deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion());
+ automationComposition.getVersion());
}
}
@@ -173,19 +163,19 @@ class AutomationCompositionInstantiationProviderTest {
void testInstantiationDelete() throws Exception {
AutomationCompositions automationCompositions =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");
AutomationComposition automationComposition0 = automationCompositions.getAutomationCompositionList().get(0);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition0.getName(),
- automationComposition0.getVersion())).hasMessageMatching(AUTOMATION_COMPOSITION_NOT_FOUND);
+ automationComposition0.getVersion())).hasMessageMatching(AUTOMATION_COMPOSITION_NOT_FOUND);
for (AutomationCompositionState state : AutomationCompositionState.values()) {
if (!AutomationCompositionState.UNINITIALISED.equals(state)) {
@@ -196,147 +186,111 @@ class AutomationCompositionInstantiationProviderTest {
for (AutomationComposition automationComposition : automationCompositions.getAutomationCompositionList()) {
when(acProvider.findAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
+ automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
when(acProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(automationComposition);
+ automationComposition.getVersion())).thenReturn(automationComposition);
instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion());
+ automationComposition.getVersion());
}
}
private void assertThatDeleteThrownBy(AutomationCompositions automationCompositions,
- AutomationCompositionState state) throws Exception {
+ AutomationCompositionState state) throws Exception {
AutomationComposition automationComposition = automationCompositions.getAutomationCompositionList().get(0);
automationComposition.setState(state);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion()))
- .thenReturn(Optional.of(automationComposition));
+ .thenReturn(Optional.of(automationComposition));
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
+ automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
}
@Test
void testCreateAutomationCompositions_NoDuplicates() throws Exception {
- var commissioningProvider = mock(CommissioningProvider.class);
-
- var toscaNodeTemplate1 = new ToscaNodeTemplate();
- toscaNodeTemplate1.setName("org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement");
- toscaNodeTemplate1.setVersion("1.2.3");
- when(commissioningProvider.getAutomationCompositionDefinitions(anyString(), anyString()))
- .thenReturn(List.of(toscaNodeTemplate1));
-
- var toscaNodeTemplate2 = new ToscaNodeTemplate();
- toscaNodeTemplate2.setName("org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement");
- toscaNodeTemplate2.setVersion("1.2.3");
- var toscaNodeTemplate3 = new ToscaNodeTemplate();
- toscaNodeTemplate3.setName("org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement");
- toscaNodeTemplate3.setVersion("1.2.3");
- var toscaNodeTemplate4 = new ToscaNodeTemplate();
- toscaNodeTemplate4.setName("org.onap.domain.pmsh.PMSH_DCAEMicroservice");
- toscaNodeTemplate4.setVersion("1.2.3");
-
- when(commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplate1))
- .thenReturn(List.of(toscaNodeTemplate1, toscaNodeTemplate2, toscaNodeTemplate3, toscaNodeTemplate4));
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates()).thenReturn(List.of(serviceTemplate));
AutomationCompositions automationCompositionsCreate =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates");
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates");
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
InstantiationResponse instantiationResponse =
- instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
+ instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionsCreate);
when(acProvider.findAutomationComposition(
- automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()))
- .thenReturn(Optional.of(automationCompositionsCreate.getAutomationCompositionList().get(0)));
+ automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()))
+ .thenReturn(Optional.of(automationCompositionsCreate.getAutomationCompositionList().get(0)));
assertThatThrownBy(() -> instantiationProvider.createAutomationCompositions(automationCompositionsCreate))
- .hasMessageMatching(
- automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()
- + " already defined");
+ .hasMessageMatching(
+ automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()
+ + " already defined");
}
@Test
void testCreateAutomationCompositions_CommissionedAcElementNotFound() throws Exception {
- var toscaNodeTemplate1 = new ToscaNodeTemplate();
- toscaNodeTemplate1.setName("org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement");
- toscaNodeTemplate1.setVersion("1.2.3");
-
- var toscaNodeTemplate2 = new ToscaNodeTemplate();
- toscaNodeTemplate2.setName("org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement");
- toscaNodeTemplate2.setVersion("1.2.3");
- var toscaNodeTemplate3 = new ToscaNodeTemplate();
- toscaNodeTemplate3.setName("org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement");
- toscaNodeTemplate3.setVersion("1.2.3");
- var commissioningProvider = mock(CommissioningProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates()).thenReturn(List.of(serviceTemplate));
AutomationCompositions automationCompositions = InstantiationUtils.getAutomationCompositionsFromResource(
- AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "AcElementNotFound");
-
- when(commissioningProvider.getAutomationCompositionDefinitions(
- automationCompositions.getAutomationCompositionList().get(0).getDefinition().getName(),
- automationCompositions.getAutomationCompositionList().get(0).getDefinition().getVersion()))
- .thenReturn(List.of(toscaNodeTemplate1));
-
- when(commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplate1))
- .thenReturn(List.of(toscaNodeTemplate1, toscaNodeTemplate2, toscaNodeTemplate3));
+ AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "AcElementNotFound");
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var provider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> provider.createAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
+ .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
assertThatThrownBy(() -> provider.updateAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
+ .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
}
@Test
void testCreateAutomationCompositions_CommissionedAcNotFound() throws Exception {
AutomationCompositions automationCompositions = InstantiationUtils
- .getAutomationCompositionsFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
+ .getAutomationCompositionsFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
- var provider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> provider.createAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
assertThatThrownBy(() -> provider.updateAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
}
@Test
- void testIssueAutomationCompositionCommand_OrderedStateInvalid()
- throws AutomationCompositionRuntimeException {
+ void testIssueAutomationCompositionCommand_OrderedStateInvalid() throws AutomationCompositionRuntimeException {
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> instantiationProvider.issueAutomationCompositionCommand(new InstantiationCommand()))
- .hasMessageMatching(ORDERED_STATE_INVALID);
+ .hasMessageMatching(ORDERED_STATE_INVALID);
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index 7cdc8a975..228412133 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
+import java.util.UUID;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
@@ -44,8 +45,8 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -65,9 +66,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ActiveProfiles("test")
class InstantiationControllerTest extends CommonRestController {
- private static final String ID_NAME = "PMSH_Test_Instance";
- private static final String ID_VERSION = "1.2.3";
-
private static final String AC_INSTANTIATION_CREATE_JSON =
"src/test/resources/rest/acm/AutomationCompositions.json";
@@ -80,12 +78,13 @@ class InstantiationControllerTest extends CommonRestController {
private static final String INSTANTIATION_COMMAND_ENDPOINT = "instantiation/command";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+ private UUID compositionId;
@Autowired
private AutomationCompositionRepository automationCompositionRepository;
@Autowired
- private ServiceTemplateProvider serviceTemplateProvider;
+ private AcDefinitionProvider acDefinitionProvider;
@Autowired
private AutomationCompositionInstantiationProvider instantiationProvider;
@@ -347,14 +346,15 @@ class InstantiationControllerTest extends CommonRestController {
private synchronized void deleteEntryInDB() throws Exception {
automationCompositionRepository.deleteAll();
- var list = serviceTemplateProvider.getAllServiceTemplates();
+ var list = acDefinitionProvider.getAllServiceTemplates();
if (!list.isEmpty()) {
- serviceTemplateProvider.deleteServiceTemplate(list.get(0).getName(), list.get(0).getVersion());
+ acDefinitionProvider.deleteAcDefintion(compositionId);
}
}
private synchronized void createEntryInDB() throws Exception {
deleteEntryInDB();
- serviceTemplateProvider.createServiceTemplate(serviceTemplate);
+ var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate);
+ compositionId = acmDefinition.getCompositionId();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index 7e9b102a8..e4d382133 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -54,9 +54,9 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -119,15 +119,15 @@ class SupervisionHandlerTest {
.thenReturn(Optional.of(automationComposition));
when(automationCompositionProvider.getAutomationComposition(identifier)).thenReturn(automationComposition);
- var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
- when(serviceTemplateProvider.getAllServiceTemplates())
+ var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates())
.thenReturn(List.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(
TOSCA_SERVICE_TEMPLATE_YAML))));
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
- serviceTemplateProvider, mock(AutomationCompositionUpdatePublisher.class),
+ acDefinitionProvider, mock(AutomationCompositionUpdatePublisher.class),
automationCompositionStateChangePublisher, mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class));
@@ -355,18 +355,18 @@ class SupervisionHandlerTest {
.thenReturn(Optional.of(automationComposition));
when(automationCompositionProvider.getAutomationComposition(identifier)).thenReturn(automationComposition);
- var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
- when(serviceTemplateProvider.getServiceTemplateList(any(), any()))
+ var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getServiceTemplateList(any(), any()))
.thenReturn(List.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(
TOSCA_SERVICE_TEMPLATE_YAML))));
- when(serviceTemplateProvider.getAllServiceTemplates())
+ when(acDefinitionProvider.getAllServiceTemplates())
.thenReturn(List.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(
TOSCA_SERVICE_TEMPLATE_YAML))));
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
return new SupervisionHandler(automationCompositionProvider, participantProvider,
- serviceTemplateProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
+ acDefinitionProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index cc3a95e81..50d5246b0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -45,9 +45,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -57,7 +57,7 @@ class SupervisionScannerTest {
private static final String AC_JSON = "src/test/resources/rest/acm/AutomationCompositionsSmoke.json";
- private static final ServiceTemplateProvider serviceTemplateProvider = mock(ServiceTemplateProvider.class);
+ private static final AcDefinitionProvider acDefinitionProvider = mock(AcDefinitionProvider.class);
private static final String PARTICIPANT_NAME = "Participant0";
private static final String PARTICIPANT_VERSION = "1.0.0";
@@ -68,7 +68,7 @@ class SupervisionScannerTest {
@BeforeAll
public static void setUpBeforeAll() throws Exception {
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
- when(serviceTemplateProvider.getAllServiceTemplates())
+ when(acDefinitionProvider.getAllServiceTemplates())
.thenReturn(List.of(Objects.requireNonNull(serviceTemplate)));
}
@@ -86,7 +86,7 @@ class SupervisionScannerTest {
InstantiationUtils.getAutomationCompositionsFromResource(AC_JSON, "Crud").getAutomationCompositionList();
when(automationCompositionProvider.getAutomationCompositions()).thenReturn(automationCompositions);
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
supervisionScanner.run(false);
@@ -110,7 +110,7 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
supervisionScanner.run(false);
@@ -136,7 +136,7 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
@@ -173,7 +173,7 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
@@ -207,7 +207,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index ad97201e2..11a060029 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -43,9 +43,9 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.models.base.PfModelException;
@@ -68,14 +68,14 @@ class SupervisionMessagesTest extends CommonRestController {
public static void setupDbProviderParameters() throws PfModelException {
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
+ var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
var automationCompositionUpdatePublisher = Mockito.mock(AutomationCompositionUpdatePublisher.class);
var automationCompositionStateChangePublisher = Mockito.mock(AutomationCompositionStateChangePublisher.class);
var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
supervisionHandler = new SupervisionHandler(acProvider, participantProvider,
- serviceTemplateProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
+ acDefinitionProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
}
@@ -157,7 +157,7 @@ class SupervisionMessagesTest extends CommonRestController {
@Test
void testParticipantUpdatePublisherDecomisioning() {
- var publisher = new ParticipantUpdatePublisher(mock(ServiceTemplateProvider.class));
+ var publisher = new ParticipantUpdatePublisher(mock(AcDefinitionProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
publisher.sendDecomisioning();
@@ -166,7 +166,7 @@ class SupervisionMessagesTest extends CommonRestController {
@Test
void testParticipantUpdatePublisherComissioning() {
- var publisher = new ParticipantUpdatePublisher(mock(ServiceTemplateProvider.class));
+ var publisher = new ParticipantUpdatePublisher(mock(AcDefinitionProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
publisher.sendComissioningBroadcast("NAME", "1.0.0");