diff options
author | krishnaa96 <krishna.moorthy6@wipro.com> | 2020-08-26 14:59:04 +0530 |
---|---|---|
committer | krishnaa96 <krishna.moorthy6@wipro.com> | 2020-09-01 19:00:35 +0530 |
commit | 0690ef13433cb30d3d6c475990a818a714f0538d (patch) | |
tree | bb0ec20c49777f224057b2bb929b64aa79c6b456 /models-interactions/model-actors | |
parent | b13f57c283bf7e90db88e159d0e3e8bd6ba6f698 (diff) |
Add Modify NSSI operation in SO actor
Issue-ID: POLICY-2586
Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com>
Change-Id: I6ac184a6e731767f06401a0ac984c6b448c5d82f
Diffstat (limited to 'models-interactions/model-actors')
12 files changed, 273 insertions, 16 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyNssi.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyNssi.java new file mode 100644 index 000000000..69d11fd14 --- /dev/null +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/ModifyNssi.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * 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.SoRequest3gpp; + +public class ModifyNssi extends SoOperation { + public static final String NAME = "Modify NSSI"; + + private static final List<String> PROPERTY_NAMES = List.of( + OperationProperties.AAI_SERVICE, + OperationProperties.EVENT_PAYLOAD); + + /** + * Constructs the object. + * + * @param params operation parameters + * @param config configuration for this operation + */ + public ModifyNssi(ControlLoopOperationParams params, HttpPollingConfig config) { + super(params, config, PROPERTY_NAMES); + } + + @Override + protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { + + SoRequest3gpp soRequest = makeRequest(); + + String path = getPath(); + String url = getClient().getBaseUrl() + path; + + String strRequest = prettyPrint(soRequest); + logMessage(NetLoggerUtil.EventType.OUT, Topic.CommInfrastructure.REST, url, strRequest); + + Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON); + Map<String, Object> headers = createSimpleHeaders(); + + return handleResponse(outcome, url, callback -> getClient().put(callback, path, entity, headers)); + } + + private SoRequest3gpp makeRequest() { + + Map<String, Object> payload = params.getPayload(); + + try { + return getCoder().convert(payload, SoRequest3gpp.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 a6619710e..195fbcb96 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 @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,5 +37,6 @@ public class SoActor extends HttpActor<HttpPollingActorParams> { addOperator(new HttpPollingOperator(NAME, VfModuleCreate.NAME, VfModuleCreate::new)); addOperator(new HttpPollingOperator(NAME, VfModuleDelete.NAME, VfModuleDelete::new)); + addOperator(new HttpPollingOperator(NAME, ModifyNssi.NAME, ModifyNssi::new)); } } diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java index 8a0cb703b..ac25c841e 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,13 +76,16 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { public static final String REQ_PARAM_NM = "requestParameters"; public static final String CONFIG_PARAM_NM = "configurationParameters"; - // values extracted from the parameter Target + /* Values extracted from the parameter Target. These fields are required by any + subclasses that make use of prepareSoModelInfo(). + */ private final String modelCustomizationId; private final String modelInvariantId; private final String modelVersionId; private final String modelName; private final String modelVersion; + private final String vfCountKey; @@ -95,25 +99,45 @@ public abstract class SoOperation extends HttpOperation<SoResponse> { public SoOperation(ControlLoopOperationParams params, HttpPollingConfig config, List<String> propertyNames) { super(params, config, SoResponse.class, propertyNames); - setUsePolling(); + this.modelCustomizationId = null; + this.modelInvariantId = null; + this.modelVersionId = null; + this.modelVersion = null; + this.modelName = null; + this.vfCountKey = null; verifyNotNull("Target information", params.getTargetType()); + } - verifyNotNull("Target entity Ids information", params.getTargetEntityIds()); + /** + * Constructs the object. + * + * @param params operation parameters + * @param config configuration for this operation + * @param propertyNames names of properties required by this operation + * @param targetEntityIds Target Entity information + */ + public SoOperation(ControlLoopOperationParams params, HttpPollingConfig config, List<String> propertyNames, + Map<String, String> targetEntityIds) { + super(params, config, SoResponse.class, propertyNames); - this.modelCustomizationId = params.getTargetEntityIds() + verifyNotNull("Target entity Ids information", targetEntityIds); + + this.modelCustomizationId = targetEntityIds .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID); - this.modelInvariantId = params.getTargetEntityIds() + this.modelInvariantId = targetEntityIds .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_INVARIANT_ID); - this.modelVersionId = params.getTargetEntityIds() + this.modelVersionId = targetEntityIds .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION_ID); - this.modelVersion = params.getTargetEntityIds() + this.modelVersion = targetEntityIds .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_VERSION); - this.modelName = params.getTargetEntityIds() + this.modelName = targetEntityIds .get(ControlLoopOperationParams.PARAMS_ENTITY_MODEL_NAME); - vfCountKey = SoConstants.VF_COUNT_PREFIX + "[" + modelCustomizationId + "][" + modelInvariantId + "][" - + modelVersionId + "]"; + this.vfCountKey = SoConstants.VF_COUNT_PREFIX + "[" + modelCustomizationId + "][" + modelInvariantId + "][" + + modelVersionId + "]"; + + verifyNotNull("Target information", params.getTargetType()); } @Override diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java index 7e95bda03..af06c9184 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,8 +79,9 @@ public class VfModuleCreate extends SoOperation { * @param config configuration for this operation */ public VfModuleCreate(ControlLoopOperationParams params, HttpPollingConfig config) { - super(params, config, PROPERTY_NAMES); + super(params, config, PROPERTY_NAMES, params.getTargetEntityIds()); + setUsePolling(); // ensure we have the necessary parameters validateTarget(); } diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java index 0ff833c59..f35cdb4e1 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +85,9 @@ public class VfModuleDelete extends SoOperation { * @param config configuration for this operation */ public VfModuleDelete(ControlLoopOperationParams params, HttpPollingConfig config) { - super(params, config, PROPERTY_NAMES); + super(params, config, PROPERTY_NAMES, params.getTargetEntityIds()); + + setUsePolling(); // ensure we have the necessary parameters validateTarget(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java new file mode 100644 index 000000000..21d7229a3 --- /dev/null +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * 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.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Map; +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.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +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 ModifyNssiTest extends BasicSoOperation { + + private ModifyNssi oper; + + private static StandardCoder coder = new StandardCoder(); + + public ModifyNssiTest() { + super(DEFAULT_ACTOR, ModifyNssi.NAME); + } + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + + @Before + public void setUp() throws Exception { + super.setUp(); + oper = new ModifyNssi(params, config); + } + + @Test + public void testSuccess() throws Exception { + HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT) + .path("3gppservices/v7/modify").pollPath("orchestrationRequests/v5/") + .maxPolls(2).build(); + config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + + oper = new ModifyNssi(params, config); + + outcome = oper.start().get(); + + assertEquals(OperationResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SoResponse); + } + + @Test + public void testConstructor() { + assertEquals(DEFAULT_ACTOR, oper.getActorName()); + assertEquals(ModifyNssi.NAME, oper.getName()); + assertFalse(oper.isUsePolling()); + + params = params.toBuilder().targetType(null).build(); + assertThatIllegalArgumentException().isThrownBy(() -> new ModifyNssi(params, config)) + .withMessageContaining("Target information"); + } + + @Test + public void testGetPropertyNames() { + assertThat(oper.getPropertyNames()).isEqualTo( + List.of( + OperationProperties.AAI_SERVICE, + OperationProperties.EVENT_PAYLOAD)); + } + + @Override + protected Map<String, Object> makePayload() { + String payloadString = ResourceUtils + .getResourceAsString("src/test/resources/ModifyNSSI.json"); + + try { + return coder.decode(payloadString, Map.class); + } catch (CoderException e) { + throw new IllegalArgumentException("invalid payload value: " + payloadString, e); + } + } +} diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java index b42b3f8dd..79b9944d3 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java @@ -5,6 +5,7 @@ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2018-2020 AT&T. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +37,8 @@ public class SoActorTest extends BasicActor { SoActor prov = new SoActor(); // verify that it has the operators we expect - var expected = Arrays.asList(VfModuleCreate.NAME, VfModuleDelete.NAME).stream().sorted() - .collect(Collectors.toList()); + var expected = Arrays.asList(VfModuleCreate.NAME, VfModuleDelete.NAME, ModifyNssi.NAME).stream() + .sorted().collect(Collectors.toList()); var actual = prov.getOperationNames().stream().sorted().collect(Collectors.toList()); assertEquals(expected.toString(), actual.toString()); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index 464e5d162..e9a49545e 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +82,7 @@ public class SoOperationTest extends BasicSoOperation { initConfig(); - oper = new SoOperation(params, config, PROP_NAMES) {}; + oper = new SoOperation(params, config, PROP_NAMES, params.getTargetEntityIds()) {}; } @Test @@ -89,7 +90,6 @@ public class SoOperationTest extends BasicSoOperation { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(DEFAULT_OPERATION, oper.getName()); assertSame(config, oper.getConfig()); - assertTrue(oper.isUsePolling()); // check when Target is null params = params.toBuilder().targetType(null).build(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java index f1741d677..9d4d00908 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +63,8 @@ import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; public class VfModuleCreateTest extends BasicSoOperation { + + private static final String MODEL_NAME2 = "my-model-name-B"; private static final String MODEL_VERS2 = "my-model-version-B"; private static final String SVC_INSTANCE_ID = "my-service-instance-id"; @@ -158,6 +161,7 @@ public class VfModuleCreateTest extends BasicSoOperation { public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(VfModuleCreate.NAME, oper.getName()); + assertTrue(oper.isUsePolling()); // verify that target validation is done params = params.toBuilder().targetType(null).build(); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java index 2ab1dbe83..300d73b53 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -179,6 +180,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(VfModuleDelete.NAME, oper.getName()); + assertTrue(oper.isUsePolling()); // verify that target validation is done params = params.toBuilder().targetType(null).build(); diff --git a/models-interactions/model-actors/actor.so/src/test/resources/ModifyNSSI.json b/models-interactions/model-actors/actor.so/src/test/resources/ModifyNSSI.json new file mode 100644 index 000000000..50dbbcbec --- /dev/null +++ b/models-interactions/model-actors/actor.so/src/test/resources/ModifyNSSI.json @@ -0,0 +1,19 @@ +{ + "name": "eMBB-001", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "networkType": "an", + "serviceInstanceID": "02328c27-bb1a-4b0d-a437-111dc7087665", + "additionalProperties": { + "modifyAction": "allocate", + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "", + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + } +} 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 e16e7d74a..81b0f2e26 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 @@ -34,3 +34,5 @@ actors: path: serviceInstantiation/v7/serviceInstances VF Module Delete: path: serviceInstances/v7 + Modify NSSI: + path: 3gppservices/v7/modify |