From f95ba842b148c6f31ca528a2e22498ee2885ad47 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Mon, 8 Apr 2019 17:11:37 -0400 Subject: [PATCH] Code changes for OOF SON Use Case Companian review to https://gerrit.onap.org/r/#/c/84361/ Issue-ID: POLICY-1463 Change-Id: I2640f01c07890a4b1e8938175b637b84dcc19f3c Signed-off-by: Pamela Dragosh --- .../actor/sdnr/SdnrActorServiceProvider.java | 37 +++++- .../actor/sdnr/SdnrActorServiceProviderTest.java | 30 ++++- .../policy/controlloop/ControlLoopResponse.java | 143 +++++++++++++++++++++ .../controlloop/ControlLoopResponseTest.java | 66 ++++++++++ 4 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopResponse.java create mode 100644 models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopResponseTest.java diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java index 24db0bd3e..32346bfa2 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java @@ -3,7 +3,7 @@ * SdnrActorServiceProvider * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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. @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.List; import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.ControlLoopResponse; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.policy.Policy; @@ -69,6 +70,7 @@ public class SdnrActorServiceProvider implements Actor { // Strings for recipes private static final String RECIPE_MODIFY = "ModifyConfig"; + private static final String RECIPE_MODIFY_ANR = "ModifyConfigANR"; /* To be used in future releases when pci ModifyConfig is used */ private static final String SDNR_REQUEST_PARAMS = "request-parameters"; @@ -253,4 +255,37 @@ public class SdnrActorServiceProvider implements Actor { } return new SdnrActorServiceProvider.Pair<>(result, message); } + + /** + * Converts the SDNR response to ControlLoopResponse object. + * + * @param dmaapResponse + * the dmaap wrapper message that contains the actual SDNR reponse + * inside the body field + * + * @return a ControlLoopResponse object to send to DCAE_CL_RSP topic + */ + public static ControlLoopResponse getControlLoopResponse(PciResponseWrapper dmaapResponse, + VirtualControlLoopEvent event) { + + logger.info("SDNR getClosedLoopResponse called : {} {}", dmaapResponse, event); + + /* The actual SDNR response is inside the wrapper's body field. */ + PciResponse sdnrResponse = dmaapResponse.getBody(); + + /* The ControlLoop response determined from the SDNR Response and input event. */ + ControlLoopResponse clRsp = new ControlLoopResponse(); + clRsp.setPayload(sdnrResponse.getPayload()); + clRsp.setFrom("SDNR"); + clRsp.setTarget("DCAE"); + clRsp.setClosedLoopControlName(event.getClosedLoopControlName()); + clRsp.setPolicyName(event.getPolicyName()); + clRsp.setPolicyVersion(event.getPolicyVersion()); + clRsp.setRequestId(event.getRequestId()); + clRsp.setVersion(event.getVersion()); + logger.info("SDNR getClosedLoopResponse clRsp : {}", clRsp); + + return clRsp; + } + } diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java index 226c3da47..265aea341 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java @@ -2,7 +2,7 @@ * SdnrActorServiceProviderTest * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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. @@ -31,6 +31,7 @@ import java.util.UUID; import org.junit.Test; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.ControlLoopResponse; import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.policy.Policy; @@ -38,6 +39,7 @@ import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.TargetType; import org.onap.policy.sdnr.PciRequest; import org.onap.policy.sdnr.PciResponse; +import org.onap.policy.sdnr.PciResponseWrapper; import org.onap.policy.sdnr.util.Serialization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,6 +89,32 @@ public class SdnrActorServiceProviderTest { policy.setPayload(null); policy.setRetry(2); policy.setTimeout(300); + + } + + @Test + public void getControlLoopResponseTest() { + PciRequest sdnrRequest; + sdnrRequest = SdnrActorServiceProvider.constructRequest(onsetEvent, operation, policy).getBody(); + PciResponse sdnrResponse = new PciResponse(sdnrRequest); + sdnrResponse.getStatus().setCode(200); + sdnrResponse.getStatus().setValue("SDNR success"); + sdnrResponse.setPayload("sdnr payload "); + /* Print out request as json to make sure serialization works */ + String jsonResponse = Serialization.gsonPretty.toJson(sdnrResponse); + logger.info(jsonResponse); + PciResponseWrapper pciResponseWrapper = new PciResponseWrapper(); + pciResponseWrapper.setBody(sdnrResponse); + + ControlLoopResponse clRsp = SdnrActorServiceProvider.getControlLoopResponse(pciResponseWrapper, onsetEvent); + assertEquals(clRsp.getClosedLoopControlName(), onsetEvent.getClosedLoopControlName()); + assertEquals(clRsp.getRequestId(), onsetEvent.getRequestId()); + assertEquals(clRsp.getPolicyName(), onsetEvent.getPolicyName()); + assertEquals(clRsp.getPolicyVersion(), onsetEvent.getPolicyVersion()); + assertEquals(clRsp.getVersion(), onsetEvent.getVersion()); + assertEquals(clRsp.getFrom(), "SDNR"); + assertEquals(clRsp.getTarget(), "DCAE"); + assertEquals(clRsp.getPayload(), sdnrResponse.getPayload()); } @Test diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopResponse.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopResponse.java new file mode 100644 index 000000000..a73d47744 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopResponse.java @@ -0,0 +1,143 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2019 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.UUID; + +public class ControlLoopResponse implements Serializable { + + private static final long serialVersionUID = 2391252138583119195L; + + @SerializedName("closedLoopControlName") + private String closedLoopControlName; + + @SerializedName("version") + private String version = "1.0.0"; + + @SerializedName("requestID") + private UUID requestId; + + @SerializedName("target") + private String target; + + @SerializedName("from") + private String from; + + @SerializedName("policyName") + private String policyName; + + @SerializedName("policyVersion") + private String policyVersion; + + @SerializedName("payload") + private String payload; + + public ControlLoopResponse() { + + } + + /** + * Construct an instace from an existing instance. + * + * @param response + * the existing instance + */ + public ControlLoopResponse(ControlLoopResponse response) { + if (response == null) { + return; + } + this.closedLoopControlName = response.closedLoopControlName; + this.requestId = response.requestId; + this.target = response.target; + this.from = response.from; + this.policyName = response.policyName; + this.policyVersion = response.policyVersion; + this.payload = response.payload; + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopResponseTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopResponseTest.java new file mode 100644 index 000000000..b0f64eb0f --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopResponseTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2019 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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; + +import static org.junit.Assert.assertEquals; + +import java.util.UUID; +import org.junit.Test; + +public class ControlLoopResponseTest { + + @Test + public void test() { + ControlLoopResponse rsp = new ControlLoopResponse(); + + assertEquals("1.0.0", rsp.getVersion()); + + rsp = new ControlLoopResponse(null); + assertEquals("1.0.0", rsp.getVersion()); + + rsp.setClosedLoopControlName("name"); + assertEquals("name", rsp.getClosedLoopControlName()); + + rsp.setFrom("from"); + assertEquals("from", rsp.getFrom()); + + rsp.setPayload("payload"); + assertEquals("payload", rsp.getPayload()); + + rsp.setPolicyName("policyname"); + assertEquals("policyname", rsp.getPolicyName()); + + rsp.setPolicyVersion("1"); + assertEquals("1", rsp.getPolicyVersion()); + + UUID id = UUID.randomUUID(); + rsp.setRequestId(id); + assertEquals(id, rsp.getRequestId()); + + rsp.setTarget("target"); + assertEquals("target", rsp.getTarget()); + + rsp.setVersion("foo"); + assertEquals("foo", rsp.getVersion()); + + } +} -- 2.16.6