diff options
author | Ofir Sonsino <os0695@intl.att.com> | 2019-10-15 20:48:56 +0300 |
---|---|---|
committer | Ofir Sonsino <os0695@intl.att.com> | 2019-10-15 20:48:56 +0300 |
commit | b6ac738434954b586b751f7a04ff3d1ea94f1460 (patch) | |
tree | 3c8fe01ba26473dbcfdda9e6a927962029cd80bc /sdc-distribution-client/src/main | |
parent | 75b5636a5ecb293b021409e287d4c22481c1aa90 (diff) |
Aligning elalto branch to 1.4.05.0.2-ONAP1.4.0elalto
Change-Id: Iaca7575f385ee448b54ccaf1f8c2b9b6668a3739
Issue-ID: SDC-2504
Signed-off-by: Ofir Sonsino <os0695@intl.att.com>
Diffstat (limited to 'sdc-distribution-client/src/main')
8 files changed, 306 insertions, 25 deletions
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java index 7871816..a93b4a7 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java @@ -3,7 +3,6 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -30,7 +29,6 @@ import java.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; -import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,6 +41,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; +import org.apache.commons.codec.binary.Base64; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; @@ -84,7 +83,7 @@ public class HttpAsdcClient implements IHttpAsdcClient { initSSL(username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth()); String userNameAndPassword = username + ":" + password; - this.authHeaderValue = "Basic " + Base64.getEncoder().encodeToString(userNameAndPassword.getBytes()); + this.authHeaderValue = "Basic " + Base64.encodeBase64String(userNameAndPassword.getBytes()); } // @SuppressWarnings("deprecation") diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java index 33fedc7..d294fef 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java @@ -3,7 +3,6 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -59,7 +58,7 @@ import com.google.gson.reflect.TypeToken; import fj.data.Either; public class SdcConnectorClient { - String contentDispositionHeader = "Content-Disposition"; + private String contentDispositionHeader = "Content-Disposition"; private static Logger log = LoggerFactory.getLogger(SdcConnectorClient.class.getName()); private IConfiguration configuration; private HttpAsdcClient httpClient = null; @@ -165,7 +164,7 @@ public class SdcConnectorClient { DistributionClientResultImpl response = null; String requestId = UUID.randomUUID().toString(); - HttpAsdcClient httpClient = createNewHttpClient(); + HttpAsdcClient httpClient = new HttpAsdcClient(configuration); Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId); RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress()); @@ -192,10 +191,6 @@ public class SdcConnectorClient { } - HttpAsdcClient createNewHttpClient() { - return new HttpAsdcClient(configuration); - } - public DistributionClientDownloadResultImpl dowloadArtifact(IArtifactInfo artifactInfo) { DistributionClientDownloadResultImpl response = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to download artifact from ASDC"); diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java new file mode 100644 index 0000000..f7a0041 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * 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.onap.sdc.impl; + +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.impl.mock.DistributionClientStubImpl; + +public class DistributionClientFactory { + + private DistributionClientFactory() { + } + + public static IDistributionClient createDistributionClient() { + return new DistributionClientImpl(); + } + + public static IDistributionClient createMockDistributionClient() { + return new DistributionClientStubImpl(); + } +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java index de5d1ec..1d46186 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java @@ -3,7 +3,6 @@ * SDC * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +27,7 @@ public class StatusDataImpl implements IStatusData { private String distributionID; private String consumerID; - private Long timestamp; + private long timestamp; private String artifactURL; private DistributionStatusEnum status; private String componentName; @@ -57,7 +56,7 @@ public class StatusDataImpl implements IStatusData { return timestamp; } - public void setTimestamp(Long timestamp) { + public void setTimestamp(long timestamp) { this.timestamp = timestamp; } @@ -82,7 +81,7 @@ public class StatusDataImpl implements IStatusData { @Override public String toString() { - return "StatusDataImpl [distributionID=" + distributionID + ", consumerID=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status + ", errorReason=" + errorReason + "]"; + return "StatusDataImpl [distributionId=" + distributionID + ", consumerId=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status + ", errorReason=" + errorReason + "]"; } @Override diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java new file mode 100644 index 0000000..5ffb655 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * 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.onap.sdc.impl.mock; + +import org.onap.sdc.api.results.IDistributionClientDownloadResult; + +/** + * Mock Implementation + */ +public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements IDistributionClientDownloadResult { + + @Override + public byte[] getArtifactPayload() { + String mockPayload = + "heat_template_version: 2013-05-23\r\n" + + "\r\n" + + "description: >\r\n" + + " HOT template that creates one COR network (direct).\r\n" + + "\r\n" + + "parameters:\r\n" + + " cor_direct_net_name:\r\n" + + " type: string\r\n" + + " description: Name of COR direct network\r\n" + + " cor_direct_net_cidr:\r\n" + + " type: string\r\n" + + " description: Direct network address (CIDR notation)\r\n" + + " cor_direct_net_gateway:\r\n" + + " type: string\r\n" + + " description: Direct network gateway address\r\n" + + " cor_direct_net_RT:\r\n" + + " type: string\r\n" + + " description: Direct network route-target (RT)\r\n" + + "\r\n" + + "resources:\r\n" + + " cor_direct_net:\r\n" + + " type: OS::Contrail::VirtualNetwork\r\n" + + " properties:\r\n" + + " name: { get_param: cor_direct_net_name }\r\n" + + " route_targets: [ get_param: cor_direct_net_RT ]\r\n" + + "\r\n" + + " cor_direct_ip_subnet:\r\n" + + " type: OS::Neutron::Subnet\r\n" + + " properties:\r\n" + + " network_id: { get_resource: cor_direct_net }\r\n" + + " cidr: {get_param: cor_direct_net_cidr}\r\n" + + " gateway_ip: { get_param: cor_direct_net_gateway }\r\n"; + + return mockPayload.getBytes(); + } + + @Override + public String getArtifactName() { + // TODO Auto-generated method stub + return "MackArtifactName"; + } + + @Override + public String getArtifactFilename() { + // TODO Auto-generated method stub + return "MackArtifactName"; + } + +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java new file mode 100644 index 0000000..d176608 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * 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.onap.sdc.impl.mock; + +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; + +/** + * Mock Implementation + */ +public class DistributionClientResultStubImpl implements IDistributionClientResult { + @Override + public DistributionActionResultEnum getDistributionActionResult() { + return DistributionActionResultEnum.SUCCESS; + } + + @Override + public String getDistributionMessageResult() { + return "Stub Result, method not implemented!"; + } + +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java new file mode 100644 index 0000000..40e1869 --- /dev/null +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * 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.onap.sdc.impl.mock; + +import java.util.List; + +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; +import org.onap.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; +import org.onap.sdc.api.consumer.INotificationCallback; +import org.onap.sdc.api.consumer.IStatusCallback; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IVfModuleMetadata; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.api.results.IDistributionClientResult; + +/** + * Mock Implementation + */ +public class DistributionClientStubImpl implements IDistributionClient { + + + public IDistributionClientResult updateConfiguration(IConfiguration newConf) { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult start() { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult stop() { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage) { + return new DistributionClientResultStubImpl(); + } + + public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage) { + return new DistributionClientResultStubImpl(); + } + + @Override + public IDistributionClientDownloadResult download(IArtifactInfo artifactInfo) { + return new DistributionClientDownloadResultStubImpl(); + } + + @Override + public IDistributionClientResult init(IConfiguration conf, INotificationCallback callback) { + return new DistributionClientResultStubImpl(); + } + + @Override + public IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback, + IStatusCallback statusCallback) { + return new DistributionClientResultStubImpl(); + } + + @Override + public IConfiguration getConfiguration() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendDownloadStatus( + IDistributionStatusMessage statusMessage, String errorReason) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendDeploymentStatus( + IDistributionStatusMessage statusMessage, String errorReason) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage) { + return null; + } + + @Override + public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage) { + return null; + } + + @Override + public List<IVfModuleMetadata> decodeVfModuleArtifact(byte[] artifactPayload) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage, + String errorReason) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage, String errorReason) { + // TODO Auto-generated method stub + return null; + } + + +} diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java index d550b74..ac2a904 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java @@ -3,7 +3,6 @@ * sdc-distribution-client * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications copyright (C) 2019 Nokia. 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. @@ -21,15 +20,13 @@ package org.onap.sdc.utils; -import com.google.common.base.Charsets; -import com.google.common.hash.Hashing; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Base64; import java.util.List; import java.util.regex.Pattern; +import org.apache.commons.codec.binary.Base64; import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.impl.DistributionClientResultImpl; import org.slf4j.Logger; @@ -39,21 +36,24 @@ import fj.data.Either; public class GeneralUtils { private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUtils.class.getName()); - private static final int STRING_LENGTH_DIVIDER = 4; + public static final int STRING_LENGTH_DIVIDER = 4; private GeneralUtils() { + } public static String calculateMD5(String data) { - String calculatedMd5 = Hashing.md5().hashString(data, Charsets.UTF_8).toString(); + String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data); // encode base-64 result - byte[] encodeBase64 = Base64.getEncoder().encode(calculatedMd5.getBytes()); - return new String(encodeBase64); + byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes()); + String encodeBase64Str = new String(encodeBase64); + return encodeBase64Str; + } public static String calculateMD5(byte[] decodedPayload) { - String decodedMd5 = Hashing.md5().hashBytes(decodedPayload).toString(); - byte[] encodeMd5 = Base64.getEncoder().encode(decodedMd5.getBytes()); + String decodedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(decodedPayload); + byte[] encodeMd5 = Base64.encodeBase64(decodedMd5.getBytes()); return new String(encodeMd5); } @@ -61,7 +61,7 @@ public class GeneralUtils { boolean isEncoded = false; try { // If no exception is caught, then it is possibly a base64 encoded string - byte[] data = Base64.getDecoder().decode(str); + byte[] data = Base64.decodeBase64(str); // checks if the string was properly padded to the isEncoded = ((str.length() % STRING_LENGTH_DIVIDER == 0) && (Pattern.matches("\\A[a-zA-Z0-9/+]+={1,2}\\z", str))); |