diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-14 14:10:58 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-06-17 09:04:18 +0000 |
commit | ca2ee94054c580827fcfc7f07c9db641301d6b9a (patch) | |
tree | 837edef253934aa10a09ecafa5819035b9ca0097 /participant/participant-impl/participant-impl-http | |
parent | b52e095b34ee7c576f7ee83df05e2a09366a8c8a (diff) |
Remove restarting implementation from participants
Remove restarting implementation from participants and
Remove local Map from a1pms and kserve participants.
Issue-ID: POLICY-5046
Change-Id: I9cc2a33d603751c60007475414b45ca54f0aac25
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-http')
3 files changed, 55 insertions, 70 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java index 752b8d938..161cf9278 100644 --- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java @@ -36,7 +36,6 @@ import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.models.base.PfModelException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -76,11 +75,9 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 { * @param automationCompositionId the automationComposition Id * @param element the information on the automation composition element * @param properties properties Map - * @throws PfModelException in case of a exception */ @Override - public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { + public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) { try { var configRequest = getConfigRequest(properties); var restResponseMap = acHttpClient.run(configRequest); @@ -104,11 +101,13 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 { private ConfigRequest getConfigRequest(Map<String, Object> properties) throws AutomationCompositionException { try { var configRequest = CODER.convert(properties, ConfigRequest.class); - var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest); - if (!violations.isEmpty()) { - LOGGER.error("Violations found in the config request parameters: {}", violations); - throw new AutomationCompositionException(Status.BAD_REQUEST, - "Constraint violations in the config request"); + try (var validatorFactory = Validation.buildDefaultValidatorFactory()) { + var violations = validatorFactory.getValidator().validate(configRequest); + if (!violations.isEmpty()) { + LOGGER.error("Violations found in the config request parameters: {}", violations); + throw new AutomationCompositionException(Status.BAD_REQUEST, + "Constraint violations in the config request"); + } } return configRequest; } catch (CoderException e) { diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java index 634e78880..9c0b9aecd 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,13 @@ package org.onap.policy.clamp.acm.participant.http.handler; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler; import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest; @@ -40,6 +42,8 @@ import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.springframework.http.HttpStatus; class AcElementHandlerTest { @@ -63,7 +67,7 @@ class AcElementHandlerTest { } @Test - void testDeployConstraintViolations() throws PfModelException { + void testDeployConstraintViolations() { var instanceId = commonTestData.getAutomationCompositionId(); var element = commonTestData.getAutomationCompositionElement(); var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); @@ -78,7 +82,7 @@ class AcElementHandlerTest { } @Test - void testDeployError() throws PfModelException { + void testDeployError() { var instanceId = commonTestData.getAutomationCompositionId(); var element = commonTestData.getAutomationCompositionElement(); var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); @@ -95,7 +99,30 @@ class AcElementHandlerTest { } @Test - void testDeploy() throws Exception { + void testDeployFailed() { + var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca(); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); + var element = commonTestData.getAutomationCompositionElement(); + map.putAll(element.getProperties()); + var instanceId = commonTestData.getAutomationCompositionId(); + var acHttpClient = mock(AcHttpClient.class); + when(acHttpClient.run(any())).thenReturn(Map.of(new ToscaConceptIdentifier(), + Pair.of(HttpStatus.BAD_REQUEST.value(), ""))); + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(participantIntermediaryApi, acHttpClient); + + automationCompositionElementHandler.deploy(instanceId, element, map); + verify(acHttpClient).run(any(ConfigRequest.class)); + verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, + "Error on Invoking the http request: [(400,)]"); + } + + @Test + void testDeploy() { var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca(); var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); @@ -198,50 +225,6 @@ class AcElementHandlerTest { } @Test - void testHandleRestartComposition() throws PfModelException { - var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); - var automationCompositionElementHandler = - new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class)); - - var compositionId = UUID.randomUUID(); - automationCompositionElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED); - verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, - StateChangeResult.NO_ERROR, "Restarted"); - } - - @Test - void testHandleRestartInstanceDeploying() throws PfModelException { - var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca(); - var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); - var element = commonTestData.getAutomationCompositionElement(); - map.putAll(element.getProperties()); - var instanceId = commonTestData.getAutomationCompositionId(); - var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); - var automationCompositionElementHandler = - new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class)); - - automationCompositionElementHandler.handleRestartInstance(instanceId, element, map, DeployState.DEPLOYING, - LockState.NONE); - verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); - } - - @Test - void testHandleRestartInstanceDeployed() throws PfModelException { - var element = commonTestData.getAutomationCompositionElement(); - var instanceId = commonTestData.getAutomationCompositionId(); - var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); - var automationCompositionElementHandler = - new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class)); - - automationCompositionElementHandler.handleRestartInstance(instanceId, element, element.getProperties(), - DeployState.DEPLOYED, LockState.LOCKED); - verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), - DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted"); - } - - @Test void testMigrate() throws PfModelException { var instanceId = commonTestData.getAutomationCompositionId(); var element = commonTestData.getAutomationCompositionElement(); diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java index f6c0c5a8a..149d8d910 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,39 +53,42 @@ class ActuatorControllerTest extends CommonActuatorController { } @Test - void testGetHealth_Unauthorized() throws Exception { + void testGetHealth_Unauthorized() { assertUnauthorizedActGet(HEALTH_ENDPOINT); } @Test - void testGetMetrics_Unauthorized() throws Exception { + void testGetMetrics_Unauthorized() { assertUnauthorizedActGet(METRICS_ENDPOINT); } @Test - void testGetPrometheus_Unauthorized() throws Exception { + void testGetPrometheus_Unauthorized() { assertUnauthorizedActGet(PROMETHEUS_ENDPOINT); } @Test - void testGetHealth() throws Exception { + void testGetHealth() { var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test - void testGetMetrics() throws Exception { + void testGetMetrics() { var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test - void testGePrometheus() throws Exception { + void testGePrometheus() { var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } } |