From 7d7f8664785f7b3b8cc220716ce90882a53f6b6c Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Fri, 31 Mar 2017 16:17:57 -0400 Subject: [SDNC-5] Rebase sdnc-plugins Port to OpenDaylight Boron and sync updates since 16.10 Change-Id: Ie55f9ae53eb814d65eafb92aada5721f9b0554e8 Signed-off-by: Dan Timoney --- README.md | 1 - pom.xml | 2 +- .../features/src/main/resources/features.xml | 2 +- .../src/assembly/assemble_installer_zip.xml | 2 +- .../src/assembly/assemble_mvnrepo_zip.xml | 2 +- .../src/main/resources/scripts/install-feature.sh | 2 +- .../org/openecomp/sdnc/prop/PropertiesNode.java | 2 +- .../META-INF/spring/properties-node-context.xml | 2 +- .../spring/properties-node-osgi-context.xml | 2 +- .../features/src/main/resources/features.xml | 2 +- .../src/assembly/assemble_installer_zip.xml | 2 +- .../src/assembly/assemble_mvnrepo_zip.xml | 2 +- .../src/main/resources/scripts/install-feature.sh | 2 +- .../org/openecomp/sdnc/restapicall/JsonParser.java | 2 +- .../sdnc/restapicall/RestapiCallNode.java | 175 ++++++++++++++++++--- .../openecomp/sdnc/restapicall/RetryException.java | 30 ++++ .../openecomp/sdnc/restapicall/RetryPolicy.java | 59 +++++++ .../sdnc/restapicall/RetryPolicyStore.java | 54 +++++++ .../openecomp/sdnc/restapicall/XmlJsonUtil.java | 2 +- .../org/openecomp/sdnc/restapicall/XmlParser.java | 2 +- .../META-INF/spring/restapi-call-node-context.xml | 13 +- .../spring/restapi-call-node-osgi-context.xml | 2 +- .../src/main/resources/northbound-api-template.xml | 4 +- .../openecomp/sdnc/restapicall/TestJsonParser.java | 2 +- .../sdnc/restapicall/TestRestapiCallNode.java | 2 +- .../sdnc/restapicall/TestXmlJsonUtil.java | 6 +- .../openecomp/sdnc/restapicall/TestXmlParser.java | 2 +- .../provider/src/test/resources/test.xml | 2 +- .../provider/src/test/resources/test3.xml | 2 +- 29 files changed, 330 insertions(+), 54 deletions(-) create mode 100644 restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryException.java create mode 100644 restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicy.java create mode 100644 restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicyStore.java diff --git a/README.md b/README.md index fe9a514..bd17a23 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,3 @@ To compile this code: 2. To compile, run "mvn clean install". - diff --git a/pom.xml b/pom.xml index 768fc76..e6edd15 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.openecomp.sdnc.core root - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 4.0.0 diff --git a/properties-node/features/src/main/resources/features.xml b/properties-node/features/src/main/resources/features.xml index 1137b6a..2608ec5 100644 --- a/properties-node/features/src/main/resources/features.xml +++ b/properties-node/features/src/main/resources/features.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/properties-node/installer/src/assembly/assemble_installer_zip.xml b/properties-node/installer/src/assembly/assemble_installer_zip.xml index 0ce9b1a..728afca 100644 --- a/properties-node/installer/src/assembly/assemble_installer_zip.xml +++ b/properties-node/installer/src/assembly/assemble_installer_zip.xml @@ -3,7 +3,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml b/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml index ba21dda..c14f8ae 100644 --- a/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -3,7 +3,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/properties-node/installer/src/main/resources/scripts/install-feature.sh b/properties-node/installer/src/main/resources/scripts/install-feature.sh index 33e9b03..93236c5 100644 --- a/properties-node/installer/src/main/resources/scripts/install-feature.sh +++ b/properties-node/installer/src/main/resources/scripts/install-feature.sh @@ -5,7 +5,7 @@ # openECOMP : SDN-C # ================================================================================ # Copyright (C) 2017 AT&T Intellectual Property. All rights -# reserved. +# reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java b/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java index 3026a84..0c58db3 100644 --- a/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java +++ b/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml index 368e58a..0c793f0 100644 --- a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml +++ b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml index 19b7fde..715e094 100644 --- a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml +++ b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/restapi-call-node/features/src/main/resources/features.xml b/restapi-call-node/features/src/main/resources/features.xml index 882bfdf..0407e5e 100644 --- a/restapi-call-node/features/src/main/resources/features.xml +++ b/restapi-call-node/features/src/main/resources/features.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/restapi-call-node/installer/src/assembly/assemble_installer_zip.xml b/restapi-call-node/installer/src/assembly/assemble_installer_zip.xml index 0ce9b1a..728afca 100644 --- a/restapi-call-node/installer/src/assembly/assemble_installer_zip.xml +++ b/restapi-call-node/installer/src/assembly/assemble_installer_zip.xml @@ -3,7 +3,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/restapi-call-node/installer/src/assembly/assemble_mvnrepo_zip.xml b/restapi-call-node/installer/src/assembly/assemble_mvnrepo_zip.xml index ba21dda..c14f8ae 100644 --- a/restapi-call-node/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/restapi-call-node/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -3,7 +3,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/restapi-call-node/installer/src/main/resources/scripts/install-feature.sh b/restapi-call-node/installer/src/main/resources/scripts/install-feature.sh index 33e9b03..93236c5 100644 --- a/restapi-call-node/installer/src/main/resources/scripts/install-feature.sh +++ b/restapi-call-node/installer/src/main/resources/scripts/install-feature.sh @@ -5,7 +5,7 @@ # openECOMP : SDN-C # ================================================================================ # Copyright (C) 2017 AT&T Intellectual Property. All rights -# reserved. +# reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/JsonParser.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/JsonParser.java index c03191a..125d45a 100644 --- a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/JsonParser.java +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/JsonParser.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RestapiCallNode.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RestapiCallNode.java index d6d3529..c412612 100644 --- a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RestapiCallNode.java +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RestapiCallNode.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ package org.openecomp.sdnc.restapicall; import java.io.FileInputStream; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; import java.security.KeyStore; @@ -31,6 +32,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import javax.net.ssl.HostnameVerifier; @@ -40,10 +42,12 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriBuilder; import org.openecomp.sdnc.sli.SvcLogicContext; import org.openecomp.sdnc.sli.SvcLogicException; import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,12 +65,61 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { private String uebServers; private String defaultUebTemplateFileName = "/opt/bvc/restapi/templates/default-ueb-message.json"; + public RetryPolicyStore retryPolicyStore; + public RetryPolicyStore getRetryPolicyStore() { + return retryPolicyStore; + } + + public void setRetryPolicyStore(RetryPolicyStore retryPolicyStore) { + this.retryPolicyStore = retryPolicyStore; + } + + public RestapiCallNode() { + + } + + /** + * Allows Directed Graphs the ability to interact with REST APIs. + * @param parameters HashMap of parameters passed by the DG to this function + * + * + * + * + * + * + * + * + * + * + * + * vpn-information.vrf-details + * + * + * + * + * + * + *
parameterMandatory/Optionaldescriptionexample values
templateFileNameOptionalfull path to template file that can be used to build a request/sdncopt/bvc/restapi/templates/vnf_service-configuration-operation_minimal.json
restapiUrlMandatoryurl to send the request tohttps://sdncodl:8543/restconf/operations/L3VNF-API:create-update-vnf-request
restapiUserOptionaluser name to use for http basic authenticationsdnc_ws
restapiPasswordOptionalunencrypted password to use for http basic authenticationplain_password
contentTypeOptionalhttp content type to set in the http headerusually application/json or application/xml
formatOptionalshould match request body formatjson or xml
httpMethodOptionalhttp method to use when sending the requestget post put delete patch
responsePrefixOptionallocation the response will be written to in context memorytmp.restapi.result
listName[i]OptionalUsed for processing XML responses with repeating elements.
skipSendingOptionaltrue or false
convertResponse Optionalwhether the response should be convertedtrue or false
customHttpHeadersOptionala list additional http headers to be passed in, follow the format in the exampleX-CSI-MessageId=messageId,headerFieldName=headerFieldValue
dumpHeadersOptionalwhen true writes http header content to context memorytrue or false
partnerOptionalneeded for DME2 callsdme2proxy
+ * @param ctx Reference to context memory + * @throws SvcLogicException + * @since 11.0.2 + * @see String#split(String, int) + */ public void sendRequest(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { + sendRequest(paramMap, ctx, null); + } + + public void sendRequest(Map paramMap, SvcLogicContext ctx, Integer retryCount) + throws SvcLogicException { + + RetryPolicy retryPolicy = null; HttpResponse r = null; try { Param p = getParameters(paramMap); - + if (p.partner != null) { + retryPolicy = retryPolicyStore.getRetryPolicy(p.partner); + } String pp = p.responsePrefix != null ? p.responsePrefix + '.' : ""; String req = null; @@ -77,6 +130,12 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { r = sendHttpRequest(req, p); setResponseStatus(ctx, p.responsePrefix, r); + if (p.dumpHeaders && r.headers != null) { + for (Entry> a : r.headers.entrySet()) { + ctx.setAttribute(pp + "header." + a.getKey(), StringUtils.join(a.getValue(), ",")); + } + } + if (r.body != null && r.body.trim().length() > 0) { ctx.setAttribute(pp + "httpResponse", r.body); @@ -93,13 +152,48 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { } } } catch (Exception e) { - log.error("Error sending the request: " + e.getMessage(), e); + boolean shouldRetry = false; + if (e.getCause() instanceof java.net.SocketException) { + shouldRetry = true; + } - r = new HttpResponse(); - r.code = 500; - r.message = e.getMessage(); + log.error("Error sending the request: " + e.getMessage(), e); String prefix = parseParam(paramMap, "responsePrefix", false, null); - setResponseStatus(ctx, prefix, r); + if (retryPolicy == null || shouldRetry == false) { + setFailureResponseStatus(ctx, prefix, e.getMessage(), r); + } else { + if (retryCount == null) { + retryCount = 0; + } + String retryMessage = retryCount + " attempts were made out of " + retryPolicy.getMaximumRetries() + + " maximum retries."; + log.debug(retryMessage); + try { + retryCount = retryCount + 1; + if (retryCount < retryPolicy.getMaximumRetries() + 1) { + URI uri = new URI(paramMap.get("restapiUrl")); + String hostname = uri.getHost(); + String retryString = retryPolicy.getNextHostName((uri.toString())); + URI uriTwo = new URI(retryString); + URI retryUri = UriBuilder.fromUri(uri).host(uriTwo.getHost()).port(uriTwo.getPort()).scheme( + uriTwo.getScheme()).build(); + paramMap.put("restapiUrl", retryUri.toString()); + log.debug("URL was set to " + retryUri.toString()); + log.debug("Failed to communicate with host " + hostname + + ". Request will be re-attempted using the host " + retryString + "."); + log.debug("This is retry attempt " + retryCount + " out of " + retryPolicy.getMaximumRetries()); + sendRequest(paramMap, ctx, retryCount); + } else { + log.debug("Maximum retries reached, calling setFailureResponseStatus."); + setFailureResponseStatus(ctx, prefix, e.getMessage(), r); + } + } catch (Exception ex) { + log.error("Could not attempt retry.", ex); + String retryErrorMessage = + "Retry attempt has failed. No further retry shall be attempted, calling setFailureResponseStatus."; + setFailureResponseStatus(ctx, prefix, retryErrorMessage, r); + } + } } if (r != null && r.code >= 300) @@ -110,8 +204,9 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { Param p = new Param(); p.templateFileName = parseParam(paramMap, "templateFileName", false, null); p.restapiUrl = parseParam(paramMap, "restapiUrl", true, null); - p.restapiUser = parseParam(paramMap, "restapiUser", true, null); - p.restapiPassword = parseParam(paramMap, "restapiPassword", true, null); + p.restapiUser = parseParam(paramMap, "restapiUser", false, null); + p.restapiPassword = parseParam(paramMap, "restapiPassword", false, null); + p.contentType = parseParam(paramMap, "contentType", false, null); p.format = Format.fromString(parseParam(paramMap, "format", false, "json")); p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); @@ -125,6 +220,9 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { p.keyStorePassword = parseParam(paramMap, "keyStorePassword", false, null); p.ssl = p.trustStoreFileName != null && p.trustStorePassword != null && p.keyStoreFileName != null && p.keyStorePassword != null; + p.customHttpHeaders = parseParam(paramMap, "customHttpHeaders", false, null); + p.partner = parseParam(paramMap, "partner", false, null); + p.dumpHeaders = Boolean.valueOf(parseParam(paramMap, "dumpHeaders", false, null)); return p; } @@ -179,6 +277,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { public String restapiUser; public String restapiPassword; public Format format; + public String contentType; public HttpMethod httpMethod; public String responsePrefix; public Set listNameList; @@ -189,9 +288,12 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { public String trustStoreFileName; public String trustStorePassword; public boolean ssl; + public String customHttpHeaders; + public String partner; + public Boolean dumpHeaders; } - private static enum Format { + protected static enum Format { JSON, XML; public static Format fromString(String s) { @@ -206,7 +308,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { } private static enum HttpMethod { - GET, POST, PUT, DELETE; + GET, POST, PUT, DELETE, PATCH; public static HttpMethod fromString(String s) { if (s == null) @@ -219,11 +321,13 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { return PUT; if (s.equalsIgnoreCase("delete")) return DELETE; + if (s.equalsIgnoreCase("patch")) + return PATCH; throw new IllegalArgumentException("Invalid value for HTTP Method: " + s); } } - private String buildXmlJsonRequest(SvcLogicContext ctx, String template, Format format) { + protected String buildXmlJsonRequest(SvcLogicContext ctx, String template, Format format) { log.info("Building " + format + " started"); long t1 = System.currentTimeMillis(); @@ -345,7 +449,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { return expandRepeats(ctx, newTemplate.toString(), level + 1); } - private String readFile(String fileName) throws Exception { + protected String readFile(String fileName) throws Exception { byte[] encoded = Files.readAllBytes(Paths.get(fileName)); return new String(encoded, "UTF-8"); } @@ -372,7 +476,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { Client client = Client.create(config); client.setConnectTimeout(5000); - client.addFilter(new HTTPBasicAuthFilter(p.restapiUser, p.restapiPassword)); + if (p.restapiUser != null) + client.addFilter(new HTTPBasicAuthFilter(p.restapiUser, p.restapiPassword)); WebResource webResource = client.resource(p.restapiUrl); log.info("Sending request:"); @@ -385,16 +490,24 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { if (!p.skipSending) { String tt = p.format == Format.XML ? "application/xml" : "application/json"; String tt1 = tt + ";charset=UTF-8"; + if (p.contentType != null) { + tt = p.contentType; + tt1 = p.contentType; + } - ClientResponse response = null; - if (p.httpMethod == HttpMethod.GET) - response = webResource.accept(tt).type(tt1).get(ClientResponse.class); - else if (p.httpMethod == HttpMethod.POST) - response = webResource.accept(tt).type(tt1).post(ClientResponse.class, request); - else if (p.httpMethod == HttpMethod.PUT) - response = webResource.accept(tt).type(tt1).put(ClientResponse.class, request); - else if (p.httpMethod == HttpMethod.DELETE) - response = webResource.accept(tt).type(tt1).delete(ClientResponse.class, request); + WebResource.Builder webResourceBuilder = webResource.accept(tt).type(tt1); + + if (p.customHttpHeaders != null && p.customHttpHeaders.length() > 0) { + String[] keyValuePairs = p.customHttpHeaders.split(","); + for (String singlePair : keyValuePairs) { + int equalPosition = singlePair.indexOf('='); + webResourceBuilder.header(singlePair.substring(0, equalPosition), singlePair.substring(equalPosition + 1, singlePair.length())); + } + } + + webResourceBuilder.header("X-ECOMP-RequestID",org.slf4j.MDC.get("X-ECOMP-RequestID")); + + ClientResponse response = webResourceBuilder.method(p.httpMethod.toString(), ClientResponse.class, request); r.code = response.getStatus(); r.headers = response.getHeaders(); @@ -453,6 +566,15 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { public MultivaluedMap headers; } + private void setFailureResponseStatus(SvcLogicContext ctx, String prefix, String errorMessage, HttpResponse r) { + r = new HttpResponse(); + r.code = 500; + r.message = errorMessage; + String pp = prefix != null ? prefix + '.' : ""; + ctx.setAttribute(pp + "response-code", String.valueOf(r.code)); + ctx.setAttribute(pp + "response-message", r.message); + } + private void setResponseStatus(SvcLogicContext ctx, String prefix, HttpResponse r) { String pp = prefix != null ? prefix + '.' : ""; ctx.setAttribute(pp + "response-code", String.valueOf(r.code)); @@ -497,8 +619,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { FileParam p = new FileParam(); p.fileName = parseParam(paramMap, "fileName", true, null); p.url = parseParam(paramMap, "url", true, null); - p.user = parseParam(paramMap, "user", true, null); - p.password = parseParam(paramMap, "password", true, null); + p.user = parseParam(paramMap, "user", false, null); + p.password = parseParam(paramMap, "password", false, null); p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); String skipSendingStr = paramMap.get("skipSending"); @@ -510,7 +632,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { Client client = Client.create(); client.setConnectTimeout(5000); client.setFollowRedirects(true); - client.addFilter(new HTTPBasicAuthFilter(p.user, p.password)); + if (p.user != null) + client.addFilter(new HTTPBasicAuthFilter(p.user, p.password)); WebResource webResource = client.resource(p.url); log.info("Sending file"); diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryException.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryException.java new file mode 100644 index 0000000..effdf22 --- /dev/null +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryException.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.sdnc.restapicall; + +public class RetryException extends Exception { + + public RetryException(String message) { + super(message); + } + +} diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicy.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicy.java new file mode 100644 index 0000000..afe398c --- /dev/null +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicy.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.sdnc.restapicall; + +public class RetryPolicy { + private String[] hostnames; + private Integer maximumRetries; + + public Integer getMaximumRetries() { + return maximumRetries; + } + + public String getNextHostName(String uri) throws RetryException { + Integer position = null; + + for (int i = 0; i < hostnames.length; i++) { + if (uri.contains(hostnames[i])) { + position = i; + break; + } + } + + if(position == null){ + throw new RetryException("No match found for the provided uri[" + uri + "] so the next host name could not be retreived"); + } + position++; + + if (position > hostnames.length - 1) { + position = 0; + } + return hostnames[position]; + } + + public RetryPolicy(String[] hostnames, Integer maximumRetries){ + this.hostnames = hostnames; + this.maximumRetries = maximumRetries; + } + + +} diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicyStore.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicyStore.java new file mode 100644 index 0000000..a5533ac --- /dev/null +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/RetryPolicyStore.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.sdnc.restapicall; + +import java.util.HashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RetryPolicyStore { + private static final Logger log = LoggerFactory.getLogger(RetryPolicyStore.class); + + HashMap retryPolicies; + public String proxyServers; + + public String getProxyServers() { + return proxyServers; + } + + public void setProxyServers(String admServers) { + this.proxyServers = admServers; + String[] adminServersArray = admServers.split(","); + RetryPolicy adminPortalRetry = new RetryPolicy(adminServersArray, adminServersArray.length); + retryPolicies.put("dme2proxy", adminPortalRetry); + } + + public RetryPolicyStore() { + retryPolicies = new HashMap(); + } + + public RetryPolicy getRetryPolicy(String policyName) { + return (this.retryPolicies.get(policyName)); + } + +} diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlJsonUtil.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlJsonUtil.java index 85175c3..6988abb 100644 --- a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlJsonUtil.java +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlJsonUtil.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlParser.java b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlParser.java index cf461e9..5bdcbdb 100644 --- a/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlParser.java +++ b/restapi-call-node/provider/src/main/java/org/openecomp/sdnc/restapicall/XmlParser.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml index 7aa4fc5..f27f118 100644 --- a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml +++ b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +26,12 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - + + + file:${SDNC_CONFIG_DIR}/ueb.properties + file:${SDNC_CONFIG_DIR}/dme2.properties + + @@ -35,6 +40,10 @@ + + + + diff --git a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml index aa12761..c2de5bf 100644 --- a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml +++ b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/main/resources/northbound-api-template.xml b/restapi-call-node/provider/src/main/resources/northbound-api-template.xml index 3738840..b6a0a67 100644 --- a/restapi-call-node/provider/src/main/resources/northbound-api-template.xml +++ b/restapi-call-node/provider/src/main/resources/northbound-api-template.xml @@ -3,7 +3,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ --> + <${northbound-Container}> ${service-topology-operation-input.request-information.notification-url} ${service-topology-operation-input.request-information.request-action} @@ -38,4 +39,5 @@ ${service-topology-operation-input.service-information.subscriber-name} ${'northbound-anyData} + diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java index d0632ea..986bb24 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java index 97112e3..5cc9ab2 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java index 3663b4d..9d7cb27 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java @@ -3,14 +3,14 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * 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. diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java index 914f901..117a423 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java @@ -3,7 +3,7 @@ * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/test/resources/test.xml b/restapi-call-node/provider/src/test/resources/test.xml index 4a31d94..e9b24d6 100644 --- a/restapi-call-node/provider/src/test/resources/test.xml +++ b/restapi-call-node/provider/src/test/resources/test.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/restapi-call-node/provider/src/test/resources/test3.xml b/restapi-call-node/provider/src/test/resources/test3.xml index 7392b24..948a988 100644 --- a/restapi-call-node/provider/src/test/resources/test3.xml +++ b/restapi-call-node/provider/src/test/resources/test3.xml @@ -4,7 +4,7 @@ openECOMP : SDN-C ================================================================================ Copyright (C) 2017 AT&T Intellectual Property. All rights - reserved. + reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. -- cgit 1.2.3-korg