summaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java23
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java20
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java8
3 files changed, 18 insertions, 33 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) {
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 da43b1fb2..c84d7ea80 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
@@ -29,12 +29,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import java.util.HashMap;
+import java.util.Map;
import java.util.UUID;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
@@ -128,7 +128,6 @@ class CommissioningControllerTest extends CommonRestController {
}
}
- @Disabled
@Test
void testUpdate() {
var toscaDataType = new ToscaDataType();
@@ -143,8 +142,9 @@ class CommissioningControllerTest extends CommonRestController {
var compositionId = createEntryInDB("forUpdate");
var serviceTemplateUpdate = new ToscaServiceTemplate(serviceTemplate);
serviceTemplateUpdate.getDataTypes().put(toscaDataType.getName(), toscaDataType);
- var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
- var resp = invocationBuilder.put(Entity.json(serviceTemplateUpdate));
+ serviceTemplateUpdate.setMetadata(Map.of("compositionId", compositionId));
+ var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
+ var resp = invocationBuilder.post(Entity.json(serviceTemplateUpdate));
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
var commissioningResponse = resp.readEntity(CommissioningResponse.class);
assertNotNull(commissioningResponse);