summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
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/src/main
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/src/main')
-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
9 files changed, 199 insertions, 519 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: