diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-01-03 10:48:36 +0000 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-01-04 09:54:47 +0000 |
commit | 951196b4e0d4c64403f186693c2d1c53e25df3b1 (patch) | |
tree | bdfbd91c858902522be7866081496e2f5e878db4 /runtime-acm/src/main/java/org/onap | |
parent | c6fb86de3dae6f26aec9813cd5ef4cc8d9268359 (diff) |
Refactor Post compositions to create and update ACM definitions
Issue-ID: POLICY-4492
Change-Id: Ica3885c7e2a048500a86abc194624ac22efd6bc2
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/main/java/org/onap')
2 files changed, 14 insertions, 29 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 1d3b2992b..9f898d88d 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 @@ -25,13 +25,10 @@ import java.util.UUID; import java.util.stream.Collectors; import javax.ws.rs.core.Response.Status; 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.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.utils.AcmUtils; -import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -61,9 +58,8 @@ public class CommissioningProvider { * @param supervisionHandler the Supervision Handler * @param participantProvider the Participant Provider */ - public CommissioningProvider(AcDefinitionProvider acDefinitionProvider, - AutomationCompositionProvider acProvider, SupervisionHandler supervisionHandler, - ParticipantProvider participantProvider) { + public CommissioningProvider(AcDefinitionProvider acDefinitionProvider, AutomationCompositionProvider acProvider, + SupervisionHandler supervisionHandler, ParticipantProvider participantProvider) { this.acDefinitionProvider = acDefinitionProvider; this.acProvider = acProvider; this.supervisionHandler = supervisionHandler; @@ -113,19 +109,10 @@ public class CommissioningProvider { public CommissioningResponse updateCompositionDefinition(UUID compositionId, ToscaServiceTemplate serviceTemplate) { var automationCompositions = acProvider.getAcInstancesByCompositionId(compositionId); - 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()); + if (!automationCompositions.isEmpty()) { + throw new PfModelRuntimeException(Status.BAD_REQUEST, + "There are ACM instances, Update of ACM Definition not allowed"); } - acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate); return createCommissioningResponse(compositionId, serviceTemplate); 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 a6b1ab38d..7f9dc8d19 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 @@ -28,7 +28,6 @@ import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionDefi import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate; 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.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; import org.springframework.context.annotation.Profile; @@ -54,10 +53,15 @@ public class CommissioningController extends AbstractRestController implements A */ @Override public ResponseEntity<CommissioningResponse> createCompositionDefinitions(ToscaServiceTemplate body, - UUID requestId) { - - var response = provider.createAutomationCompositionDefinitions(body); - return ResponseEntity.created(createUri("/compositions/" + response.getCompositionId())).body(response); + UUID requestId) { + var compositionId = body.getMetadata() != null ? body.getMetadata().get("compositionId") : null; + if (compositionId == null) { + var response = provider.createAutomationCompositionDefinitions(body); + return ResponseEntity.created(createUri("/compositions/" + response.getCompositionId())).body(response); + } else { + return ResponseEntity.ok() + .body(provider.updateCompositionDefinition(UUID.fromString(compositionId.toString()), body)); + } } /** @@ -79,7 +83,6 @@ public class CommissioningController extends AbstractRestController implements A * @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 public ResponseEntity<ToscaServiceTemplates> queryCompositionDefinitions(String name, String version, @@ -92,11 +95,6 @@ public class CommissioningController extends AbstractRestController implements A return ResponseEntity.ok().body(provider.getAutomationCompositionDefinitions(compositionId)); } - public ResponseEntity<CommissioningResponse> updateCompositionDefinition(UUID compositionId, - ToscaServiceTemplate body, UUID requestId) { - return ResponseEntity.ok().body(provider.updateCompositionDefinition(compositionId, body)); - } - @Override public ResponseEntity<Void> compositionDefinitionPriming(UUID compositionId, UUID requestId, @Valid AcTypeStateUpdate body) { |