aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm/src/main')
-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
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) {