summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm/src')
-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
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java4
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java7
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java2
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java15
10 files changed, 54 insertions, 48 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
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index fe0180a74..6ecb8e6f2 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.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");
@@ -88,7 +88,7 @@ class CommissioningProviderTest {
var provider =
new CommissioningProvider(acDefinitionProvider, acProvider, supervisionHandler, participantProvider);
var affectedDefinitions = provider
- .createAutomationCompositionDefinitions(serviceTemplate).getAffectedAutomationCompositionDefinitions();
+ .createAutomationCompositionDefinition(serviceTemplate).getAffectedAutomationCompositionDefinitions();
verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
verify(supervisionHandler).handleSendCommissionMessage(acmDefinition);
// Response should return the number of node templates present in the service template
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 c84d7ea80..53fa945b2 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
@@ -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");
@@ -39,6 +39,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+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.models.tosca.authorative.concepts.ToscaDataType;
@@ -159,8 +160,8 @@ class CommissioningControllerTest extends CommonRestController {
invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
resp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- var entity = resp.readEntity(ToscaServiceTemplate.class);
- assertThat(entity.getDataTypes()).containsKey(toscaDataType.getName());
+ var entity = resp.readEntity(AutomationCompositionDefinition.class);
+ assertThat(entity.getServiceTemplate().getDataTypes()).containsKey(toscaDataType.getName());
}
@Test
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
index e6f7118da..461f4ee28 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
@@ -61,7 +61,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ "test", "default" })
-public class ParticipantControllerTest extends CommonRestController {
+class ParticipantControllerTest extends CommonRestController {
private static final String PARTICIPANTS_ENDPOINT = "participants";
@LocalServerPort
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index 1db95e4b5..10332117c 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -95,13 +95,15 @@ class SupervisionHandlerTest {
automationComposition.setState(AutomationCompositionState.PASSIVE);
automationComposition.setCompositionId(UUID.randomUUID());
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
- when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(
- Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML)));
+ var acDefinition = new AutomationCompositionDefinition();
+ acDefinition.setCompositionId(automationComposition.getCompositionId());
+ acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
+ when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
mock(ParticipantUpdatePublisher.class));
@@ -302,8 +304,11 @@ class SupervisionHandlerTest {
var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
when(acDefinitionProvider.getServiceTemplateList(any(), any())).thenReturn(List
.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML))));
- when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()))
- .thenReturn(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
+
+ var acDefinition = new AutomationCompositionDefinition();
+ acDefinition.setCompositionId(automationComposition.getCompositionId());
+ acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
+ when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
return new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,