summaryrefslogtreecommitdiffstats
path: root/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap
diff options
context:
space:
mode:
authorDunietz, Irwin <id1681@att.com>2020-01-16 15:13:14 -0500
committerTakamune Cho <takamune.cho@att.com>2020-01-29 19:44:48 +0000
commitb5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch)
tree3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap
parent9b32cb60360a2a2973c621053510718de0072111 (diff)
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting. Issue-ID: APPC-1789 Signed-off-by: Dunietz, Irwin <id1681@att.com> Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap')
-rw-r--r--appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java59
-rw-r--r--appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java15
2 files changed, 35 insertions, 39 deletions
diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java
index 42006018e..50cfb8f59 100644
--- a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java
+++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/ProviderOperations.java
@@ -17,17 +17,17 @@
* 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.appc.sdc.listener;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.URL;
-import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -37,11 +37,9 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
@@ -61,13 +59,9 @@ import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.onap.appc.exceptions.APPCException;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
public class ProviderOperations {
-
private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ProviderOperations.class);
-
private static String basic_auth;
private static URL defaultUrl;
@@ -82,9 +76,12 @@ public class ProviderOperations {
post.setHeader("Content-Type", "application/json");
post.setHeader("Accept", "application/json");
- // Set Auth
- if (basic_auth != null) {
+ // Set Auth if Provider URL is specified and basic auth has been configured
+ if (basic_auth != null && defaultUrl != null && url.equals(defaultUrl)) {
post.setHeader("Authorization", "Basic " + basic_auth);
+ LOG.debug("ASDCListener ProviderOperations: Using basic authentication for request to url " + url);
+ } else {
+ LOG.debug("ASDCListener ProviderOperations: Not Using basic authentication for request to url " + url);
}
if (adtl_headers != null) {
@@ -115,17 +112,17 @@ public class ProviderOperations {
}
/**
- * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
- * to null
+ * Sets the basic authentication header for the given user and password. If either entry is null
+ * then set basic auth to null
*
- * @param user
- * The user with optional domain name (for AAF)
- * @param password
- * The password for the user
+ * @param user The user with optional domain name (for AAF)
+ * @param password The password for the user
* @return The new value of the basic auth string that will be used in the request headers
*/
public static String setAuthentication(String user, String password) {
if (user != null && password != null) {
+ LOG.debug("SDCListener ProviderOperations:setAuthentication user is: " + user
+ + " Encrypted password: XXXX");
String authStr = user + ":" + password;
basic_auth = new String(Base64.encodeBase64(authStr.getBytes()));
} else {
@@ -137,15 +134,12 @@ public class ProviderOperations {
/**
* Sets the default Provider URL to the provided URL. If the entry is null then sets to null.
*
- * @param URL The URL
+ * @param URL url The URL
*/
- public static void setDefaultUrl(URL URL) {
- if (URL != null) {
- defaultUrl = URL;
- } else {
- defaultUrl = null;
- }
+ public static void setDefaultUrl(URL url) {
+ defaultUrl = url;
}
+
@SuppressWarnings("deprecation")
private static HttpClient getHttpClient(URL url) throws APPCException {
HttpClient client;
@@ -175,7 +169,7 @@ public class ProviderOperations {
client = new DefaultHttpClient();
} else {
throw new APPCException(
- "The provider.topology.url property is invalid. The url did not start with http[s]");
+ "The provider.topology.url property is invalid. The url did not start with http[s]");
}
return client;
}
@@ -184,18 +178,16 @@ public class ProviderOperations {
public static class MySSLSocketFactory extends SSLSocketFactory {
private SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
- public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
- KeyStoreException, UnrecoverableKeyException {
+ public MySSLSocketFactory(KeyStore truststore)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
@Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
@Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
@Override
public X509Certificate[] getAcceptedIssuers() {
@@ -203,14 +195,11 @@ public class ProviderOperations {
}
};
- sslContext.init(null, new TrustManager[] {
- tm
- }, null);
+ sslContext.init(null, new TrustManager[] {tm}, null);
}
@Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
- throws IOException, UnknownHostException {
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java
index c67535e11..fffc106ea 100644
--- a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java
+++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcListener.java
@@ -69,8 +69,8 @@ public class SdcListener {
config = new SdcConfig(props);
ukey = props.getProperty("appc.sdc.provider.user");
uval = props.getProperty("appc.sdc.provider.pass");
- logger.debug(String.format("[%d] created SDC config provider URL [%s]", timeStamp, config.getStoreOpURI().toString()));
-
+ logger.debug(String.format("[%d] created SDC config provider URL [%s]",
+ timeStamp, config.getStoreOpURI().toString()));
client = DistributionClientFactory.createDistributionClient();
logger.debug(String.format("[%d] created SDC client", timeStamp));
@@ -197,14 +197,21 @@ public class SdcListener {
URL url = new URL(String.format("http%s://%s/sdc2/rest/v1/consumers",
host.contains("443") ? "s" : "", host));
- logger.info(String.format("Attempting to register user %s on %s with salted pass of %s",
- config.getUser(), url, saltedPass[1]));
+ /*logger.info(String.format("Attempting to register user %s on %s with salted pass of %s",
+ config.getUser(), url, saltedPass[1]));*/
+ logger.info(String.format("Attempting to register user %s on %s with salted pass",
+ config.getUser(), url));
ProviderOperations providerOperations = new ProviderOperations();
ProviderOperations.setDefaultUrl(config.getStoreOpURI().toURL());
ProviderOperations.setAuthentication(ukey, uval);
ProviderResponse result = providerOperations.post(url, json, headers);
+/*
+ result = ProviderOperations.post(config.getStoreOpURI().toURL(), "{\"input\": {\"document-parameters\":{\"service-uuid\":\"c2d96f2c-58b2-45c1-b952-56d4982b48f4\",\"artifact-name\":\"reference_AllAction_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.json\",\"artifact-version\":\"1\",\"resource-name\":\"vDBE_VF_VoLTE_DBE\",\"artifact-description\":\"Reference file of VoLTE\",\"distribution-id\":\"6bdabf7d-2270-4da7-ba50-9b57e4a5e95b\",\"service-name\":\"vDBE_Svc_VoLTE_DBE_vDBE_U\",\"resource-instance-name\":\"vDBE_VF_VoLTE_DBE 0\",\"artifact-uuid\":\"93e9a91f-4b7f-4234-ae43-d7b3ba7bfb84\",\"resource-version\":\"7.0\",\"artifact-type\":\"APPC_CONFIG\",\"service-artifacts\":\"[]\",\"service-description\":\"ASDC vDBE Service for the VoLTE-vDBE project\",\"resource-uuid\":\"93bf7180-eba8-4b49-b81d-78fcd515ec89\",\"resource-type\":\"VF\",\"artifact-contents\":\"{\n\t\\\"reference_data\\\": [\n\t\t{\n\t\t\t\\\"action\\\": \\\"Configure\\\",\n\t\t\t\\\"action-level\\\": \\\"vnf\\\",\n\t\t\t\\\"scope\\\": {\n\t\t\t\t\\\"vnf-type\\\": \\\"vDBE_Svc_VoLTE_DBE_vDBE_U/vDBE_VF_VoLTE_DBE 0\\\",\n\t\t\t\t\\\"vnfc-type\\\": \\\"\\\"\n\t\t\t},\n\t\t\t\\\"template\\\": \\\"Y\\\",\n\t\t\t\\\"vm\\\": [\n\t\t\t\t{\n\t\t\t\t\t\\\"vm-instance\\\": 1,\n\t\t\t\t\t\\\"vnfc\\\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\\\"vnfc-instance\\\": \\\"1\\\",\n\t\t\t\t\t\t\t\\\"vnfc-function-code\\\": \\\"dbu\\\",\n\t\t\t\t\t\t\t\\\"ipaddress-v4-oam-vip\\\": \\\"Y\\\",\n\t\t\t\t\t\t\t\\\"group-notation-type\\\": \\\"first-vnfc-name\\\",\n\t\t\t\t\t\t\t\\\"group-notation-value\\\": \\\"pair\\\",\n\t\t\t\t\t\t\t\\\"vnfc-type\\\": \\\"vDBE-V - DBUX\\\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\\\"vm-instance\\\": 2,\n\t\t\t\t\t\\\"vnfc\\\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\\\"vnfc-instance\\\": \\\"1\\\",\n\t\t\t\t\t\t\t\\\"vnfc-function-code\\\": \\\"dbu\\\",\n\t\t\t\t\t\t\t\\\"ipaddress-v4-oam-vip\\\": \\\"Y\\\",\n\t\t\t\t\t\t\t\\\"group-notation-type\\\": \\\"first-vnfc-name\\\",\n\t\t\t\t\t\t\t\\\"group-notation-value\\\": \\\"pair\\\",\n\t\t\t\t\t\t\t\\\"vnfc-type\\\": \\\"vDBE-V - DBUX\\\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t],\n\t\t\t\\\"device-protocol\\\": \\\"NETCONF-XML\\\",\n\t\t\t\\\"user-name\\\": \\\"root\\\",\n\t\t\t\\\"port-number\\\": \\\"830\\\",\n\t\t\t\\\"artifact-list\\\": [\n\t\t\t\t{\n\t\t\t\t\t\\\"artifact-name\\\": \\\"template_Configure_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.xml\\\",\n\t\t\t\t\t\\\"artifact-type\\\": \\\"config_template\\\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\\\"artifact-name\\\": \\\"pd_Configure_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.yaml\\\",\n\t\t\t\t\t\\\"artifact-type\\\": \\\"parameter_definitions\\\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\\\"scopeType\\\": \\\"vnf-type\\\"\n\t\t},\n\t\t{\n\t\t\t\\\"action\\\": \\\"AllAction\\\",\n\t\t\t\\\"action-level\\\": \\\"vnf\\\",\n\t\t\t\\\"scope\\\": {\n\t\t\t\t\\\"vnf-type\\\": \\\"vDBE_Svc_VoLTE_DBE_vDBE_U/vDBE_VF_VoLTE_DBE 0\\\",\n\t\t\t\t\\\"vnfc-type\\\": \\\"\\\"\n\t\t\t},\n\t\t\t\\\"artifact-list\\\": [\n\t\t\t\t{\n\t\t\t\t\t\\\"artifact-name\\\": \\\"reference_AllAction_vDBE_Svc_VoLTE_DBE_vDBE_U_vDBE_VF_VoLTE_DBE0_0.0.1V.json\\\",\n\t\t\t\t\t\\\"artifact-type\\\": \\\"reference_template\\\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\"}, \"request-information\":{\"request-action\":\"StoreSdcDocumentRequest\",\"source\":\"SDC\",\"request-id\":\"c2d96f2c-58b2-45c1-b952-56d4982b48f4\"}}}", null);
+ logger.info(String.format("Result Status 3 = %d", result.getStatus()));
+*/
return result.getStatus() == 200;
+
} catch (Exception e) {
logger.error(
"Error performing initial registration with SDC server. User may not be able to connect",