diff options
author | Vidyashree Rama <vidyashree.rama@huawei.com> | 2018-10-18 11:45:52 +0530 |
---|---|---|
committer | Vidyashree Rama <vidyashree.rama@huawei.com> | 2018-10-23 18:28:01 +0530 |
commit | b9007182f9a8fa0dea48fc970e38fb6761bf6c24 (patch) | |
tree | 8acc33b3aab928e3b7e1d4db7baee7c5ee4135af /controlloop/common | |
parent | ecffd0e5dfe112bcc69ee420848bbc476571637c (diff) |
Add CCVPN policy
CCVPN policy
Issue-ID: POLICY-1209
Change-Id: I8adea233f8672c9ff43b4a169b50336d9e43c91d
Signed-off-by: Vidyashree Rama <vidyashree.rama@huawei.com>
Diffstat (limited to 'controlloop/common')
4 files changed, 119 insertions, 0 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index 980799171..5abfca47b 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -356,6 +356,11 @@ public class ControlLoopOperationManager implements Serializable { // Cast VFC response and handle it // return onResponse((VFCResponse) response); + } else if (response instanceof SdncResponse) { + // + // Cast SDNC response and handle it + // + return onResponse((SdncResponse) response); } else { return null; } @@ -583,6 +588,36 @@ public class ControlLoopOperationManager implements Serializable { } /** + * This method handles operation responses from SDNC. + * + * @param sdncResponse the VFC response + * @return The result of the response handling + */ + private PolicyResult onResponse(SdncResponse sdncResponse) { + if ("200".equals(sdncResponse.getResponseOutput().getResponseCode())) { + // + // Consider it as success + // + this.completeOperation(this.attempts, " Success", PolicyResult.SUCCESS); + if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) { + return null; + } + return PolicyResult.SUCCESS; + } else { + // + // Consider it as failure + // + this.completeOperation(this.attempts, " Failed", PolicyResult.FAILURE); + if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) { + return null; + } + // increment operation attempts for retries + this.attempts += 1; + return PolicyResult.FAILURE; + } + } + + /** * Get the operation timeout. * * @return the timeout diff --git a/controlloop/common/simulators/pom.xml b/controlloop/common/simulators/pom.xml index 3eabd6391..5259890ca 100644 --- a/controlloop/common/simulators/pom.xml +++ b/controlloop/common/simulators/pom.xml @@ -68,5 +68,10 @@ <artifactId>gson</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> + <artifactId>sdnc</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project> diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java new file mode 100644 index 000000000..47bdf01ed --- /dev/null +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2018 Huawei. 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.simulators; + +import java.util.UUID; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + + +import org.onap.policy.sdnc.SdncResponse; +import org.onap.policy.sdnc.SdncResponseOutput; +import org.onap.policy.sdnc.util.Serialization; + + +@Path("/restconf/operations/") +public class SdncSimulatorJaxRs { + + /** + * SDNC post query. + * + * @return the response + */ + @POST + @Path("/GENERIC-RESOURCE-API:network-topology-operation") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String sdncPostQuery() { + final SdncResponse response = new SdncResponse(); + response.setRequestId(UUID.randomUUID().toString()); + SdncResponseOutput responseOutput = new SdncResponseOutput(); + responseOutput.setResponseCode("200"); + responseOutput.setAckFinalIndicator("Y"); + responseOutput.setSvcRequestId(UUID.randomUUID().toString()); + response.setResponseOutput(responseOutput); + return Serialization.gsonPretty.toJson(response); + } +} diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java index 16ae615af..1de77638b 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -30,11 +30,13 @@ public class Util { public static final String SOSIM_SERVER_NAME = "soSim"; public static final String VFCSIM_SERVER_NAME = "vfcSim"; public static final String GUARDSIM_SERVER_NAME = "guardSim"; + public static final String SDNCSIM_SERVER_NAME = "sdncSim"; public static final int AAISIM_SERVER_PORT = 6666; public static final int SOSIM_SERVER_PORT = 6667; public static final int VFCSIM_SERVER_PORT = 6668; public static final int GUARDSIM_SERVER_PORT = 6669; + public static final int SDNCSIM_SERVER_PORT = 6670; private static final String CANNOT_CONNECT = "cannot connect to port "; private static final String LOCALHOST = "localhost"; @@ -62,6 +64,25 @@ public class Util { } /** + * Build an SDNC simulator. + * + * @return the simulator + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an IO errror occurs + */ + public static HttpServletServer buildSdncSim() throws InterruptedException, IOException { + final HttpServletServer testServer = + HttpServletServer.factory.build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true); + testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName()); + testServer.waitedStart(5000); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); + } + return testServer; + } + + + /** * Build an SO simulator. * * @return the simulator |