diff options
author | ning.xi <ning.xi@est.tech> | 2019-04-03 16:10:03 +0800 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-05 09:51:10 -0400 |
commit | bcb139f4bf3ccbf573b28cd88e91381cd0da0eaa (patch) | |
tree | dda357b15c431d21603c58db5bfdf85be22c94c1 /models-interactions/model-simulators/src/main/java | |
parent | 162cb586fe139460dd3d0404274e85b3f4ead15b (diff) |
move two modules from drools-application to models
Also removed reference to drools logging util.
Issue-ID: POLICY-1264
Change-Id: I7795f23b2b06fcb98f4099c3a6c303561a68e55f
Signed-off-by: ning.xi <ning.xi@est.tech>
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'models-interactions/model-simulators/src/main/java')
6 files changed, 703 insertions, 0 deletions
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java new file mode 100644 index 000000000..a4694b6d1 --- /dev/null +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java @@ -0,0 +1,295 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; +import java.util.UUID; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.apache.commons.io.IOUtils; +import org.onap.policy.aai.AaiNqRequest; +import org.onap.policy.aai.util.Serialization; + +@Path("/aai") +public class AaiSimulatorJaxRs { + + private static final String VSERVER = "vserver"; + private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop"; + private static final String ERROR = "error"; + private static final String GETFAIL = "getFail"; + + /** + * A&AI get query. + * + * @param vnfId the VNF Id + * @return the result + */ + @GET + @Path("/v8/network/generic-vnfs/generic-vnf/{vnfId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String aaiGetQuery(@PathParam("vnfID") final String vnfId) { + return "{\"relationship-list\": {\"relationship\":[{\"related-to-property\": [{\"property-key\": " + + "\"service-instance.service-instance-name\"}]},{\"related-to-property\": [ {\"property-key\": " + + "\"vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}"; + } + + /** + * A&AI post query. + * + * @param req the request + * @return the response + * @throws IOException if a response file cannot be read + */ + @POST + @Path("/search/named-query") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String aaiPostQuery(final String req) throws IOException { + final AaiNqRequest request = Serialization.gsonPretty.fromJson(req, AaiNqRequest.class); + + if (request.getInstanceFilters().getInstanceFilter().get(0).containsKey(VSERVER)) { + final String vserverName = + request.getInstanceFilters().getInstanceFilter().get(0).get(VSERVER).get("vserver-name"); + if (ERROR.equals(vserverName)) { + Map<String,String> params = new TreeMap<>(); + params.put("type", VSERVER); + return load("aai/AaiNqResponse-Error.json", params); + } else { + // vll format - new + // new aai response from Brian 11/13/2017 + return load("aai/AaiNqResponse-Vserver.json", new TreeMap<>()); + } + } else { + final String vnfId = + request.getInstanceFilters().getInstanceFilter().get(0).get("generic-vnf").get("vnf-id"); + if (ERROR.equals(vnfId)) { + Map<String,String> params = new TreeMap<>(); + params.put("type", "generic-vnf"); + return load("aai/AaiNqResponse-Error.json", params); + } else { + Map<String, String> params = new TreeMap<>(); + params.put("vnfId", "" + vnfId); + params.put("vnfName", getUuidValue(vnfId, "ZRDM2MMEX39")); + params.put("pnfVndName", "pnf-test-" + vnfId); + params.put("pnfVnfId", getUuidValue(params.get("pnfVndName"), "jimmy-test")); + + params.put("serviceInstanceVnfName", "service-instance-test-" + vnfId); + params.put("serviceInstanceVnfId", + getUuidValue(params.get("serviceInstanceVnfName"), "jimmy-test-vnf2")); + + return load("aai/AaiNqResponse-GenericVnf.json", params); + } + } + } + + /** + * Get by VNF name. + * + * @param vnfName the VNF name + * @return the response + */ + @GET + @Path("/v11/network/generic-vnfs/generic-vnf") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String getByVnfName(@QueryParam("vnf-name") final String vnfName) { + if (GETFAIL.equals(vnfName)) { + return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs" + + "/generic-vnf\",\"ERR.5.4.6114\"]}}}"; + } + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName); + if (ERROR.equals(vnfName)) { + return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName + + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"" + + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"" + + "ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \"" + + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \"" + + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", " + + "\"is-closed-loop-disabled\": " + isDisabled + + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \"" + + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/" + + "1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/" + + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \"" + + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \"" + + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type" + + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \"" + + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01" + + "\"} ], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name" + + "\"}]},{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/" + + "cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/" + + "USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver/3b2558f4-39d8-40e7-bfc7-30660fb52c45" + + "\", \"relationship-data\":[{ \"relationship-key\": \"cloud-region.cloud-owner\", \"" + + "relationship-value\": \"att-aic\"},{ \"relationship-key\": \"cloud-region.cloud-region-id" + + "\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"tenant.tenant-id" + + "\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"relationship-key\": \"" + + "vserver.vserver-id\", \"relationship-value\": \"3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"" + + "related-to-property\": [ {\"property-key\": \"vserver.vserver-name\",\"property-value\": \"" + + "USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}"; + + } + final String vnfId = getUuidValue(vnfName, "5e49ca06-2972-4532-9ed4-6d071588d792"); + return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName + + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"" + + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT" + + "\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \"" + + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \"" + + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", " + + "\"is-closed-loop-disabled\": " + isDisabled + + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \"" + + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer" + + "/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/" + + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \"" + + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \"" + + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type" + + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \"" + + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} ], \"" + + "related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},{ \"" + + "related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/" + + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver" + + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \"" + + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \"" + + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"" + + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"" + + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \"" + + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \"" + + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}"; + } + + /** + * Get by VNF Id. + * + * @param vnfId the VNF Id + * @return the response + */ + @GET + @Path("/v11/network/generic-vnfs/generic-vnf/{vnfId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String getByVnfId(@PathParam("vnfId") final String vnfId) { + if (GETFAIL.equals(vnfId)) { + return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/" + + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}"; + } + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId); + final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01"); + return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName + + "\", \"vnf-type\": \"RT\", \"service-id\": \"" + + "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status" + + "\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"" + + "ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345" + + "\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, " + + "\"prov-status\":\"ACTIVE\", \"" + "" + + "is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1493389458092\", \"" + + "relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link" + + "\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions" + + "/service-subscription/uCPE-VMS/service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"" + + "relationship-data\":[{ \"relationship-key\": \"customer.global-customer-id\", \"" + + "relationship-value\": \"1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"" + + "service-subscription.service-type\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key" + + "\": \"service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} " + + "], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]}," + + "{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/" + + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver" + + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \"" + + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \"" + + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"" + + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"" + + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \"" + + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \"" + + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}"; + } + + /** + * Get by VServer name. + * + * @param vserverName the VServer name + * @return the response + */ + @GET + @Path("/v11/nodes/vservers") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String getByVserverName(@QueryParam("vserver-name") final String vserverName) { + if (GETFAIL.equals(vserverName)) { + return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not" + + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}"; + } + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName); + final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8"); + return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \"" + vserverName + + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": " + + isDisabled + + ", \"prov-status\":\"ACTIVE\", \"resource-version\": \"1494001931513\", " + + "\"relationship-list\": {\"relationship\":[{ \"related-to" + + "\": \"generic-vnf\", \"related-link\": \"/aai/v11/network/generic-vnfs/generic-vnf/" + + "e1a41e99-4ede-409a-8f9d-b5e12984203a\", \"relationship-data\": [ {\"relationship-key\": \"" + + "generic-vnf.vnf-id\",\"relationship-value\": \"e1a41e99-4ede-409a-8f9d-b5e12984203a\" }], \"" + + "related-to-property\": [ {\"property-key\": \"generic-vnf.vnf-name\",\"property-value\": \"" + + "USMSO1SX7NJ0103UJSW01\" }]},{ \"related-to\": \"pserver\", \"related-link\": \"/aai/v11/" + + "cloud-infrastructure/pservers/pserver/USMSO1SX7NJ0103UJZZ01\", \"relationship-data\": [ {\"" + + "relationship-key\": \"pserver.hostname\",\"relationship-value\": \"USMSO1SX7NJ0103UJZZ01\" }], \"" + + "related-to-property\": [{\"property-key\": \"pserver.pserver-name2\"}]} ]}}]}"; + } + + private String getUuidValue(final String value, final String defaultValue) { + return value != null ? UUID.nameUUIDFromBytes(value.getBytes()).toString() : defaultValue; + } + + /** + * Loads a JSON response from a file and then replaces parameters of the form, ${xxx}, + * with values. + * + * @param fileName name of the file containing the JSON + * @param params parameters to be substituted + * @return the JSON response, after parameter substitution + * @throws IOException if the file cannot be read + */ + private String load(String fileName, Map<String, String> params) throws IOException { + String json = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8); + + // perform parameter substitution + for (Entry<String, String> ent : params.entrySet()) { + String name = "${" + ent.getKey() + "}"; + String value = ent.getValue(); + json = json.replace(name, value); + } + + return json; + } +} diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java new file mode 100644 index 000000000..e79b563df --- /dev/null +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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 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.json.JSONObject; + +@Path("/pdp/api") +public class GuardSimulatorJaxRs { + public static final String DENY_CLNAME = "denyGuard"; + + /** + * Get a guard decision. + * + * @param req the request + * @return the response + */ + @POST + @Path("/getDecision") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String getGuardDecision(String req) { + String clName = new JSONObject(req).getJSONObject("decisionAttributes").getString("clname"); + if (DENY_CLNAME.equals(clName)) { + return "{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}"; + } else { + return "{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}"; + } + } +} diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java new file mode 100644 index 000000000..1b40ae486 --- /dev/null +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdncSimulatorJaxRs.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java new file mode 100644 index 000000000..fec124782 --- /dev/null +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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 com.att.aft.dme2.internal.gson.Gson; +import java.util.UUID; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.onap.policy.so.SoRequest; +import org.onap.policy.so.SoRequestReferences; +import org.onap.policy.so.SoRequestStatus; +import org.onap.policy.so.SoResponse; + +@Path("/serviceInstantiation") +public class SoSimulatorJaxRs { + + /** + * SO post query. + * + * @param serviceInstanceId the service instance Id + * @param vnfInstanceId the VNF Id + * @return the response + */ + @POST + @Path("/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String soPostQuery(@PathParam("serviceInstanceId") final String serviceInstanceId, + @PathParam("vnfInstanceId") final String vnfInstanceId) { + final SoRequest request = new SoRequest(); + final SoRequestStatus requestStatus = new SoRequestStatus(); + requestStatus.setRequestState("COMPLETE"); + request.setRequestStatus(requestStatus); + request.setRequestId(UUID.randomUUID()); + + final SoResponse response = new SoResponse(); + + final SoRequestReferences requestReferences = new SoRequestReferences(); + final String requestId = UUID.randomUUID().toString(); + requestReferences.setRequestId(requestId); + response.setRequestReferences(requestReferences); + + response.setRequest(request); + + return new Gson().toJson(response); + } +} diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java new file mode 100644 index 000000000..99f9017a2 --- /dev/null +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.io.IOException; + +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.utils.network.NetworkUtil; + +public class Util { + public static final String AAISIM_SERVER_NAME = "aaiSim"; + 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"; + + private Util() { + // Prevent instantiation of thic class + } + + /** + * Build an A&AI simulator. + * + * @return the simulator + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an IO errror occurs + */ + public static HttpServletServer buildAaiSim() throws InterruptedException, IOException { + final HttpServletServer testServer = + HttpServletServer.factory.build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); + testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName()); + testServer.waitedStart(5000); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); + } + return testServer; + } + + /** + * 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 + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an IO errror occurs + */ + public static HttpServletServer buildSoSim() throws InterruptedException, IOException { + final HttpServletServer testServer = + HttpServletServer.factory.build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); + testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName()); + testServer.waitedStart(5000); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); + } + return testServer; + } + + /** + * Build a VFC simulator. + * + * @return the simulator + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an IO errror occurs + */ + public static HttpServletServer buildVfcSim() throws InterruptedException, IOException { + final HttpServletServer testServer = + HttpServletServer.factory.build(VFCSIM_SERVER_NAME,LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); + testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName()); + testServer.waitedStart(5000); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); + } + return testServer; + } + + /** + * Build a guard simulator. + * + * @return the simulator + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an IO errror occurs + */ + public static HttpServletServer buildGuardSim() throws InterruptedException, IOException { + HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST, + GUARDSIM_SERVER_PORT, "/", false, true); + testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName()); + testServer.waitedStart(5000); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); + } + return testServer; + } +} diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java new file mode 100644 index 000000000..836db86cc --- /dev/null +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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 javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/api/nslcm/v1") +public class VfcSimulatorJaxRs { + + /** + * VFC post query. + * + * @param nsInstanceId the NS instance + * @param response the response + * @return the response + */ + @POST + @Path("/ns/{nsInstanceId}/heal") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String vfcPostQuery(@PathParam("nsInstanceId") String nsInstanceId, + @Context final HttpServletResponse response) { + response.setStatus(HttpServletResponse.SC_ACCEPTED); + try { + response.flushBuffer(); + } catch (Exception e) { + final Logger logger = LoggerFactory.getLogger(VfcSimulatorJaxRs.class); + logger.error("flushBuffer threw: ", e); + return ""; + } + + return "{\"jobId\":\"1\"}"; + } + + /** + * VFC get query. + * + * @param jobId tthe job id + * @return the response + */ + @GET + @Path("/jobs/{jobId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String vfcGetQuery(@PathParam("jobId") String jobId) { + return "{\"jobId\" : " + jobId + + ",\"responseDescriptor\" : {\"progress\" : \"40\",\"status\" : \"finished\",\"statusDescription" + + "\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\": 101 ,\"" + + "responseHistoryList\": [{\"progress\" : \"40\",\"status\" : \"proccessing\",\"statusDescription" + + "\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"1\"}, {\"" + + "progress\" : \"41\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are " + + "decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"2\"}]}}"; + } + +} + |