aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-24 16:27:21 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-01-25 13:47:20 +0000
commitdb615d9fed370c7896a638704d00807c19b6f5d3 (patch)
tree4d7d55756bf2ca8c566627e17308ec0ce6ffe4a0 /runtime-acm/src/main
parentc5e57c1b1cd0e778ebf47edd20fd9a340471ab72 (diff)
Models for refactor Prime and Deprime in ACM
Refactor Ac Definition to store Prime and Deprime status and refactor CommissioningController to show the status of the AC Definition and of all elements. Issue-ID: POLICY-4502 Change-Id: Ifd90fc8d5788ec2ddebc12ee2e78beef4c0254c8 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.java39
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java10
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java8
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java3
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdatePublisher.java5
-rw-r--r--runtime-acm/src/main/resources/openapi/openapi.yaml9
6 files changed, 37 insertions, 37 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 9f898d88d..450c75564 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,10 @@ package org.onap.policy.clamp.acm.runtime.commissioning;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
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;
@@ -42,29 +45,14 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Service
@Transactional
+@RequiredArgsConstructor
public class CommissioningProvider {
public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionProvider acProvider;
- private final ParticipantProvider participantProvider;
private final SupervisionHandler supervisionHandler;
-
- /**
- * Create a commissioning provider.
- *
- * @param acDefinitionProvider the ServiceTemplate Provider
- * @param acProvider the AutomationComposition Provider
- * @param supervisionHandler the Supervision Handler
- * @param participantProvider the Participant Provider
- */
- public CommissioningProvider(AcDefinitionProvider acDefinitionProvider, AutomationCompositionProvider acProvider,
- SupervisionHandler supervisionHandler, ParticipantProvider participantProvider) {
- this.acDefinitionProvider = acDefinitionProvider;
- this.acProvider = acProvider;
- this.supervisionHandler = supervisionHandler;
- this.participantProvider = participantProvider;
- }
+ private final ParticipantProvider participantProvider;
private CommissioningResponse createCommissioningResponse(UUID compositionId,
ToscaServiceTemplate serviceTemplate) {
@@ -83,12 +71,12 @@ public class CommissioningProvider {
}
/**
- * Create automation compositions from a service template.
+ * Create automation composition from a service template.
*
* @param serviceTemplate the service template
* @return the result of the commissioning operation
*/
- public CommissioningResponse createAutomationCompositionDefinitions(ToscaServiceTemplate serviceTemplate) {
+ public CommissioningResponse createAutomationCompositionDefinition(ToscaServiceTemplate serviceTemplate) {
var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate);
serviceTemplate = acmDefinition.getServiceTemplate();
@@ -107,12 +95,15 @@ public class CommissioningProvider {
* @return the result of the commissioning operation
*/
public CommissioningResponse updateCompositionDefinition(UUID compositionId, ToscaServiceTemplate serviceTemplate) {
-
- var automationCompositions = acProvider.getAcInstancesByCompositionId(compositionId);
- if (!automationCompositions.isEmpty()) {
+ if (verifyIfInstanceExists(compositionId)) {
throw new PfModelRuntimeException(Status.BAD_REQUEST,
"There are ACM instances, Update of ACM Definition not allowed");
}
+ var acDefinition = acDefinitionProvider.getAcDefinition(compositionId);
+ if (AcTypeState.COMMISSIONED.equals(acDefinition.getState())) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST,
+ "ACM not in COMMISSIONED state, Update of ACM Definition not allowed");
+ }
acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate);
return createCommissioningResponse(compositionId, serviceTemplate);
@@ -161,7 +152,7 @@ public class CommissioningProvider {
* @return automation composition definition
*/
@Transactional(readOnly = true)
- public ToscaServiceTemplate getAutomationCompositionDefinitions(UUID compositionId) {
+ public AutomationCompositionDefinition getAutomationCompositionDefinition(UUID compositionId) {
return acDefinitionProvider.getAcDefinition(compositionId);
}
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 7f9dc8d19..6d7ae7d4d 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionDefinitionApi;
import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
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.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -56,7 +57,7 @@ public class CommissioningController extends AbstractRestController implements A
UUID requestId) {
var compositionId = body.getMetadata() != null ? body.getMetadata().get("compositionId") : null;
if (compositionId == null) {
- var response = provider.createAutomationCompositionDefinitions(body);
+ var response = provider.createAutomationCompositionDefinition(body);
return ResponseEntity.created(createUri("/compositions/" + response.getCompositionId())).body(response);
} else {
return ResponseEntity.ok()
@@ -91,8 +92,9 @@ public class CommissioningController extends AbstractRestController implements A
}
@Override
- public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition(UUID compositionId, UUID requestId) {
- return ResponseEntity.ok().body(provider.getAutomationCompositionDefinitions(compositionId));
+ public ResponseEntity<AutomationCompositionDefinition> getCompositionDefinition(UUID compositionId,
+ UUID requestId) {
+ return ResponseEntity.ok().body(provider.getAutomationCompositionDefinition(compositionId));
}
@Override
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java
index 98c71dc6f..adcb1410b 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionDefinitionApi;
import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
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.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -72,8 +73,9 @@ public class CommissioningControllerStub extends AbstractRestController implemen
}
@Override
- public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition(UUID compositionId, UUID xonaprequestid) {
- return stubUtils.getResponse(pathToSingleDefinition, ToscaServiceTemplate.class);
+ public ResponseEntity<AutomationCompositionDefinition> getCompositionDefinition(UUID compositionId,
+ UUID xonaprequestid) {
+ return stubUtils.getResponse(pathToSingleDefinition, AutomationCompositionDefinition.class);
}
@Override
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 761c3800c..2c5d48717 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
@@ -305,7 +305,8 @@ public class SupervisionHandler {
}
private int getFirstStartPhase(AutomationComposition automationComposition) {
- var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
+ var toscaServiceTemplate =
+ acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate();
return ParticipantUtils.getFirstStartPhase(automationComposition, toscaServiceTemplate);
}
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 7b114c920..57556e088 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021,2022 Nordix Foundation.
+ * Copyright (C) 2021,2023 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -73,7 +73,8 @@ public class AutomationCompositionUpdatePublisher extends AbstractParticipantPub
automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getInstanceId());
automationCompositionUpdateMsg.setMessageId(UUID.randomUUID());
automationCompositionUpdateMsg.setTimestamp(Instant.now());
- var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
+ var toscaServiceTemplate =
+ acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate();
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (var element : automationComposition.getElements().values()) {
diff --git a/runtime-acm/src/main/resources/openapi/openapi.yaml b/runtime-acm/src/main/resources/openapi/openapi.yaml
index f2692a900..c060fba3f 100644
--- a/runtime-acm/src/main/resources/openapi/openapi.yaml
+++ b/runtime-acm/src/main/resources/openapi/openapi.yaml
@@ -640,7 +640,7 @@ paths:
200:
description:
Serialised instance of
- [ToscaServiceTemplate](https://github.com/onap/policy-models/blob/master/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java)
+ [AutomationCompositionDefinition](https://github.com/onap/policy-clamp/blob/master/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java)
containing the requested automation composition definition.
headers:
X-LatestVersion:
@@ -659,12 +659,12 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/ToscaServiceTemplate'
+ $ref: '#/components/schemas/AutomationCompositionDefinition'
example:
externalValue: 'https://raw.githubusercontent.com/onap/policy-clamp/master/runtime-acm/src/main/resources/openapi/examples/getSingleCompositionDefinition.json'
application/yaml:
schema:
- $ref: '#/components/schemas/ToscaServiceTemplate'
+ $ref: '#/components/schemas/AutomationCompositionDefinition'
example:
externalValue: 'https://raw.githubusercontent.com/onap/policy-clamp/master/runtime-acm/src/main/resources/openapi/examples/getSingleCompositionDefinition.yaml'
401:
@@ -1578,6 +1578,9 @@ components:
ToscaServiceTemplate:
title: ToscaServiceTemplate
type: object
+ AutomationCompositionDefinition:
+ title: AutomationCompositionDefinition
+ type: object
AutomationComposition:
title: AutomationComposition
type: object