From 448c221502fac54c52e088caca56b9aa45797ef7 Mon Sep 17 00:00:00 2001 From: zhaoyh6 Date: Tue, 1 Mar 2022 14:58:07 +0800 Subject: Closed loop operation guarantee for ccvpn Issue-ID: REQ-1074 Signed-off-by: zhaoyh6 Change-Id: Ib2c60a1e5ebd1fda5e04e75c265e863733caa278 --- .../policy/controlloop/actor/so/ModifyCll.java | 79 ++++++++++++++ .../onap/policy/controlloop/actor/so/SoActor.java | 2 + .../policy/controlloop/actor/so/ModifyCllTest.java | 116 +++++++++++++++++++++ .../actor.so/src/test/resources/ModifyCll.json | 16 +++ .../actor.so/src/test/resources/service.yaml | 3 + 5 files changed, 216 insertions(+) create mode 100644 models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyCll.java create mode 100644 models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java create mode 100644 models-interactions/model-actors/actor.so/src/test/resources/ModifyCll.json (limited to 'models-interactions/model-actors/actor.so') diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyCll.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyCll.java new file mode 100644 index 000000000..48e20e309 --- /dev/null +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyCll.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2022 CTC, Inc. and others. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.so; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import org.onap.policy.common.endpoints.event.comm.Topic; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; +import org.onap.policy.so.SoRequestCll; + +public class ModifyCll extends SoOperation { + public static final String NAME = "ModifyCloudLeasedLine"; + + private static final List PROPERTY_NAMES = List.of( + OperationProperties.EVENT_PAYLOAD); + + /** + * Constructs the object. + * + * @param params operation parameters + * @param config configuration for this operation + */ + public ModifyCll(ControlLoopOperationParams params, HttpPollingConfig config) { + super(params, config, PROPERTY_NAMES); + } + + @Override + protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { + + SoRequestCll soRequest = makeRequest(); + + String path = getPath(); + String url = getClient().getBaseUrl() + path; + + String strRequest = prettyPrint(soRequest); + logMessage(NetLoggerUtil.EventType.OUT, Topic.CommInfrastructure.REST, url, strRequest); + + Entity entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON); + Map headers = createSimpleHeaders(); + + return handleResponse(outcome, url, callback -> getClient().put(callback, path, entity, headers)); + } + + protected SoRequestCll makeRequest() { + + String payload = getRequiredProperty(OperationProperties.EVENT_PAYLOAD, "event payload"); + try { + return getCoder().convert(payload, SoRequestCll.class); + } catch (CoderException e) { + throw new IllegalArgumentException("invalid payload value: " + payload, e); + } + } +} diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java index 195fbcb96..f1505ed46 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java @@ -5,6 +5,7 @@ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2020 Wipro Limited. + * Modifications Copyright (C) 2022 CTC, Inc. and others. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,5 +39,6 @@ public class SoActor extends HttpActor { addOperator(new HttpPollingOperator(NAME, VfModuleCreate.NAME, VfModuleCreate::new)); addOperator(new HttpPollingOperator(NAME, VfModuleDelete.NAME, VfModuleDelete::new)); addOperator(new HttpPollingOperator(NAME, ModifyNssi.NAME, ModifyNssi::new)); + addOperator(new HttpPollingOperator(NAME, ModifyNssi.NAME, ModifyCll::new)); } } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java new file mode 100644 index 000000000..1c8920368 --- /dev/null +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2022 CTC, Inc. and others. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.so; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; +import org.onap.policy.so.SoResponse; + +public class ModifyCllTest extends BasicSoOperation { + + private ModifyCll oper; + + + public ModifyCllTest() { + super(DEFAULT_ACTOR, ModifyCll.NAME); + } + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + oper = new ModifyCll(params, config); + } + + @Test + public void testSuccess() throws Exception { + HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT) + .path("infra/serviceIntent/v1/modify") + .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); + config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + params = params.toBuilder().retry(0).timeoutSec(50).executor(blockingExecutor).build(); + + oper = new ModifyCll(params, config); + oper.setProperty(OperationProperties.EVENT_PAYLOAD, getPayload()); + outcome = oper.start().get(); + + assertEquals(OperationResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SoResponse); + } + + @Test + public void testConstructor() { + assertEquals(DEFAULT_ACTOR, oper.getActorName()); + assertEquals(ModifyCll.NAME, oper.getName()); + assertFalse(oper.isUsePolling()); + + params = params.toBuilder().targetType(null).build(); + assertThatIllegalArgumentException().isThrownBy(() -> new ModifyCll(params, config)) + .withMessageContaining("Target information"); + } + + @Test + public void testGetPropertyNames() { + assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD)); + } + + private String getPayload() { + return ResourceUtils.getResourceAsString("src/test/resources/ModifyCll.json"); + } + + /** + * Tests makeRequest() when a property is missing. + */ + @Test + public void testMakeRequestMissingProperty() throws Exception { + oper = new ModifyCll(params, config); + + assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest()) + .withMessageContaining("missing event payload"); + } + +} diff --git a/models-interactions/model-actors/actor.so/src/test/resources/ModifyCll.json b/models-interactions/model-actors/actor.so/src/test/resources/ModifyCll.json new file mode 100644 index 000000000..03c048474 --- /dev/null +++ b/models-interactions/model-actors/actor.so/src/test/resources/ModifyCll.json @@ -0,0 +1,16 @@ +{ + "name": "cloud-leased-line-101", + "globalSubscriberId": "IBNCustomer", + "subscriptionServiceType": "IBN", + "serviceType": "CLL", + "serviceInstanceID": "cll-instance-01", + "additionalProperties": { + "modifyAction": "bandwdith", + "enableSdnc": "true", + "transportNetworks": [ + { "id": "cll-101-network-001", + "sla": + { "latency": 2, "maxBandwidth": 8000 } + }] + } +} diff --git a/models-interactions/model-actors/actor.so/src/test/resources/service.yaml b/models-interactions/model-actors/actor.so/src/test/resources/service.yaml index 81b0f2e26..11197e933 100644 --- a/models-interactions/model-actors/actor.so/src/test/resources/service.yaml +++ b/models-interactions/model-actors/actor.so/src/test/resources/service.yaml @@ -3,6 +3,7 @@ # ONAP # =============================================================================== # Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# Modifications Copyright (C) 2022 CTC, Inc. and others. # =============================================================================== # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,3 +37,5 @@ actors: path: serviceInstances/v7 Modify NSSI: path: 3gppservices/v7/modify + ModifyCloudLeasedLine: + path: infra/serviceIntent/v1/modify \ No newline at end of file -- cgit 1.2.3-korg