diff options
author | Liam Fallon <liam.fallon@est.tech> | 2023-01-05 09:41:14 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-01-05 09:41:14 +0000 |
commit | bce4edfb6a9140a07d12470d977352d7b3a4105c (patch) | |
tree | bec8d5ad77fa103c9f6082403de981dc2d6ad791 | |
parent | 951196b4e0d4c64403f186693c2d1c53e25df3b1 (diff) | |
parent | a76f5614e10f99658114ea1ff2eaf334e0df01c8 (diff) |
Merge "Refactor Post instances to create and update ACM instances"
11 files changed, 100 insertions, 222 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java index b19f54c3b..83c51eadb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -37,7 +37,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @Data @EqualsAndHashCode(callSuper = true) public class AutomationComposition extends ToscaEntity implements Comparable<AutomationComposition> { - @NonNull + private UUID instanceId; @NonNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationUpdate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationUpdate.java deleted file mode 100644 index 7aab59436..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationUpdate.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.models.acm.messages.rest.instantiation; - -import java.util.Map; -import java.util.UUID; -import lombok.Data; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; - -@Data -public class InstantiationUpdate { - - private InstantiationCommand instantiationCommand; - - private Map<UUID, AutomationCompositionElement> elements; -} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index b723dba7f..099c0e740 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -37,7 +37,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate; 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; @@ -102,29 +101,27 @@ public class AutomationCompositionInstantiationProvider { * Update automation composition. * * @param compositionId The UUID of the automation composition definition - * @param instanceId The UUID of the automation composition instance - * @param instanceUpdate the automation composition + * @param automationComposition the automation composition * @return the result of the update */ - public InstantiationResponse updateAutomationComposition(UUID compositionId, UUID instanceId, - InstantiationUpdate instanceUpdate) { - var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId); - if (!compositionId.equals(automationComposition.getCompositionId())) { + public InstantiationResponse updateAutomationComposition(UUID compositionId, + AutomationComposition automationComposition) { + var instanceId = automationComposition.getInstanceId(); + var acToUpdate = automationCompositionProvider.getAutomationComposition(instanceId); + if (!compositionId.equals(acToUpdate.getCompositionId())) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId); } - if (instanceUpdate.getElements() != null) { - automationComposition.setElements(instanceUpdate.getElements()); - var validationResult = validateAutomationComposition(automationComposition); - if (!validationResult.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); - } - automationComposition = automationCompositionProvider.updateAutomationComposition(automationComposition); - } - - if (instanceUpdate.getInstantiationCommand() != null) { - issueAutomationCompositionCommand(automationComposition, instanceUpdate.getInstantiationCommand()); + acToUpdate.setElements(automationComposition.getElements()); + acToUpdate.setName(automationComposition.getName()); + acToUpdate.setVersion(automationComposition.getVersion()); + acToUpdate.setDescription(automationComposition.getDescription()); + acToUpdate.setDerivedFrom(automationComposition.getDerivedFrom()); + var validationResult = validateAutomationComposition(acToUpdate); + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); } + automationComposition = automationCompositionProvider.updateAutomationComposition(acToUpdate); var response = new InstantiationResponse(); response.setInstanceId(instanceId); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java index 1ff7c019e..94c111e00 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java @@ -31,7 +31,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate; import org.springframework.context.annotation.Profile; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -59,10 +58,14 @@ public class InstantiationController extends AbstractRestController implements A public ResponseEntity<InstantiationResponse> createCompositionInstance(UUID compositionId, AutomationComposition automationComposition, UUID requestId) { - var response = provider.createAutomationComposition(compositionId, automationComposition); - return ResponseEntity - .created(createUri("/compositions/" + compositionId + "/instances/" + response.getInstanceId())) - .body(response); + if (automationComposition.getInstanceId() == null) { + var response = provider.createAutomationComposition(compositionId, automationComposition); + return ResponseEntity + .created(createUri("/compositions/" + compositionId + "/instances/" + response.getInstanceId())) + .body(response); + } else { + return ResponseEntity.ok().body(provider.updateAutomationComposition(compositionId, automationComposition)); + } } /** @@ -96,22 +99,6 @@ public class InstantiationController extends AbstractRestController implements A } /** - * Updates a automation composition. - * - * @param compositionId The UUID of the automation composition definition - * @param instanceId The UUID of the automation composition instance - * @param instanceUpdate the automation composition to update - * @param requestId request ID used in ONAP logging - * @return a response - */ - public ResponseEntity<InstantiationResponse> updateCompositionInstance(UUID compositionId, UUID instanceId, - InstantiationUpdate instanceUpdate, UUID requestId) { - - return ResponseEntity.ok() - .body(provider.updateAutomationComposition(compositionId, instanceId, instanceUpdate)); - } - - /** * Deletes a automation composition definition. * * @param compositionId The UUID of the automation composition definition @@ -127,8 +114,8 @@ public class InstantiationController extends AbstractRestController implements A } @Override - public ResponseEntity<Void> ompositionInstanceState(UUID compositionId, UUID instanceId, - @Valid AcInstanceStateUpdate body, UUID requestId) { + public ResponseEntity<Void> compositionInstanceState(UUID compositionId, UUID instanceId, + @Valid AcInstanceStateUpdate body, UUID requestId) { // TODO Auto-generated method stub return null; } 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 833b3fa0b..98c71dc6f 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 @@ -21,37 +21,24 @@ package org.onap.policy.clamp.acm.runtime.main.rest.stub; import java.util.UUID; -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; +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.messages.rest.commissioning.AcTypeStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @Profile("stub") -public class CommissioningControllerStub extends AbstractRestController - implements AutomationCompositionDefinitionApi { +@RequiredArgsConstructor +public class CommissioningControllerStub extends AbstractRestController implements AutomationCompositionDefinitionApi { - private static final Logger log = LoggerFactory.getLogger(CommissioningControllerStub.class); - - private StubUtils stubUtils = new StubUtils(); - - @Autowired - private HttpServletRequest request; + private final StubUtils stubUtils; @Value("${stub.deleteCompositionDefinitionResponse}") private String pathToResponseFile; @@ -69,44 +56,35 @@ public class CommissioningControllerStub extends AbstractRestController private String pathToPutUpdate; @Override - public ResponseEntity<CommissioningResponse> createCompositionDefinitions( - @Valid @RequestBody ToscaServiceTemplate body, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToPostResponse, CommissioningResponse.class, request, log); + public ResponseEntity<CommissioningResponse> createCompositionDefinitions(ToscaServiceTemplate body, + UUID xonaprequestid) { + var compositionId = body.getMetadata() != null ? body.getMetadata().get("compositionId") : null; + if (compositionId == null) { + return stubUtils.getResponse(pathToPostResponse, CommissioningResponse.class); + } else { + return stubUtils.getResponse(pathToPutUpdate, CommissioningResponse.class); + } } @Override - public ResponseEntity<CommissioningResponse> deleteCompositionDefinition( - @PathVariable("compositionId") UUID compositionId, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToResponseFile, CommissioningResponse.class, request, log); + public ResponseEntity<CommissioningResponse> deleteCompositionDefinition(UUID compositionId, UUID xonaprequestid) { + return stubUtils.getResponse(pathToResponseFile, CommissioningResponse.class); } @Override - public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition( - @PathVariable("compositionId") UUID compositionId, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToSingleDefinition, ToscaServiceTemplate.class, request, log); + public ResponseEntity<ToscaServiceTemplate> getCompositionDefinition(UUID compositionId, UUID xonaprequestid) { + return stubUtils.getResponse(pathToSingleDefinition, ToscaServiceTemplate.class); } @Override - public ResponseEntity<ToscaServiceTemplates> queryCompositionDefinitions( - @Valid @RequestParam(value = "name", required = false) String name, - @Valid @RequestParam(value = "version", required = false) String version, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToAllDefinitions, ToscaServiceTemplates.class, request, log); - } - - public ResponseEntity<CommissioningResponse> updateCompositionDefinition( - @PathVariable("compositionId") UUID compositionId, - @Valid @RequestBody ToscaServiceTemplate body, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToPutUpdate, CommissioningResponse.class, request, log); + public ResponseEntity<ToscaServiceTemplates> queryCompositionDefinitions(String name, String version, + UUID xonaprequestid) { + return stubUtils.getResponse(pathToAllDefinitions, ToscaServiceTemplates.class); } @Override public ResponseEntity<Void> compositionDefinitionPriming(UUID compositionId, UUID requestId, - AcTypeStateUpdate body) { + AcTypeStateUpdate body) { // TODO Auto-generated method stub return null; } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java index ac34f227d..d0b190dd3 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java @@ -21,37 +21,25 @@ package org.onap.policy.clamp.acm.runtime.main.rest.stub; import java.util.UUID; -import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionInstanceApi; import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @Profile("stub") +@RequiredArgsConstructor public class InstantiationControllerStub extends AbstractRestController implements AutomationCompositionInstanceApi { - private static final Logger log = LoggerFactory.getLogger(InstantiationControllerStub.class); - - private StubUtils stubUtils = new StubUtils(); - - @Autowired - private HttpServletRequest request; + private final StubUtils stubUtils; @Value("${stub.deleteCompositionInstanceResponse}") private String pathToResponseFile; @@ -69,50 +57,37 @@ public class InstantiationControllerStub extends AbstractRestController implemen private String pathToPutUpdate; @Override - public ResponseEntity<InstantiationResponse> createCompositionInstance( - @PathVariable("compositionId") UUID compositionId, - @Valid @RequestBody AutomationComposition body, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathPostIntance, InstantiationResponse.class, request, log); + public ResponseEntity<InstantiationResponse> createCompositionInstance(UUID compositionId, + AutomationComposition body, UUID xonaprequestid) { + if (body.getInstanceId() == null) { + return stubUtils.getResponse(pathPostIntance, InstantiationResponse.class); + } else { + return stubUtils.getResponse(pathToResponseFile, InstantiationResponse.class); + } } @Override - public ResponseEntity<InstantiationResponse> deleteCompositionInstance( - @PathVariable("compositionId") UUID compositionId, - @PathVariable("instanceId") UUID instanceId, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToResponseFile, InstantiationResponse.class, request, log); + public ResponseEntity<InstantiationResponse> deleteCompositionInstance(UUID compositionId, UUID instanceId, + UUID xonaprequestid) { + return stubUtils.getResponse(pathToResponseFile, InstantiationResponse.class); } @Override - public ResponseEntity<AutomationComposition> getCompositionInstance( - @PathVariable("compositionId") UUID compositionId, - @PathVariable("instanceId") UUID instanceId, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToSingleIntance, AutomationComposition.class, request, log); + public ResponseEntity<AutomationComposition> getCompositionInstance(UUID compositionId, UUID instanceId, + UUID xonaprequestid) { + return stubUtils.getResponse(pathToSingleIntance, AutomationComposition.class); } @Override - public ResponseEntity<AutomationCompositions> queryCompositionInstances( - @PathVariable("compositionId") UUID compositionId, - @Valid @RequestParam(value = "name", required = false) String name, - @Valid @RequestParam(value = "version", required = false) String version, - @RequestHeader(value = "X-onap-RequestId", required = false) UUID xonaprequestid) { - return stubUtils.getResponse(pathToAllIntances, AutomationCompositions.class, request, log); - } - - public ResponseEntity<InstantiationResponse> updateCompositionInstance( - UUID compositionId, - UUID instanceId, - InstantiationUpdate body, - UUID xonaprequestid) { - return stubUtils.getResponse(pathToResponseFile, InstantiationResponse.class, request, log); + public ResponseEntity<AutomationCompositions> queryCompositionInstances(UUID compositionId, String name, + String version, UUID xonaprequestid) { + return stubUtils.getResponse(pathToAllIntances, AutomationCompositions.class); } @Override - public ResponseEntity<Void> ompositionInstanceState(UUID compositionId, UUID instanceId, - @Valid AcInstanceStateUpdate body, UUID requestId) { + public ResponseEntity<Void> compositionInstanceState(UUID compositionId, UUID instanceId, + @Valid AcInstanceStateUpdate body, UUID requestId) { // TODO Auto-generated method stub return null; } -}
\ No newline at end of file +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java index 650426681..3a209a096 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java @@ -22,13 +22,13 @@ package org.onap.policy.clamp.acm.runtime.main.rest.stub; import com.google.gson.Gson; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Profile; import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpStatus; @@ -40,21 +40,23 @@ import org.springframework.stereotype.Service; @Profile("stub") public class StubUtils { + private static final Logger log = LoggerFactory.getLogger(StubUtils.class); + private final HttpServletRequest request; + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); private static final Gson JSON_TRANSLATOR = new Gson(); private static final String YAML = "application/yaml"; private static final String ACCEPT = "Accept"; - <T> ResponseEntity<T> getResponse(String path, Class<T> clazz, - HttpServletRequest request, Logger log) { - String accept = request.getHeader(ACCEPT); - final ClassPathResource resource = new ClassPathResource(path); - try (InputStream inputStream = resource.getInputStream()) { + <T> ResponseEntity<T> getResponse(String path, Class<T> clazz) { + var accept = request.getHeader(ACCEPT); + final var resource = new ClassPathResource(path); + try (var inputStream = resource.getInputStream()) { if (accept.contains(YAML)) { var targetObject = YAML_TRANSLATOR.decode(inputStream, clazz); return new ResponseEntity<>(targetObject, HttpStatus.OK); } else { - final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); var targetObject = JSON_TRANSLATOR.fromJson(string, clazz); return new ResponseEntity<>(targetObject, HttpStatus.OK); } diff --git a/runtime-acm/src/main/resources/openapi/openapi.yaml b/runtime-acm/src/main/resources/openapi/openapi.yaml index 170e233c9..655ce7eeb 100644 --- a/runtime-acm/src/main/resources/openapi/openapi.yaml +++ b/runtime-acm/src/main/resources/openapi/openapi.yaml @@ -1316,7 +1316,7 @@ paths: description: This request manages deployment and locking of an automation composition instance. This endpoint can order deployment and undeployment of an AC Instance to participants and order unlocking and locking of AC instances on participants - operationId: ompositionInstanceState + operationId: compositionInstanceState parameters: - name : compositionId in: path diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java index c14d64069..cd6e021c5 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java @@ -40,7 +40,6 @@ import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate; 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; @@ -117,32 +116,24 @@ class AutomationCompositionInstantiationProviderTest { assertThat(automationCompositionCreate) .isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0)); - var instanceUpdate = new InstantiationUpdate(); var automationCompositionUpdate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); automationCompositionUpdate.setCompositionId(compositionId); - instanceUpdate.setElements(automationCompositionUpdate.getElements()); when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) .thenReturn(automationCompositionUpdate); when(acProvider.updateAutomationComposition(automationCompositionUpdate)) .thenReturn(automationCompositionUpdate); - instantiationResponse = - instantiationProvider.updateAutomationComposition(automationCompositionUpdate.getCompositionId(), - automationCompositionUpdate.getInstanceId(), instanceUpdate); + instantiationResponse = instantiationProvider.updateAutomationComposition( + automationCompositionUpdate.getCompositionId(), automationCompositionUpdate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate); verify(acProvider).updateAutomationComposition(automationCompositionUpdate); - var instanceUpdateCommand = new InstantiationUpdate(); var instantiationCommand = InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON); - instanceUpdateCommand.setInstantiationCommand(instantiationCommand); - instantiationResponse = - instantiationProvider.updateAutomationComposition(automationCompositionUpdate.getCompositionId(), - automationCompositionUpdate.getInstanceId(), instanceUpdateCommand); - InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate); - + instantiationProvider.issueAutomationCompositionCommand(automationCompositionUpdate, + instantiationCommand); verify(supervisionHandler).triggerAutomationCompositionSupervision(automationCompositionUpdate); // in order to delete a automationComposition the state must be UNINITIALISED @@ -262,11 +253,8 @@ class AutomationCompositionInstantiationProviderTest { when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); - var instanceUpdate = new InstantiationUpdate(); - instanceUpdate.setElements(automationComposition.getElements()); - var instanceId = automationComposition.getInstanceId(); - assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, instanceId, instanceUpdate)) + assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND); } @@ -288,17 +276,14 @@ class AutomationCompositionInstantiationProviderTest { assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_DEFINITION_NOT_FOUND); - var instanceUpdate = new InstantiationUpdate(); - instanceUpdate.setElements(automationComposition.getElements()); - var instanceId = automationComposition.getInstanceId(); - assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, instanceId, instanceUpdate)) + assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_DEFINITION_NOT_FOUND); var wrongCompositionId = UUID.randomUUID(); assertThatThrownBy(() -> provider.createAutomationComposition(wrongCompositionId, automationComposition)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); - assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, instanceId, instanceUpdate)) + assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, automationComposition)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); } @@ -310,17 +295,12 @@ class AutomationCompositionInstantiationProviderTest { var acDefinitionProvider = mock(AcDefinitionProvider.class); var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, participantProvider, acDefinitionProvider); - var instanceUpdate = new InstantiationUpdate(); - instanceUpdate.setInstantiationCommand(new InstantiationCommand()); var automationComposition = InstantiationUtils .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); - var compositionId = automationComposition.getCompositionId(); - var instanceId = automationComposition.getInstanceId(); - assertThatThrownBy( - () -> instantiationProvider.updateAutomationComposition(compositionId, instanceId, instanceUpdate)) - .hasMessageMatching(ORDERED_STATE_INVALID); + assertThatThrownBy(() -> instantiationProvider.issueAutomationCompositionCommand(automationComposition, + new InstantiationCommand())).hasMessageMatching(ORDERED_STATE_INVALID); } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java index 9bc29d9ce..d3a3f3eb8 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java @@ -41,10 +41,10 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.main.rest.InstantiationController; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; @@ -218,7 +218,6 @@ class InstantiationControllerTest extends CommonRestController { assertEquals(automationComposition, automationCompositionsQuery.getAutomationCompositionList().get(0)); } - @Disabled @Test void testUpdate() { var automationCompositionCreate = @@ -231,10 +230,8 @@ class InstantiationControllerTest extends CommonRestController { InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update"); automationComposition.setCompositionId(compositionId); automationComposition.setInstanceId(response.getInstanceId()); - var instantiationUpdate = new InstantiationUpdate(); - instantiationUpdate.setElements(automationComposition.getElements()); - var invocationBuilder = super.sendRequest(getInstanceEndPoint(response.getInstanceId())); - var resp = invocationBuilder.put(Entity.json(automationComposition)); + var invocationBuilder = super.sendRequest(getInstanceEndPoint()); + var resp = invocationBuilder.post(Entity.json(automationComposition)); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); var instResponse = resp.readEntity(InstantiationResponse.class); @@ -285,7 +282,7 @@ class InstantiationControllerTest extends CommonRestController { @Test void testCommand_NotFound1() { var invocationBuilder = super.sendRequest(getInstanceEndPoint(UUID.randomUUID())); - var resp = invocationBuilder.put(Entity.json(new InstantiationUpdate())); + var resp = invocationBuilder.post(Entity.json(new AutomationComposition())); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus()); } @@ -298,9 +295,9 @@ class InstantiationControllerTest extends CommonRestController { var instResponse = instantiationProvider.createAutomationComposition(compositionId, acFromRsc); - var command = new InstantiationUpdate(); - command.setInstantiationCommand(new InstantiationCommand()); - command.getInstantiationCommand().setOrderedState(null); + var command = new AcInstanceStateUpdate(); + command.setDeployOrder(null); + command.setLockOrder(null); var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId())); var resp = invocationBuilder.put(Entity.json(command)); @@ -320,9 +317,7 @@ class InstantiationControllerTest extends CommonRestController { participantProvider.saveParticipant(participant); } - var instantiationUpdate = new InstantiationUpdate(); - var command = InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON); - instantiationUpdate.setInstantiationCommand(command); + var instantiationUpdate = new AcInstanceStateUpdate(); var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId())); var resp = invocationBuilder.put(Entity.json(instantiationUpdate)); @@ -335,8 +330,6 @@ class InstantiationControllerTest extends CommonRestController { var automationCompositionsGet = instantiationProvider.getAutomationCompositions(compositionId, toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion()); assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1); - assertEquals(command.getOrderedState(), - automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState()); } private synchronized void deleteEntryInDB() { diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java index afddc4d01..30c8ed173 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java @@ -28,7 +28,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; @@ -44,7 +45,6 @@ class InstantiationControllerStubTest extends CommonRestController { private static final String INSTANTIATION_ENDPOINT = "instances"; private static final String COMPOSITION_ID = "1aeed185-a98b-45b6-af22-8d5d20485ea3"; private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c23"; - private static InstantiationUpdate instantiationUpdate = new InstantiationUpdate(); @LocalServerPort private int randomServerPort; @@ -79,7 +79,7 @@ class InstantiationControllerStubTest extends CommonRestController { + "/" + COMPOSITION_ID + "/" + INSTANTIATION_ENDPOINT + "/" + INSTANCE_ID); - var respPost = invocationBuilder.put(Entity.json(instantiationUpdate)); + var respPost = invocationBuilder.put(Entity.json(new AcInstanceStateUpdate())); assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus()); } @@ -88,7 +88,7 @@ class InstantiationControllerStubTest extends CommonRestController { var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + COMPOSITION_ID + "/" + INSTANTIATION_ENDPOINT); - var respPost = invocationBuilder.post(Entity.json(instantiationUpdate)); + var respPost = invocationBuilder.post(Entity.json(new AutomationComposition())); assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus()); } |