summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-07-12 09:31:29 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-07-22 08:32:48 +0000
commit517e1d7a4729272350268f4e92b6b178bf2cafe2 (patch)
tree3c8fe01ba26473dbcfdda9e6a927962029cd80bc
parent759ea36d4c2f5eb65a6a42eb7c3bff92e28961ee (diff)
fixing warnings from checkstyle
Issue-ID: SDC-2430 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: Ia97159585b4f7ae14c677560bba4a7db1f97504d
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java357
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionStatusMessageJsonBuilder.java6
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/RegistrationRequest.java58
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/ServerListResponse.java18
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IComponentDoneStatusMessage.java9
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IConfiguration.java266
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessage.java12
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessageBasic.java13
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IFinalDistrStatusMessage.java14
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/INotificationCallback.java13
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IStatusCallback.java8
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IArtifactInfo.java163
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/INotificationData.java95
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IResourceInstance.java96
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IStatusData.java72
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IVfModuleMetadata.java86
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientDownloadResult.java50
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientResult.java14
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/AsdcUrls.java18
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java571
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcResponse.java76
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/IHttpAsdcClient.java16
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java618
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/TopicRegistrationResponse.java40
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java328
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java392
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java94
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java22
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java1416
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java40
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java167
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java234
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java263
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java281
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java296
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java51
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java141
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java76
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java103
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java25
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java190
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/ArtifactTypeEnum.java46
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionActionResultEnum.java72
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionClientConstants.java37
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionStatusEnum.java82
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java106
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/Pair.java30
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/Wrapper.java48
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/YamlToObjectConverter.java168
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatConfiguration.java25
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java373
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameterConstraint.java146
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParser.java89
53 files changed, 4088 insertions, 3942 deletions
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java
index d3a8188..ce17318 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,189 +22,190 @@ package org.onap.sdc.api;
import java.util.List;
-import org.onap.sdc.api.consumer.*;
+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.results.IDistributionClientDownloadResult;
import org.onap.sdc.api.results.IDistributionClientResult;
-import org.onap.sdc.api.consumer.*;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.IVfModuleMetadata;
public interface IDistributionClient {
- /**
- * Update the configuration of the distribution client <br>
- * Updatable configuration parameters are: pollingInterval, pollingTimeout,
- * consumerGroup and relevantArtifactTypes
- *
- * @param newConf
- * - contains updated configuration
- *
- * @return IDistributionClientResult
- */
- IDistributionClientResult updateConfiguration(IConfiguration newConf);
-
- /**
- * Retrieve the configuration of the distribution client <br>
- *
- * @return IConfiguration
- */
- IConfiguration getConfiguration();
-
- /**
- * Start distribution client <br>
- * - start polling notification topic <br>
- *
- * @return IDistributionClientResult
- */
- IDistributionClientResult start();
-
- /**
- * Stop distribution client <br>
- * - stop polling notification topic <br>
- * - unregister topics (via ASDC) <br>
- * - delete keys from UEB
- *
- * @return IDistributionClientResult
- */
- IDistributionClientResult stop();
-
- /**
- * Downloads an artifact from ASDC Catalog <br>
- *
- * @param artifactInfo
- * @return IDistributionClientDownloadResult
- */
- IDistributionClientDownloadResult download(IArtifactInfo artifactInfo);
-
- /**
- * Initialize the distribution client <br>
- * - fetch the UEB server list from ASDC <br>
- * - create keys in UEB <br>
- * - register for topics (via ASDC) <br>
- * - set the notification callback <br>
- *
- * Note: all configuration fields are mandatory. <br>
- * Password must be in clear text and not encrypted <br>
- * ONAP-Component MUST store password as SHA-2 (256) hashed with
- * dynamically generated salt value <br>
- *
- * @param conf
- * @param callback
- * @return IDistributionClientResult
- */
- IDistributionClientResult init(IConfiguration conf, INotificationCallback callback);
-
- /**
- * Initialize the distribution client <br>
- * - fetch the UEB server list from ASDC <br>
- * - create keys in UEB <br>
- * - register for topics (via ASDC) <br>
- * - set the notification callback <br>
- *
- * Note: all configuration fields are mandatory. <br>
- * Password must be in clear text and not encrypted <br>
- * ONAP-Component MUST store password as SHA-2 (256) hashed with
- * dynamically generated salt value <br>
- *
- * @param conf
- * @param notificationCallback
- * @param statusCallback
- * @return IDistributionClientResult
- */
- IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback,
- IStatusCallback statusCallback);
-
- /**
- * Build and publish Distribution Download Status event to Distribution
- * Status Topic
- *
- * @param statusMessage
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage);
-
- /**
- * Build and publish Distribution Download Status event to Distribution
- * Status Topic With Error Reason.
- *
- * @param statusMessage
- * @param errorReason
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage, String errorReason);
-
- /**
- * Build and publish Distribution Deployment Status event to Distribution
- * Status Topic
- *
- * @param statusMessage
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage);
-
- /**
- * Build and publish Distribution Deployment Status event to Distribution
- * Status Topic With Error Reason.
- *
- * @param statusMessage
- * @param errorReason
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage, String errorReason);
-
- /**
- * Build and publish Distribution Component Status event to Distribution
- * Status Topic
- *
- * @param statusMessage
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage);
-
- /**
- * Build and publish Distribution Component Status event to Distribution
- * Status Topic With Error Reason.
- *
- * @param statusMessage
- * @param errorReason
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage, String errorReason);
-
-
- /**
- * Build and publish Distribution Final Status event to Distribution
- * Status Topic
- *
- * @param statusMessage
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage);
-
-
- /**
- * Build and publish Distribution Final Status event to Distribution
- * Status Topic With Error Reason.
- *
- * @param statusMessage
- * @param errorReason
- * @return IDistributionClientResult
- */
- IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage, String errorReason);
-
-
- /**
- * This method parses artifact of type VF_MODULES_METADATA payload data
- * .<br>
- * Method is deprecated due to VF Module changes. Only backward
- * compatibility is supported.<br>
- *
- * @param artifactPayload
- * @return IVfModuleMetadata list
- */
- @Deprecated
- List<IVfModuleMetadata> decodeVfModuleArtifact(byte[] artifactPayload);
-
+ /**
+ * Update the configuration of the distribution client <br>
+ * Updatable configuration parameters are: pollingInterval, pollingTimeout,
+ * consumerGroup and relevantArtifactTypes
+ *
+ * @param newConf - contains updated configuration
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult updateConfiguration(IConfiguration newConf);
+
+ /**
+ * Retrieve the configuration of the distribution client <br>
+ *
+ * @return IConfiguration
+ */
+ IConfiguration getConfiguration();
+
+ /**
+ * Start distribution client <br>
+ * - start polling notification topic <br>
+ *
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult start();
+
+ /**
+ * Stop distribution client <br>
+ * - stop polling notification topic <br>
+ * - unregister topics (via ASDC) <br>
+ * - delete keys from UEB
+ *
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult stop();
+
+ /**
+ * Downloads an artifact from ASDC Catalog <br>
+ *
+ * @param artifactInfo
+ * @return IDistributionClientDownloadResult
+ */
+ IDistributionClientDownloadResult download(IArtifactInfo artifactInfo);
+
+ /**
+ * Initialize the distribution client <br>
+ * - fetch the UEB server list from ASDC <br>
+ * - create keys in UEB <br>
+ * - register for topics (via ASDC) <br>
+ * - set the notification callback <br>
+ * <p>
+ * Note: all configuration fields are mandatory. <br>
+ * Password must be in clear text and not encrypted <br>
+ * ONAP-Component MUST store password as SHA-2 (256) hashed with
+ * dynamically generated salt value <br>
+ *
+ * @param conf
+ * @param callback
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult init(IConfiguration conf, INotificationCallback callback);
+
+ /**
+ * Initialize the distribution client <br>
+ * - fetch the UEB server list from ASDC <br>
+ * - create keys in UEB <br>
+ * - register for topics (via ASDC) <br>
+ * - set the notification callback <br>
+ * <p>
+ * Note: all configuration fields are mandatory. <br>
+ * Password must be in clear text and not encrypted <br>
+ * ONAP-Component MUST store password as SHA-2 (256) hashed with
+ * dynamically generated salt value <br>
+ *
+ * @param conf
+ * @param notificationCallback
+ * @param statusCallback
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback,
+ IStatusCallback statusCallback);
+
+ /**
+ * Build and publish Distribution Download Status event to Distribution
+ * Status Topic
+ *
+ * @param statusMessage
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage);
+
+ /**
+ * Build and publish Distribution Download Status event to Distribution
+ * Status Topic With Error Reason.
+ *
+ * @param statusMessage
+ * @param errorReason
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage, String errorReason);
+
+ /**
+ * Build and publish Distribution Deployment Status event to Distribution
+ * Status Topic
+ *
+ * @param statusMessage
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage);
+
+ /**
+ * Build and publish Distribution Deployment Status event to Distribution
+ * Status Topic With Error Reason.
+ *
+ * @param statusMessage
+ * @param errorReason
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage, String errorReason);
+
+ /**
+ * Build and publish Distribution Component Status event to Distribution
+ * Status Topic
+ *
+ * @param statusMessage
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage);
+
+ /**
+ * Build and publish Distribution Component Status event to Distribution
+ * Status Topic With Error Reason.
+ *
+ * @param statusMessage
+ * @param errorReason
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage, String errorReason);
+
+
+ /**
+ * Build and publish Distribution Final Status event to Distribution
+ * Status Topic
+ *
+ * @param statusMessage
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage);
+
+
+ /**
+ * Build and publish Distribution Final Status event to Distribution
+ * Status Topic With Error Reason.
+ *
+ * @param statusMessage
+ * @param errorReason
+ * @return IDistributionClientResult
+ */
+ IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage, String errorReason);
+
+
+ /**
+ * This method parses artifact of type VF_MODULES_METADATA payload data
+ * .<br>
+ * Method is deprecated due to VF Module changes. Only backward
+ * compatibility is supported.<br>
+ *
+ * @param artifactPayload
+ * @return IVfModuleMetadata list
+ */
+ @Deprecated
+ List<IVfModuleMetadata> decodeVfModuleArtifact(byte[] artifactPayload);
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionStatusMessageJsonBuilder.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionStatusMessageJsonBuilder.java
index 6db00fa..3e94d69 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionStatusMessageJsonBuilder.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionStatusMessageJsonBuilder.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,5 +21,5 @@
package org.onap.sdc.api;
public interface IDistributionStatusMessageJsonBuilder {
- String build();
+ String build();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/RegistrationRequest.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/RegistrationRequest.java
index 6e64396..765da4c 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/RegistrationRequest.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/RegistrationRequest.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,33 +24,33 @@ import java.util.List;
public class RegistrationRequest {
- String apiPublicKey;
- String distrEnvName;
- Boolean isConsumerToSdcDistrStatusTopic;
- List<String> distEnvEndPoints;
-
- public RegistrationRequest(String apiPublicKey, String distrEnvName, boolean isConsumerToSdcDistrStatusTopic, List<String> distEnvEndPoints) {
- this.apiPublicKey = apiPublicKey;
- this.distrEnvName = distrEnvName;
- this.isConsumerToSdcDistrStatusTopic = isConsumerToSdcDistrStatusTopic;
- this.distEnvEndPoints = distEnvEndPoints;
- }
-
- public String getApiPublicKey() {
- return apiPublicKey;
- }
-
- public String getDistrEnvName() {
- return distrEnvName;
- }
-
- public Boolean getIsConsumerToSdcDistrStatusTopic() {
- return isConsumerToSdcDistrStatusTopic;
- }
-
- public List<String> getDistEnvEndPoints() {
- return distEnvEndPoints;
- }
+ private String apiPublicKey;
+ private String distrEnvName;
+ private Boolean isConsumerToSdcDistrStatusTopic;
+ private List<String> distEnvEndPoints;
+
+ public RegistrationRequest(String apiPublicKey, String distrEnvName, boolean isConsumerToSdcDistrStatusTopic, List<String> distEnvEndPoints) {
+ this.apiPublicKey = apiPublicKey;
+ this.distrEnvName = distrEnvName;
+ this.isConsumerToSdcDistrStatusTopic = isConsumerToSdcDistrStatusTopic;
+ this.distEnvEndPoints = distEnvEndPoints;
+ }
+
+ public String getApiPublicKey() {
+ return apiPublicKey;
+ }
+
+ public String getDistrEnvName() {
+ return distrEnvName;
+ }
+
+ public Boolean getIsConsumerToSdcDistrStatusTopic() {
+ return isConsumerToSdcDistrStatusTopic;
+ }
+
+ public List<String> getDistEnvEndPoints() {
+ return distEnvEndPoints;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/ServerListResponse.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/ServerListResponse.java
index 8d3b823..901b067 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/ServerListResponse.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/asdc/ServerListResponse.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,13 +24,13 @@ import java.util.List;
public class ServerListResponse {
- private List<String> uebServerList;
+ private List<String> uebServerList;
- public List<String> getUebServerList() {
- return uebServerList;
- }
+ public List<String> getUebServerList() {
+ return uebServerList;
+ }
- public void setUebServerList(List<String> uebServerList) {
- this.uebServerList = uebServerList;
- }
+ public void setUebServerList(List<String> uebServerList) {
+ this.uebServerList = uebServerList;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IComponentDoneStatusMessage.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IComponentDoneStatusMessage.java
index 1a6bd24..9fa310d 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IComponentDoneStatusMessage.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IComponentDoneStatusMessage.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,6 +22,9 @@ package org.onap.sdc.api.consumer;
public interface IComponentDoneStatusMessage extends IDistributionStatusMessageBasic {
String getComponentName();
- default String getArtifactURL(){return "";}
+
+ default String getArtifactURL() {
+ return "";
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IConfiguration.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IConfiguration.java
index c5a1857..88db133 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IConfiguration.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IConfiguration.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,134 +24,136 @@ import java.util.List;
import org.onap.sdc.api.notification.INotificationData;
public interface IConfiguration {
- /**
- * SDC Distribution Engine address. Value can be either hostname (with or
- * without port), IP:port or FQDN (Fully Qualified Domain Name). * @return
- * SDC Distribution Engine address.
- */
- String getAsdcAddress();
-
- /**SDC Distribution Addresses from ONAP Component
- * Values need to be set from impl
- */
- List<String> getMsgBusAddress();
-
- /**
- * User Name for SDC distribution consumer authentication.
- *
- * @return User Name.
- */
- String getUser();
-
- /**
- * User Password for SDC distribution consumer authentication.
- *
- * @return User Password.
- */
- String getPassword();
-
- /**
- * Distribution Client Polling Interval towards UEB in seconds. Can Be
- * reconfigured in runtime.
- *
- * @return Distribution Client Polling Interval.
- */
- int getPollingInterval();
-
- /**
- * Distribution Client Timeout in seconds waiting to UEB server response in
- * each fetch interval. Can Be reconfigured in runtime.
- *
- * @return Distribution Client Timeout in seconds.
- */
- int getPollingTimeout();
-
- /**
- * List of artifact types.<br>
- * If the service contains any of the artifacts in the list, the callback
- * will be activated. Can Be reconfigured in runtime.
- *
- * @return List of artifact types.
- */
- List<String> getRelevantArtifactTypes();
-
- /**
- * Returns the consumer group defined for this ECOMP component, if no
- * consumer group is defined return null.
- *
- * @return Consumer group.
- */
- String getConsumerGroup();
-
- /**
- * Returns the environment name (testing, production etc...). Can Be
- * reconfigured in runtime.
- *
- * @return
- */
- String getEnvironmentName();
-
- /**
- * Unique ID of ECOMP component instance (e.x INSTAR name).
- *
- * @return
- */
- String getConsumerID();
-
- /**
- * Return full path to Client's Key Store that contains either CA
- * certificate or the ASDC's public key (e.g /etc/keystore/asdc-client.jks)
- * file will be deployed with sdc-distribution jar.
- *
- * @return
- */
- String getKeyStorePath();
-
- /**
- * @return Returns client's Key Store password
- */
- String getKeyStorePassword();
-
- /**
- * Sets whether SDC server TLS authentication is activated. If set to false,
- * Key Store path and password are not needed to be set.
- *
- * @return
- */
- boolean activateServerTLSAuth();
-
- /**
- * If set to true the method {@link INotificationData#getResources()} will
- * return all found resources.<br>
- * That means that metadata of resources that do not contain relevant
- * artifacts types (artifacts that are defined in
- * {@link #getRelevantArtifactTypes()} will be returned.<br>
- * Setting the method to false will activate the legacy behavior, in which
- * empty resources are not part of the notification.<br>
- *
- * @return
- */
- boolean isFilterInEmptyResources();
-
- /**
- * By default, Distribution Client will use HTTPS (TLS 1.2) when connecting
- * to DMAAP. This param can be null, then default (HTTPS) behavior will be
- * applied. If set to false, distribution client will use HTTP when
- * connecting to DMAAP.
- *
- * @return
- */
- Boolean isUseHttpsWithDmaap();
-
- /**
- * By default, (false value) Distribution Client will trigger the regular registration
- * towards SDC (register component as consumer to the SDC-DISTR-NOTIF-TOPIC-[ENV] topic and register component as producer to the SDC-DISTR-STATUS-TOPIC-[ENV]).<br>
- * If set to true, distribution client trigger Register to SDC indicating
- * that this component request to be consumer and producer of the
- * SDC-DISTR-STATUS-TOPIC-[ENV] topic.<br>
- * @return
- */
- default boolean isConsumeProduceStatusTopic() {
- return false;
- }
+ /**
+ * SDC Distribution Engine address. Value can be either hostname (with or
+ * without port), IP:port or FQDN (Fully Qualified Domain Name). * @return
+ * SDC Distribution Engine address.
+ */
+ String getAsdcAddress();
+
+ /**
+ * SDC Distribution Addresses from ONAP Component
+ * Values need to be set from impl
+ */
+ List<String> getMsgBusAddress();
+
+ /**
+ * User Name for SDC distribution consumer authentication.
+ *
+ * @return User Name.
+ */
+ String getUser();
+
+ /**
+ * User Password for SDC distribution consumer authentication.
+ *
+ * @return User Password.
+ */
+ String getPassword();
+
+ /**
+ * Distribution Client Polling Interval towards UEB in seconds. Can Be
+ * reconfigured in runtime.
+ *
+ * @return Distribution Client Polling Interval.
+ */
+ int getPollingInterval();
+
+ /**
+ * Distribution Client Timeout in seconds waiting to UEB server response in
+ * each fetch interval. Can Be reconfigured in runtime.
+ *
+ * @return Distribution Client Timeout in seconds.
+ */
+ int getPollingTimeout();
+
+ /**
+ * List of artifact types.<br>
+ * If the service contains any of the artifacts in the list, the callback
+ * will be activated. Can Be reconfigured in runtime.
+ *
+ * @return List of artifact types.
+ */
+ List<String> getRelevantArtifactTypes();
+
+ /**
+ * Returns the consumer group defined for this ECOMP component, if no
+ * consumer group is defined return null.
+ *
+ * @return Consumer group.
+ */
+ String getConsumerGroup();
+
+ /**
+ * Returns the environment name (testing, production etc...). Can Be
+ * reconfigured in runtime.
+ *
+ * @return
+ */
+ String getEnvironmentName();
+
+ /**
+ * Unique ID of ECOMP component instance (e.x INSTAR name).
+ *
+ * @return
+ */
+ String getConsumerID();
+
+ /**
+ * Return full path to Client's Key Store that contains either CA
+ * certificate or the ASDC's public key (e.g /etc/keystore/asdc-client.jks)
+ * file will be deployed with sdc-distribution jar.
+ *
+ * @return
+ */
+ String getKeyStorePath();
+
+ /**
+ * @return Returns client's Key Store password
+ */
+ String getKeyStorePassword();
+
+ /**
+ * Sets whether SDC server TLS authentication is activated. If set to false,
+ * Key Store path and password are not needed to be set.
+ *
+ * @return
+ */
+ boolean activateServerTLSAuth();
+
+ /**
+ * If set to true the method {@link INotificationData#getResources()} will
+ * return all found resources.<br>
+ * That means that metadata of resources that do not contain relevant
+ * artifacts types (artifacts that are defined in
+ * {@link #getRelevantArtifactTypes()} will be returned.<br>
+ * Setting the method to false will activate the legacy behavior, in which
+ * empty resources are not part of the notification.<br>
+ *
+ * @return
+ */
+ boolean isFilterInEmptyResources();
+
+ /**
+ * By default, Distribution Client will use HTTPS (TLS 1.2) when connecting
+ * to DMAAP. This param can be null, then default (HTTPS) behavior will be
+ * applied. If set to false, distribution client will use HTTP when
+ * connecting to DMAAP.
+ *
+ * @return
+ */
+ Boolean isUseHttpsWithDmaap();
+
+ /**
+ * By default, (false value) Distribution Client will trigger the regular registration
+ * towards SDC (register component as consumer to the SDC-DISTR-NOTIF-TOPIC-[ENV] topic and register component as producer to the SDC-DISTR-STATUS-TOPIC-[ENV]).<br>
+ * If set to true, distribution client trigger Register to SDC indicating
+ * that this component request to be consumer and producer of the
+ * SDC-DISTR-STATUS-TOPIC-[ENV] topic.<br>
+ *
+ * @return
+ */
+ default boolean isConsumeProduceStatusTopic() {
+ return false;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessage.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessage.java
index fd73bac..7740746 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessage.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessage.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,9 +20,11 @@
package org.onap.sdc.api.consumer;
-public interface IDistributionStatusMessage extends IDistributionStatusMessageBasic{
+public interface IDistributionStatusMessage extends IDistributionStatusMessageBasic {
- /**Resource URL of the downloaded/deployed artifact - URL specified in the distribution notification message*/
- String getArtifactURL();
+ /**
+ * Resource URL of the downloaded/deployed artifact - URL specified in the distribution notification message
+ */
+ String getArtifactURL();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessageBasic.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessageBasic.java
index cc54dae..3d0b237 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessageBasic.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IDistributionStatusMessageBasic.java
@@ -7,9 +7,9 @@
* 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.
@@ -35,7 +35,9 @@ public interface IDistributionStatusMessageBasic {
*/
String getDistributionID();
- /**Unique ID of ONAP component instance (e.x INSTAR name)*/
+ /**
+ * Unique ID of ONAP component instance (e.x INSTAR name)
+ */
String getConsumerID();
/**
@@ -43,6 +45,9 @@ public interface IDistributionStatusMessageBasic {
* The number of seconds that have elapsed since January 1, 1970.
*/
long getTimestamp();
- /**Download/Deployment status*/
+
+ /**
+ * Download/Deployment status
+ */
DistributionStatusEnum getStatus();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IFinalDistrStatusMessage.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IFinalDistrStatusMessage.java
index 4257eb0..7bdccdc 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IFinalDistrStatusMessage.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IFinalDistrStatusMessage.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,9 +21,13 @@
package org.onap.sdc.api.consumer;
+public interface IFinalDistrStatusMessage extends IDistributionStatusMessageBasic {
-public interface IFinalDistrStatusMessage extends IDistributionStatusMessageBasic{
+ default String getConsumerID() {
+ return "";
+ }
- default String getConsumerID(){return "";}
- default String getComponentName(){return "";}
+ default String getComponentName() {
+ return "";
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/INotificationCallback.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/INotificationCallback.java
index 5121407..3c1ec65 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/INotificationCallback.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/INotificationCallback.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,9 +21,12 @@
package org.onap.sdc.api.consumer;
import org.onap.sdc.api.notification.INotificationData;
-/**When a relevant notification will be found activateCallback method will be activated with the notification data.<br>
- * Please implement it according to your desired callback logic.*/
+
+/**
+ * When a relevant notification will be found activateCallback method will be activated with the notification data.<br>
+ * Please implement it according to your desired callback logic.
+ */
public interface INotificationCallback {
- void activateCallback(INotificationData data);
+ void activateCallback(INotificationData data);
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IStatusCallback.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IStatusCallback.java
index 5bcc4a2..f9c0b22 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IStatusCallback.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/consumer/IStatusCallback.java
@@ -7,9 +7,9 @@
* 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.
@@ -29,7 +29,7 @@ import org.onap.sdc.api.notification.IStatusData;
*/
@FunctionalInterface
public interface IStatusCallback {
- void activateCallback(IStatusData data);
+ void activateCallback(IStatusData data);
+
-
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IArtifactInfo.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IArtifactInfo.java
index 8c34185..c13f63b 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IArtifactInfo.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IArtifactInfo.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,81 +24,86 @@ import java.util.List;
public interface IArtifactInfo {
-
- /**
- * @return String of the Artifact File Name.
- */
- String getArtifactName();
-
- /**
- * Artifact Type.<br>
- * Following are valid values : HEAT , DG_XML. <br>
- * List of values will be extended in post-1510 releases.
- *
- * @return String of the artifact type.
- */
- String getArtifactType();
-
- /**
- * Relative artifact's URL. Should be used in REST GET API to download the artifact's payload.<br>
- * The full artifact URL will be in the following format :<br>
- * https://{serverBaseURL}/{resourcePath}<br>
- * serverBaseURL - Hostname ( SDC LB FQDN) + optional port <br>
- * resourcePath - "artifactURL" <br>
- * Ex : https://sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml
- *
- * @return String of the Relative artifact's URL.
- */
- String getArtifactURL();
-
- /**
- * Base-64 encoded MD5 checksum of the artifact's payload.<br>
- * Should be used for data integrity validation when an artifact's payload is downloaded.<br>
- *
- * @return String of the checksum of the artifact's payload.
- */
- String getArtifactChecksum();
-
- /**
- * Installation timeout in minutes.<br>
- * Used by the Orchestrator to determine how much time to wait for a heat (or other deployment artifact)<br>
- * This field is only relevant for artifacts of ArtifactTypeEnum HEAT, for other artifacts it will be null.<br>
- * deployment process to finish.<br>
- *
- * @return String of the Installation timeout in minutes.
- */
- Integer getArtifactTimeout();
-
- /**
- * Artifact description
- * @return
- */
- String getArtifactDescription();
-
- /**
- * Artifact Version
- * @return
- */
- String getArtifactVersion();
-
- /**
- * Artifact Unique ID
- * @return
- */
- String getArtifactUUID();
-
-
- /**
- * Returns the artifact it is generated from (relevant for heat_env), or null if there is no such artifact.
- * @return
- */
- IArtifactInfo getGeneratedArtifact();
-
- /**
- * Returns the list of related artifacts (relevant for HEAT_NESTED or HEAT_ARTIFACT), or null if there is no such artifacts.
- * @return
- */
- List<IArtifactInfo> getRelatedArtifacts();
-
-
+
+ /**
+ * @return String of the Artifact File Name.
+ */
+ String getArtifactName();
+
+ /**
+ * Artifact Type.<br>
+ * Following are valid values : HEAT , DG_XML. <br>
+ * List of values will be extended in post-1510 releases.
+ *
+ * @return String of the artifact type.
+ */
+ String getArtifactType();
+
+ /**
+ * Relative artifact's URL. Should be used in REST GET API to download the artifact's payload.<br>
+ * The full artifact URL will be in the following format :<br>
+ * https://{serverBaseURL}/{resourcePath}<br>
+ * serverBaseURL - Hostname ( SDC LB FQDN) + optional port <br>
+ * resourcePath - "artifactURL" <br>
+ * Ex : https://sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml
+ *
+ * @return String of the Relative artifact's URL.
+ */
+ String getArtifactURL();
+
+ /**
+ * Base-64 encoded MD5 checksum of the artifact's payload.<br>
+ * Should be used for data integrity validation when an artifact's payload is downloaded.<br>
+ *
+ * @return String of the checksum of the artifact's payload.
+ */
+ String getArtifactChecksum();
+
+ /**
+ * Installation timeout in minutes.<br>
+ * Used by the Orchestrator to determine how much time to wait for a heat (or other deployment artifact)<br>
+ * This field is only relevant for artifacts of ArtifactTypeEnum HEAT, for other artifacts it will be null.<br>
+ * deployment process to finish.<br>
+ *
+ * @return String of the Installation timeout in minutes.
+ */
+ Integer getArtifactTimeout();
+
+ /**
+ * Artifact description
+ *
+ * @return
+ */
+ String getArtifactDescription();
+
+ /**
+ * Artifact Version
+ *
+ * @return
+ */
+ String getArtifactVersion();
+
+ /**
+ * Artifact Unique ID
+ *
+ * @return
+ */
+ String getArtifactUUID();
+
+
+ /**
+ * Returns the artifact it is generated from (relevant for heat_env), or null if there is no such artifact.
+ *
+ * @return
+ */
+ IArtifactInfo getGeneratedArtifact();
+
+ /**
+ * Returns the list of related artifacts (relevant for HEAT_NESTED or HEAT_ARTIFACT), or null if there is no such artifacts.
+ *
+ * @return
+ */
+ List<IArtifactInfo> getRelatedArtifacts();
+
+
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/INotificationData.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/INotificationData.java
index ecc4a5b..5df130a 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/INotificationData.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/INotificationData.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,49 +23,60 @@ package org.onap.sdc.api.notification;
import java.util.List;
+public interface INotificationData {
+ /**
+ * Global Distribution Identifier: UUID generated by ASDC per each distribution activation.<br>
+ * Generated UUID is compliant with RFC 4122.<br>
+ * It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
+ * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getDistributionID();
+ /**
+ * Logical Service Name.
+ */
+ String getServiceName();
+ /**
+ * Service Version.<br>
+ * Two dot (".") separated digit blocks.<br>
+ * Ex. : "2.0"
+ */
+ String getServiceVersion();
-public interface INotificationData {
- /** Global Distribution Identifier: UUID generated by ASDC per each distribution activation.<br>
- * Generated UUID is compliant with RFC 4122.<br>
- * It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
- Ex.: AA97B177-9383-4934-8543-0F91A7A02836 */
- String getDistributionID();
-
- /**Logical Service Name.*/
- String getServiceName();
-
- /** Service Version.<br>
- * Two dot (".") separated digit blocks.<br>
- Ex. : "2.0"*/
- String getServiceVersion();
-
- /**Global UUID generated by ASDC per each service version. Generated UUID is compliant with RFC 4122.<br>
- It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
- Ex. : AA97B177-9383-4934-8543-0F91A7A02836*/
- String getServiceUUID();
-
- /**
- * Service description
- */
- String getServiceDescription();
-
- /** List of the resource instances */
- List<IResourceInstance> getResources();
-
- /** List of Artifacts On Service Level */
- List<IArtifactInfo> getServiceArtifacts();
-
- /**This method allows getting details of the artifact by its uuid.*/
- IArtifactInfo getArtifactMetadataByUUID(String artifactUUID);
-
- /**
- * Invariant UUID
- */
- String getServiceInvariantUUID();
+ /**
+ * Global UUID generated by ASDC per each service version. Generated UUID is compliant with RFC 4122.<br>
+ * It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
+ * Ex. : AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getServiceUUID();
+
+ /**
+ * Service description
+ */
+ String getServiceDescription();
+
+ /**
+ * List of the resource instances
+ */
+ List<IResourceInstance> getResources();
+
+ /**
+ * List of Artifacts On Service Level
+ */
+ List<IArtifactInfo> getServiceArtifacts();
+
+ /**
+ * This method allows getting details of the artifact by its uuid.
+ */
+ IArtifactInfo getArtifactMetadataByUUID(String artifactUUID);
+
+ /**
+ * Invariant UUID
+ */
+ String getServiceInvariantUUID();
- String getWorkloadContext();
+ String getWorkloadContext();
- void setWorkloadContext(String workloadContext);
+ void setWorkloadContext(String workloadContext);
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IResourceInstance.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IResourceInstance.java
index 0cc3ca4..aece6d0 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IResourceInstance.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IResourceInstance.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,43 +23,63 @@ package org.onap.sdc.api.notification;
import java.util.List;
public interface IResourceInstance {
- /**Logical Resource Instance Name. <br>
- * Unique Identifier of the instance of the specific resource in the service context.**/
- String getResourceInstanceName();
-
- /**resource name */
- String getResourceName();
-
- /**resource version */
- String getResourceVersion();
+ /**
+ * Logical Resource Instance Name. <br>
+ * Unique Identifier of the instance of the specific resource in the service context.
+ **/
+ String getResourceInstanceName();
- /**Resource Type (For Example: VF (Virtual Function) - A subsystem in a service, it can include one or more VFCs. This is what NFV spec refers as VNF.)**/
- String getResourceType();
-
- /**Global UUID of the resource that specific artifact belongs to.<br>
- It is generated by SDC per each resource version.<br>
- Generated UUID is compliant with RFC 4122. It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-"). <br>
- Ex.: AA97B177-9383-4934-8543-0F91A7A02836**/
- String getResourceUUID();
+ /**
+ * resource name
+ */
+ String getResourceName();
- /**List of resource instance deployment artifacts.**/
- List<IArtifactInfo> getArtifacts();
-
- /**Invariant (constant) resource UUID generated on resource creation.**/
- String getResourceInvariantUUID();
-
- /**This UUID is unique in the context of the service.<br>
- It is regenerated whenever a designer makes changes to the resource instance.<br>
- A change may be updating HEAT value, updating property value or name of the resource instance.<br>
- It is also regenerated when an artifact is uploaded to the resource instance.**/
- String getResourceCustomizationUUID();
-
- /**The category of the resource model.<br>
- E.g. "Application L4+".**/
- String getCategory();
-
- /**The subcategory of the resource model.<br>
- E.g. "Call Control"**/
- String getSubcategory();
+ /**
+ * resource version
+ */
+ String getResourceVersion();
+
+ /**
+ * Resource Type (For Example: VF (Virtual Function) - A subsystem in a service, it can include one or more VFCs. This is what NFV spec refers as VNF.)
+ **/
+ String getResourceType();
+
+ /**
+ * Global UUID of the resource that specific artifact belongs to.<br>
+ * It is generated by SDC per each resource version.<br>
+ * Generated UUID is compliant with RFC 4122. It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-"). <br>
+ * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
+ **/
+ String getResourceUUID();
+
+ /**
+ * List of resource instance deployment artifacts.
+ **/
+ List<IArtifactInfo> getArtifacts();
+
+ /**
+ * Invariant (constant) resource UUID generated on resource creation.
+ **/
+ String getResourceInvariantUUID();
+
+ /**
+ * This UUID is unique in the context of the service.<br>
+ * It is regenerated whenever a designer makes changes to the resource instance.<br>
+ * A change may be updating HEAT value, updating property value or name of the resource instance.<br>
+ * It is also regenerated when an artifact is uploaded to the resource instance.
+ **/
+ String getResourceCustomizationUUID();
+
+ /**
+ * The category of the resource model.<br>
+ * E.g. "Application L4+".
+ **/
+ String getCategory();
+
+ /**
+ * The subcategory of the resource model.<br>
+ * E.g. "Call Control"
+ **/
+ String getSubcategory();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IStatusData.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IStatusData.java
index 734c200..314c592 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IStatusData.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IStatusData.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,43 +23,47 @@ package org.onap.sdc.api.notification;
import org.onap.sdc.utils.DistributionStatusEnum;
public interface IStatusData {
- /**
- * Global Distribution Identifier: UUID generated by SDC per each
- * distribution activation.<br>
- * Generated UUID is compliant with RFC 4122.<br>
- * It is a 128-bit value formatted into blocks of hexadecimal digits
- * separated by a hyphen ("-").<br>
- * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
- */
- String getDistributionID();
+ /**
+ * Global Distribution Identifier: UUID generated by SDC per each
+ * distribution activation.<br>
+ * Generated UUID is compliant with RFC 4122.<br>
+ * It is a 128-bit value formatted into blocks of hexadecimal digits
+ * separated by a hyphen ("-").<br>
+ * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getDistributionID();
- /** Unique ID of ONAP component instance (e.x INSTAR name). */
- String getConsumerID();
+ /**
+ * Unique ID of ONAP component instance (e.x INSTAR name).
+ */
+ String getConsumerID();
- /** The predefined ONAP component name configured on the component. */
- String getComponentName();
+ /**
+ * The predefined ONAP component name configured on the component.
+ */
+ String getComponentName();
- /**
- * Timestamp of the distribution status report creation. The number of
- * seconds that have elapsed since January 1, 1970
- */
- Long getTimestamp();
- /**
- * Resource URL of the downloaded/deployed artifact - URL specified in the
- * distribution notification message.
- */
- String getArtifactURL();
- /**
- * Status Event type
- */
- DistributionStatusEnum getStatus();
- /**
- * Error Reason describing the Status Event.
- */
- String getErrorReason();
+ /**
+ * Timestamp of the distribution status report creation. The number of
+ * seconds that have elapsed since January 1, 1970
+ */
+ Long getTimestamp();
+ /**
+ * Resource URL of the downloaded/deployed artifact - URL specified in the
+ * distribution notification message.
+ */
+ String getArtifactURL();
+ /**
+ * Status Event type
+ */
+ DistributionStatusEnum getStatus();
+
+ /**
+ * Error Reason describing the Status Event.
+ */
+ String getErrorReason();
-
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IVfModuleMetadata.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IVfModuleMetadata.java
index 3613c94..5347189 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IVfModuleMetadata.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/notification/IVfModuleMetadata.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,43 +21,49 @@
package org.onap.sdc.api.notification;
import java.util.List;
-/**VF Module in the resource (VF) context*/
+
+/**
+ * VF Module in the resource (VF) context
+ */
public interface IVfModuleMetadata {
- /**Logical VF Module Name. Unique Identifier of VF Module in the resource (VF) context.<br>
- Ex. : "PCRF-module-0"
- */
- String getVfModuleModelName();
-
- /**Invariant VF Module UUID generated on VF Module creation according to RFC 4122 <br>
- It is generated on service creation and stays invariant even if service name /version are updated.
- */
- String getVfModuleModelInvariantUUID();
-
- /**
- Resource Version . Ex. : "1"
- */
- String getVfModuleModelVersion();
-
- /**Global UUID of the VF Module.<br>
- It is generated by ASDC per each new VF module version. Generated UUID is compliant with RFC 4122. It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
- Ex.: AA97B177-9383-4934-8543-0F91A7A02836
- */
- String getVfModuleModelUUID();
-
-
- /**
- * VF Module textual description. Can be empty.
- */
- String getVfModuleModelDescription();
-
-
- /**
- * Is this VF module is the base module of the VF.
- * */
- boolean isBase();
-
- /**
- * Array of VF Module deployment artifacts UUID.
- * */
- List<String> getArtifacts();
+ /**
+ * Logical VF Module Name. Unique Identifier of VF Module in the resource (VF) context.<br>
+ * Ex. : "PCRF-module-0"
+ */
+ String getVfModuleModelName();
+
+ /**
+ * Invariant VF Module UUID generated on VF Module creation according to RFC 4122 <br>
+ * It is generated on service creation and stays invariant even if service name /version are updated.
+ */
+ String getVfModuleModelInvariantUUID();
+
+ /**
+ * Resource Version . Ex. : "1"
+ */
+ String getVfModuleModelVersion();
+
+ /**
+ * Global UUID of the VF Module.<br>
+ * It is generated by ASDC per each new VF module version. Generated UUID is compliant with RFC 4122. It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
+ * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getVfModuleModelUUID();
+
+
+ /**
+ * VF Module textual description. Can be empty.
+ */
+ String getVfModuleModelDescription();
+
+
+ /**
+ * Is this VF module is the base module of the VF.
+ */
+ boolean isBase();
+
+ /**
+ * Array of VF Module deployment artifacts UUID.
+ */
+ List<String> getArtifacts();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientDownloadResult.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientDownloadResult.java
index 47fe023..8183b7d 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientDownloadResult.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientDownloadResult.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,26 +20,28 @@
package org.onap.sdc.api.results;
-/**Distribution Client Result For Download API*/
-public interface IDistributionClientDownloadResult extends IDistributionClientResult{
-
-
- byte[] getArtifactPayload();
-
-
- /**
- * @deprecated
- * This method is deprecated and will be removed in 1710.
- * It returns <b>attachment; filename="filename"</b> rather than <b>"filename"</b>.
- * Please use {@link #getArtifactFilename()}.
- * @return
- */
- @Deprecated
- String getArtifactName();
-
- /**
- * Returns the filename of the artifact.
- * @return the filename of the artifact.
- */
- String getArtifactFilename();
+/**
+ * Distribution Client Result For Download API
+ */
+public interface IDistributionClientDownloadResult extends IDistributionClientResult {
+
+
+ byte[] getArtifactPayload();
+
+
+ /**
+ * @return
+ * @deprecated This method is deprecated and will be removed in 1710.
+ * It returns <b>attachment; filename="filename"</b> rather than <b>"filename"</b>.
+ * Please use {@link #getArtifactFilename()}.
+ */
+ @Deprecated
+ String getArtifactName();
+
+ /**
+ * Returns the filename of the artifact.
+ *
+ * @return the filename of the artifact.
+ */
+ String getArtifactFilename();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientResult.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientResult.java
index 4f33555..9843095 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientResult.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/results/IDistributionClientResult.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,8 +21,12 @@
package org.onap.sdc.api.results;
import org.onap.sdc.utils.DistributionActionResultEnum;
-/**General Distribution Client Result*/
+
+/**
+ * General Distribution Client Result
+ */
public interface IDistributionClientResult {
- DistributionActionResultEnum getDistributionActionResult();
- String getDistributionMessageResult();
+ DistributionActionResultEnum getDistributionActionResult();
+
+ String getDistributionMessageResult();
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/AsdcUrls.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/AsdcUrls.java
index 72a51d3..b1d51d9 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/AsdcUrls.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/AsdcUrls.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,9 +22,13 @@ package org.onap.sdc.http;
public class AsdcUrls {
- public static final String GET_CLUSTER_SERVER_LIST = "/sdc/v1/distributionUebCluster";
- public static final String GET_VALID_ARTIFACT_TYPES = "/sdc/v1/artifactTypes";
- public static final String POST_FOR_TOPIC_REGISTRATION = "/sdc/v1/registerForDistribution";
- public static final String POST_FOR_UNREGISTER = "/sdc/v1/unRegisterForDistribution";
-
+ private AsdcUrls() {
+
+ }
+
+ public static final String GET_CLUSTER_SERVER_LIST = "/sdc/v1/distributionUebCluster";
+ public static final String GET_VALID_ARTIFACT_TYPES = "/sdc/v1/artifactTypes";
+ public static final String POST_FOR_TOPIC_REGISTRATION = "/sdc/v1/registerForDistribution";
+ public static final String POST_FOR_UNREGISTER = "/sdc/v1/unRegisterForDistribution";
+
}
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 c241bec..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
@@ -7,9 +7,9 @@
* 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.
@@ -66,286 +66,291 @@ import org.slf4j.LoggerFactory;
public class HttpAsdcClient implements IHttpAsdcClient {
- private static final String TLS = "TLSv1.2";
- private static final String AUTHORIZATION_HEADER = "Authorization";
- private static final String HTTPS = "https://";
- private static Logger log = LoggerFactory.getLogger(HttpAsdcClient.class.getName());
- private CloseableHttpClient httpClient = null;
- private String serverFqdn = null;
- private String authHeaderValue = "";
-
- public HttpAsdcClient(IConfiguration configuraion) {
- this.serverFqdn = configuraion.getAsdcAddress();
-
- String username = configuraion.getUser();
- String password = configuraion.getPassword();
- initSSL(username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth());
-
- String userNameAndPassword = username + ":" + password;
- this.authHeaderValue = "Basic " + Base64.encodeBase64String(userNameAndPassword.getBytes());
- }
-
- // @SuppressWarnings("deprecation")
- private void initSSL(String username, String password, String keyStorePath, String keyStoePass, boolean isSupportSSLVerification) {
-
- try {
- HostnameVerifier hostnameVerifier = new HostnameVerifier() {
-
- @Override
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- };
-
- // SSLContextBuilder is not thread safe
- // @SuppressWarnings("deprecation")
- CredentialsProvider credsProvider = new BasicCredentialsProvider();
- credsProvider.setCredentials(new AuthScope("localhost", 443), new UsernamePasswordCredentials(username, password));
- SSLContext sslContext;
- sslContext = SSLContext.getInstance(TLS);
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- KeyStore trustStore = null;
- tmf.init(trustStore);
- TrustManager[] tms = tmf.getTrustManagers();
- if (isSupportSSLVerification) {
-
- if (keyStorePath != null && !keyStorePath.isEmpty()) {
- // trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- // trustStore.load(new FileInputStream(keyStorePath), keyStoePass.toCharArray());
-
- // Using null here initialises the TMF with the default trust store.
-
- // Get hold of the default trust manager
- X509TrustManager defaultTm = null;
- for (TrustManager tm : tmf.getTrustManagers()) {
- if (tm instanceof X509TrustManager) {
- defaultTm = (X509TrustManager) tm;
- break;
- }
- }
-
- // Do the same with your trust store this time
- // Adapt how you load the keystore to your needs
- trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- trustStore.load(new FileInputStream(keyStorePath), keyStoePass.toCharArray());
-
- tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(trustStore);
-
- // Get hold of the default trust manager
- X509TrustManager myTm = null;
- for (TrustManager tm : tmf.getTrustManagers()) {
- if (tm instanceof X509TrustManager) {
- myTm = (X509TrustManager) tm;
- break;
- }
- }
-
- // Wrap it in your own class.
- final X509TrustManager finalDefaultTm = defaultTm;
- final X509TrustManager finalMyTm = myTm;
- X509TrustManager customTm = new X509TrustManager() {
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- // If you're planning to use client-cert auth,
- // merge results from "defaultTm" and "myTm".
- return finalDefaultTm.getAcceptedIssuers();
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- try {
- finalMyTm.checkServerTrusted(chain, authType);
- } catch (CertificateException e) {
- // This will throw another CertificateException if this fails too.
- finalDefaultTm.checkServerTrusted(chain, authType);
- }
- }
-
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- // If you're planning to use client-cert auth,
- // do the same as checking the server.
- finalDefaultTm.checkClientTrusted(chain, authType);
- }
- };
-
- tms = new TrustManager[] { customTm };
-
- }
-
- sslContext.init(null, tms, null);
- SSLContext.setDefault(sslContext);
-
-
-
- } else {
-
- SSLContextBuilder builder = new SSLContextBuilder();
-
- builder.loadTrustMaterial(null, new TrustStrategy() {
- public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- return true;
- }
- });
-
- sslContext = builder.build();
- }
-
- SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" }, null, hostnameVerifier);
- httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).setSSLSocketFactory(sslsf).build();
-
- } catch (Exception e) {
- log.error("Failed to create https client", e);
-
- }
-
- return;
- }
-
- public HttpAsdcResponse postRequest(String requestUrl, HttpEntity entity, Map<String, String> headersMap) {
- return postRequest(requestUrl, entity, headersMap, true).getFirst();
- }
-
- public Pair<HttpAsdcResponse, CloseableHttpResponse> postRequest(String requestUrl, HttpEntity entity, Map<String, String> headersMap, boolean closeTheRequest) {
- Pair<HttpAsdcResponse, CloseableHttpResponse> ret;
- CloseableHttpResponse httpResponse = null;
- HttpAsdcResponse response = null;
- HttpPost httpPost = new HttpPost(HTTPS + serverFqdn + requestUrl);
- List<Header> headers = addHeadersToHttpRequest(headersMap);
- for (Header header : headers) {
- httpPost.addHeader(header);
- }
-
- httpPost.setHeader(AUTHORIZATION_HEADER, this.authHeaderValue);
-
- httpPost.setEntity(entity);
- try {
- httpResponse = httpClient.execute(httpPost);
- response = new HttpAsdcResponse(httpResponse.getStatusLine().getStatusCode(), httpResponse.getEntity());
-
- } catch (IOException e) {
- log.error("failed to send request to url: " + requestUrl);
- StringEntity errorEntity = null;
- try {
- errorEntity = new StringEntity("failed to send request");
- } catch (UnsupportedEncodingException e1) {
- }
-
- response = new HttpAsdcResponse(500, errorEntity);
-
- } finally {
- if (closeTheRequest) {
- if (httpResponse != null) {
- try {
- httpResponse.close();
-
- } catch (IOException e) {
- log.error("failed to close http response");
- }
- }
- ret = new Pair<>(response, null);
- } else {
- ret = new Pair<>(response, httpResponse);
- }
- }
-
- return ret;
- }
-
- public HttpAsdcResponse getRequest(String requestUrl, Map<String, String> headersMap) {
-
- return getRequest(requestUrl, headersMap, true).getFirst();
-
- }
-
- public Pair<HttpAsdcResponse, CloseableHttpResponse> getRequest(String requestUrl, Map<String, String> headersMap, boolean closeTheRequest) {
- Pair<HttpAsdcResponse, CloseableHttpResponse> ret;
- CloseableHttpResponse httpResponse = null;
- String url = HTTPS + serverFqdn + requestUrl;
- log.debug("url to send {}", url);
- HttpGet httpGet = new HttpGet(url);
- List<Header> headers = addHeadersToHttpRequest(headersMap);
- for (Header header : headers) {
- httpGet.addHeader(header);
- }
-
- httpGet.setHeader(AUTHORIZATION_HEADER, this.authHeaderValue);
-
- HttpAsdcResponse response = null;
- try {
- httpResponse = httpClient.execute(httpGet);
-
- log.debug("GET Response Status {}", httpResponse.getStatusLine().getStatusCode());
- Header[] headersRes = httpResponse.getAllHeaders();
- Map<String, String> headersResMap = new HashMap<>();
- for (Header header : headersRes) {
- headersResMap.put(header.getName(), header.getValue());
- }
- response = new HttpAsdcResponse(httpResponse.getStatusLine().getStatusCode(), httpResponse.getEntity(), headersResMap);
-
- } catch (UnknownHostException | ConnectException e) {
- log.error("failed to connect to url: {}", requestUrl, e);
- StringEntity errorEntity = null;
- try {
- errorEntity = new StringEntity("failed to connect");
- } catch (UnsupportedEncodingException e1) {
- }
-
- response = new HttpAsdcResponse(HttpStatus.SC_BAD_GATEWAY, errorEntity);
-
- } catch (IOException e) {
- log.error("failed to send request to url: " + requestUrl + " error " + e.getMessage());
- StringEntity errorEntity = null;
- try {
- errorEntity = new StringEntity("failed to send request " + e.getMessage());
- } catch (UnsupportedEncodingException e1) {
- }
-
- response = new HttpAsdcResponse(HttpStatus.SC_BAD_GATEWAY, errorEntity);
-
- } finally {
-
- if (closeTheRequest) {
- if (httpResponse != null) {
- try {
- httpResponse.close();
-
- } catch (IOException e) {
- log.error("failed to close http response");
- }
- }
- ret = new Pair<HttpAsdcResponse, CloseableHttpResponse>(response, null);
- } else {
- ret = new Pair<HttpAsdcResponse, CloseableHttpResponse>(response, httpResponse);
- }
- }
-
- return ret;
-
- }
-
- public void closeHttpClient() {
- try {
- httpClient.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- log.error("failed to close http client");
- }
-
- }
-
- private List<Header> addHeadersToHttpRequest(Map<String, String> headersMap) {
-
- List<Header> requestHeaders = new ArrayList<Header>();
-
- Set<String> headersKyes = headersMap.keySet();
- for (String key : headersKyes) {
- Header requestHeader = new BasicHeader(key, headersMap.get(key));
- requestHeaders.add(requestHeader);
- }
-
- return requestHeaders;
- }
+ private static final String TLS = "TLSv1.2";
+ private static final String AUTHORIZATION_HEADER = "Authorization";
+ private static final String HTTPS = "https://";
+ public static final int AUTHORIZATION_SCOPE_PORT = 443;
+ private static Logger log = LoggerFactory.getLogger(HttpAsdcClient.class.getName());
+ private CloseableHttpClient httpClient = null;
+ private String serverFqdn = null;
+ private String authHeaderValue = "";
+
+ public HttpAsdcClient(IConfiguration configuraion) {
+ this.serverFqdn = configuraion.getAsdcAddress();
+
+ String username = configuraion.getUser();
+ String password = configuraion.getPassword();
+ initSSL(username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth());
+
+ String userNameAndPassword = username + ":" + password;
+ this.authHeaderValue = "Basic " + Base64.encodeBase64String(userNameAndPassword.getBytes());
+ }
+
+ // @SuppressWarnings("deprecation")
+ private void initSSL(String username, String password, String keyStorePath, String keyStoePass, boolean isSupportSSLVerification) {
+
+ try {
+ HostnameVerifier hostnameVerifier = new HostnameVerifier() {
+
+ @Override
+ public boolean verify(String hostname, SSLSession session) {
+ return true;
+ }
+ };
+
+ // SSLContextBuilder is not thread safe
+ // @SuppressWarnings("deprecation")
+ CredentialsProvider credsProvider = new BasicCredentialsProvider();
+ credsProvider.setCredentials(new AuthScope("localhost", AUTHORIZATION_SCOPE_PORT), new UsernamePasswordCredentials(username, password));
+ SSLContext sslContext;
+ sslContext = SSLContext.getInstance(TLS);
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ KeyStore trustStore = null;
+ tmf.init(trustStore);
+ TrustManager[] tms = tmf.getTrustManagers();
+ if (isSupportSSLVerification) {
+
+ if (keyStorePath != null && !keyStorePath.isEmpty()) {
+ // trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ // trustStore.load(new FileInputStream(keyStorePath), keyStoePass.toCharArray());
+
+ // Using null here initialises the TMF with the default trust store.
+
+ // Get hold of the default trust manager
+ X509TrustManager defaultTm = null;
+ for (TrustManager tm : tmf.getTrustManagers()) {
+ if (tm instanceof X509TrustManager) {
+ defaultTm = (X509TrustManager) tm;
+ break;
+ }
+ }
+
+ // Do the same with your trust store this time
+ // Adapt how you load the keystore to your needs
+ trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ trustStore.load(new FileInputStream(keyStorePath), keyStoePass.toCharArray());
+
+ tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(trustStore);
+
+ // Get hold of the default trust manager
+ X509TrustManager myTm = null;
+ for (TrustManager tm : tmf.getTrustManagers()) {
+ if (tm instanceof X509TrustManager) {
+ myTm = (X509TrustManager) tm;
+ break;
+ }
+ }
+
+ // Wrap it in your own class.
+ final X509TrustManager finalDefaultTm = defaultTm;
+ final X509TrustManager finalMyTm = myTm;
+ X509TrustManager customTm = new X509TrustManager() {
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ // If you're planning to use client-cert auth,
+ // merge results from "defaultTm" and "myTm".
+ return finalDefaultTm.getAcceptedIssuers();
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType)
+ throws CertificateException {
+ try {
+ finalMyTm.checkServerTrusted(chain, authType);
+ } catch (CertificateException e) {
+ // This will throw another CertificateException if this fails too.
+ finalDefaultTm.checkServerTrusted(chain, authType);
+ }
+ }
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType)
+ throws CertificateException {
+ // If you're planning to use client-cert auth,
+ // do the same as checking the server.
+ finalDefaultTm.checkClientTrusted(chain, authType);
+ }
+ };
+
+ tms = new TrustManager[]{customTm};
+
+ }
+
+ sslContext.init(null, tms, null);
+ SSLContext.setDefault(sslContext);
+
+
+ } else {
+
+ SSLContextBuilder builder = new SSLContextBuilder();
+
+ builder.loadTrustMaterial(null, new TrustStrategy() {
+ public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ return true;
+ }
+ });
+
+ sslContext = builder.build();
+ }
+
+ SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1.2"}, null, hostnameVerifier);
+ httpClient = HttpClientBuilder.create().
+ setDefaultCredentialsProvider(credsProvider).
+ setSSLSocketFactory(sslsf).
+ build();
+
+ } catch (Exception e) {
+ log.error("Failed to create https client", e);
+
+ }
+
+ return;
+ }
+
+ public HttpAsdcResponse postRequest(String requestUrl, HttpEntity entity, Map<String, String> headersMap) {
+ return postRequest(requestUrl, entity, headersMap, true).getFirst();
+ }
+
+ public Pair<HttpAsdcResponse, CloseableHttpResponse> postRequest(String requestUrl, HttpEntity entity, Map<String, String> headersMap, boolean closeTheRequest) {
+ Pair<HttpAsdcResponse, CloseableHttpResponse> ret;
+ CloseableHttpResponse httpResponse = null;
+ HttpAsdcResponse response = null;
+ HttpPost httpPost = new HttpPost(HTTPS + serverFqdn + requestUrl);
+ List<Header> headers = addHeadersToHttpRequest(headersMap);
+ for (Header header : headers) {
+ httpPost.addHeader(header);
+ }
+
+ httpPost.setHeader(AUTHORIZATION_HEADER, this.authHeaderValue);
+
+ httpPost.setEntity(entity);
+ try {
+ httpResponse = httpClient.execute(httpPost);
+ response = new HttpAsdcResponse(httpResponse.getStatusLine().getStatusCode(), httpResponse.getEntity());
+
+ } catch (IOException e) {
+ log.error("failed to send request to url: " + requestUrl);
+ StringEntity errorEntity = null;
+ try {
+ errorEntity = new StringEntity("failed to send request");
+ } catch (UnsupportedEncodingException e1) {
+ }
+
+ response = new HttpAsdcResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, errorEntity);
+
+ } finally {
+ if (closeTheRequest) {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+
+ } catch (IOException e) {
+ log.error("failed to close http response");
+ }
+ }
+ ret = new Pair<>(response, null);
+ } else {
+ ret = new Pair<>(response, httpResponse);
+ }
+ }
+
+ return ret;
+ }
+
+ public HttpAsdcResponse getRequest(String requestUrl, Map<String, String> headersMap) {
+
+ return getRequest(requestUrl, headersMap, true).getFirst();
+
+ }
+
+ public Pair<HttpAsdcResponse, CloseableHttpResponse> getRequest(String requestUrl, Map<String, String> headersMap, boolean closeTheRequest) {
+ Pair<HttpAsdcResponse, CloseableHttpResponse> ret;
+ CloseableHttpResponse httpResponse = null;
+ String url = HTTPS + serverFqdn + requestUrl;
+ log.debug("url to send {}", url);
+ HttpGet httpGet = new HttpGet(url);
+ List<Header> headers = addHeadersToHttpRequest(headersMap);
+ for (Header header : headers) {
+ httpGet.addHeader(header);
+ }
+
+ httpGet.setHeader(AUTHORIZATION_HEADER, this.authHeaderValue);
+
+ HttpAsdcResponse response = null;
+ try {
+ httpResponse = httpClient.execute(httpGet);
+
+ log.debug("GET Response Status {}", httpResponse.getStatusLine().getStatusCode());
+ Header[] headersRes = httpResponse.getAllHeaders();
+ Map<String, String> headersResMap = new HashMap<>();
+ for (Header header : headersRes) {
+ headersResMap.put(header.getName(), header.getValue());
+ }
+ response = new HttpAsdcResponse(httpResponse.getStatusLine().getStatusCode(), httpResponse.getEntity(), headersResMap);
+
+ } catch (UnknownHostException | ConnectException e) {
+ log.error("failed to connect to url: {}", requestUrl, e);
+ StringEntity errorEntity = null;
+ try {
+ errorEntity = new StringEntity("failed to connect");
+ } catch (UnsupportedEncodingException e1) {
+ }
+
+ response = new HttpAsdcResponse(HttpStatus.SC_BAD_GATEWAY, errorEntity);
+
+ } catch (IOException e) {
+ log.error("failed to send request to url: " + requestUrl + " error " + e.getMessage());
+ StringEntity errorEntity = null;
+ try {
+ errorEntity = new StringEntity("failed to send request " + e.getMessage());
+ } catch (UnsupportedEncodingException e1) {
+ }
+
+ response = new HttpAsdcResponse(HttpStatus.SC_BAD_GATEWAY, errorEntity);
+
+ } finally {
+
+ if (closeTheRequest) {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+
+ } catch (IOException e) {
+ log.error("failed to close http response");
+ }
+ }
+ ret = new Pair<HttpAsdcResponse, CloseableHttpResponse>(response, null);
+ } else {
+ ret = new Pair<HttpAsdcResponse, CloseableHttpResponse>(response, httpResponse);
+ }
+ }
+
+ return ret;
+
+ }
+
+ public void closeHttpClient() {
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ log.error("failed to close http client");
+ }
+
+ }
+
+ private List<Header> addHeadersToHttpRequest(Map<String, String> headersMap) {
+
+ List<Header> requestHeaders = new ArrayList<Header>();
+
+ Set<String> headersKyes = headersMap.keySet();
+ for (String key : headersKyes) {
+ Header requestHeader = new BasicHeader(key, headersMap.get(key));
+ requestHeaders.add(requestHeader);
+ }
+
+ return requestHeaders;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcResponse.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcResponse.java
index 9734a32..8b85684 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcResponse.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcResponse.java
@@ -7,9 +7,9 @@
* 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.
@@ -26,46 +26,46 @@ import org.apache.http.HttpEntity;
public class HttpAsdcResponse {
- int status;
- HttpEntity message;
- Map<String, String> headersMap;
-
- public HttpAsdcResponse(int status, HttpEntity message) {
- super();
- this.status = status;
- this.message = message;
- }
-
- public HttpAsdcResponse(int status, HttpEntity message, Map<String, String> headersMap) {
- super();
- this.status = status;
- this.message = message;
- this.headersMap = headersMap;
- }
+ private int status;
+ private HttpEntity message;
+ private Map<String, String> headersMap;
- public Map<String, String> getHeadersMap() {
- return headersMap;
- }
+ public HttpAsdcResponse(int status, HttpEntity message) {
+ super();
+ this.status = status;
+ this.message = message;
+ }
- public void setHeadersMap(Map<String, String> headersMap) {
- this.headersMap = headersMap;
- }
+ public HttpAsdcResponse(int status, HttpEntity message, Map<String, String> headersMap) {
+ super();
+ this.status = status;
+ this.message = message;
+ this.headersMap = headersMap;
+ }
- public int getStatus() {
- return status;
- }
+ public Map<String, String> getHeadersMap() {
+ return headersMap;
+ }
- public void setStatus(int status) {
- this.status = status;
- }
+ public void setHeadersMap(Map<String, String> headersMap) {
+ this.headersMap = headersMap;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public HttpEntity getMessage() {
+ return message;
+ }
+
+ public void setMessage(HttpEntity message) {
+ this.message = message;
+ }
- public HttpEntity getMessage() {
- return message;
- }
- public void setMessage(HttpEntity message) {
- this.message = message;
- }
-
-
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/IHttpAsdcClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/IHttpAsdcClient.java
index a3cc5e5..2a0d9a0 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/IHttpAsdcClient.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/IHttpAsdcClient.java
@@ -7,9 +7,9 @@
* 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.
@@ -25,9 +25,11 @@ import java.util.Map;
import org.apache.http.HttpEntity;
public interface IHttpAsdcClient {
-
- HttpAsdcResponse postRequest(String requestUrl, HttpEntity entity, Map<String, String> headersMap);
- HttpAsdcResponse getRequest(String requestUrl, Map<String, String> headersMap);
- void closeHttpClient();
-
+
+ HttpAsdcResponse postRequest(String requestUrl, HttpEntity entity, Map<String, String> headersMap);
+
+ HttpAsdcResponse getRequest(String requestUrl, Map<String, String> headersMap);
+
+ void closeHttpClient();
+
}
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 41d78ba..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
@@ -7,9 +7,9 @@
* 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.
@@ -58,341 +58,333 @@ import com.google.gson.reflect.TypeToken;
import fj.data.Either;
public class SdcConnectorClient {
- String contentDispositionHeader = "Content-Disposition";
- private static Logger log = LoggerFactory.getLogger(SdcConnectorClient.class.getName());
- private IConfiguration configuration;
- private HttpAsdcClient httpClient = null;
+ private String contentDispositionHeader = "Content-Disposition";
+ private static Logger log = LoggerFactory.getLogger(SdcConnectorClient.class.getName());
+ private IConfiguration configuration;
+ private HttpAsdcClient httpClient = null;
- public void init(IConfiguration configuraion) {
- this.configuration = configuraion;
- httpClient = new HttpAsdcClient(configuration);
- }
+ public void init(IConfiguration configuraion) {
+ this.configuration = configuraion;
+ httpClient = new HttpAsdcClient(configuration);
+ }
- public void close() {
- if (httpClient != null) {
- httpClient.closeHttpClient();
- }
- }
+ public void close() {
+ if (httpClient != null) {
+ httpClient.closeHttpClient();
+ }
+ }
- public IConfiguration getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(IConfiguration configuration) {
- this.configuration = configuration;
- }
-
- public HttpAsdcClient getHttpClient() {
- return httpClient;
- }
+ public IConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(IConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public HttpAsdcClient getHttpClient() {
+ return httpClient;
+ }
- public void setHttpClient(HttpAsdcClient httpClient) {
- this.httpClient = httpClient;
- }
+ public void setHttpClient(HttpAsdcClient httpClient) {
+ this.httpClient = httpClient;
+ }
- public Either<List<String>, IDistributionClientResult> getValidArtifactTypesList() {
- Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair = performAsdcServerRequest(AsdcUrls.GET_VALID_ARTIFACT_TYPES);
- HttpAsdcResponse getArtifactTypeResponse = getServersResponsePair.getFirst();
+ public Either<List<String>, IDistributionClientResult> getValidArtifactTypesList() {
+ Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair = performAsdcServerRequest(AsdcUrls.GET_VALID_ARTIFACT_TYPES);
+ HttpAsdcResponse getArtifactTypeResponse = getServersResponsePair.getFirst();
- Either<List<String>, IDistributionClientResult> response;
- if (getArtifactTypeResponse.getStatus() == HttpStatus.SC_OK) {
- response = parseGetValidArtifactTypesResponse(getArtifactTypeResponse);
- } else {
- IDistributionClientResult asdcError = handleAsdcError(getArtifactTypeResponse);
- response = Either.right(asdcError);
+ Either<List<String>, IDistributionClientResult> response;
+ if (getArtifactTypeResponse.getStatus() == HttpStatus.SC_OK) {
+ response = parseGetValidArtifactTypesResponse(getArtifactTypeResponse);
+ } else {
+ IDistributionClientResult asdcError = handleAsdcError(getArtifactTypeResponse);
+ response = Either.right(asdcError);
- }
- handeAsdcConnectionClose(getServersResponsePair);
- return response;
+ }
+ handeAsdcConnectionClose(getServersResponsePair);
+ return response;
- }
+ }
- private void handeAsdcConnectionClose(Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair) {
- if (getServersResponsePair.getSecond() != null) {
- try {
- getServersResponsePair.getSecond().close();
+ private void handeAsdcConnectionClose(Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair) {
+ if (getServersResponsePair.getSecond() != null) {
+ try {
+ getServersResponsePair.getSecond().close();
- } catch (IOException e) {
- log.error("failed to close http response");
- }
+ } catch (IOException e) {
+ log.error("failed to close http response");
+ }
- }
- }
+ }
+ }
- private Pair<HttpAsdcResponse, CloseableHttpResponse> performAsdcServerRequest(final String url) {
- String requestId = UUID.randomUUID().toString();
- Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId);
- log.debug("about to perform getServerList. requestId= {} url= {}", requestId, url);
- Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair = httpClient.getRequest(url, requestHeaders, false);
- return getServersResponsePair;
- }
+ private Pair<HttpAsdcResponse, CloseableHttpResponse> performAsdcServerRequest(final String url) {
+ String requestId = UUID.randomUUID().toString();
+ Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId);
+ log.debug("about to perform getServerList. requestId= {} url= {}", requestId, url);
+ Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair = httpClient.getRequest(url, requestHeaders, false);
+ return getServersResponsePair;
+ }
- public Either<TopicRegistrationResponse, DistributionClientResultImpl> registerAsdcTopics(ApiCredential credential) {
+ public Either<TopicRegistrationResponse, DistributionClientResultImpl> registerAsdcTopics(ApiCredential credential) {
- Either<TopicRegistrationResponse, DistributionClientResultImpl> response = null;
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> response = null;
- String requestId = UUID.randomUUID().toString();
- Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId);
+ String requestId = UUID.randomUUID().toString();
+ Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId);
- RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress());
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String jsonRequest = gson.toJson(registrationRequest);
- StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON);
+ RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress());
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String jsonRequest = gson.toJson(registrationRequest);
+ StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON);
- log.debug("about to perform registerAsdcTopics. requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_TOPIC_REGISTRATION);
- Pair<HttpAsdcResponse, CloseableHttpResponse> registerResponsePair = httpClient.postRequest(AsdcUrls.POST_FOR_TOPIC_REGISTRATION, body, requestHeaders, false);
- HttpAsdcResponse registerResponse = registerResponsePair.getFirst();
- int status = registerResponse.getStatus();
+ log.debug("about to perform registerAsdcTopics. requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_TOPIC_REGISTRATION);
+ Pair<HttpAsdcResponse, CloseableHttpResponse> registerResponsePair = httpClient.postRequest(AsdcUrls.POST_FOR_TOPIC_REGISTRATION, body, requestHeaders, false);
+ HttpAsdcResponse registerResponse = registerResponsePair.getFirst();
+ int status = registerResponse.getStatus();
- if (status == HttpStatus.SC_OK) {
- response = parseRegistrationResponse(registerResponse);
+ if (status == HttpStatus.SC_OK) {
+ response = parseRegistrationResponse(registerResponse);
- } else {
- DistributionClientResultImpl asdcError = handleAsdcError(registerResponse);
- return Either.right(asdcError);
- }
- handeAsdcConnectionClose(registerResponsePair);
-
- log.debug("registerAsdcTopics response= " + status + ". requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_TOPIC_REGISTRATION);
- return response;
-
- }
-
- public IDistributionClientResult unregisterTopics(ApiCredential credential) {
+ } else {
+ DistributionClientResultImpl asdcError = handleAsdcError(registerResponse);
+ return Either.right(asdcError);
+ }
+ handeAsdcConnectionClose(registerResponsePair);
+
+ log.debug("registerAsdcTopics response= " + status + ". requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_TOPIC_REGISTRATION);
+ return response;
+
+ }
+
+ public IDistributionClientResult unregisterTopics(ApiCredential credential) {
- DistributionClientResultImpl response = null;
+ DistributionClientResultImpl response = null;
- String requestId = UUID.randomUUID().toString();
- HttpAsdcClient httpClient = new HttpAsdcClient(configuration);
- Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId);
+ String requestId = UUID.randomUUID().toString();
+ HttpAsdcClient httpClient = new HttpAsdcClient(configuration);
+ Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId);
- RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress());
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String jsonRequest = gson.toJson(registrationRequest);
- StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON);
+ RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress());
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String jsonRequest = gson.toJson(registrationRequest);
+ StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON);
- log.debug("about to perform unregisterTopics. requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_UNREGISTER);
- Pair<HttpAsdcResponse, CloseableHttpResponse> unRegisterResponsePair = httpClient.postRequest(AsdcUrls.POST_FOR_UNREGISTER, body, requestHeaders, false);
- HttpAsdcResponse unRegisterResponse = unRegisterResponsePair.getFirst();
- int status = unRegisterResponse.getStatus();
- if (status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_OK) {
- response = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "unregistration successful");
+ log.debug("about to perform unregisterTopics. requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_UNREGISTER);
+ Pair<HttpAsdcResponse, CloseableHttpResponse> unRegisterResponsePair = httpClient.postRequest(AsdcUrls.POST_FOR_UNREGISTER, body, requestHeaders, false);
+ HttpAsdcResponse unRegisterResponse = unRegisterResponsePair.getFirst();
+ int status = unRegisterResponse.getStatus();
+ if (status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_OK) {
+ response = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "unregistration successful");
- } else {
- response = handleAsdcError(unRegisterResponse);
- }
-
- handeAsdcConnectionClose(unRegisterResponsePair);
-
- log.debug("unregisterTopics response = " + status + ". requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_UNREGISTER);
-
- return response;
-
- }
-
- public DistributionClientDownloadResultImpl dowloadArtifact(IArtifactInfo artifactInfo) {
- DistributionClientDownloadResultImpl response = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to download artifact from ASDC");
-
- String requestId = UUID.randomUUID().toString();
- Map<String, String> requestHeaders = new HashMap<String, String>();
- requestHeaders.put(DistributionClientConstants.HEADER_REQUEST_ID, requestId);
- requestHeaders.put(DistributionClientConstants.HEADER_INSTANCE_ID, configuration.getConsumerID());
- requestHeaders.put(HttpHeaders.ACCEPT, ContentType.APPLICATION_OCTET_STREAM.toString());
- String requestUrl = artifactInfo.getArtifactURL();
- Pair<HttpAsdcResponse, CloseableHttpResponse> downloadPair = httpClient.getRequest(requestUrl, requestHeaders, false);
- HttpAsdcResponse downloadResponse = downloadPair.getFirst();
-
- int status = downloadResponse.getStatus();
- if (status == 200) {
-
- response = parseDownloadArtifactResponse(artifactInfo, downloadResponse);
- } else {
- response = handleAsdcDownloadArtifactError(downloadResponse);
-
- }
- handeAsdcConnectionClose(downloadPair);
- return response;
- }
-
- /* **************************** private methods ********************************************/
-
- private Either<List<String>, IDistributionClientResult> parseGetServersResponse(HttpAsdcResponse getServersResponse) {
- Either<List<String>, IDistributionClientResult> result;
- try {
- String jsonMessage = IOUtils.toString(getServersResponse.getMessage().getContent());
-
- Gson gson = new GsonBuilder().create();
- ServerListResponse serverListResponse = gson.fromJson(jsonMessage, ServerListResponse.class);
- List<String> serverList = serverListResponse.getUebServerList();
- result = Either.left(serverList);
-
- } catch (UnsupportedOperationException | IOException e) {
- result = handleParsingError(e);
- }
-
- return result;
- }
-
- private Either<List<String>, IDistributionClientResult> parseGetValidArtifactTypesResponse(HttpAsdcResponse getArtifactTypesResponse) {
- Either<List<String>, IDistributionClientResult> result;
- try {
- String jsonMessage = IOUtils.toString(getArtifactTypesResponse.getMessage().getContent());
- Type listType = new TypeToken<ArrayList<String>>() {
- }.getType();
- Gson gson = new GsonBuilder().create();
- List<String> artifactTypesList = gson.fromJson(jsonMessage, listType);
- result = Either.left(artifactTypesList);
-
- } catch (UnsupportedOperationException | IOException e) {
- result = handleParsingError(e);
- }
-
- return result;
- }
-
- private Either<List<String>, IDistributionClientResult> handleParsingError(Exception e) {
- Either<List<String>, IDistributionClientResult> result;
- log.error("failed to parse response from ASDC. error: " + e.getMessage());
- IDistributionClientResult response = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to parse response from ASDC");
- result = Either.right(response);
- return result;
- }
-
- Either<TopicRegistrationResponse, DistributionClientResultImpl> parseRegistrationResponse(HttpAsdcResponse registerResponse) {
-
- String jsonMessage;
- try {
- jsonMessage = IOUtils.toString(registerResponse.getMessage().getContent());
-
- Gson gson = new GsonBuilder().create();
- TopicRegistrationResponse registrationResponse = gson.fromJson(jsonMessage, TopicRegistrationResponse.class);
-
- if (registrationResponse.getDistrNotificationTopicName() == null) {
- DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.FAIL, "failed to receive notification topic from ASDC");
- return Either.right(response);
- }
-
- if (registrationResponse.getDistrStatusTopicName() == null) {
- DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.FAIL, "failed to receive status topic from ASDC");
- return Either.right(response);
- }
- return Either.left(registrationResponse);
-
- } catch (UnsupportedOperationException | IOException e) {
- log.error("failed to pars response from ASDC. error: " + e.getMessage());
- DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to parse response from ASDC");
- return Either.right(response);
- }
- }
-
- protected Map<String, String> addHeadersToHttpRequest(String requestId) {
- Map<String, String> requestHeaders = new HashMap<>();
- requestHeaders.put(DistributionClientConstants.HEADER_REQUEST_ID, requestId);
- requestHeaders.put(DistributionClientConstants.HEADER_INSTANCE_ID, configuration.getConsumerID());
- requestHeaders.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
-
- return requestHeaders;
- }
-
- private DistributionClientResultImpl handleAsdcError(HttpAsdcResponse registerResponse) {
- int status = registerResponse.getStatus();
- DistributionClientResultImpl errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to send request to ASDC");
- if (status == HttpStatus.SC_UNAUTHORIZED) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_AUTHENTICATION_FAILED, "authentication to ASDC failed for user " + configuration.getUser());
- } else if (status == HttpStatus.SC_FORBIDDEN) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_AUTHORIZATION_FAILED, "authorization failure for user " + configuration.getUser());
- } else if (status == HttpStatus.SC_BAD_REQUEST) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.BAD_REQUEST, "ASDC call failed due to missing information");
- } else if (status == HttpStatus.SC_NOT_FOUND) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_NOT_FOUND, "ASDC not found");
- } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, "ASDC server problem");
- } else if (status == HttpStatus.SC_BAD_GATEWAY) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_CONNECTION_FAILED, "ASDC server problem");
- } else if (status == HttpStatus.SC_GATEWAY_TIMEOUT) {
- errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_SERVER_TIMEOUT, "ASDC server problem");
- }
- log.error("status from ASDC is " + registerResponse);
- log.error(errorResponse.toString());
- try {
- String errorString = IOUtils.toString(registerResponse.getMessage().getContent());
- log.debug("error from ASDC is: " + errorString);
- } catch (UnsupportedOperationException | IOException e) {
- }
- return errorResponse;
-
- }
-
- private DistributionClientDownloadResultImpl handleAsdcDownloadArtifactError(HttpAsdcResponse registerResponse) {
- int status = registerResponse.getStatus();
- DistributionClientDownloadResultImpl errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to send request to ASDC");
- if (status == HttpStatus.SC_UNAUTHORIZED) {
- errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_AUTHENTICATION_FAILED, "authentication to ASDC failed for user " + configuration.getUser());
- } else if (status == HttpStatus.SC_FORBIDDEN) {
- errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_AUTHORIZATION_FAILED, "authorization failure for user " + configuration.getUser());
- } else if (status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_NOT_FOUND) {
- errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ARTIFACT_NOT_FOUND, "Specified artifact is not found");
- // } else if (status == 404){
- // errorResponse = new DistributionClientDownloadResultImpl(
- // DistributionActionResultEnum.ASDC_NOT_FOUND,
- // "ASDC not found");
- } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
- errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, "ASDC server problem");
- }
- log.error("status from ASDC is " + registerResponse);
- log.error(errorResponse.toString());
- try {
- String errorString = IOUtils.toString(registerResponse.getMessage().getContent());
- log.debug("error from ASDC is: " + errorString);
- } catch (UnsupportedOperationException | IOException e) {
- }
- return errorResponse;
-
- }
-
- private DistributionClientDownloadResultImpl parseDownloadArtifactResponse(IArtifactInfo artifactInfo, HttpAsdcResponse getServersResponse) {
- HttpEntity entity = getServersResponse.getMessage();
- InputStream is;
- try {
- is = entity.getContent();
- String artifactName = "";
- if (getServersResponse.getHeadersMap().containsKey(contentDispositionHeader))
- artifactName = getServersResponse.getHeadersMap().get(contentDispositionHeader);
-
- byte[] payload = IOUtils.toByteArray(is);
- if (artifactInfo.getArtifactChecksum() == null || artifactInfo.getArtifactChecksum().isEmpty()) {
- return new DistributionClientDownloadResultImpl(DistributionActionResultEnum.DATA_INTEGRITY_PROBLEM, "failed to get artifact from ASDC. Empty checksum");
- }
-
- DistributionClientDownloadResultImpl resResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS, "success", artifactName, payload);
- return resResponse;
-
- //Validate checksum removed as fix to bug 293657
- /*if (validateChecksum(artifactInfo, payload)) {
- DistributionClientDownloadResultImpl resResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS, "success", artifactName, payload);
- return resResponse;
-
- } else {
-
- return new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "Invalid checksum. ArtifactInfo checksum ");
- }*/
-
- } catch (UnsupportedOperationException | IOException e) {
- log.error("failed to get artifact from response ");
- return new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "UnsupportedOperationException ");
- }
-
- }
-
- private boolean validateChecksum(IArtifactInfo artifactInfo, byte[] payload) {
- boolean bRes = false;
- String calculatedMD5 = GeneralUtils.calculateMD5(payload);
- if (artifactInfo.getArtifactChecksum().equals(calculatedMD5)) {
- bRes = true;
- }
-
- return bRes;
- }
+ } else {
+ response = handleAsdcError(unRegisterResponse);
+ }
+
+ handeAsdcConnectionClose(unRegisterResponsePair);
+
+ log.debug("unregisterTopics response = " + status + ". requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_UNREGISTER);
+
+ return response;
+
+ }
+
+ public DistributionClientDownloadResultImpl dowloadArtifact(IArtifactInfo artifactInfo) {
+ DistributionClientDownloadResultImpl response = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to download artifact from ASDC");
+
+ String requestId = UUID.randomUUID().toString();
+ Map<String, String> requestHeaders = new HashMap<String, String>();
+ requestHeaders.put(DistributionClientConstants.HEADER_REQUEST_ID, requestId);
+ requestHeaders.put(DistributionClientConstants.HEADER_INSTANCE_ID, configuration.getConsumerID());
+ requestHeaders.put(HttpHeaders.ACCEPT, ContentType.APPLICATION_OCTET_STREAM.toString());
+ String requestUrl = artifactInfo.getArtifactURL();
+ Pair<HttpAsdcResponse, CloseableHttpResponse> downloadPair = httpClient.getRequest(requestUrl, requestHeaders, false);
+ HttpAsdcResponse downloadResponse = downloadPair.getFirst();
+
+ int status = downloadResponse.getStatus();
+ if (status == HttpStatus.SC_OK) {
+
+ response = parseDownloadArtifactResponse(artifactInfo, downloadResponse);
+ } else {
+ response = handleAsdcDownloadArtifactError(downloadResponse);
+
+ }
+ handeAsdcConnectionClose(downloadPair);
+ return response;
+ }
+
+ /* **************************** private methods ********************************************/
+
+ private Either<List<String>, IDistributionClientResult> parseGetServersResponse(HttpAsdcResponse getServersResponse) {
+ Either<List<String>, IDistributionClientResult> result;
+ try {
+ String jsonMessage = IOUtils.toString(getServersResponse.getMessage().getContent());
+
+ Gson gson = new GsonBuilder().create();
+ ServerListResponse serverListResponse = gson.fromJson(jsonMessage, ServerListResponse.class);
+ List<String> serverList = serverListResponse.getUebServerList();
+ result = Either.left(serverList);
+
+ } catch (UnsupportedOperationException | IOException e) {
+ result = handleParsingError(e);
+ }
+
+ return result;
+ }
+
+ private Either<List<String>, IDistributionClientResult> parseGetValidArtifactTypesResponse(HttpAsdcResponse getArtifactTypesResponse) {
+ Either<List<String>, IDistributionClientResult> result;
+ try {
+ String jsonMessage = IOUtils.toString(getArtifactTypesResponse.getMessage().getContent());
+ Type listType = new TypeToken<ArrayList<String>>() {
+ }.getType();
+ Gson gson = new GsonBuilder().create();
+ List<String> artifactTypesList = gson.fromJson(jsonMessage, listType);
+ result = Either.left(artifactTypesList);
+
+ } catch (UnsupportedOperationException | IOException e) {
+ result = handleParsingError(e);
+ }
+
+ return result;
+ }
+
+ private Either<List<String>, IDistributionClientResult> handleParsingError(Exception e) {
+ Either<List<String>, IDistributionClientResult> result;
+ log.error("failed to parse response from ASDC. error: " + e.getMessage());
+ IDistributionClientResult response = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to parse response from ASDC");
+ result = Either.right(response);
+ return result;
+ }
+
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> parseRegistrationResponse(HttpAsdcResponse registerResponse) {
+
+ String jsonMessage;
+ try {
+ jsonMessage = IOUtils.toString(registerResponse.getMessage().getContent());
+
+ Gson gson = new GsonBuilder().create();
+ TopicRegistrationResponse registrationResponse = gson.fromJson(jsonMessage, TopicRegistrationResponse.class);
+
+ if (registrationResponse.getDistrNotificationTopicName() == null) {
+ DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.FAIL, "failed to receive notification topic from ASDC");
+ return Either.right(response);
+ }
+
+ if (registrationResponse.getDistrStatusTopicName() == null) {
+ DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.FAIL, "failed to receive status topic from ASDC");
+ return Either.right(response);
+ }
+ return Either.left(registrationResponse);
+
+ } catch (UnsupportedOperationException | IOException e) {
+ log.error("failed to pars response from ASDC. error: " + e.getMessage());
+ DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to parse response from ASDC");
+ return Either.right(response);
+ }
+ }
+
+ protected Map<String, String> addHeadersToHttpRequest(String requestId) {
+ Map<String, String> requestHeaders = new HashMap<>();
+ requestHeaders.put(DistributionClientConstants.HEADER_REQUEST_ID, requestId);
+ requestHeaders.put(DistributionClientConstants.HEADER_INSTANCE_ID, configuration.getConsumerID());
+ requestHeaders.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
+
+ return requestHeaders;
+ }
+
+ private DistributionClientResultImpl handleAsdcError(HttpAsdcResponse registerResponse) {
+ int status = registerResponse.getStatus();
+ DistributionClientResultImpl errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to send request to ASDC");
+ if (status == HttpStatus.SC_UNAUTHORIZED) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_AUTHENTICATION_FAILED, "authentication to ASDC failed for user " + configuration.getUser());
+ } else if (status == HttpStatus.SC_FORBIDDEN) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_AUTHORIZATION_FAILED, "authorization failure for user " + configuration.getUser());
+ } else if (status == HttpStatus.SC_BAD_REQUEST) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.BAD_REQUEST, "ASDC call failed due to missing information");
+ } else if (status == HttpStatus.SC_NOT_FOUND) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_NOT_FOUND, "ASDC not found");
+ } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, "ASDC server problem");
+ } else if (status == HttpStatus.SC_BAD_GATEWAY) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_CONNECTION_FAILED, "ASDC server problem");
+ } else if (status == HttpStatus.SC_GATEWAY_TIMEOUT) {
+ errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_SERVER_TIMEOUT, "ASDC server problem");
+ }
+ log.error("status from ASDC is " + registerResponse);
+ log.error(errorResponse.toString());
+ try {
+ String errorString = IOUtils.toString(registerResponse.getMessage().getContent());
+ log.debug("error from ASDC is: " + errorString);
+ } catch (UnsupportedOperationException | IOException e) {
+ }
+ return errorResponse;
+
+ }
+
+ private DistributionClientDownloadResultImpl handleAsdcDownloadArtifactError(HttpAsdcResponse registerResponse) {
+ int status = registerResponse.getStatus();
+ DistributionClientDownloadResultImpl errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to send request to ASDC");
+ if (status == HttpStatus.SC_UNAUTHORIZED) {
+ errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_AUTHENTICATION_FAILED, "authentication to ASDC failed for user " + configuration.getUser());
+ } else if (status == HttpStatus.SC_FORBIDDEN) {
+ errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_AUTHORIZATION_FAILED, "authorization failure for user " + configuration.getUser());
+ } else if (status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_NOT_FOUND) {
+ errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ARTIFACT_NOT_FOUND, "Specified artifact is not found");
+ // } else if (status == 404){
+ // errorResponse = new DistributionClientDownloadResultImpl(
+ // DistributionActionResultEnum.ASDC_NOT_FOUND,
+ // "ASDC not found");
+ } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, "ASDC server problem");
+ }
+ log.error("status from ASDC is " + registerResponse);
+ log.error(errorResponse.toString());
+ try {
+ String errorString = IOUtils.toString(registerResponse.getMessage().getContent());
+ log.debug("error from ASDC is: " + errorString);
+ } catch (UnsupportedOperationException | IOException e) {
+ }
+ return errorResponse;
+
+ }
+
+ private DistributionClientDownloadResultImpl parseDownloadArtifactResponse(IArtifactInfo artifactInfo, HttpAsdcResponse getServersResponse) {
+ HttpEntity entity = getServersResponse.getMessage();
+ InputStream is;
+ try {
+ is = entity.getContent();
+ String artifactName = "";
+ if (getServersResponse.getHeadersMap().containsKey(contentDispositionHeader)) {
+ artifactName = getServersResponse.getHeadersMap().get(contentDispositionHeader);
+ }
+
+ byte[] payload = IOUtils.toByteArray(is);
+ if (artifactInfo.getArtifactChecksum() == null || artifactInfo.getArtifactChecksum().isEmpty()) {
+ return new DistributionClientDownloadResultImpl(DistributionActionResultEnum.DATA_INTEGRITY_PROBLEM, "failed to get artifact from ASDC. Empty checksum");
+ }
+
+ DistributionClientDownloadResultImpl resResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS, "success", artifactName, payload);
+ return resResponse;
+
+
+ } catch (UnsupportedOperationException | IOException e) {
+ log.error("failed to get artifact from response ");
+ return new DistributionClientDownloadResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "UnsupportedOperationException ");
+ }
+
+ }
+
+ private boolean validateChecksum(IArtifactInfo artifactInfo, byte[] payload) {
+ boolean bRes = false;
+ String calculatedMD5 = GeneralUtils.calculateMD5(payload);
+ if (artifactInfo.getArtifactChecksum().equals(calculatedMD5)) {
+ bRes = true;
+ }
+
+ return bRes;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/TopicRegistrationResponse.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/TopicRegistrationResponse.java
index e8d0545..448005c 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/TopicRegistrationResponse.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/TopicRegistrationResponse.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,21 +21,23 @@
package org.onap.sdc.http;
public class TopicRegistrationResponse {
- String distrNotificationTopicName;
- String distrStatusTopicName;
-
-
- public void setDistrNotificationTopicName(String distrNotificationTopicName) {
- this.distrNotificationTopicName = distrNotificationTopicName;
- }
- public void setDistrStatusTopicName(String distrStatusTopicName) {
- this.distrStatusTopicName = distrStatusTopicName;
- }
-
- public String getDistrNotificationTopicName() {
- return distrNotificationTopicName;
- }
- public String getDistrStatusTopicName() {
- return distrStatusTopicName;
- }
+ private String distrNotificationTopicName;
+ private String distrStatusTopicName;
+
+
+ public void setDistrNotificationTopicName(String distrNotificationTopicName) {
+ this.distrNotificationTopicName = distrNotificationTopicName;
+ }
+
+ public void setDistrStatusTopicName(String distrStatusTopicName) {
+ this.distrStatusTopicName = distrStatusTopicName;
+ }
+
+ public String getDistrNotificationTopicName() {
+ return distrNotificationTopicName;
+ }
+
+ public String getDistrStatusTopicName() {
+ return distrStatusTopicName;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java
index 6a3da83..c59ba3f 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,166 +27,168 @@ import org.onap.sdc.api.notification.IArtifactInfo;
class ArtifactInfoImpl implements IArtifactInfo {
- private String artifactName;
- private String artifactType;
- private String artifactURL;
- private String artifactChecksum;
- private String artifactDescription;
- private Integer artifactTimeout;
- private String artifactVersion;
- private String artifactUUID;
- private String generatedFromUUID;
- private IArtifactInfo generatedArtifact;
- private List<String> relatedArtifacts;
- private List<IArtifactInfo> relatedArtifactsInfo;
- ArtifactInfoImpl(){}
-
- private ArtifactInfoImpl(IArtifactInfo iArtifactInfo){
- artifactName = iArtifactInfo.getArtifactName();
- artifactType = iArtifactInfo.getArtifactType();
- artifactURL = iArtifactInfo.getArtifactURL();
- artifactChecksum = iArtifactInfo.getArtifactChecksum();
- artifactDescription = iArtifactInfo.getArtifactDescription();
- artifactTimeout = iArtifactInfo.getArtifactTimeout();
- artifactVersion = iArtifactInfo.getArtifactVersion();
- artifactUUID = iArtifactInfo.getArtifactUUID();
- generatedArtifact = iArtifactInfo.getGeneratedArtifact();
- relatedArtifactsInfo = iArtifactInfo.getRelatedArtifacts();
- relatedArtifacts = fillRelatedArtifactsUUID(relatedArtifactsInfo);
-
- }
-
-
- private List<String> fillRelatedArtifactsUUID(List<IArtifactInfo> relatedArtifactsInfo) {
- List<String> relatedArtifactsUUID = null;
- if( relatedArtifactsInfo != null && !relatedArtifactsInfo.isEmpty()){
- relatedArtifactsUUID = new ArrayList<>();
- for(IArtifactInfo curr: relatedArtifactsInfo){
- relatedArtifactsUUID.add(curr.getArtifactUUID());
- }
- }
- return relatedArtifactsUUID;
- }
-
- public static List<ArtifactInfoImpl> convertToArtifactInfoImpl(List<IArtifactInfo> list){
- List<ArtifactInfoImpl> ret = new ArrayList<ArtifactInfoImpl>();
- if( list != null ){
- for(IArtifactInfo artifactInfo : list ){
- ret.add(new ArtifactInfoImpl(artifactInfo));
- }
- }
- return ret;
- }
-
- public String getArtifactName() {
- return artifactName;
- }
-
- public void setArtifactName(String artifactName) {
- this.artifactName = artifactName;
- }
-
- public String getArtifactType() {
- return artifactType;
- }
-
- public void setArtifactType(String artifactType) {
- this.artifactType = artifactType;
- }
-
- public String getArtifactURL() {
- return artifactURL;
- }
-
- public void setArtifactURL(String artifactURL) {
- this.artifactURL = artifactURL;
- }
-
- public String getArtifactChecksum() {
- return artifactChecksum;
- }
-
- public void setArtifactChecksum(String artifactChecksum) {
- this.artifactChecksum = artifactChecksum;
- }
-
- public String getArtifactDescription() {
- return artifactDescription;
- }
-
- public void setArtifactDescription(String artifactDescription) {
- this.artifactDescription = artifactDescription;
- }
-
- public Integer getArtifactTimeout() {
- return artifactTimeout;
- }
-
- public void setArtifactTimeout(Integer artifactTimeout) {
- this.artifactTimeout = artifactTimeout;
- }
-
- @Override
- public String toString() {
- return "BaseArtifactInfoImpl [artifactName=" + artifactName
- + ", artifactType=" + artifactType + ", artifactURL="
- + artifactURL + ", artifactChecksum=" + artifactChecksum
- + ", artifactDescription=" + artifactDescription
- + ", artifactVersion=" + artifactVersion
- + ", artifactUUID=" + artifactUUID
- + ", artifactTimeout=" + artifactTimeout + "]";
- }
-
- public String getArtifactVersion() {
- return artifactVersion;
- }
-
- public void setArtifactVersion(String artifactVersion) {
- this.artifactVersion = artifactVersion;
- }
-
- public String getArtifactUUID() {
- return artifactUUID;
- }
-
- public void setArtifactUUID(String artifactUUID) {
- this.artifactUUID = artifactUUID;
- }
-
- public String getGeneratedFromUUID() {
- return generatedFromUUID;
- }
-
- public void setGeneratedFromUUID(String generatedFromUUID) {
- this.generatedFromUUID = generatedFromUUID;
- }
-
- public IArtifactInfo getGeneratedArtifact() {
- return generatedArtifact;
- }
-
- public void setGeneratedArtifact(IArtifactInfo generatedArtifact) {
- this.generatedArtifact = generatedArtifact;
- }
-
- public List<IArtifactInfo> getRelatedArtifacts(){
- List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
- if( relatedArtifactsInfo != null ){
- temp.addAll(relatedArtifactsInfo);
- }
- return temp;
- }
-
- public void setRelatedArtifacts(List<String> relatedArtifacts) {
- this.relatedArtifacts = relatedArtifacts;
- }
-
- public void setRelatedArtifactsInfo(List<IArtifactInfo> relatedArtifactsInfo) {
- this.relatedArtifactsInfo = relatedArtifactsInfo;
- }
-
- public List<String> getRelatedArtifactsUUID(){
- return relatedArtifacts;
- }
+ private String artifactName;
+ private String artifactType;
+ private String artifactURL;
+ private String artifactChecksum;
+ private String artifactDescription;
+ private Integer artifactTimeout;
+ private String artifactVersion;
+ private String artifactUUID;
+ private String generatedFromUUID;
+ private IArtifactInfo generatedArtifact;
+ private List<String> relatedArtifacts;
+ private List<IArtifactInfo> relatedArtifactsInfo;
+
+ ArtifactInfoImpl() {
+ }
+
+ private ArtifactInfoImpl(IArtifactInfo iArtifactInfo) {
+ artifactName = iArtifactInfo.getArtifactName();
+ artifactType = iArtifactInfo.getArtifactType();
+ artifactURL = iArtifactInfo.getArtifactURL();
+ artifactChecksum = iArtifactInfo.getArtifactChecksum();
+ artifactDescription = iArtifactInfo.getArtifactDescription();
+ artifactTimeout = iArtifactInfo.getArtifactTimeout();
+ artifactVersion = iArtifactInfo.getArtifactVersion();
+ artifactUUID = iArtifactInfo.getArtifactUUID();
+ generatedArtifact = iArtifactInfo.getGeneratedArtifact();
+ relatedArtifactsInfo = iArtifactInfo.getRelatedArtifacts();
+ relatedArtifacts = fillRelatedArtifactsUUID(relatedArtifactsInfo);
+
+ }
+
+
+ private List<String> fillRelatedArtifactsUUID(List<IArtifactInfo> relatedArtifactsInfo) {
+ List<String> relatedArtifactsUUID = null;
+ if (relatedArtifactsInfo != null && !relatedArtifactsInfo.isEmpty()) {
+ relatedArtifactsUUID = new ArrayList<>();
+ for (IArtifactInfo curr : relatedArtifactsInfo) {
+ relatedArtifactsUUID.add(curr.getArtifactUUID());
+ }
+ }
+ return relatedArtifactsUUID;
+ }
+
+ public static List<ArtifactInfoImpl> convertToArtifactInfoImpl(List<IArtifactInfo> list) {
+ List<ArtifactInfoImpl> ret = new ArrayList<ArtifactInfoImpl>();
+ if (list != null) {
+ for (IArtifactInfo artifactInfo : list) {
+ ret.add(new ArtifactInfoImpl(artifactInfo));
+ }
+ }
+ return ret;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+
+ public String getArtifactType() {
+ return artifactType;
+ }
+
+ public void setArtifactType(String artifactType) {
+ this.artifactType = artifactType;
+ }
+
+ public String getArtifactURL() {
+ return artifactURL;
+ }
+
+ public void setArtifactURL(String artifactURL) {
+ this.artifactURL = artifactURL;
+ }
+
+ public String getArtifactChecksum() {
+ return artifactChecksum;
+ }
+
+ public void setArtifactChecksum(String artifactChecksum) {
+ this.artifactChecksum = artifactChecksum;
+ }
+
+ public String getArtifactDescription() {
+ return artifactDescription;
+ }
+
+ public void setArtifactDescription(String artifactDescription) {
+ this.artifactDescription = artifactDescription;
+ }
+
+ public Integer getArtifactTimeout() {
+ return artifactTimeout;
+ }
+
+ public void setArtifactTimeout(Integer artifactTimeout) {
+ this.artifactTimeout = artifactTimeout;
+ }
+
+ @Override
+ public String toString() {
+ return "BaseArtifactInfoImpl [artifactName=" + artifactName
+ + ", artifactType=" + artifactType + ", artifactURL="
+ + artifactURL + ", artifactChecksum=" + artifactChecksum
+ + ", artifactDescription=" + artifactDescription
+ + ", artifactVersion=" + artifactVersion
+ + ", artifactUUID=" + artifactUUID
+ + ", artifactTimeout=" + artifactTimeout + "]";
+ }
+
+ public String getArtifactVersion() {
+ return artifactVersion;
+ }
+
+ public void setArtifactVersion(String artifactVersion) {
+ this.artifactVersion = artifactVersion;
+ }
+
+ public String getArtifactUUID() {
+ return artifactUUID;
+ }
+
+ public void setArtifactUUID(String artifactUUID) {
+ this.artifactUUID = artifactUUID;
+ }
+
+ public String getGeneratedFromUUID() {
+ return generatedFromUUID;
+ }
+
+ public void setGeneratedFromUUID(String generatedFromUUID) {
+ this.generatedFromUUID = generatedFromUUID;
+ }
+
+ public IArtifactInfo getGeneratedArtifact() {
+ return generatedArtifact;
+ }
+
+ public void setGeneratedArtifact(IArtifactInfo generatedArtifact) {
+ this.generatedArtifact = generatedArtifact;
+ }
+
+ public List<IArtifactInfo> getRelatedArtifacts() {
+ List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
+ if (relatedArtifactsInfo != null) {
+ temp.addAll(relatedArtifactsInfo);
+ }
+ return temp;
+ }
+
+ public void setRelatedArtifacts(List<String> relatedArtifacts) {
+ this.relatedArtifacts = relatedArtifacts;
+ }
+
+ public void setRelatedArtifactsInfo(List<IArtifactInfo> relatedArtifactsInfo) {
+ this.relatedArtifactsInfo = relatedArtifactsInfo;
+ }
+
+ public List<String> getRelatedArtifactsUUID() {
+ return relatedArtifacts;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java
index a33f911..75e4acc 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,199 +27,199 @@ import org.onap.sdc.api.consumer.IConfiguration;
public class Configuration implements IConfiguration {
- private List<String> msgBusAddressList;
- private String asdcAddress;
- private String user;
- private String password;
- private int pollingInterval = DistributionClientConstants.MIN_POLLING_INTERVAL_SEC;
- private int pollingTimeout = DistributionClientConstants.POLLING_TIMEOUT_SEC;
- private List<String> relevantArtifactTypes;
- private String consumerGroup;
- private String environmentName;
- private String comsumerID;
- private String keyStorePath;
- private String keyStorePassword;
- private boolean activateServerTLSAuth;
- private boolean filterInEmptyResources;
- private Boolean useHttpsWithDmaap;
- private boolean consumeProduceStatusTopic;
-
- public Configuration(IConfiguration other) {
- this.asdcAddress = other.getAsdcAddress();
- this.msgBusAddressList = other.getMsgBusAddress();
- this.comsumerID = other.getConsumerID();
- this.consumerGroup = other.getConsumerGroup();
- this.environmentName = other.getEnvironmentName();
- this.password = other.getPassword();
- this.pollingInterval = other.getPollingInterval();
- this.pollingTimeout = other.getPollingTimeout();
- this.relevantArtifactTypes = other.getRelevantArtifactTypes();
- this.user = other.getUser();
- this.keyStorePath = other.getKeyStorePath();
- this.keyStorePassword = other.getKeyStorePassword();
- this.activateServerTLSAuth = other.activateServerTLSAuth();
- this.filterInEmptyResources = other.isFilterInEmptyResources();
- this.useHttpsWithDmaap = other.isUseHttpsWithDmaap();
- this.consumeProduceStatusTopic = other.isConsumeProduceStatusTopic();
- }
-
- @Override
- public String getAsdcAddress() {
- return asdcAddress;
- }
-
- @Override
- public List<String> getMsgBusAddress() {
- return msgBusAddressList;
- }
-
- @Override
- public String getUser() {
- return user;
- }
-
- @Override
- public String getPassword() {
- return password;
- }
-
- @Override
- public int getPollingInterval() {
- return pollingInterval;
- }
-
- @Override
- public int getPollingTimeout() {
- return pollingTimeout;
- }
-
- @Override
- public List<String> getRelevantArtifactTypes() {
- return relevantArtifactTypes;
- }
-
- @Override
- public String getConsumerGroup() {
- return consumerGroup;
- }
-
- @Override
- public String getEnvironmentName() {
- return environmentName;
- }
-
- @Override
- public String getConsumerID() {
- return comsumerID;
- }
-
- @Override
- public String getKeyStorePath() {
- return keyStorePath;
- }
-
- @Override
- public String getKeyStorePassword() {
- return keyStorePassword;
- }
-
- public String getComsumerID() {
- return comsumerID;
- }
-
- public void setComsumerID(String comsumerID) {
- this.comsumerID = comsumerID;
- }
-
- public void setAsdcAddress(String asdcAddress) {
- this.asdcAddress = asdcAddress;
- }
-
- public void setUser(String user) {
- this.user = user;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public void setPollingInterval(int pollingInterval) {
- this.pollingInterval = pollingInterval;
- }
-
- public void setPollingTimeout(int pollingTimeout) {
- this.pollingTimeout = pollingTimeout;
- }
-
- public void setRelevantArtifactTypes(List<String> relevantArtifactTypes) {
- this.relevantArtifactTypes = relevantArtifactTypes;
- }
-
- public void setConsumerGroup(String consumerGroup) {
- this.consumerGroup = consumerGroup;
- }
-
- public void setEnvironmentName(String environmentName) {
- this.environmentName = environmentName;
- }
-
- public void setKeyStorePath(String keyStorePath) {
- this.keyStorePath = keyStorePath;
- }
-
- public void setKeyStorePassword(String keyStorePassword) {
- this.keyStorePassword = keyStorePassword;
- }
-
- public void setactivateServerTLSAuth(boolean activateServerTLSAuth) {
- this.activateServerTLSAuth = activateServerTLSAuth;
- }
-
- @Override
- public boolean activateServerTLSAuth() {
- return this.activateServerTLSAuth;
- }
-
- @Override
- public boolean isFilterInEmptyResources() {
- return this.filterInEmptyResources;
- }
-
- @Override
- public Boolean isUseHttpsWithDmaap() {
- return this.useHttpsWithDmaap;
- }
-
- public void setUseHttpsWithDmaap(boolean useHttpsWithDmaap) {
- this.useHttpsWithDmaap = useHttpsWithDmaap;
- }
-
- @Override
- public boolean isConsumeProduceStatusTopic() {
- return this.consumeProduceStatusTopic;
- }
-
- @Override
- public String toString() {
- //@formatter:off
- return "Configuration ["+
- "asdcAddress=" + asdcAddress +
- ", user=" + user +
- ", password=" + password +
- ", pollingInterval=" + pollingInterval +
- ", pollingTimeout=" + pollingTimeout +
- ", relevantArtifactTypes=" + relevantArtifactTypes +
- ", consumerGroup=" + consumerGroup +
- ", environmentName=" + environmentName +
- ", comsumerID=" + comsumerID +
- ", keyStorePath=" + keyStorePath +
- ", keyStorePassword=" + keyStorePassword +
- ", activateServerTLSAuth=" + activateServerTLSAuth +
- ", filterInEmptyResources=" + filterInEmptyResources +
- ", useHttpsWithDmaap=" + useHttpsWithDmaap +
- ", consumeProduceStatusTopic=" + consumeProduceStatusTopic +
- "]";
- //@formatter:on
- }
+ private List<String> msgBusAddressList;
+ private String asdcAddress;
+ private String user;
+ private String password;
+ private int pollingInterval = DistributionClientConstants.MIN_POLLING_INTERVAL_SEC;
+ private int pollingTimeout = DistributionClientConstants.POLLING_TIMEOUT_SEC;
+ private List<String> relevantArtifactTypes;
+ private String consumerGroup;
+ private String environmentName;
+ private String comsumerID;
+ private String keyStorePath;
+ private String keyStorePassword;
+ private boolean activateServerTLSAuth;
+ private boolean filterInEmptyResources;
+ private Boolean useHttpsWithDmaap;
+ private boolean consumeProduceStatusTopic;
+
+ public Configuration(IConfiguration other) {
+ this.asdcAddress = other.getAsdcAddress();
+ this.msgBusAddressList = other.getMsgBusAddress();
+ this.comsumerID = other.getConsumerID();
+ this.consumerGroup = other.getConsumerGroup();
+ this.environmentName = other.getEnvironmentName();
+ this.password = other.getPassword();
+ this.pollingInterval = other.getPollingInterval();
+ this.pollingTimeout = other.getPollingTimeout();
+ this.relevantArtifactTypes = other.getRelevantArtifactTypes();
+ this.user = other.getUser();
+ this.keyStorePath = other.getKeyStorePath();
+ this.keyStorePassword = other.getKeyStorePassword();
+ this.activateServerTLSAuth = other.activateServerTLSAuth();
+ this.filterInEmptyResources = other.isFilterInEmptyResources();
+ this.useHttpsWithDmaap = other.isUseHttpsWithDmaap();
+ this.consumeProduceStatusTopic = other.isConsumeProduceStatusTopic();
+ }
+
+ @Override
+ public String getAsdcAddress() {
+ return asdcAddress;
+ }
+
+ @Override
+ public List<String> getMsgBusAddress() {
+ return msgBusAddressList;
+ }
+
+ @Override
+ public String getUser() {
+ return user;
+ }
+
+ @Override
+ public String getPassword() {
+ return password;
+ }
+
+ @Override
+ public int getPollingInterval() {
+ return pollingInterval;
+ }
+
+ @Override
+ public int getPollingTimeout() {
+ return pollingTimeout;
+ }
+
+ @Override
+ public List<String> getRelevantArtifactTypes() {
+ return relevantArtifactTypes;
+ }
+
+ @Override
+ public String getConsumerGroup() {
+ return consumerGroup;
+ }
+
+ @Override
+ public String getEnvironmentName() {
+ return environmentName;
+ }
+
+ @Override
+ public String getConsumerID() {
+ return comsumerID;
+ }
+
+ @Override
+ public String getKeyStorePath() {
+ return keyStorePath;
+ }
+
+ @Override
+ public String getKeyStorePassword() {
+ return keyStorePassword;
+ }
+
+ public String getComsumerID() {
+ return comsumerID;
+ }
+
+ public void setComsumerID(String comsumerID) {
+ this.comsumerID = comsumerID;
+ }
+
+ public void setAsdcAddress(String asdcAddress) {
+ this.asdcAddress = asdcAddress;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public void setPollingInterval(int pollingInterval) {
+ this.pollingInterval = pollingInterval;
+ }
+
+ public void setPollingTimeout(int pollingTimeout) {
+ this.pollingTimeout = pollingTimeout;
+ }
+
+ public void setRelevantArtifactTypes(List<String> relevantArtifactTypes) {
+ this.relevantArtifactTypes = relevantArtifactTypes;
+ }
+
+ public void setConsumerGroup(String consumerGroup) {
+ this.consumerGroup = consumerGroup;
+ }
+
+ public void setEnvironmentName(String environmentName) {
+ this.environmentName = environmentName;
+ }
+
+ public void setKeyStorePath(String keyStorePath) {
+ this.keyStorePath = keyStorePath;
+ }
+
+ public void setKeyStorePassword(String keyStorePassword) {
+ this.keyStorePassword = keyStorePassword;
+ }
+
+ public void setactivateServerTLSAuth(boolean activateServerTLSAuth) {
+ this.activateServerTLSAuth = activateServerTLSAuth;
+ }
+
+ @Override
+ public boolean activateServerTLSAuth() {
+ return this.activateServerTLSAuth;
+ }
+
+ @Override
+ public boolean isFilterInEmptyResources() {
+ return this.filterInEmptyResources;
+ }
+
+ @Override
+ public Boolean isUseHttpsWithDmaap() {
+ return this.useHttpsWithDmaap;
+ }
+
+ public void setUseHttpsWithDmaap(boolean useHttpsWithDmaap) {
+ this.useHttpsWithDmaap = useHttpsWithDmaap;
+ }
+
+ @Override
+ public boolean isConsumeProduceStatusTopic() {
+ return this.consumeProduceStatusTopic;
+ }
+
+ @Override
+ public String toString() {
+ //@formatter:off
+ return "Configuration ["
+ + "asdcAddress=" + asdcAddress
+ + ", user=" + user
+ + ", password=" + password
+ + ", pollingInterval=" + pollingInterval
+ + ", pollingTimeout=" + pollingTimeout
+ + ", relevantArtifactTypes=" + relevantArtifactTypes
+ + ", consumerGroup=" + consumerGroup
+ + ", environmentName=" + environmentName
+ + ", comsumerID=" + comsumerID
+ + ", keyStorePath=" + keyStorePath
+ + ", keyStorePassword=" + keyStorePassword
+ + ", activateServerTLSAuth=" + activateServerTLSAuth
+ + ", filterInEmptyResources=" + filterInEmptyResources
+ + ", useHttpsWithDmaap=" + useHttpsWithDmaap
+ + ", consumeProduceStatusTopic=" + consumeProduceStatusTopic
+ + "]";
+ //@formtter:on
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java
index 6323113..ae2b893 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,52 +23,52 @@ package org.onap.sdc.impl;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.utils.DistributionActionResultEnum;
-public class DistributionClientDownloadResultImpl extends DistributionClientResultImpl implements IDistributionClientDownloadResult {
- byte[] artifactPayload;
- String artifactName;
+public class DistributionClientDownloadResultImpl extends DistributionClientResultImpl implements IDistributionClientDownloadResult {
+ private byte[] artifactPayload;
+ private String artifactName;
-
- public DistributionClientDownloadResultImpl(
+
+ public DistributionClientDownloadResultImpl(
DistributionActionResultEnum responseStatus, String responseMessage) {
- super(responseStatus, responseMessage);
-
- }
-
- public DistributionClientDownloadResultImpl(
- DistributionActionResultEnum responseStatus,
- String responseMessage, String artifactName, byte[] artifactPayload) {
- super(responseStatus, responseMessage);
- this.artifactPayload = artifactPayload;
- this.artifactName = artifactName;
- }
-
-
- public void setArtifactPayload(byte[] payload) {
- this.artifactPayload = payload;
- }
-
-
- public byte[] getArtifactPayload() {
-
- return artifactPayload;
- }
-
- public String getArtifactName(){
- return artifactName;
- }
-
- public void setArtifactName(String artifactName){
- this.artifactName = artifactName;
- }
-
- @Override
- public String getArtifactFilename() {
- //Fix of bug 292443 in TDP
- if (artifactName == null || !artifactName.matches("attachment;\\s*filename=\".*?\"")){
- return artifactName;
- }
- String fileName = "filename=\"";
- return artifactName.substring(artifactName.indexOf(fileName)+fileName.length(), artifactName.lastIndexOf("\""));
- }
+ super(responseStatus, responseMessage);
+
+ }
+
+ public DistributionClientDownloadResultImpl(
+ DistributionActionResultEnum responseStatus,
+ String responseMessage, String artifactName, byte[] artifactPayload) {
+ super(responseStatus, responseMessage);
+ this.artifactPayload = artifactPayload;
+ this.artifactName = artifactName;
+ }
+
+
+ public void setArtifactPayload(byte[] payload) {
+ this.artifactPayload = payload;
+ }
+
+
+ public byte[] getArtifactPayload() {
+
+ return artifactPayload;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+
+ @Override
+ public String getArtifactFilename() {
+ //Fix of bug 292443 in TDP
+ if (artifactName == null || !artifactName.matches("attachment;\\s*filename=\".*?\"")) {
+ return artifactName;
+ }
+ String fileName = "filename=\"";
+ return artifactName.substring(artifactName.indexOf(fileName) + fileName.length(), artifactName.lastIndexOf("\""));
+ }
}
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
index 96aabc2..f7a0041 100644
--- 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
@@ -7,9 +7,9 @@
* 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.
@@ -24,11 +24,15 @@ import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.impl.mock.DistributionClientStubImpl;
public class DistributionClientFactory {
- public static IDistributionClient createDistributionClient(){
- return new DistributionClientImpl();
- }
-
- public static IDistributionClient createMockDistributionClient(){
- return new DistributionClientStubImpl();
- }
+
+ 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/DistributionClientImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java
index 5d15046..eda9cf6 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java
@@ -7,9 +7,9 @@
* 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.
@@ -28,6 +28,7 @@ import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@@ -38,7 +39,12 @@ import java.util.regex.Matcher;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.IDistributionStatusMessageJsonBuilder;
-import org.onap.sdc.api.consumer.*;
+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.results.IDistributionClientDownloadResult;
import org.onap.sdc.api.results.IDistributionClientResult;
@@ -48,7 +54,6 @@ import org.onap.sdc.utils.DistributionActionResultEnum;
import org.onap.sdc.utils.DistributionClientConstants;
import org.onap.sdc.utils.GeneralUtils;
import org.onap.sdc.utils.Wrapper;
-import org.onap.sdc.api.consumer.*;
import org.onap.sdc.api.notification.IVfModuleMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,708 +77,703 @@ import fj.data.Either;
public class DistributionClientImpl implements IDistributionClient {
- private static Logger log = LoggerFactory.getLogger(DistributionClientImpl.class.getName());
-
- protected SdcConnectorClient asdcConnector = new SdcConnectorClient();
- private ScheduledExecutorService executorPool = null;
- protected CambriaIdentityManager cambriaIdentityManager = null;
- private List<String> brokerServers;
- protected ApiCredential credential;
- protected Configuration configuration;
- private INotificationCallback callback;
- private IStatusCallback statusCallback;
- private String notificationTopic;
- private String statusTopic;
- private boolean isConsumerGroupGenerated = false;
-
- private boolean isInitialized, isStarted, isTerminated;
-
- @Override
- public IConfiguration getConfiguration() {
- return configuration;
- }
-
- @Override
- /* see javadoc */
- public synchronized IDistributionClientResult updateConfiguration(IConfiguration conf) {
-
- log.info("update DistributionClient configuration");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
-
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
-
- IDistributionClientResult updateResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "configuration updated successfuly");
-
- boolean needToUpdateCambriaConsumer = false;
-
- if (conf.getRelevantArtifactTypes() != null && !conf.getRelevantArtifactTypes().isEmpty()) {
- configuration.setRelevantArtifactTypes(conf.getRelevantArtifactTypes());
- needToUpdateCambriaConsumer = true;
- }
- if (isPollingIntervalValid(conf.getPollingInterval())) {
- configuration.setPollingInterval(conf.getPollingInterval());
- needToUpdateCambriaConsumer = true;
- }
- if (isPollingTimeoutValid(conf.getPollingTimeout())) {
- configuration.setPollingTimeout(conf.getPollingTimeout());
- needToUpdateCambriaConsumer = true;
- }
- if (conf.getConsumerGroup() != null) {
- configuration.setConsumerGroup(conf.getConsumerGroup());
- isConsumerGroupGenerated = false;
- needToUpdateCambriaConsumer = true;
- } else if (!isConsumerGroupGenerated) {
- generateConsumerGroup();
- }
-
- if (needToUpdateCambriaConsumer) {
- updateResult = restartConsumer();
- }
-
- return updateResult;
- }
-
- @Override
- /**
- * Start polling the Notification topic
- */
- public synchronized IDistributionClientResult start() {
-
- log.info("start DistributionClient");
- IDistributionClientResult startResult;
- CambriaConsumer cambriaNotificationConsumer = null;
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (errorWrapper.isEmpty()) {
- validateNotStarted(errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- try {
- cambriaNotificationConsumer = new ConsumerBuilder().authenticatedBy(credential.getApiKey(), credential.getApiSecret()).knownAs(configuration.getConsumerGroup(), configuration.getConsumerID()).onTopic(notificationTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers)
- .withSocketTimeout(configuration.getPollingTimeout() * 1000).build();
-
- } catch (MalformedURLException | GeneralSecurityException e) {
- handleCambriaInitFailure(errorWrapper, e);
- }
- }
- if (errorWrapper.isEmpty()) {
-
- List<String> relevantArtifactTypes = configuration.getRelevantArtifactTypes();
- // Remove nulls from list - workaround for how configuration is built
- while (relevantArtifactTypes.remove(null));
-
- NotificationConsumer consumer = new NotificationConsumer(cambriaNotificationConsumer, callback, relevantArtifactTypes, this);
- executorPool = Executors.newScheduledThreadPool(DistributionClientConstants.POOL_SIZE);
- executorPool.scheduleAtFixedRate(consumer, 0, configuration.getPollingInterval(), TimeUnit.SECONDS);
-
- handleStatusConsumer(errorWrapper, executorPool);
- }
- if (!errorWrapper.isEmpty()) {
- startResult = errorWrapper.getInnerElement();
- }
- else{
- startResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "distribution client started successfuly");
- isStarted = true;
- }
- return startResult;
- }
-
- private void handleStatusConsumer(Wrapper<IDistributionClientResult> errorWrapper, ScheduledExecutorService executorPool) {
- if( configuration.isConsumeProduceStatusTopic()){
- CambriaConsumer cambriaStatusConsumer = null;
- try {
- cambriaStatusConsumer = new ConsumerBuilder().authenticatedBy(credential.getApiKey(), credential.getApiSecret()).knownAs(configuration.getConsumerGroup(), configuration.getConsumerID()).onTopic(statusTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers)
- .withSocketTimeout(configuration.getPollingTimeout() * 1000).build();
- StatusConsumer statusConsumer = new StatusConsumer(cambriaStatusConsumer, statusCallback);
- executorPool.scheduleAtFixedRate(statusConsumer, 0, configuration.getPollingInterval(), TimeUnit.SECONDS);
- } catch (MalformedURLException | GeneralSecurityException e) {
- handleCambriaInitFailure(errorWrapper, e);
- }
- }
- }
-
- @Override
- /* see javadoc */
- public synchronized IDistributionClientResult stop() {
-
- log.info("stop DistributionClient");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- // 1. stop polling notification topic
- shutdownExecutor();
-
- // 2. send to ASDC unregister to topic
- IDistributionClientResult unregisterResult = asdcConnector.unregisterTopics(credential);
- if (unregisterResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- log.info("client failed to unregister from topics");
- } else {
- log.info("client unregistered from topics successfully");
- }
- asdcConnector.close();
-
- try {
- cambriaIdentityManager.deleteCurrentApiKey();
- } catch (HttpException | IOException e) {
- log.debug("failed to delete cambria keys", e);
- }
- cambriaIdentityManager.close();
-
- isInitialized = false;
- isTerminated = true;
-
- DistributionClientResultImpl stopResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "distribution client stopped successfuly");
- return stopResult;
- }
-
- @Override
- public IDistributionClientDownloadResult download(IArtifactInfo artifactInfo) {
- log.info("DistributionClient - download");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- IDistributionClientResult result = errorWrapper.getInnerElement();
- IDistributionClientDownloadResult downloadResult = new DistributionClientDownloadResultImpl(result.getDistributionActionResult(), result.getDistributionMessageResult());
- return downloadResult;
- }
- return asdcConnector.dowloadArtifact(artifactInfo);
- }
- @Override
- public synchronized IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback,
- IStatusCallback statusCallback) {
- IDistributionClientResult initResult;
- if( !conf.isConsumeProduceStatusTopic() ){
- initResult = new DistributionClientResultImpl(DistributionActionResultEnum.CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG, "configuration is invalid: isConsumeProduceStatusTopic() should be set to 'true'" );
-
- }
- else if( isNull(statusCallback) ){
- initResult = new DistributionClientResultImpl(DistributionActionResultEnum.CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG, "configuration is invalid: statusCallback is not defined" );
- }
- else{
- this.statusCallback = statusCallback;
- initResult = init(conf, notificationCallback);
- }
- return initResult;
- }
-
- @Override
- /*
- * see javadoc
- */
- public synchronized IDistributionClientResult init(IConfiguration conf, INotificationCallback callback) {
-
- log.info("DistributionClient - init");
-
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateNotInitilized(errorWrapper);
- if (errorWrapper.isEmpty()) {
- validateNotTerminated(errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- validateAndInitConfiguration(errorWrapper, conf);
- }
- // 1. get ueb server list from configuration
- if (errorWrapper.isEmpty()) {
- initUebServerList(errorWrapper);
- }
- // 2.validate artifact types against asdc server
- if (errorWrapper.isEmpty()) {
- validateArtifactTypesWithAsdcServer(conf, errorWrapper);
- }
- // 3. create keys
- if (errorWrapper.isEmpty()) {
- this.callback = callback;
- createUebKeys(errorWrapper);
- }
- // 4. register for topics
- if (errorWrapper.isEmpty()) {
- registerForTopics(errorWrapper);
- }
-
- IDistributionClientResult result;
- if (errorWrapper.isEmpty()) {
- isInitialized = true;
- result = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "distribution client initialized successfuly");
- } else {
- result = errorWrapper.getInnerElement();
- }
-
- return result;
- }
-
- private void registerForTopics(Wrapper<IDistributionClientResult> errorWrapper) {
- Either<TopicRegistrationResponse, DistributionClientResultImpl> registerAsdcTopics = asdcConnector.registerAsdcTopics(credential);
- if (registerAsdcTopics.isRight()) {
-
- try {
- cambriaIdentityManager.deleteCurrentApiKey();
- } catch (HttpException | IOException e) {
- log.debug("failed to delete cambria keys", e);
- }
- errorWrapper.setInnerElement(registerAsdcTopics.right().value());
- } else {
- TopicRegistrationResponse topics = registerAsdcTopics.left().value();
- notificationTopic = topics.getDistrNotificationTopicName();
- statusTopic = topics.getDistrStatusTopicName();
- }
-
- }
-
- private void createUebKeys(Wrapper<IDistributionClientResult> errorWrapper) {
- initCambriaClient(errorWrapper);
- if (errorWrapper.isEmpty()) {
- log.debug("create keys");
- DistributionClientResultImpl createKeysResponse = createUebKeys();
- if (createKeysResponse.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- errorWrapper.setInnerElement(createKeysResponse);
- }
- }
- }
-
- private void validateArtifactTypesWithAsdcServer(IConfiguration conf, Wrapper<IDistributionClientResult> errorWrapper) {
- asdcConnector.init(configuration);
- Either<List<String>, IDistributionClientResult> eitherValidArtifactTypesList = asdcConnector.getValidArtifactTypesList();
- if (eitherValidArtifactTypesList.isRight()) {
- DistributionActionResultEnum errorType = eitherValidArtifactTypesList.right().value().getDistributionActionResult();
- // Support the case of a new client and older ASDC Server which does not have the API
- if (errorType != DistributionActionResultEnum.ASDC_NOT_FOUND) {
- errorWrapper.setInnerElement(eitherValidArtifactTypesList.right().value());
- }
- } else {
- final List<String> artifactTypesFromAsdc = eitherValidArtifactTypesList.left().value();
- boolean isArtifactTypesValid = artifactTypesFromAsdc.containsAll(conf.getRelevantArtifactTypes());
- if (!isArtifactTypesValid) {
- List<String> invalidArtifactTypes = new ArrayList<>();
- invalidArtifactTypes.addAll(conf.getRelevantArtifactTypes());
- invalidArtifactTypes.removeAll(artifactTypesFromAsdc);
- DistributionClientResultImpl errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.CONF_CONTAINS_INVALID_ARTIFACT_TYPES,
- "configuration contains invalid artifact types:" + invalidArtifactTypes + " valid types are:" + artifactTypesFromAsdc);
- errorWrapper.setInnerElement(errorResponse);
- } else {
- log.debug("Artifact types: {} were validated with ASDC server", conf.getRelevantArtifactTypes());
- }
- }
- }
-
- private void initUebServerList(Wrapper<IDistributionClientResult> errorWrapper) {
- log.debug("get ueb cluster server list from component(configuration file)");
-
- Either<List<String>, IDistributionClientResult> serverListResponse = getUEBServerList();
- if (serverListResponse.isRight()) {
- errorWrapper.setInnerElement(serverListResponse.right().value());
- } else {
-
- brokerServers = serverListResponse.left().value();
- }
-
- }
-
- private void validateNotInitilized(Wrapper<IDistributionClientResult> errorWrapper) {
- if (isInitialized) {
- log.warn("distribution client already initialized");
- DistributionClientResultImpl alreadyInitResponse = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_ALREADY_INITIALIZED, "distribution client already initialized");
- errorWrapper.setInnerElement(alreadyInitResponse);
- }
- }
-
- @Override
- public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage) {
- log.info("DistributionClient - sendDownloadStatus");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
-
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
- }
-
- private IDistributionClientResult sendStatus(IDistributionStatusMessageJsonBuilder builder) {
- DistributionClientResultImpl statusResult = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "Failed to send status");
- log.info("DistributionClient - sendStatus");
- Either<CambriaBatchingPublisher, IDistributionClientResult> eitherPublisher = getCambriaPublisher();
- if (eitherPublisher.isRight()) {
- return eitherPublisher.right().value();
- }
- CambriaBatchingPublisher pub = eitherPublisher.left().value();
-
- log.debug("after create publisher server list " + brokerServers.toString());
- String jsonRequest = builder.build();
-
- log.debug("try to send status " + jsonRequest);
-
- try {
- pub.send("MyPartitionKey", jsonRequest);
- Thread.sleep(1000L);
- } catch (IOException e) {
- log.debug("DistributionClient - sendDownloadStatus. Failed to send download status");
- } catch (InterruptedException e) {
- log.debug("DistributionClient - sendDownloadStatus. thread was interrupted");
- }
-
- finally {
-
- try {
- List<message> stuck = pub.close(10L, TimeUnit.SECONDS);
-
- if (!stuck.isEmpty()) {
- log.debug("DistributionClient - sendDownloadStatus. " + stuck.size() + " messages unsent");
- } else {
- statusResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "messages successfully sent");
- }
- } catch (IOException | InterruptedException e) {
- log.debug("DistributionClient - sendDownloadStatus. failed to send messages and close publisher ");
- }
-
- }
- return statusResult;
- }
-
- private Either<CambriaBatchingPublisher, IDistributionClientResult> getCambriaPublisher() {
- CambriaBatchingPublisher cambriaPublisher = null;
- try {
- cambriaPublisher = new PublisherBuilder().onTopic(statusTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers).build();
- cambriaPublisher.setApiCredentials(credential.getApiKey(), credential.getApiSecret());
- } catch (MalformedURLException | GeneralSecurityException e) {
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- handleCambriaInitFailure(errorWrapper, e);
- return Either.right(errorWrapper.getInnerElement());
- }
- return Either.left(cambriaPublisher);
- }
-
- @Override
- public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage) {
- log.info("DistributionClient - sendDeploymentStatus");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
- }
-
- IDistributionClientResult sendNotificationStatus(long currentTimeMillis, String distributionId, ArtifactInfoImpl artifactInfo, boolean isNotified) {
- log.info("DistributionClient - sendNotificationStatus");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.prepareBuilderForNotificationStatus(getConfiguration().getConsumerID(), currentTimeMillis, distributionId, artifactInfo, isNotified));
- }
-
- /* *************************** Private Methods *************************************************** */
-
- protected DistributionClientResultImpl createUebKeys() {
- DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "keys created successfuly");
- try {
- String description = String.format(DistributionClientConstants.CLIENT_DESCRIPTION, configuration.getConsumerID());
- credential = cambriaIdentityManager.createApiKey(DistributionClientConstants.EMAIL, description);
- cambriaIdentityManager.setApiCredentials(credential.getApiKey(), credential.getApiSecret());
-
- } catch (HttpException | CambriaApiException | IOException e) {
- response = new DistributionClientResultImpl(DistributionActionResultEnum.UEB_KEYS_CREATION_FAILED, "failed to create keys: " + e.getMessage());
- log.error(response.toString());
- }
- return response;
- }
-
- private IDistributionClientResult restartConsumer() {
- shutdownExecutor();
- return start();
- }
-
- protected DistributionActionResultEnum validateAndInitConfiguration(Wrapper<IDistributionClientResult> errorWrapper, IConfiguration conf) {
- DistributionActionResultEnum result = DistributionActionResultEnum.SUCCESS;
-
- if (conf == null) {
- result = DistributionActionResultEnum.CONFIGURATION_IS_MISSING;
- } else if (conf.getConsumerID() == null || conf.getConsumerID().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_CONSUMER_ID;
- } else if (conf.getUser() == null || conf.getUser().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_USERNAME;
- } else if (conf.getPassword() == null || conf.getPassword().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_PASSWORD;
- } else if (conf.getMsgBusAddress() == null || conf.getMsgBusAddress().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_MSG_BUS_ADDRESS;
- } else if (conf.getAsdcAddress() == null || conf.getAsdcAddress().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_ASDC_FQDN;
- } else if (!isValidFqdn(conf.getAsdcAddress())) {
- result = DistributionActionResultEnum.CONF_INVALID_ASDC_FQDN;
- } else if (!isValidFqdns(conf.getMsgBusAddress())){
- result = DistributionActionResultEnum.CONF_INVALID_MSG_BUS_ADDRESS;
- } else if (conf.getEnvironmentName() == null || conf.getEnvironmentName().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_ENVIRONMENT_NAME;
- } else if (conf.getRelevantArtifactTypes() == null || conf.getRelevantArtifactTypes().isEmpty()) {
- result = DistributionActionResultEnum.CONF_MISSING_ARTIFACT_TYPES;
- }
- else if( conf.isConsumeProduceStatusTopic() && Objects.isNull(statusCallback) ){
- result = DistributionActionResultEnum.CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG;
- }
- // DistributionActionResultEnum.SUCCESS
- else {
- handleValidConf(conf);
- }
-
- if (result != DistributionActionResultEnum.SUCCESS) {
-
- DistributionClientResultImpl initResult = new DistributionClientResultImpl(result, "configuration is invalid: " + result.name());
-
- log.error(initResult.toString());
- errorWrapper.setInnerElement(initResult);
- }
- return result;
- }
-
- private void handleValidConf(IConfiguration conf) {
- this.configuration = new Configuration(conf);
- if (!isPollingIntervalValid(conf.getPollingInterval())) {
- configuration.setPollingInterval(DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
- }
- if (!isPollingTimeoutValid(conf.getPollingTimeout())) {
- configuration.setPollingTimeout(DistributionClientConstants.POLLING_TIMEOUT_SEC);
- }
- if (conf.getConsumerGroup() == null) {
- generateConsumerGroup();
- }
-
- //Default use HTTPS with DMAAP
- if (conf.isUseHttpsWithDmaap() == null){
- configuration.setUseHttpsWithDmaap(true);
- }
- }
-
- private void generateConsumerGroup() {
- String generatedConsumerGroup = UUID.randomUUID().toString();
- configuration.setConsumerGroup(generatedConsumerGroup);
- isConsumerGroupGenerated = true;
- }
-
- protected boolean isValidFqdn(String fqdn) {
- try {
- Matcher matcher = DistributionClientConstants.FQDN_PATTERN.matcher(fqdn);
- return matcher.matches();
- } catch (Exception e) {
- }
- return false;
- }
- protected boolean isValidFqdns(List<String> fqdns) {
- if (fqdns != null && !fqdns.isEmpty()) {
- for (String fqdn : fqdns) {
- if (isValidFqdn(fqdn)) {
- continue;
- } else {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- private void shutdownExecutor() {
- if (executorPool == null)
- return;
-
- executorPool.shutdown(); // Disable new tasks from being submitted
- try {
- // Wait a while for existing tasks to terminate
- if (!executorPool.awaitTermination(60, TimeUnit.SECONDS)) {
- executorPool.shutdownNow(); // Cancel currently executing tasks
- // Wait a while for tasks to respond to being cancelled
- if (!executorPool.awaitTermination(60, TimeUnit.SECONDS))
- log.error("Pool did not terminate");
- }
- } catch (InterruptedException ie) {
- // (Re-)Cancel if current thread also interrupted
- executorPool.shutdownNow();
- // Preserve interrupt status
- Thread.currentThread().interrupt();
- } finally {
- isStarted = false;
- }
- }
-
- private void validateRunReady(Wrapper<IDistributionClientResult> errorWrapper) {
- if (errorWrapper.isEmpty()) {
- validateInitilized(errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- validateNotTerminated(errorWrapper);
- }
-
- }
-
- private void validateInitilized(Wrapper<IDistributionClientResult> errorWrapper) {
- if (!isInitialized) {
- log.debug("client was not initialized");
- IDistributionClientResult result = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_NOT_INITIALIZED, "distribution client was not initialized");
- errorWrapper.setInnerElement(result);
- }
- }
-
- private void validateNotStarted(Wrapper<IDistributionClientResult> errorWrapper) {
- if (isStarted) {
- log.debug("client already started");
- IDistributionClientResult result = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_ALREADY_STARTED, "distribution client already started");
- errorWrapper.setInnerElement(result);
- }
- }
-
- private void validateNotTerminated(Wrapper<IDistributionClientResult> errorWrapper) {
- if (isTerminated) {
- log.debug("client was terminated");
- IDistributionClientResult result = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_IS_TERMINATED, "distribution client was terminated");
- errorWrapper.setInnerElement(result);
- }
- }
-
- private boolean isPollingTimeoutValid(int timeout) {
- boolean isValid = (timeout >= DistributionClientConstants.POLLING_TIMEOUT_SEC);
- if (!isValid) {
- log.warn("polling interval is out of range. value should be greater than or equals to " + DistributionClientConstants.POLLING_TIMEOUT_SEC);
- log.warn("setting polling interval to default: " + DistributionClientConstants.POLLING_TIMEOUT_SEC);
- }
- return isValid;
- }
-
- private boolean isPollingIntervalValid(int pollingInt) {
- boolean isValid = (pollingInt >= DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
- if (!isValid) {
- log.warn("polling interval is out of range. value should be greater than or equals to " + DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
- log.warn("setting polling interval to default: " + DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
- }
- return isValid;
- }
-
- private synchronized void initCambriaClient(Wrapper<IDistributionClientResult> errorWrapper) {
- if (cambriaIdentityManager == null) {
- try {
- AbstractAuthenticatedManagerBuilder<CambriaIdentityManager> managerBuilder = new IdentityManagerBuilder().usingHosts(brokerServers);
- if (configuration.isUseHttpsWithDmaap()){
- managerBuilder = managerBuilder.usingHttps();
- }
- cambriaIdentityManager = managerBuilder.build();
- } catch (MalformedURLException | GeneralSecurityException e) {
- handleCambriaInitFailure(errorWrapper, e);
- }
- }
- }
-
- private void handleCambriaInitFailure(Wrapper<IDistributionClientResult> errorWrapper, Exception e) {
- final String errorMessage = "Failed initilizing cambria component:" + e.getMessage();
- IDistributionClientResult errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.CAMBRIA_INIT_FAILED, errorMessage);
- errorWrapper.setInnerElement(errorResponse);
- log.error(errorMessage);
- log.debug(errorMessage, e);
- }
-
- @Override
- public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage, String errorReason) {
- log.info("DistributionClient - sendDownloadStatus with errorReason");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
-
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
-
- }
-
- @Override
- public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage, String errorReason) {
- log.info("DistributionClient - sendDeploymentStatus with errorReason");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
-
- }
-
- @Override
- public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage) {
- log.info("DistributionClient - sendComponentDone status");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
-
- }
-
- @Override
- public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage,
- String errorReason) {
- log.info("DistributionClient - sendComponentDone status with errorReason");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
- }
-
-
- @Override
- public List<IVfModuleMetadata> decodeVfModuleArtifact(byte[] artifactPayload) {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String vfModuleJsonString = new String(artifactPayload, StandardCharsets.UTF_8);
- final Type type = new TypeToken<List<VfModuleMetadata>>() {
- }.getType();
- List<IVfModuleMetadata> vfModules = gson.fromJson(vfModuleJsonString, type);
- return vfModules;
- }
-
-
- public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage) {
- log.info("DistributionClient - sendFinalDistributionStatus status");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
-
- }
-
-
- @Override
- public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage,
- String errorReason) {
- log.info("DistributionClient - sendFinalDistributionStatus status with errorReason");
- Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
- validateRunReady(errorWrapper);
- if (!errorWrapper.isEmpty()) {
- return errorWrapper.getInnerElement();
- }
- return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
-
-
- }
-
- public Either<List<String>,IDistributionClientResult> getUEBServerList() {
- List<String> msgBusAddresses = configuration.getMsgBusAddress();
- if(msgBusAddresses.isEmpty()){
- return Either.right(new DistributionClientResultImpl(DistributionActionResultEnum.CONF_MISSING_MSG_BUS_ADDRESS, "Message bus address was not found in the config file"));
- }
- else{
- return GeneralUtils.convertToValidHostName(msgBusAddresses);
- }
- }
-
-
-
-
-
-
+ public static final int POLLING_TIMEOUT_MULTIPLIER = 1000;
+ public static final long SLEEPING_THREAD_TIME = 1000L;
+ public static final long PUBLISHER_TIMEOUT = 10L;
+ public static final int TERMINATION_TIMEOUT = 60;
+ private static Logger log = LoggerFactory.getLogger(DistributionClientImpl.class.getName());
+
+ protected SdcConnectorClient asdcConnector = new SdcConnectorClient();
+ private ScheduledExecutorService executorPool = null;
+ protected CambriaIdentityManager cambriaIdentityManager = null;
+ private List<String> brokerServers;
+ protected ApiCredential credential;
+ protected Configuration configuration;
+ private INotificationCallback callback;
+ private IStatusCallback statusCallback;
+ private String notificationTopic;
+ private String statusTopic;
+ private boolean isConsumerGroupGenerated = false;
+
+ private boolean isInitialized, isStarted, isTerminated;
+
+ @Override
+ public IConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ /* see javadoc */
+ public synchronized IDistributionClientResult updateConfiguration(IConfiguration conf) {
+
+ log.info("update DistributionClient configuration");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+
+ IDistributionClientResult updateResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "configuration updated successfuly");
+
+ boolean needToUpdateCambriaConsumer = false;
+
+ if (conf.getRelevantArtifactTypes() != null && !conf.getRelevantArtifactTypes().isEmpty()) {
+ configuration.setRelevantArtifactTypes(conf.getRelevantArtifactTypes());
+ needToUpdateCambriaConsumer = true;
+ }
+ if (isPollingIntervalValid(conf.getPollingInterval())) {
+ configuration.setPollingInterval(conf.getPollingInterval());
+ needToUpdateCambriaConsumer = true;
+ }
+ if (isPollingTimeoutValid(conf.getPollingTimeout())) {
+ configuration.setPollingTimeout(conf.getPollingTimeout());
+ needToUpdateCambriaConsumer = true;
+ }
+ if (conf.getConsumerGroup() != null) {
+ configuration.setConsumerGroup(conf.getConsumerGroup());
+ isConsumerGroupGenerated = false;
+ needToUpdateCambriaConsumer = true;
+ } else if (!isConsumerGroupGenerated) {
+ generateConsumerGroup();
+ }
+
+ if (needToUpdateCambriaConsumer) {
+ updateResult = restartConsumer();
+ }
+
+ return updateResult;
+ }
+
+ @Override
+ /**
+ * Start polling the Notification topic
+ */
+ public synchronized IDistributionClientResult start() {
+
+ log.info("start DistributionClient");
+ IDistributionClientResult startResult;
+ CambriaConsumer cambriaNotificationConsumer = null;
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ validateNotStarted(errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ try {
+ cambriaNotificationConsumer = new ConsumerBuilder().authenticatedBy(credential.getApiKey(), credential.getApiSecret()).knownAs(configuration.getConsumerGroup(), configuration.getConsumerID()).onTopic(notificationTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers)
+ .withSocketTimeout(configuration.getPollingTimeout() * POLLING_TIMEOUT_MULTIPLIER).build();
+
+ } catch (MalformedURLException | GeneralSecurityException e) {
+ handleCambriaInitFailure(errorWrapper, e);
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+
+ List<String> relevantArtifactTypes = configuration.getRelevantArtifactTypes();
+ // Remove nulls from list - workaround for how configuration is built
+ relevantArtifactTypes.removeAll(Collections.singleton(null));
+
+ NotificationConsumer consumer = new NotificationConsumer(cambriaNotificationConsumer, callback, relevantArtifactTypes, this);
+ executorPool = Executors.newScheduledThreadPool(DistributionClientConstants.POOL_SIZE);
+ executorPool.scheduleAtFixedRate(consumer, 0, configuration.getPollingInterval(), TimeUnit.SECONDS);
+
+ handleStatusConsumer(errorWrapper, executorPool);
+ }
+ if (!errorWrapper.isEmpty()) {
+ startResult = errorWrapper.getInnerElement();
+ } else {
+ startResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "distribution client started successfuly");
+ isStarted = true;
+ }
+ return startResult;
+ }
+
+ private void handleStatusConsumer(Wrapper<IDistributionClientResult> errorWrapper, ScheduledExecutorService executorPool) {
+ if (configuration.isConsumeProduceStatusTopic()) {
+ CambriaConsumer cambriaStatusConsumer;
+ try {
+ cambriaStatusConsumer = new ConsumerBuilder().authenticatedBy(credential.getApiKey(), credential.getApiSecret()).knownAs(configuration.getConsumerGroup(), configuration.getConsumerID()).onTopic(statusTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers)
+ .withSocketTimeout(configuration.getPollingTimeout() * POLLING_TIMEOUT_MULTIPLIER).build();
+ StatusConsumer statusConsumer = new StatusConsumer(cambriaStatusConsumer, statusCallback);
+ executorPool.scheduleAtFixedRate(statusConsumer, 0, configuration.getPollingInterval(), TimeUnit.SECONDS);
+ } catch (MalformedURLException | GeneralSecurityException e) {
+ handleCambriaInitFailure(errorWrapper, e);
+ }
+ }
+ }
+
+ @Override
+ /* see javadoc */
+ public synchronized IDistributionClientResult stop() {
+
+ log.info("stop DistributionClient");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ // 1. stop polling notification topic
+ shutdownExecutor();
+
+ // 2. send to ASDC unregister to topic
+ IDistributionClientResult unregisterResult = asdcConnector.unregisterTopics(credential);
+ if (unregisterResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
+ log.info("client failed to unregister from topics");
+ } else {
+ log.info("client unregistered from topics successfully");
+ }
+ asdcConnector.close();
+
+ try {
+ cambriaIdentityManager.deleteCurrentApiKey();
+ } catch (HttpException | IOException e) {
+ log.debug("failed to delete cambria keys", e);
+ }
+ cambriaIdentityManager.close();
+
+ isInitialized = false;
+ isTerminated = true;
+
+ DistributionClientResultImpl stopResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "distribution client stopped successfuly");
+ return stopResult;
+ }
+
+ @Override
+ public IDistributionClientDownloadResult download(IArtifactInfo artifactInfo) {
+ log.info("DistributionClient - download");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ IDistributionClientResult result = errorWrapper.getInnerElement();
+ IDistributionClientDownloadResult downloadResult = new DistributionClientDownloadResultImpl(result.getDistributionActionResult(), result.getDistributionMessageResult());
+ return downloadResult;
+ }
+ return asdcConnector.dowloadArtifact(artifactInfo);
+ }
+
+ @Override
+ public synchronized IDistributionClientResult init(IConfiguration conf, INotificationCallback notificationCallback,
+ IStatusCallback statusCallback) {
+ IDistributionClientResult initResult;
+ if (!conf.isConsumeProduceStatusTopic()) {
+ initResult = new DistributionClientResultImpl(DistributionActionResultEnum.CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG, "configuration is invalid: isConsumeProduceStatusTopic() should be set to 'true'");
+
+ } else if (isNull(statusCallback)) {
+ initResult = new DistributionClientResultImpl(DistributionActionResultEnum.CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG, "configuration is invalid: statusCallback is not defined");
+ } else {
+ this.statusCallback = statusCallback;
+ initResult = init(conf, notificationCallback);
+ }
+ return initResult;
+ }
+
+ @Override
+ /*
+ * see javadoc
+ */
+ public synchronized IDistributionClientResult init(IConfiguration conf, INotificationCallback callback) {
+
+ log.info("DistributionClient - init");
+
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateNotInitilized(errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ validateNotTerminated(errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ validateAndInitConfiguration(errorWrapper, conf);
+ }
+ // 1. get ueb server list from configuration
+ if (errorWrapper.isEmpty()) {
+ initUebServerList(errorWrapper);
+ }
+ // 2.validate artifact types against asdc server
+ if (errorWrapper.isEmpty()) {
+ validateArtifactTypesWithAsdcServer(conf, errorWrapper);
+ }
+ // 3. create keys
+ if (errorWrapper.isEmpty()) {
+ this.callback = callback;
+ createUebKeys(errorWrapper);
+ }
+ // 4. register for topics
+ if (errorWrapper.isEmpty()) {
+ registerForTopics(errorWrapper);
+ }
+
+ IDistributionClientResult result;
+ if (errorWrapper.isEmpty()) {
+ isInitialized = true;
+ result = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "distribution client initialized successfuly");
+ } else {
+ result = errorWrapper.getInnerElement();
+ }
+
+ return result;
+ }
+
+ private void registerForTopics(Wrapper<IDistributionClientResult> errorWrapper) {
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> registerAsdcTopics = asdcConnector.registerAsdcTopics(credential);
+ if (registerAsdcTopics.isRight()) {
+
+ try {
+ cambriaIdentityManager.deleteCurrentApiKey();
+ } catch (HttpException | IOException e) {
+ log.debug("failed to delete cambria keys", e);
+ }
+ errorWrapper.setInnerElement(registerAsdcTopics.right().value());
+ } else {
+ TopicRegistrationResponse topics = registerAsdcTopics.left().value();
+ notificationTopic = topics.getDistrNotificationTopicName();
+ statusTopic = topics.getDistrStatusTopicName();
+ }
+
+ }
+
+ private void createUebKeys(Wrapper<IDistributionClientResult> errorWrapper) {
+ initCambriaClient(errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ log.debug("create keys");
+ DistributionClientResultImpl createKeysResponse = createUebKeys();
+ if (createKeysResponse.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
+ errorWrapper.setInnerElement(createKeysResponse);
+ }
+ }
+ }
+
+ private void validateArtifactTypesWithAsdcServer(IConfiguration conf, Wrapper<IDistributionClientResult> errorWrapper) {
+ asdcConnector.init(configuration);
+ Either<List<String>, IDistributionClientResult> eitherValidArtifactTypesList = asdcConnector.getValidArtifactTypesList();
+ if (eitherValidArtifactTypesList.isRight()) {
+ DistributionActionResultEnum errorType = eitherValidArtifactTypesList.right().value().getDistributionActionResult();
+ // Support the case of a new client and older ASDC Server which does not have the API
+ if (errorType != DistributionActionResultEnum.ASDC_NOT_FOUND) {
+ errorWrapper.setInnerElement(eitherValidArtifactTypesList.right().value());
+ }
+ } else {
+ final List<String> artifactTypesFromAsdc = eitherValidArtifactTypesList.left().value();
+ boolean isArtifactTypesValid = artifactTypesFromAsdc.containsAll(conf.getRelevantArtifactTypes());
+ if (!isArtifactTypesValid) {
+ List<String> invalidArtifactTypes = new ArrayList<>();
+ invalidArtifactTypes.addAll(conf.getRelevantArtifactTypes());
+ invalidArtifactTypes.removeAll(artifactTypesFromAsdc);
+ DistributionClientResultImpl errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.CONF_CONTAINS_INVALID_ARTIFACT_TYPES,
+ "configuration contains invalid artifact types:" + invalidArtifactTypes + " valid types are:" + artifactTypesFromAsdc);
+ errorWrapper.setInnerElement(errorResponse);
+ } else {
+ log.debug("Artifact types: {} were validated with ASDC server", conf.getRelevantArtifactTypes());
+ }
+ }
+ }
+
+ private void initUebServerList(Wrapper<IDistributionClientResult> errorWrapper) {
+ log.debug("get ueb cluster server list from component(configuration file)");
+
+ Either<List<String>, IDistributionClientResult> serverListResponse = getUEBServerList();
+ if (serverListResponse.isRight()) {
+ errorWrapper.setInnerElement(serverListResponse.right().value());
+ } else {
+
+ brokerServers = serverListResponse.left().value();
+ }
+
+ }
+
+ private void validateNotInitilized(Wrapper<IDistributionClientResult> errorWrapper) {
+ if (isInitialized) {
+ log.warn("distribution client already initialized");
+ DistributionClientResultImpl alreadyInitResponse = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_ALREADY_INITIALIZED, "distribution client already initialized");
+ errorWrapper.setInnerElement(alreadyInitResponse);
+ }
+ }
+
+ @Override
+ public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage) {
+ log.info("DistributionClient - sendDownloadStatus");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
+ }
+
+ private IDistributionClientResult sendStatus(IDistributionStatusMessageJsonBuilder builder) {
+ DistributionClientResultImpl statusResult = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "Failed to send status");
+ log.info("DistributionClient - sendStatus");
+ Either<CambriaBatchingPublisher, IDistributionClientResult> eitherPublisher = getCambriaPublisher();
+ if (eitherPublisher.isRight()) {
+ return eitherPublisher.right().value();
+ }
+ CambriaBatchingPublisher pub = eitherPublisher.left().value();
+
+ log.debug("after create publisher server list " + brokerServers.toString());
+ String jsonRequest = builder.build();
+
+ log.debug("try to send status " + jsonRequest);
+
+ try {
+ pub.send("MyPartitionKey", jsonRequest);
+ Thread.sleep(SLEEPING_THREAD_TIME);
+ } catch (IOException e) {
+ log.debug("DistributionClient - sendDownloadStatus. Failed to send download status");
+ } catch (InterruptedException e) {
+ log.debug("DistributionClient - sendDownloadStatus. thread was interrupted");
+ } finally {
+
+ try {
+ List<message> stuck = pub.close(PUBLISHER_TIMEOUT, TimeUnit.SECONDS);
+
+ if (!stuck.isEmpty()) {
+ log.debug("DistributionClient - sendDownloadStatus. " + stuck.size() + " messages unsent");
+ } else {
+ statusResult = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "messages successfully sent");
+ }
+ } catch (IOException | InterruptedException e) {
+ log.debug("DistributionClient - sendDownloadStatus. failed to send messages and close publisher ");
+ }
+
+ }
+ return statusResult;
+ }
+
+ private Either<CambriaBatchingPublisher, IDistributionClientResult> getCambriaPublisher() {
+ CambriaBatchingPublisher cambriaPublisher = null;
+ try {
+ cambriaPublisher = new PublisherBuilder().onTopic(statusTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers).build();
+ cambriaPublisher.setApiCredentials(credential.getApiKey(), credential.getApiSecret());
+ } catch (MalformedURLException | GeneralSecurityException e) {
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ handleCambriaInitFailure(errorWrapper, e);
+ return Either.right(errorWrapper.getInnerElement());
+ }
+ return Either.left(cambriaPublisher);
+ }
+
+ @Override
+ public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage) {
+ log.info("DistributionClient - sendDeploymentStatus");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
+ }
+
+ IDistributionClientResult sendNotificationStatus(long currentTimeMillis, String distributionId, ArtifactInfoImpl artifactInfo, boolean isNotified) {
+ log.info("DistributionClient - sendNotificationStatus");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.prepareBuilderForNotificationStatus(getConfiguration().getConsumerID(), currentTimeMillis, distributionId, artifactInfo, isNotified));
+ }
+
+ /* *************************** Private Methods *************************************************** */
+
+ protected DistributionClientResultImpl createUebKeys() {
+ DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, "keys created successfuly");
+ try {
+ String description = String.format(DistributionClientConstants.CLIENT_DESCRIPTION, configuration.getConsumerID());
+ credential = cambriaIdentityManager.createApiKey(DistributionClientConstants.EMAIL, description);
+ cambriaIdentityManager.setApiCredentials(credential.getApiKey(), credential.getApiSecret());
+
+ } catch (HttpException | CambriaApiException | IOException e) {
+ response = new DistributionClientResultImpl(DistributionActionResultEnum.UEB_KEYS_CREATION_FAILED, "failed to create keys: " + e.getMessage());
+ log.error(response.toString());
+ }
+ return response;
+ }
+
+ private IDistributionClientResult restartConsumer() {
+ shutdownExecutor();
+ return start();
+ }
+
+ protected DistributionActionResultEnum validateAndInitConfiguration(Wrapper<IDistributionClientResult> errorWrapper, IConfiguration conf) {
+ DistributionActionResultEnum result = DistributionActionResultEnum.SUCCESS;
+
+ if (conf == null) {
+ result = DistributionActionResultEnum.CONFIGURATION_IS_MISSING;
+ } else if (conf.getConsumerID() == null || conf.getConsumerID().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_CONSUMER_ID;
+ } else if (conf.getUser() == null || conf.getUser().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_USERNAME;
+ } else if (conf.getPassword() == null || conf.getPassword().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_PASSWORD;
+ } else if (conf.getMsgBusAddress() == null || conf.getMsgBusAddress().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_MSG_BUS_ADDRESS;
+ } else if (conf.getAsdcAddress() == null || conf.getAsdcAddress().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_ASDC_FQDN;
+ } else if (!isValidFqdn(conf.getAsdcAddress())) {
+ result = DistributionActionResultEnum.CONF_INVALID_ASDC_FQDN;
+ } else if (!isValidFqdns(conf.getMsgBusAddress())) {
+ result = DistributionActionResultEnum.CONF_INVALID_MSG_BUS_ADDRESS;
+ } else if (conf.getEnvironmentName() == null || conf.getEnvironmentName().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_ENVIRONMENT_NAME;
+ } else if (conf.getRelevantArtifactTypes() == null || conf.getRelevantArtifactTypes().isEmpty()) {
+ result = DistributionActionResultEnum.CONF_MISSING_ARTIFACT_TYPES;
+ } else if (conf.isConsumeProduceStatusTopic() && Objects.isNull(statusCallback)) {
+ result = DistributionActionResultEnum.CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG;
+ } else { // DistributionActionResultEnum.SUCCESS
+ handleValidConf(conf);
+ }
+
+ if (result != DistributionActionResultEnum.SUCCESS) {
+
+ DistributionClientResultImpl initResult = new DistributionClientResultImpl(result, "configuration is invalid: " + result.name());
+
+ log.error(initResult.toString());
+ errorWrapper.setInnerElement(initResult);
+ }
+ return result;
+ }
+
+ private void handleValidConf(IConfiguration conf) {
+ this.configuration = new Configuration(conf);
+ if (!isPollingIntervalValid(conf.getPollingInterval())) {
+ configuration.setPollingInterval(DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
+ }
+ if (!isPollingTimeoutValid(conf.getPollingTimeout())) {
+ configuration.setPollingTimeout(DistributionClientConstants.POLLING_TIMEOUT_SEC);
+ }
+ if (conf.getConsumerGroup() == null) {
+ generateConsumerGroup();
+ }
+
+ //Default use HTTPS with DMAAP
+ if (conf.isUseHttpsWithDmaap() == null) {
+ configuration.setUseHttpsWithDmaap(true);
+ }
+ }
+
+ private void generateConsumerGroup() {
+ String generatedConsumerGroup = UUID.randomUUID().toString();
+ configuration.setConsumerGroup(generatedConsumerGroup);
+ isConsumerGroupGenerated = true;
+ }
+
+ protected boolean isValidFqdn(String fqdn) {
+ try {
+ Matcher matcher = DistributionClientConstants.FQDN_PATTERN.matcher(fqdn);
+ return matcher.matches();
+ } catch (Exception e) {
+ }
+ return false;
+ }
+
+ protected boolean isValidFqdns(List<String> fqdns) {
+ if (fqdns != null && !fqdns.isEmpty()) {
+ for (String fqdn : fqdns) {
+ if (isValidFqdn(fqdn)) {
+ continue;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private void shutdownExecutor() {
+ if (executorPool == null) {
+ return;
+ }
+
+ executorPool.shutdown(); // Disable new tasks from being submitted
+ try {
+ // Wait a while for existing tasks to terminate
+ if (!executorPool.awaitTermination(TERMINATION_TIMEOUT, TimeUnit.SECONDS)) {
+ executorPool.shutdownNow(); // Cancel currently executing tasks
+ // Wait a while for tasks to respond to being cancelled
+ if (!executorPool.awaitTermination(TERMINATION_TIMEOUT, TimeUnit.SECONDS)) {
+ log.error("Pool did not terminate");
+ }
+ }
+ } catch (InterruptedException ie) {
+ // (Re-)Cancel if current thread also interrupted
+ executorPool.shutdownNow();
+ // Preserve interrupt status
+ Thread.currentThread().interrupt();
+ } finally {
+ isStarted = false;
+ }
+ }
+
+ private void validateRunReady(Wrapper<IDistributionClientResult> errorWrapper) {
+ if (errorWrapper.isEmpty()) {
+ validateInitilized(errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ validateNotTerminated(errorWrapper);
+ }
+
+ }
+
+ private void validateInitilized(Wrapper<IDistributionClientResult> errorWrapper) {
+ if (!isInitialized) {
+ log.debug("client was not initialized");
+ IDistributionClientResult result = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_NOT_INITIALIZED, "distribution client was not initialized");
+ errorWrapper.setInnerElement(result);
+ }
+ }
+
+ private void validateNotStarted(Wrapper<IDistributionClientResult> errorWrapper) {
+ if (isStarted) {
+ log.debug("client already started");
+ IDistributionClientResult result = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_ALREADY_STARTED, "distribution client already started");
+ errorWrapper.setInnerElement(result);
+ }
+ }
+
+ private void validateNotTerminated(Wrapper<IDistributionClientResult> errorWrapper) {
+ if (isTerminated) {
+ log.debug("client was terminated");
+ IDistributionClientResult result = new DistributionClientResultImpl(DistributionActionResultEnum.DISTRIBUTION_CLIENT_IS_TERMINATED, "distribution client was terminated");
+ errorWrapper.setInnerElement(result);
+ }
+ }
+
+ private boolean isPollingTimeoutValid(int timeout) {
+ boolean isValid = (timeout >= DistributionClientConstants.POLLING_TIMEOUT_SEC);
+ if (!isValid) {
+ log.warn("polling interval is out of range. value should be greater than or equals to " + DistributionClientConstants.POLLING_TIMEOUT_SEC);
+ log.warn("setting polling interval to default: " + DistributionClientConstants.POLLING_TIMEOUT_SEC);
+ }
+ return isValid;
+ }
+
+ private boolean isPollingIntervalValid(int pollingInt) {
+ boolean isValid = (pollingInt >= DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
+ if (!isValid) {
+ log.warn("polling interval is out of range. value should be greater than or equals to " + DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
+ log.warn("setting polling interval to default: " + DistributionClientConstants.MIN_POLLING_INTERVAL_SEC);
+ }
+ return isValid;
+ }
+
+ private synchronized void initCambriaClient(Wrapper<IDistributionClientResult> errorWrapper) {
+ if (cambriaIdentityManager == null) {
+ try {
+ AbstractAuthenticatedManagerBuilder<CambriaIdentityManager> managerBuilder = new IdentityManagerBuilder().usingHosts(brokerServers);
+ if (configuration.isUseHttpsWithDmaap()) {
+ managerBuilder = managerBuilder.usingHttps();
+ }
+ cambriaIdentityManager = managerBuilder.build();
+ } catch (MalformedURLException | GeneralSecurityException e) {
+ handleCambriaInitFailure(errorWrapper, e);
+ }
+ }
+ }
+
+ private void handleCambriaInitFailure(Wrapper<IDistributionClientResult> errorWrapper, Exception e) {
+ final String errorMessage = "Failed initilizing cambria component:" + e.getMessage();
+ IDistributionClientResult errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.CAMBRIA_INIT_FAILED, errorMessage);
+ errorWrapper.setInnerElement(errorResponse);
+ log.error(errorMessage);
+ log.debug(errorMessage, e);
+ }
+
+ @Override
+ public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage statusMessage, String errorReason) {
+ log.info("DistributionClient - sendDownloadStatus with errorReason");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
+
+ }
+
+ @Override
+ public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage statusMessage, String errorReason) {
+ log.info("DistributionClient - sendDeploymentStatus with errorReason");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
+
+ }
+
+ @Override
+ public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage) {
+ log.info("DistributionClient - sendComponentDone status");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
+
+ }
+
+ @Override
+ public IDistributionClientResult sendComponentDoneStatus(IComponentDoneStatusMessage statusMessage,
+ String errorReason) {
+ log.info("DistributionClient - sendComponentDone status with errorReason");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
+ }
+
+
+ @Override
+ public List<IVfModuleMetadata> decodeVfModuleArtifact(byte[] artifactPayload) {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String vfModuleJsonString = new String(artifactPayload, StandardCharsets.UTF_8);
+ final Type type = new TypeToken<List<VfModuleMetadata>>() {
+ }.getType();
+ List<IVfModuleMetadata> vfModules = gson.fromJson(vfModuleJsonString, type);
+ return vfModules;
+ }
+
+
+ public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage) {
+ log.info("DistributionClient - sendFinalDistributionStatus status");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getSimpleBuilder(statusMessage));
+
+ }
+
+
+ @Override
+ public IDistributionClientResult sendFinalDistrStatus(IFinalDistrStatusMessage statusMessage,
+ String errorReason) {
+ log.info("DistributionClient - sendFinalDistributionStatus status with errorReason");
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ validateRunReady(errorWrapper);
+ if (!errorWrapper.isEmpty()) {
+ return errorWrapper.getInnerElement();
+ }
+ return sendStatus(DistributionStatusMessageJsonBuilderFactory.getErrorReasonBuilder(statusMessage, errorReason));
+
+
+ }
+
+ public Either<List<String>, IDistributionClientResult> getUEBServerList() {
+ List<String> msgBusAddresses = configuration.getMsgBusAddress();
+ if (msgBusAddresses.isEmpty()) {
+ return Either.right(new DistributionClientResultImpl(DistributionActionResultEnum.CONF_MISSING_MSG_BUS_ADDRESS, "Message bus address was not found in the config file"));
+ } else {
+ return GeneralUtils.convertToValidHostName(msgBusAddresses);
+ }
+ }
+
+
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java
index 0df0b7b..4edd355 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java
@@ -7,9 +7,9 @@
* 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.
@@ -25,26 +25,26 @@ import org.onap.sdc.utils.DistributionActionResultEnum;
public class DistributionClientResultImpl implements IDistributionClientResult {
- DistributionActionResultEnum responseStatus;
- String responseMessage;
+ private DistributionActionResultEnum responseStatus;
+ private String responseMessage;
- public DistributionClientResultImpl(DistributionActionResultEnum responseStatus, String responseMessage) {
- this.responseStatus = responseStatus;
- this.responseMessage = responseMessage;
- }
+ public DistributionClientResultImpl(DistributionActionResultEnum responseStatus, String responseMessage) {
+ this.responseStatus = responseStatus;
+ this.responseMessage = responseMessage;
+ }
- @Override
- public DistributionActionResultEnum getDistributionActionResult() {
- return responseStatus;
- }
+ @Override
+ public DistributionActionResultEnum getDistributionActionResult() {
+ return responseStatus;
+ }
- @Override
- public String getDistributionMessageResult() {
- return responseMessage;
- }
+ @Override
+ public String getDistributionMessageResult() {
+ return responseMessage;
+ }
- @Override
- public String toString() {
- return "DistributionClientResultImpl [responseStatus=" + responseStatus + ", responseMessage=" + responseMessage + "]";
- }
+ @Override
+ public String toString() {
+ return "DistributionClientResultImpl [responseStatus=" + responseStatus + ", responseMessage=" + responseMessage + "]";
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java
index d5bc4ce..59da074 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,87 +27,86 @@ import org.onap.sdc.utils.DistributionStatusEnum;
class DistributionStatusMessageImpl implements IDistributionStatusMessage {
- String distributionID;
- String consumerID;
- long timestamp;
- String artifactURL;
- DistributionStatusEnum status;
- String errorReason;
- private String componentName;
-
- public DistributionStatusMessageImpl(IDistributionStatusMessage message) {
- super();
- distributionID = message.getDistributionID();
- consumerID = message.getConsumerID();
- timestamp = message.getTimestamp();
- artifactURL = message.getArtifactURL();
- status = message.getStatus();
-
- }
-
- public DistributionStatusMessageImpl(IComponentDoneStatusMessage message) {
- super();
- distributionID = message.getDistributionID();
- consumerID = message.getConsumerID();
- timestamp = message.getTimestamp();
- artifactURL = message.getArtifactURL();
- status = message.getStatus();
- componentName = message.getComponentName();
- }
-
- public DistributionStatusMessageImpl(IFinalDistrStatusMessage message) {
- super();
- distributionID = message.getDistributionID();
- consumerID = message.getConsumerID();
- timestamp = message.getTimestamp();
-
- artifactURL = "";
- status = message.getStatus();
- componentName = message.getComponentName();
- }
-
- @Override
- public String getDistributionID() {
-
- return distributionID;
- }
-
- @Override
- public String getConsumerID() {
-
- return consumerID;
- }
-
- @Override
- public long getTimestamp() {
-
- return timestamp;
- }
-
- @Override
- public String getArtifactURL() {
-
- return artifactURL;
- }
-
- @Override
- public DistributionStatusEnum getStatus() {
-
- return status;
- }
-
- public String getErrorReason() {
- return errorReason;
- }
-
- public void setErrorReason(String errorReason) {
- this.errorReason = errorReason;
- }
-
- public String getComponentName() {
- return componentName;
- }
-
-
+ private String distributionID;
+ private String consumerID;
+ private long timestamp;
+ private String artifactURL;
+ private DistributionStatusEnum status;
+ private String errorReason;
+ private String componentName;
+
+ DistributionStatusMessageImpl(IDistributionStatusMessage message) {
+ super();
+ distributionID = message.getDistributionID();
+ consumerID = message.getConsumerID();
+ timestamp = message.getTimestamp();
+ artifactURL = message.getArtifactURL();
+ status = message.getStatus();
+
+ }
+
+ DistributionStatusMessageImpl(IComponentDoneStatusMessage message) {
+ super();
+ distributionID = message.getDistributionID();
+ consumerID = message.getConsumerID();
+ timestamp = message.getTimestamp();
+ artifactURL = message.getArtifactURL();
+ status = message.getStatus();
+ componentName = message.getComponentName();
+ }
+
+ DistributionStatusMessageImpl(IFinalDistrStatusMessage message) {
+ super();
+ distributionID = message.getDistributionID();
+ consumerID = message.getConsumerID();
+ timestamp = message.getTimestamp();
+
+ artifactURL = "";
+ status = message.getStatus();
+ componentName = message.getComponentName();
+ }
+
+ @Override
+ public String getDistributionID() {
+
+ return distributionID;
+ }
+
+ @Override
+ public String getConsumerID() {
+
+ return consumerID;
+ }
+
+ @Override
+ public long getTimestamp() {
+
+ return timestamp;
+ }
+
+ @Override
+ public String getArtifactURL() {
+
+ return artifactURL;
+ }
+
+ @Override
+ public DistributionStatusEnum getStatus() {
+
+ return status;
+ }
+
+ public String getErrorReason() {
+ return errorReason;
+ }
+
+ void setErrorReason(String errorReason) {
+ this.errorReason = errorReason;
+ }
+
+ public String getComponentName() {
+ return componentName;
+ }
+
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java
index d8c722d..9792467 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java
@@ -7,9 +7,9 @@
* 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.
@@ -30,119 +30,119 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class DistributionStatusMessageJsonBuilderFactory {
- static Gson gson = new GsonBuilder().setPrettyPrinting().create();
-
- public static IDistributionStatusMessageJsonBuilder getSimpleBuilder(IDistributionStatusMessage statusMessage){
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
-
- return prepareBuilderFromImpl(message);
- }
-
- public static IDistributionStatusMessageJsonBuilder getSimpleBuilder(IComponentDoneStatusMessage statusMessage){
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
-
- return prepareBuilderFromImpl(message);
- }
-
- public static IDistributionStatusMessageJsonBuilder getSimpleBuilder(IFinalDistrStatusMessage statusMessage){
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
-
- return prepareBuilderFromImpl(message);
- }
-
- public static IDistributionStatusMessageJsonBuilder getErrorReasonBuilder(IDistributionStatusMessage statusMessage, String errorReason){
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
- message.setErrorReason(errorReason);
-
- return prepareBuilderFromImpl(message);
- }
-
- public static IDistributionStatusMessageJsonBuilder getErrorReasonBuilder(IComponentDoneStatusMessage statusMessage,
- String errorReason) {
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
- message.setErrorReason(errorReason);
- return prepareBuilderFromImpl(message);
- }
-
- public static IDistributionStatusMessageJsonBuilder getErrorReasonBuilder(IFinalDistrStatusMessage statusMessage,
- String errorReason) {
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
- message.setErrorReason(errorReason);
- return prepareBuilderFromImpl(message);
- }
-
- static IDistributionStatusMessageJsonBuilder prepareBuilderForNotificationStatus(final String consumerId, final long currentTimeMillis, final String distributionId,
- final ArtifactInfoImpl artifactInfo, boolean isNotified){
-
- final DistributionStatusEnum fakeStatusToReplace = DistributionStatusEnum.DOWNLOAD_OK;
- final String jsonRequest = buildDistributionStatusJson(consumerId, currentTimeMillis, distributionId, artifactInfo, fakeStatusToReplace);
-
- DistributionStatusNotificationEnum notificationStatus = isNotified ? DistributionStatusNotificationEnum.NOTIFIED : DistributionStatusNotificationEnum.NOT_NOTIFIED;
- final String changedRequest = jsonRequest.replace(fakeStatusToReplace.name(), notificationStatus.name());
- IDistributionStatusMessageJsonBuilder builder = new IDistributionStatusMessageJsonBuilder() {
- @Override
- public String build() {
- return changedRequest;
- }
- };
- return builder;
-
- }
-
- private static String buildDistributionStatusJson(final String consumerId,
- final long currentTimeMillis, final String distributionId,
- final ArtifactInfoImpl artifactInfo,
- final DistributionStatusEnum fakeStatusToBeReplaced) {
- IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() {
- @Override
- public long getTimestamp() {
- return currentTimeMillis;
- }
-
- @Override
- public DistributionStatusEnum getStatus() {
-
- return fakeStatusToBeReplaced;
- }
-
- @Override
- public String getDistributionID() {
- return distributionId;
- }
-
- @Override
- public String getConsumerID() {
- return consumerId;
- }
-
- @Override
- public String getArtifactURL() {
- return artifactInfo.getArtifactURL();
- }
- };
-
- DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
- final String jsonRequest = gson.toJson(message);
- return jsonRequest;
- }
-
- private static IDistributionStatusMessageJsonBuilder prepareBuilderFromImpl( DistributionStatusMessageImpl message) {
- final String jsonRequest = gson.toJson(message);
- IDistributionStatusMessageJsonBuilder builder = new IDistributionStatusMessageJsonBuilder() {
- @Override
- public String build() {
- return jsonRequest;
- }
- };
- return builder;
- }
-
- private enum DistributionStatusNotificationEnum {
- NOTIFIED, NOT_NOTIFIED
- }
-
-
-
-
-
+ private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ private DistributionStatusMessageJsonBuilderFactory() {
+ }
+
+ public static IDistributionStatusMessageJsonBuilder getSimpleBuilder(IDistributionStatusMessage statusMessage) {
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+
+ return prepareBuilderFromImpl(message);
+ }
+
+ public static IDistributionStatusMessageJsonBuilder getSimpleBuilder(IComponentDoneStatusMessage statusMessage) {
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+
+ return prepareBuilderFromImpl(message);
+ }
+
+ public static IDistributionStatusMessageJsonBuilder getSimpleBuilder(IFinalDistrStatusMessage statusMessage) {
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+
+ return prepareBuilderFromImpl(message);
+ }
+
+ public static IDistributionStatusMessageJsonBuilder getErrorReasonBuilder(IDistributionStatusMessage statusMessage, String errorReason) {
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+ message.setErrorReason(errorReason);
+
+ return prepareBuilderFromImpl(message);
+ }
+
+ public static IDistributionStatusMessageJsonBuilder getErrorReasonBuilder(IComponentDoneStatusMessage statusMessage,
+ String errorReason) {
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+ message.setErrorReason(errorReason);
+ return prepareBuilderFromImpl(message);
+ }
+
+ public static IDistributionStatusMessageJsonBuilder getErrorReasonBuilder(IFinalDistrStatusMessage statusMessage,
+ String errorReason) {
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+ message.setErrorReason(errorReason);
+ return prepareBuilderFromImpl(message);
+ }
+
+ static IDistributionStatusMessageJsonBuilder prepareBuilderForNotificationStatus(final String consumerId, final long currentTimeMillis, final String distributionId,
+ final ArtifactInfoImpl artifactInfo, boolean isNotified) {
+
+ final DistributionStatusEnum fakeStatusToReplace = DistributionStatusEnum.DOWNLOAD_OK;
+ final String jsonRequest = buildDistributionStatusJson(consumerId, currentTimeMillis, distributionId, artifactInfo, fakeStatusToReplace);
+
+ DistributionStatusNotificationEnum notificationStatus = isNotified ? DistributionStatusNotificationEnum.NOTIFIED : DistributionStatusNotificationEnum.NOT_NOTIFIED;
+ final String changedRequest = jsonRequest.replace(fakeStatusToReplace.name(), notificationStatus.name());
+ IDistributionStatusMessageJsonBuilder builder = new IDistributionStatusMessageJsonBuilder() {
+ @Override
+ public String build() {
+ return changedRequest;
+ }
+ };
+ return builder;
+
+ }
+
+ private static String buildDistributionStatusJson(final String consumerId,
+ final long currentTimeMillis, final String distributionId,
+ final ArtifactInfoImpl artifactInfo,
+ final DistributionStatusEnum fakeStatusToBeReplaced) {
+ IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() {
+ @Override
+ public long getTimestamp() {
+ return currentTimeMillis;
+ }
+
+ @Override
+ public DistributionStatusEnum getStatus() {
+
+ return fakeStatusToBeReplaced;
+ }
+
+ @Override
+ public String getDistributionID() {
+ return distributionId;
+ }
+
+ @Override
+ public String getConsumerID() {
+ return consumerId;
+ }
+
+ @Override
+ public String getArtifactURL() {
+ return artifactInfo.getArtifactURL();
+ }
+ };
+
+ DistributionStatusMessageImpl message = new DistributionStatusMessageImpl(statusMessage);
+ final String jsonRequest = gson.toJson(message);
+ return jsonRequest;
+ }
+
+ private static IDistributionStatusMessageJsonBuilder prepareBuilderFromImpl(DistributionStatusMessageImpl message) {
+ final String jsonRequest = gson.toJson(message);
+ IDistributionStatusMessageJsonBuilder builder = new IDistributionStatusMessageJsonBuilder() {
+ @Override
+ public String build() {
+ return jsonRequest;
+ }
+ };
+ return builder;
+ }
+
+ private enum DistributionStatusNotificationEnum {
+ NOTIFIED, NOT_NOTIFIED
+ }
+
+
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java
index 92dad7b..eeaf235 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,132 +27,135 @@ import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.IResourceInstance;
class JsonContainerResourceInstance implements IResourceInstance {
- JsonContainerResourceInstance (){}
- private String resourceInstanceName;
- private String resourceCustomizationUUID;
- private String resourceName;
- private String resourceVersion;
- private String resoucreType;
- private String resourceUUID;
- private String resourceInvariantUUID;
- private String category;
- private String subcategory;
- private List<ArtifactInfoImpl> artifacts;
-
- private JsonContainerResourceInstance(IResourceInstance resourceInstance){
- resourceInstanceName = resourceInstance.getResourceInstanceName();
- resourceCustomizationUUID = resourceInstance.getResourceCustomizationUUID();
- resourceName = resourceInstance.getResourceName();
- resourceVersion = resourceInstance.getResourceVersion();
- resoucreType = resourceInstance.getResourceType();
- resourceUUID = resourceInstance.getResourceUUID();
- resourceInvariantUUID = resourceInstance.getResourceInvariantUUID();
- category = resourceInstance.getCategory();
- subcategory = resourceInstance.getSubcategory();
- artifacts = ArtifactInfoImpl.convertToArtifactInfoImpl(resourceInstance.getArtifacts());
- }
-
- public static List<JsonContainerResourceInstance> convertToJsonContainer(List<IResourceInstance> resources){
- List<JsonContainerResourceInstance> buildResources = new ArrayList<JsonContainerResourceInstance>();
- if( resources != null ){
- for( IResourceInstance resourceInstance : resources ){
- buildResources.add(new JsonContainerResourceInstance(resourceInstance));
- }
- }
- return buildResources;
- }
-
- @Override
- public String getResourceInstanceName() {
- return resourceInstanceName;
- }
-
- public void setResourceInstanceName(String resourceInstanceName) {
- this.resourceInstanceName = resourceInstanceName;
- }
-
- @Override
- public String getResourceName() {
- return resourceName;
- }
-
- public void setResourceName(String resourceName) {
- this.resourceName = resourceName;
- }
-
- @Override
- public String getResourceVersion() {
- return resourceVersion;
- }
-
- public void setResourceVersion(String resourceVersion) {
- this.resourceVersion = resourceVersion;
- }
-
- @Override
- public String getResourceType() {
- return resoucreType;
- }
-
- public void setResoucreType(String resoucreType) {
- this.resoucreType = resoucreType;
- }
-
- @Override
- public String getResourceUUID() {
- return resourceUUID;
- }
-
- public void setResourceUUID(String resourceUUID) {
- this.resourceUUID = resourceUUID;
- }
-
- @Override
- public List<IArtifactInfo> getArtifacts() {
- List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
- if( artifacts != null ){
- temp.addAll(artifacts);
- }
- return temp;
- }
-
- public void setArtifacts(List<ArtifactInfoImpl> artifacts) {
- this.artifacts = artifacts;
- }
-
- public List<ArtifactInfoImpl> getArtifactsImpl(){
- return artifacts;
- }
-
- @Override
- public String getResourceInvariantUUID() {
- return resourceInvariantUUID;
- }
-
- public void setResourceInvariantUUID(String resourceInvariantUUID) {
- this.resourceInvariantUUID = resourceInvariantUUID;
- }
- public String getResourceCustomizationUUID() {
- return resourceCustomizationUUID;
- }
-
- public void setResourceCustomizationUUID(String resourceCustomizationUUID) {
- this.resourceCustomizationUUID = resourceCustomizationUUID;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public String getSubcategory() {
- return subcategory;
- }
-
- public void setSubcategory(String subcategory) {
- this.subcategory = subcategory;
- }
+ JsonContainerResourceInstance() {
+ }
+
+ private String resourceInstanceName;
+ private String resourceCustomizationUUID;
+ private String resourceName;
+ private String resourceVersion;
+ private String resoucreType;
+ private String resourceUUID;
+ private String resourceInvariantUUID;
+ private String category;
+ private String subcategory;
+ private List<ArtifactInfoImpl> artifacts;
+
+ private JsonContainerResourceInstance(IResourceInstance resourceInstance) {
+ resourceInstanceName = resourceInstance.getResourceInstanceName();
+ resourceCustomizationUUID = resourceInstance.getResourceCustomizationUUID();
+ resourceName = resourceInstance.getResourceName();
+ resourceVersion = resourceInstance.getResourceVersion();
+ resoucreType = resourceInstance.getResourceType();
+ resourceUUID = resourceInstance.getResourceUUID();
+ resourceInvariantUUID = resourceInstance.getResourceInvariantUUID();
+ category = resourceInstance.getCategory();
+ subcategory = resourceInstance.getSubcategory();
+ artifacts = ArtifactInfoImpl.convertToArtifactInfoImpl(resourceInstance.getArtifacts());
+ }
+
+ public static List<JsonContainerResourceInstance> convertToJsonContainer(List<IResourceInstance> resources) {
+ List<JsonContainerResourceInstance> buildResources = new ArrayList<JsonContainerResourceInstance>();
+ if (resources != null) {
+ for (IResourceInstance resourceInstance : resources) {
+ buildResources.add(new JsonContainerResourceInstance(resourceInstance));
+ }
+ }
+ return buildResources;
+ }
+
+ @Override
+ public String getResourceInstanceName() {
+ return resourceInstanceName;
+ }
+
+ public void setResourceInstanceName(String resourceInstanceName) {
+ this.resourceInstanceName = resourceInstanceName;
+ }
+
+ @Override
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ @Override
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ @Override
+ public String getResourceType() {
+ return resoucreType;
+ }
+
+ public void setResoucreType(String resoucreType) {
+ this.resoucreType = resoucreType;
+ }
+
+ @Override
+ public String getResourceUUID() {
+ return resourceUUID;
+ }
+
+ public void setResourceUUID(String resourceUUID) {
+ this.resourceUUID = resourceUUID;
+ }
+
+ @Override
+ public List<IArtifactInfo> getArtifacts() {
+ List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
+ if (artifacts != null) {
+ temp.addAll(artifacts);
+ }
+ return temp;
+ }
+
+ public void setArtifacts(List<ArtifactInfoImpl> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+ public List<ArtifactInfoImpl> getArtifactsImpl() {
+ return artifacts;
+ }
+
+ @Override
+ public String getResourceInvariantUUID() {
+ return resourceInvariantUUID;
+ }
+
+ public void setResourceInvariantUUID(String resourceInvariantUUID) {
+ this.resourceInvariantUUID = resourceInvariantUUID;
+ }
+
+ public String getResourceCustomizationUUID() {
+ return resourceCustomizationUUID;
+ }
+
+ public void setResourceCustomizationUUID(String resourceCustomizationUUID) {
+ this.resourceCustomizationUUID = resourceCustomizationUUID;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getSubcategory() {
+ return subcategory;
+ }
+
+ public void setSubcategory(String subcategory) {
+ this.subcategory = subcategory;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java
index aab1e29..bf28d97 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java
@@ -7,9 +7,9 @@
* 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.
@@ -39,143 +39,144 @@ import com.google.gson.GsonBuilder;
class NotificationConsumer implements Runnable {
- private static Logger log = LoggerFactory.getLogger(NotificationConsumer.class.getName());
-
- private CambriaConsumer cambriaConsumer;
- private INotificationCallback clientCallback;
- private List<String> artifactsTypes;
- private DistributionClientImpl distributionClient;
-
- public NotificationConsumer(CambriaConsumer cambriaConsumer, INotificationCallback clientCallback, List<String> artifactsTypes, DistributionClientImpl distributionClient) {
- this.cambriaConsumer = cambriaConsumer;
- this.clientCallback = clientCallback;
- this.artifactsTypes = artifactsTypes;
- this.distributionClient = distributionClient;
- }
-
- @Override
- public void run() {
-
- try {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- long currentTimeMillis = System.currentTimeMillis();
- for (String notificationMsg : cambriaConsumer.fetch()) {
- log.debug("received message from topic");
- log.debug("recieved notification from broker: {}", notificationMsg);
-
- final NotificationDataImpl notificationFromUEB = gson.fromJson(notificationMsg, NotificationDataImpl.class);
- NotificationDataImpl notificationForCallback = buildCallbackNotificationLogic(currentTimeMillis, notificationFromUEB);
- if (isActivateCallback(notificationForCallback)) {
- String stringNotificationForCallback = gson.toJson(notificationForCallback);
- log.debug("sending notification to client: {}", stringNotificationForCallback);
- clientCallback.activateCallback(notificationForCallback);
- }
- }
-
- } catch (Exception e) {
- log.error("Error exception occured when fetching with Cambria Client:{}", e.getMessage());
- log.debug("Error exception occured when fetching with Cambria Client:{}", e.getMessage(), e);
- }
- }
-
- private boolean isActivateCallback(NotificationDataImpl notificationForCallback) {
- boolean hasRelevantArtifactsInResourceInstance = notificationForCallback.getResources() != null && !notificationForCallback.getResources().isEmpty();
- boolean hasRelevantArtifactsInService = notificationForCallback.getServiceArtifacts() != null && !notificationForCallback.getServiceArtifacts().isEmpty();
-
- return hasRelevantArtifactsInResourceInstance || hasRelevantArtifactsInService;
- }
-
- protected NotificationDataImpl buildCallbackNotificationLogic(long currentTimeMillis, final NotificationDataImpl notificationFromUEB) {
- List<IResourceInstance> relevantResourceInstances = buildResourceInstancesLogic(notificationFromUEB, currentTimeMillis);
- List<ArtifactInfoImpl> relevantServiceArtifacts = handleRelevantArtifacts(notificationFromUEB, currentTimeMillis, notificationFromUEB.getServiceArtifactsImpl());
- notificationFromUEB.setResources(relevantResourceInstances);
- notificationFromUEB.setServiceArtifacts(relevantServiceArtifacts);
- return notificationFromUEB;
- }
-
- private List<IResourceInstance> buildResourceInstancesLogic(NotificationDataImpl notificationFromUEB, long currentTimeMillis) {
-
- List<IResourceInstance> relevantResourceInstances = new ArrayList<>();
-
- for (JsonContainerResourceInstance resourceInstance : notificationFromUEB.getResourcesImpl()) {
- final List<ArtifactInfoImpl> artifactsImplList = resourceInstance.getArtifactsImpl();
- List<ArtifactInfoImpl> foundRelevantArtifacts = handleRelevantArtifacts(notificationFromUEB, currentTimeMillis, artifactsImplList);
- if (!foundRelevantArtifacts.isEmpty() || distributionClient.getConfiguration().isFilterInEmptyResources()) {
- resourceInstance.setArtifacts(foundRelevantArtifacts);
- relevantResourceInstances.add(resourceInstance);
- }
- }
- return relevantResourceInstances;
-
- }
-
- private List<ArtifactInfoImpl> handleRelevantArtifacts(NotificationDataImpl notificationFromUEB, long currentTimeMillis, final List<ArtifactInfoImpl> artifactsImplList) {
- List<ArtifactInfoImpl> relevantArtifacts = new ArrayList<>();
- if (artifactsImplList != null) {
- for (ArtifactInfoImpl artifactInfo : artifactsImplList) {
- handleRelevantArtifact(notificationFromUEB, currentTimeMillis, artifactsImplList, relevantArtifacts, artifactInfo);
- }
- }
- return relevantArtifacts;
- }
-
- private void handleRelevantArtifact(NotificationDataImpl notificationFromUEB, long currentTimeMillis, final List<ArtifactInfoImpl> artifactsImplList, List<ArtifactInfoImpl> relevantArtifacts, ArtifactInfoImpl artifactInfo) {
- boolean isArtifactRelevant = artifactsTypes.contains(artifactInfo.getArtifactType());
- String artifactType = artifactInfo.getArtifactType();
- if (artifactInfo.getGeneratedFromUUID() != null && !artifactInfo.getGeneratedFromUUID().isEmpty()) {
- IArtifactInfo generatedFromArtInfo = findGeneratedFromArtifact(artifactInfo.getGeneratedFromUUID(), artifactsImplList);
- if (generatedFromArtInfo != null)
- isArtifactRelevant = isArtifactRelevant && artifactsTypes.contains(generatedFromArtInfo.getArtifactType());
- else
- isArtifactRelevant = false;
- }
- if (isArtifactRelevant) {
- setRelatedArtifacts(artifactInfo, notificationFromUEB);
- if (artifactType.equals(ArtifactTypeEnum.HEAT.name()) || artifactType.equals(ArtifactTypeEnum.HEAT_VOL.name()) || artifactType.equals(ArtifactTypeEnum.HEAT_NET.name())) {
- setGeneratedArtifact(artifactsImplList, artifactInfo);
- }
- relevantArtifacts.add(artifactInfo);
-
- }
- IDistributionClientResult notificationStatus = distributionClient.sendNotificationStatus(currentTimeMillis, notificationFromUEB.getDistributionID(), artifactInfo, isArtifactRelevant);
- if (notificationStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- log.error("Error failed to send notification status to UEB failed status:{}, error message:{}", notificationStatus.getDistributionActionResult().name(), notificationStatus.getDistributionMessageResult());
- }
- }
-
- private void setRelatedArtifacts(ArtifactInfoImpl artifact, INotificationData notificationData) {
- if (artifact.getRelatedArtifactsUUID() != null) {
- List<IArtifactInfo> relatedArtifacts = new ArrayList<>();
- for (String relatedArtifactUUID : artifact.getRelatedArtifactsUUID()) {
- relatedArtifacts.add(notificationData.getArtifactMetadataByUUID(relatedArtifactUUID));
- }
- artifact.setRelatedArtifactsInfo(relatedArtifacts);
- }
-
- }
-
- private void setGeneratedArtifact(final List<ArtifactInfoImpl> artifactsImplList, ArtifactInfoImpl artifactInfo) {
- IArtifactInfo found = null;
- String artifactUUID = artifactInfo.getArtifactUUID();
- for (ArtifactInfoImpl generatedArtifactInfo : artifactsImplList) {
- if (generatedArtifactInfo.getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.name()) && artifactUUID.equals(generatedArtifactInfo.getGeneratedFromUUID())) {
- found = generatedArtifactInfo;
- break;
- }
- }
-
- artifactInfo.setGeneratedArtifact(found);
- }
-
- private IArtifactInfo findGeneratedFromArtifact(String getGeneratedFromUUID, List<ArtifactInfoImpl> list) {
- IArtifactInfo found = null;
- for (ArtifactInfoImpl artifactInfo : list) {
- if (getGeneratedFromUUID.equals(artifactInfo.getArtifactUUID())) {
- found = artifactInfo;
- break;
- }
- }
- return found;
- }
+ private static Logger log = LoggerFactory.getLogger(NotificationConsumer.class.getName());
+
+ private CambriaConsumer cambriaConsumer;
+ private INotificationCallback clientCallback;
+ private List<String> artifactsTypes;
+ private DistributionClientImpl distributionClient;
+
+ NotificationConsumer(CambriaConsumer cambriaConsumer, INotificationCallback clientCallback, List<String> artifactsTypes, DistributionClientImpl distributionClient) {
+ this.cambriaConsumer = cambriaConsumer;
+ this.clientCallback = clientCallback;
+ this.artifactsTypes = artifactsTypes;
+ this.distributionClient = distributionClient;
+ }
+
+ @Override
+ public void run() {
+
+ try {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ long currentTimeMillis = System.currentTimeMillis();
+ for (String notificationMsg : cambriaConsumer.fetch()) {
+ log.debug("received message from topic");
+ log.debug("recieved notification from broker: {}", notificationMsg);
+
+ final NotificationDataImpl notificationFromUEB = gson.fromJson(notificationMsg, NotificationDataImpl.class);
+ NotificationDataImpl notificationForCallback = buildCallbackNotificationLogic(currentTimeMillis, notificationFromUEB);
+ if (isActivateCallback(notificationForCallback)) {
+ String stringNotificationForCallback = gson.toJson(notificationForCallback);
+ log.debug("sending notification to client: {}", stringNotificationForCallback);
+ clientCallback.activateCallback(notificationForCallback);
+ }
+ }
+
+ } catch (Exception e) {
+ log.error("Error exception occured when fetching with Cambria Client:{}", e.getMessage());
+ log.debug("Error exception occured when fetching with Cambria Client:{}", e.getMessage(), e);
+ }
+ }
+
+ private boolean isActivateCallback(NotificationDataImpl notificationForCallback) {
+ boolean hasRelevantArtifactsInResourceInstance = notificationForCallback.getResources() != null && !notificationForCallback.getResources().isEmpty();
+ boolean hasRelevantArtifactsInService = notificationForCallback.getServiceArtifacts() != null && !notificationForCallback.getServiceArtifacts().isEmpty();
+
+ return hasRelevantArtifactsInResourceInstance || hasRelevantArtifactsInService;
+ }
+
+ protected NotificationDataImpl buildCallbackNotificationLogic(long currentTimeMillis, final NotificationDataImpl notificationFromUEB) {
+ List<IResourceInstance> relevantResourceInstances = buildResourceInstancesLogic(notificationFromUEB, currentTimeMillis);
+ List<ArtifactInfoImpl> relevantServiceArtifacts = handleRelevantArtifacts(notificationFromUEB, currentTimeMillis, notificationFromUEB.getServiceArtifactsImpl());
+ notificationFromUEB.setResources(relevantResourceInstances);
+ notificationFromUEB.setServiceArtifacts(relevantServiceArtifacts);
+ return notificationFromUEB;
+ }
+
+ private List<IResourceInstance> buildResourceInstancesLogic(NotificationDataImpl notificationFromUEB, long currentTimeMillis) {
+
+ List<IResourceInstance> relevantResourceInstances = new ArrayList<>();
+
+ for (JsonContainerResourceInstance resourceInstance : notificationFromUEB.getResourcesImpl()) {
+ final List<ArtifactInfoImpl> artifactsImplList = resourceInstance.getArtifactsImpl();
+ List<ArtifactInfoImpl> foundRelevantArtifacts = handleRelevantArtifacts(notificationFromUEB, currentTimeMillis, artifactsImplList);
+ if (!foundRelevantArtifacts.isEmpty() || distributionClient.getConfiguration().isFilterInEmptyResources()) {
+ resourceInstance.setArtifacts(foundRelevantArtifacts);
+ relevantResourceInstances.add(resourceInstance);
+ }
+ }
+ return relevantResourceInstances;
+
+ }
+
+ private List<ArtifactInfoImpl> handleRelevantArtifacts(NotificationDataImpl notificationFromUEB, long currentTimeMillis, final List<ArtifactInfoImpl> artifactsImplList) {
+ List<ArtifactInfoImpl> relevantArtifacts = new ArrayList<>();
+ if (artifactsImplList != null) {
+ for (ArtifactInfoImpl artifactInfo : artifactsImplList) {
+ handleRelevantArtifact(notificationFromUEB, currentTimeMillis, artifactsImplList, relevantArtifacts, artifactInfo);
+ }
+ }
+ return relevantArtifacts;
+ }
+
+ private void handleRelevantArtifact(NotificationDataImpl notificationFromUEB, long currentTimeMillis, final List<ArtifactInfoImpl> artifactsImplList, List<ArtifactInfoImpl> relevantArtifacts, ArtifactInfoImpl artifactInfo) {
+ boolean isArtifactRelevant = artifactsTypes.contains(artifactInfo.getArtifactType());
+ String artifactType = artifactInfo.getArtifactType();
+ if (artifactInfo.getGeneratedFromUUID() != null && !artifactInfo.getGeneratedFromUUID().isEmpty()) {
+ IArtifactInfo generatedFromArtInfo = findGeneratedFromArtifact(artifactInfo.getGeneratedFromUUID(), artifactsImplList);
+ if (generatedFromArtInfo != null) {
+ isArtifactRelevant = isArtifactRelevant && artifactsTypes.contains(generatedFromArtInfo.getArtifactType());
+ } else {
+ isArtifactRelevant = false;
+ }
+ }
+ if (isArtifactRelevant) {
+ setRelatedArtifacts(artifactInfo, notificationFromUEB);
+ if (artifactType.equals(ArtifactTypeEnum.HEAT.name()) || artifactType.equals(ArtifactTypeEnum.HEAT_VOL.name()) || artifactType.equals(ArtifactTypeEnum.HEAT_NET.name())) {
+ setGeneratedArtifact(artifactsImplList, artifactInfo);
+ }
+ relevantArtifacts.add(artifactInfo);
+
+ }
+ IDistributionClientResult notificationStatus = distributionClient.sendNotificationStatus(currentTimeMillis, notificationFromUEB.getDistributionID(), artifactInfo, isArtifactRelevant);
+ if (notificationStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
+ log.error("Error failed to send notification status to UEB failed status:{}, error message:{}", notificationStatus.getDistributionActionResult().name(), notificationStatus.getDistributionMessageResult());
+ }
+ }
+
+ private void setRelatedArtifacts(ArtifactInfoImpl artifact, INotificationData notificationData) {
+ if (artifact.getRelatedArtifactsUUID() != null) {
+ List<IArtifactInfo> relatedArtifacts = new ArrayList<>();
+ for (String relatedArtifactUUID : artifact.getRelatedArtifactsUUID()) {
+ relatedArtifacts.add(notificationData.getArtifactMetadataByUUID(relatedArtifactUUID));
+ }
+ artifact.setRelatedArtifactsInfo(relatedArtifacts);
+ }
+
+ }
+
+ private void setGeneratedArtifact(final List<ArtifactInfoImpl> artifactsImplList, ArtifactInfoImpl artifactInfo) {
+ IArtifactInfo found = null;
+ String artifactUUID = artifactInfo.getArtifactUUID();
+ for (ArtifactInfoImpl generatedArtifactInfo : artifactsImplList) {
+ if (generatedArtifactInfo.getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.name()) && artifactUUID.equals(generatedArtifactInfo.getGeneratedFromUUID())) {
+ found = generatedArtifactInfo;
+ break;
+ }
+ }
+
+ artifactInfo.setGeneratedArtifact(found);
+ }
+
+ private IArtifactInfo findGeneratedFromArtifact(String getGeneratedFromUUID, List<ArtifactInfoImpl> list) {
+ IArtifactInfo found = null;
+ for (ArtifactInfoImpl artifactInfo : list) {
+ if (getGeneratedFromUUID.equals(artifactInfo.getArtifactUUID())) {
+ found = artifactInfo;
+ break;
+ }
+ }
+ return found;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java
index 7b7b532..925b79b 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java
@@ -7,9 +7,9 @@
* 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.
@@ -30,150 +30,150 @@ import org.onap.sdc.api.notification.INotificationData;
class NotificationDataImpl implements INotificationData {
- private String distributionID;
- private String serviceName;
- private String serviceVersion;
- private String serviceUUID;
- private String serviceDescription;
- private String serviceInvariantUUID;
- private List<JsonContainerResourceInstance> resources;
- private List<ArtifactInfoImpl> serviceArtifacts;
- private String workloadContext;
-
- @Override
- public String getDistributionID() {
- return distributionID;
- }
-
- @Override
- public String getServiceName() {
- return serviceName;
- }
-
- @Override
- public String getServiceVersion() {
- return serviceVersion;
- }
-
- @Override
- public String getServiceUUID() {
- return serviceUUID;
- }
-
- public void setDistributionID(String distributionID) {
- this.distributionID = distributionID;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
-
- public void setServiceVersion(String serviceVersion) {
- this.serviceVersion = serviceVersion;
- }
-
- public void setServiceUUID(String serviceUUID) {
- this.serviceUUID = serviceUUID;
- }
-
-
-
- public String getServiceDescription() {
- return serviceDescription;
- }
-
- public void setServiceDescription(String serviceDescription) {
- this.serviceDescription = serviceDescription;
- }
-
- @Override
- public String getWorkloadContext() {
- return workloadContext;
- }
-
- @Override
- public void setWorkloadContext(String workloadContext) {
- this.workloadContext = workloadContext;
- }
-
- @Override
- public String toString() {
- return "NotificationDataImpl [distributionID=" + distributionID + ", serviceName=" + serviceName
- + ", serviceVersion=" + serviceVersion + ", serviceUUID=" + serviceUUID + ", serviceDescription="
- + serviceDescription + ", serviceInvariantUUID=" + serviceInvariantUUID + ", resources=" + resources
- + ", serviceArtifacts=" + serviceArtifacts + ", workloadContext=" + workloadContext + "]";
- }
-
- @Override
- public List<IResourceInstance> getResources() {
- List<IResourceInstance> ret = new ArrayList<IResourceInstance>();
- if( resources != null ){
- ret.addAll(resources);
- }
- return ret;
- }
-
- public void setResources(List<IResourceInstance> resources){
- this.resources = JsonContainerResourceInstance.convertToJsonContainer(resources);
- }
-
- public List<JsonContainerResourceInstance> getResourcesImpl(){
- return resources;
- }
-
- List<ArtifactInfoImpl> getServiceArtifactsImpl(){
- return serviceArtifacts;
- }
-
- @Override
- public List<IArtifactInfo> getServiceArtifacts() {
-
- List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
- if( serviceArtifacts != null ){
- temp.addAll(serviceArtifacts);
- }
- return temp;
- }
-
- void setServiceArtifacts(List<ArtifactInfoImpl> relevantServiceArtifacts) {
- serviceArtifacts = relevantServiceArtifacts;
-
- }
-
- @Override
- public String getServiceInvariantUUID() {
- return serviceInvariantUUID;
- }
-
-
- public void setServiceInvariantUUID(String serviceInvariantUUID) {
- this.serviceInvariantUUID = serviceInvariantUUID;
- }
- @Override
- public IArtifactInfo getArtifactMetadataByUUID(String artifactUUID){
- IArtifactInfo ret = findArtifactInfoByUUID(artifactUUID, serviceArtifacts);
- if( ret == null && resources != null ){
- for( JsonContainerResourceInstance currResourceInstance : resources ){
- ret = findArtifactInfoByUUID(artifactUUID, currResourceInstance.getArtifactsImpl());
- if( ret != null ){
- break;
- }
- }
- }
- return ret;
-
- }
-
- private IArtifactInfo findArtifactInfoByUUID(String artifactUUID, List<ArtifactInfoImpl> listToCheck) {
- IArtifactInfo ret = null;
- if( listToCheck != null ){
- for(IArtifactInfo curr: listToCheck ){
- if(curr.getArtifactUUID().equals(artifactUUID) ){
- ret = curr;
- break;
- }
- }
- }
- return ret;
- }
+ private String distributionID;
+ private String serviceName;
+ private String serviceVersion;
+ private String serviceUUID;
+ private String serviceDescription;
+ private String serviceInvariantUUID;
+ private List<JsonContainerResourceInstance> resources;
+ private List<ArtifactInfoImpl> serviceArtifacts;
+ private String workloadContext;
+
+ @Override
+ public String getDistributionID() {
+ return distributionID;
+ }
+
+ @Override
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ @Override
+ public String getServiceVersion() {
+ return serviceVersion;
+ }
+
+ @Override
+ public String getServiceUUID() {
+ return serviceUUID;
+ }
+
+ public void setDistributionID(String distributionID) {
+ this.distributionID = distributionID;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public void setServiceVersion(String serviceVersion) {
+ this.serviceVersion = serviceVersion;
+ }
+
+ public void setServiceUUID(String serviceUUID) {
+ this.serviceUUID = serviceUUID;
+ }
+
+
+ public String getServiceDescription() {
+ return serviceDescription;
+ }
+
+ public void setServiceDescription(String serviceDescription) {
+ this.serviceDescription = serviceDescription;
+ }
+
+ @Override
+ public String getWorkloadContext() {
+ return workloadContext;
+ }
+
+ @Override
+ public void setWorkloadContext(String workloadContext) {
+ this.workloadContext = workloadContext;
+ }
+
+ @Override
+ public String toString() {
+ return "NotificationDataImpl [distributionID=" + distributionID + ", serviceName=" + serviceName
+ + ", serviceVersion=" + serviceVersion + ", serviceUUID=" + serviceUUID + ", serviceDescription="
+ + serviceDescription + ", serviceInvariantUUID=" + serviceInvariantUUID + ", resources=" + resources
+ + ", serviceArtifacts=" + serviceArtifacts + ", workloadContext=" + workloadContext + "]";
+ }
+
+ @Override
+ public List<IResourceInstance> getResources() {
+ List<IResourceInstance> ret = new ArrayList<IResourceInstance>();
+ if (resources != null) {
+ ret.addAll(resources);
+ }
+ return ret;
+ }
+
+ public void setResources(List<IResourceInstance> resources) {
+ this.resources = JsonContainerResourceInstance.convertToJsonContainer(resources);
+ }
+
+ public List<JsonContainerResourceInstance> getResourcesImpl() {
+ return resources;
+ }
+
+ List<ArtifactInfoImpl> getServiceArtifactsImpl() {
+ return serviceArtifacts;
+ }
+
+ @Override
+ public List<IArtifactInfo> getServiceArtifacts() {
+
+ List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
+ if (serviceArtifacts != null) {
+ temp.addAll(serviceArtifacts);
+ }
+ return temp;
+ }
+
+ void setServiceArtifacts(List<ArtifactInfoImpl> relevantServiceArtifacts) {
+ serviceArtifacts = relevantServiceArtifacts;
+
+ }
+
+ @Override
+ public String getServiceInvariantUUID() {
+ return serviceInvariantUUID;
+ }
+
+
+ public void setServiceInvariantUUID(String serviceInvariantUUID) {
+ this.serviceInvariantUUID = serviceInvariantUUID;
+ }
+
+ @Override
+ public IArtifactInfo getArtifactMetadataByUUID(String artifactUUID) {
+ IArtifactInfo ret = findArtifactInfoByUUID(artifactUUID, serviceArtifacts);
+ if (ret == null && resources != null) {
+ for (JsonContainerResourceInstance currResourceInstance : resources) {
+ ret = findArtifactInfoByUUID(artifactUUID, currResourceInstance.getArtifactsImpl());
+ if (ret != null) {
+ break;
+ }
+ }
+ }
+ return ret;
+
+ }
+
+ private IArtifactInfo findArtifactInfoByUUID(String artifactUUID, List<ArtifactInfoImpl> listToCheck) {
+ IArtifactInfo ret = null;
+ if (listToCheck != null) {
+ for (IArtifactInfo curr : listToCheck) {
+ if (curr.getArtifactUUID().equals(artifactUUID)) {
+ ret = curr;
+ break;
+ }
+ }
+ }
+ return ret;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java
index 49ba428..5951ed0 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java
@@ -7,9 +7,9 @@
* 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.
@@ -31,36 +31,35 @@ import com.google.gson.GsonBuilder;
class StatusConsumer implements Runnable {
- private static Logger log = LoggerFactory.getLogger(StatusConsumer.class.getName());
+ private static Logger log = LoggerFactory.getLogger(StatusConsumer.class.getName());
- private CambriaConsumer cambriaConsumer;
- private IStatusCallback clientCallback;
+ private CambriaConsumer cambriaConsumer;
+ private IStatusCallback clientCallback;
- public StatusConsumer(CambriaConsumer cambriaConsumer, IStatusCallback clientCallback) {
- this.cambriaConsumer = cambriaConsumer;
- this.clientCallback = clientCallback;
- }
+ StatusConsumer(CambriaConsumer cambriaConsumer, IStatusCallback clientCallback) {
+ this.cambriaConsumer = cambriaConsumer;
+ this.clientCallback = clientCallback;
+ }
- @Override
- public void run() {
+ @Override
+ public void run() {
- try {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- for (String statusMsg : cambriaConsumer.fetch()) {
- log.debug("received message from topic");
- log.debug("recieved notification from broker: {}", statusMsg);
- IStatusData statusData = gson.fromJson(statusMsg, StatusDataImpl.class);
- clientCallback.activateCallback(statusData);
-
-
- }
+ try {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ for (String statusMsg : cambriaConsumer.fetch()) {
+ log.debug("received message from topic");
+ log.debug("recieved notification from broker: {}", statusMsg);
+ IStatusData statusData = gson.fromJson(statusMsg, StatusDataImpl.class);
+ clientCallback.activateCallback(statusData);
- } catch (Exception e) {
- log.error("Error exception occured when fetching with Cambria Client:{}", e.getMessage());
- log.debug("Error exception occured when fetching with Cambria Client:{}", e.getMessage(), e);
- }
- }
+ }
+
+ } catch (Exception e) {
+ log.error("Error exception occured when fetching with Cambria Client:{}", e.getMessage());
+ log.debug("Error exception occured when fetching with Cambria Client:{}", e.getMessage(), e);
+ }
+ }
}
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 70513fe..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
@@ -7,9 +7,9 @@
* 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.
@@ -25,71 +25,74 @@ import org.onap.sdc.utils.DistributionStatusEnum;
public class StatusDataImpl implements IStatusData {
- String distributionID;
- String consumerID;
- long timestamp;
- String artifactURL;
- DistributionStatusEnum status;
- String componentName;
- String errorReason;
-
- @Override
- public String getDistributionID() {
- return distributionID;
- }
-
- public void setDistributionID(String distributionId) {
- this.distributionID = distributionId;
- }
- @Override
- public String getConsumerID() {
- return consumerID;
- }
-
- public void setConsumerID(String consumerId) {
- this.consumerID = consumerId;
- }
- @Override
- public Long getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
- @Override
- public String getArtifactURL() {
- return artifactURL;
- }
-
- public void setArtifactURL(String artifactURL) {
- this.artifactURL = artifactURL;
- }
- @Override
- public DistributionStatusEnum getStatus() {
- return status;
- }
-
- public void setStatus(DistributionStatusEnum status) {
- this.status = status;
- }
-
-
- @Override
- public String toString() {
- return "StatusDataImpl [distributionId=" + distributionID + ", consumerId=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status +", errorReason=" + errorReason+ "]";
- }
- @Override
- public String getComponentName() {
- return componentName;
- }
-
- @Override
- public String getErrorReason() {
- return errorReason;
- }
-
-
-
-
+ private String distributionID;
+ private String consumerID;
+ private long timestamp;
+ private String artifactURL;
+ private DistributionStatusEnum status;
+ private String componentName;
+ private String errorReason;
+
+ @Override
+ public String getDistributionID() {
+ return distributionID;
+ }
+
+ public void setDistributionID(String distributionId) {
+ this.distributionID = distributionId;
+ }
+
+ @Override
+ public String getConsumerID() {
+ return consumerID;
+ }
+
+ public void setConsumerID(String consumerId) {
+ this.consumerID = consumerId;
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ @Override
+ public String getArtifactURL() {
+ return artifactURL;
+ }
+
+ public void setArtifactURL(String artifactURL) {
+ this.artifactURL = artifactURL;
+ }
+
+ @Override
+ public DistributionStatusEnum getStatus() {
+ return status;
+ }
+
+ public void setStatus(DistributionStatusEnum status) {
+ this.status = status;
+ }
+
+
+ @Override
+ public String toString() {
+ return "StatusDataImpl [distributionId=" + distributionID + ", consumerId=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status + ", errorReason=" + errorReason + "]";
+ }
+
+ @Override
+ public String getComponentName() {
+ return componentName;
+ }
+
+ @Override
+ public String getErrorReason() {
+ return errorReason;
+ }
+
+
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java
index fb745f3..4d52dd5 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java
@@ -7,9 +7,9 @@
* 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.
@@ -25,37 +25,43 @@ import java.util.List;
import org.onap.sdc.api.notification.IVfModuleMetadata;
final class VfModuleMetadata implements IVfModuleMetadata {
- private VfModuleMetadata(){
- //This Class is only built by parsing Json
- }
-
- private String vfModuleModelName;
- private String vfModuleModelInvariantUUID;
- private String vfModuleModelVersion;
- private String vfModuleModelUUID;
- private String vfModuleModelDescription;
- private boolean isBase;
- private List<String> artifacts;
-
- public String getVfModuleModelName() {
- return vfModuleModelName;
- }
- public String getVfModuleModelInvariantUUID() {
- return vfModuleModelInvariantUUID;
- }
- public String getVfModuleModelVersion() {
- return vfModuleModelVersion;
- }
- public String getVfModuleModelUUID() {
- return vfModuleModelUUID;
- }
- public String getVfModuleModelDescription() {
- return vfModuleModelDescription;
- }
- public boolean isBase() {
- return isBase;
- }
- public List<String> getArtifacts() {
- return artifacts;
- }
+ private VfModuleMetadata() {
+ //This Class is only built by parsing Json
+ }
+
+ private String vfModuleModelName;
+ private String vfModuleModelInvariantUUID;
+ private String vfModuleModelVersion;
+ private String vfModuleModelUUID;
+ private String vfModuleModelDescription;
+ private boolean isBase;
+ private List<String> artifacts;
+
+ public String getVfModuleModelName() {
+ return vfModuleModelName;
+ }
+
+ public String getVfModuleModelInvariantUUID() {
+ return vfModuleModelInvariantUUID;
+ }
+
+ public String getVfModuleModelVersion() {
+ return vfModuleModelVersion;
+ }
+
+ public String getVfModuleModelUUID() {
+ return vfModuleModelUUID;
+ }
+
+ public String getVfModuleModelDescription() {
+ return vfModuleModelDescription;
+ }
+
+ public boolean isBase() {
+ return isBase;
+ }
+
+ public List<String> getArtifacts() {
+ return artifacts;
+ }
}
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
index e0cd56e..5ffb655 100644
--- 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
@@ -7,9 +7,9 @@
* 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.
@@ -22,57 +22,60 @@ package org.onap.sdc.impl.mock;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
-/** Mock Implementation */
+/**
+ * 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 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 getArtifactName() {
+ // TODO Auto-generated method stub
+ return "MackArtifactName";
+ }
- @Override
- public String getArtifactFilename() {
- // 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
index cf0466b..d176608 100644
--- 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
@@ -7,9 +7,9 @@
* 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.
@@ -22,16 +22,19 @@ package org.onap.sdc.impl.mock;
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionActionResultEnum;
-/** Mock Implementation */
+
+/**
+ * Mock Implementation
+ */
public class DistributionClientResultStubImpl implements IDistributionClientResult {
- @Override
- public DistributionActionResultEnum getDistributionActionResult() {
- return DistributionActionResultEnum.SUCCESS;
- }
+ @Override
+ public DistributionActionResultEnum getDistributionActionResult() {
+ return DistributionActionResultEnum.SUCCESS;
+ }
- @Override
- public String getDistributionMessageResult() {
- return "Stub Result, method not implemented!";
- }
+ @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
index 9049215..40e1869 100644
--- 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
@@ -7,9 +7,9 @@
* 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.
@@ -23,105 +23,107 @@ package org.onap.sdc.impl.mock;
import java.util.List;
import org.onap.sdc.api.IDistributionClient;
-import org.onap.sdc.api.consumer.*;
+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;
-import org.onap.sdc.api.consumer.*;
-/** Mock Implementation */
+/**
+ * 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;
- }
-
-
-
-
+
+ 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/ArtifactTypeEnum.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/ArtifactTypeEnum.java
index 8df257e..9e9f7e1 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/ArtifactTypeEnum.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/ArtifactTypeEnum.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,26 +21,26 @@
package org.onap.sdc.utils;
public enum ArtifactTypeEnum {
- HEAT,
- HEAT_VOL,
- HEAT_NET,
- MURANO_PKG,
- HEAT_ENV,
- YANG_XML,
- OTHER,
- VF_LICENSE,
- VENDOR_LICENSE,
- MODEL_INVENTORY_PROFILE,
- MODEL_QUERY_SPEC,
- APPC_CONFIG,
- VNF_CATALOG,
- HEAT_NESTED,
- HEAT_ARTIFACT,
- VF_MODULES_METADATA,
- //DCAE Artifacts
- DCAE_TOSCA, DCAE_JSON, DCAE_POLICY, DCAE_DOC,
- DCAE_EVENT, DCAE_INVENTORY_TOSCA, DCAE_INVENTORY_JSON,
- DCAE_INVENTORY_POLICY, DCAE_INVENTORY_DOC,
- DCAE_INVENTORY_BLUEPRINT, DCAE_INVENTORY_EVENT;
+ HEAT,
+ HEAT_VOL,
+ HEAT_NET,
+ MURANO_PKG,
+ HEAT_ENV,
+ YANG_XML,
+ OTHER,
+ VF_LICENSE,
+ VENDOR_LICENSE,
+ MODEL_INVENTORY_PROFILE,
+ MODEL_QUERY_SPEC,
+ APPC_CONFIG,
+ VNF_CATALOG,
+ HEAT_NESTED,
+ HEAT_ARTIFACT,
+ VF_MODULES_METADATA,
+ //DCAE Artifacts
+ DCAE_TOSCA, DCAE_JSON, DCAE_POLICY, DCAE_DOC,
+ DCAE_EVENT, DCAE_INVENTORY_TOSCA, DCAE_INVENTORY_JSON,
+ DCAE_INVENTORY_POLICY, DCAE_INVENTORY_DOC,
+ DCAE_INVENTORY_BLUEPRINT, DCAE_INVENTORY_EVENT;
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionActionResultEnum.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionActionResultEnum.java
index fe871f8..514630f 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionActionResultEnum.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionActionResultEnum.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,38 +21,38 @@
package org.onap.sdc.utils;
public enum DistributionActionResultEnum {
- SUCCESS,
- FAIL,
- GENERAL_ERROR,
- BAD_REQUEST,
- DISTRIBUTION_CLIENT_NOT_INITIALIZED,
- DISTRIBUTION_CLIENT_IS_TERMINATED,
- DISTRIBUTION_CLIENT_ALREADY_INITIALIZED,
- DISTRIBUTION_CLIENT_ALREADY_STARTED,
-
- DATA_INTEGRITY_PROBLEM,
- ARTIFACT_NOT_FOUND,
-
- CONFIGURATION_IS_MISSING,
- CONF_MISSING_USERNAME,
- CONF_MISSING_PASSWORD,
- CONF_MISSING_ASDC_FQDN,
- CONF_MISSING_ARTIFACT_TYPES,
- CONF_CONTAINS_INVALID_ARTIFACT_TYPES,
- CONF_MISSING_CONSUMER_ID,
- CONF_MISSING_ENVIRONMENT_NAME,
- CONF_MISSING_CONSUMER_GROUP,
- CONF_INVALID_ASDC_FQDN,
- CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG,
- CONF_MISSING_MSG_BUS_ADDRESS,
- CONF_INVALID_MSG_BUS_ADDRESS,
- ASDC_AUTHENTICATION_FAILED,
- ASDC_AUTHORIZATION_FAILED,
- ASDC_NOT_FOUND,
- ASDC_SERVER_PROBLEM,
- ASDC_CONNECTION_FAILED,
- ASDC_SERVER_TIMEOUT,
-
- CAMBRIA_INIT_FAILED,
- UEB_KEYS_CREATION_FAILED
+ SUCCESS,
+ FAIL,
+ GENERAL_ERROR,
+ BAD_REQUEST,
+ DISTRIBUTION_CLIENT_NOT_INITIALIZED,
+ DISTRIBUTION_CLIENT_IS_TERMINATED,
+ DISTRIBUTION_CLIENT_ALREADY_INITIALIZED,
+ DISTRIBUTION_CLIENT_ALREADY_STARTED,
+
+ DATA_INTEGRITY_PROBLEM,
+ ARTIFACT_NOT_FOUND,
+
+ CONFIGURATION_IS_MISSING,
+ CONF_MISSING_USERNAME,
+ CONF_MISSING_PASSWORD,
+ CONF_MISSING_ASDC_FQDN,
+ CONF_MISSING_ARTIFACT_TYPES,
+ CONF_CONTAINS_INVALID_ARTIFACT_TYPES,
+ CONF_MISSING_CONSUMER_ID,
+ CONF_MISSING_ENVIRONMENT_NAME,
+ CONF_MISSING_CONSUMER_GROUP,
+ CONF_INVALID_ASDC_FQDN,
+ CONF_INVALID_CONSUME_PRODUCE_STATUS_TOPIC_FALG,
+ CONF_MISSING_MSG_BUS_ADDRESS,
+ CONF_INVALID_MSG_BUS_ADDRESS,
+ ASDC_AUTHENTICATION_FAILED,
+ ASDC_AUTHORIZATION_FAILED,
+ ASDC_NOT_FOUND,
+ ASDC_SERVER_PROBLEM,
+ ASDC_CONNECTION_FAILED,
+ ASDC_SERVER_TIMEOUT,
+
+ CAMBRIA_INIT_FAILED,
+ UEB_KEYS_CREATION_FAILED
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionClientConstants.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionClientConstants.java
index 58be8dc..8432611 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionClientConstants.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionClientConstants.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,22 +24,25 @@ import java.util.regex.Pattern;
/**
* Constants Used By Distribution Client
- * @author mshitrit
*
+ * @author mshitrit
*/
public final class DistributionClientConstants {
- public static final String CLIENT_DESCRIPTION = "ASDC Distribution Client Key for %s";
- public static final Pattern FQDN_PATTERN = Pattern.compile("^" +
- "([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*(:[0-9]{2,5})*$", Pattern.CASE_INSENSITIVE);
- public static final String EMAIL = "";
- public static final int MIN_POLLING_INTERVAL_SEC = 15;
- public static final int POOL_SIZE = 10;
- public static final int POLLING_TIMEOUT_SEC = 15;
-
- public static final String HEADER_INSTANCE_ID = "X-ECOMP-InstanceID";
- public static final String HEADER_REQUEST_ID = "X-ECOMP-RequestID";
- public static final String APPLICATION_JSON = "application/json";
- public static final String HEADER_CONTENT_TYPE = "Content-Type";
-
- private DistributionClientConstants(){ throw new UnsupportedOperationException();}
+ public static final String CLIENT_DESCRIPTION = "ASDC Distribution Client Key for %s";
+ public static final Pattern FQDN_PATTERN = Pattern.compile(
+ "^"
+ + "([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*(:[0-9]{2,5})*$", Pattern.CASE_INSENSITIVE);
+ public static final String EMAIL = "";
+ public static final int MIN_POLLING_INTERVAL_SEC = 15;
+ public static final int POOL_SIZE = 10;
+ public static final int POLLING_TIMEOUT_SEC = 15;
+
+ public static final String HEADER_INSTANCE_ID = "X-ECOMP-InstanceID";
+ public static final String HEADER_REQUEST_ID = "X-ECOMP-RequestID";
+ public static final String APPLICATION_JSON = "application/json";
+ public static final String HEADER_CONTENT_TYPE = "Content-Type";
+
+ private DistributionClientConstants() {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionStatusEnum.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionStatusEnum.java
index e620195..3e7f061 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionStatusEnum.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/DistributionStatusEnum.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,36 +21,50 @@
package org.onap.sdc.utils;
public enum DistributionStatusEnum {
- /**Can be sent when ONAP component successfully downloaded the specific artifact*/
- DOWNLOAD_OK,
-
- /**Can be sent when ONAP component failed to download the specific artifact (corrupted file)*/
- DOWNLOAD_ERROR,
-
- /**Can be sent only if the repeated distribution notification event is sent when the ONAP component already downloaded the artifact , but still not stored it in the local repository .*/
- ALREADY_DOWNLOADED,
-
- /**Can be sent when ONAP component successfully deployed the specific artifact in the local repository*/
- DEPLOY_OK,
-
- /**Can be sent when ONAP component failed to store the downloaded artifact in the local repository*/
- DEPLOY_ERROR,
-
- /**Sent when the repeated distribution notification event is sent for already stored in the local repository service artifact ( artifact's version and checksum match the one stored in the local repository)*/
- ALREADY_DEPLOYED,
- /**
- * ONAP component is requested to publish this status once component successfully complete downloading and storing all the data it needs from the service.
- */
- COMPONENT_DONE_OK,
-
- /**ONAP component is requested to publish this status when component failed to download or failed to store one or more of the mandatory information it requires from the service model.
-
- It is recommended to populate the errorReason field with appropriate description of the error
-*/
- COMPONENT_DONE_ERROR,
- /** The DISTRIBUTION_COMPLETE_OK/ERROR status indicating the overall ONAP components status of retrieving and storing the information.
-*/
- DISTRIBUTION_COMPLETE_OK,
-
- DISTRIBUTION_COMPLETE_ERROR
+ /**
+ * Can be sent when ONAP component successfully downloaded the specific artifact
+ */
+ DOWNLOAD_OK,
+
+ /**
+ * Can be sent when ONAP component failed to download the specific artifact (corrupted file)
+ */
+ DOWNLOAD_ERROR,
+
+ /**
+ * Can be sent only if the repeated distribution notification event is sent when the ONAP component already downloaded the artifact , but still not stored it in the local repository .
+ */
+ ALREADY_DOWNLOADED,
+
+ /**
+ * Can be sent when ONAP component successfully deployed the specific artifact in the local repository
+ */
+ DEPLOY_OK,
+
+ /**
+ * Can be sent when ONAP component failed to store the downloaded artifact in the local repository
+ */
+ DEPLOY_ERROR,
+
+ /**
+ * Sent when the repeated distribution notification event is sent for already stored in the local repository service artifact ( artifact's version and checksum match the one stored in the local repository)
+ */
+ ALREADY_DEPLOYED,
+ /**
+ * ONAP component is requested to publish this status once component successfully complete downloading and storing all the data it needs from the service.
+ */
+ COMPONENT_DONE_OK,
+
+ /**
+ * ONAP component is requested to publish this status when component failed to download or failed to store one or more of the mandatory information it requires from the service model.
+ * <p>
+ * It is recommended to populate the errorReason field with appropriate description of the error
+ */
+ COMPONENT_DONE_ERROR,
+ /**
+ * The DISTRIBUTION_COMPLETE_OK/ERROR status indicating the overall ONAP components status of retrieving and storing the information.
+ */
+ DISTRIBUTION_COMPLETE_OK,
+
+ DISTRIBUTION_COMPLETE_ERROR
}
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 a69e479..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
@@ -7,9 +7,9 @@
* 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.
@@ -35,58 +35,60 @@ import org.slf4j.LoggerFactory;
import fj.data.Either;
public class GeneralUtils {
- private static final Logger log = LoggerFactory.getLogger(GeneralUtils.class.getName());
- public static String calculateMD5 (String data){
- String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
- // encode base-64 result
- byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes());
- String encodeBase64Str = new String(encodeBase64);
- return encodeBase64Str;
+ private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUtils.class.getName());
+ public static final int STRING_LENGTH_DIVIDER = 4;
- }
-
- public static String calculateMD5(byte[] decodedPayload) {
- String decodedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(decodedPayload);
- byte[] encodeMd5 = Base64.encodeBase64(decodedMd5.getBytes());
- return new String(encodeMd5);
- }
-
- public static boolean isBase64Encoded(String str){
- boolean isEncoded = false;
- try
- {
- // If no exception is caught, then it is possibly a base64 encoded string
- byte[] data = Base64.decodeBase64(str);
- // checks if the string was properly padded to the
- isEncoded= ((str.length() % 4 == 0) && (Pattern.matches("\\A[a-zA-Z0-9/+]+={1,2}\\z", str)));
-
- }
- catch (Exception e)
- {
- // If exception is caught, then it is not a base64 encoded string
- isEncoded= false;
- }
- return isEncoded;
- }
+ private GeneralUtils() {
+ }
- public static Either<List<String>, IDistributionClientResult> convertToValidHostName(List<String> msgBusAddresses) {
- List<String> uebLocalHostsNames = new ArrayList<>();
- for(String name : msgBusAddresses){
- try {
- uebLocalHostsNames.add(InetAddress.getByName(name).getHostName());
- } catch (UnknownHostException e) {
- log.debug("UnknownHost: {}", e.getMessage(), e);
- }
- }
- Either<List<String>, IDistributionClientResult> response;
- if( uebLocalHostsNames.isEmpty() ){
- response = Either.right(new DistributionClientResultImpl(DistributionActionResultEnum.CONF_INVALID_MSG_BUS_ADDRESS, "configuration is invalid: " + DistributionActionResultEnum.CONF_INVALID_MSG_BUS_ADDRESS.name()));
+ public static String calculateMD5(String data) {
+ String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
+ // encode base-64 result
+ byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes());
+ String encodeBase64Str = new String(encodeBase64);
+ return encodeBase64Str;
- }
- else{
- response = Either.left(uebLocalHostsNames);
- }
- return response;
- }
+ }
+
+ public static String calculateMD5(byte[] decodedPayload) {
+ String decodedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(decodedPayload);
+ byte[] encodeMd5 = Base64.encodeBase64(decodedMd5.getBytes());
+ return new String(encodeMd5);
+ }
+
+ public static boolean isBase64Encoded(String str) {
+ boolean isEncoded = false;
+ try {
+ // If no exception is caught, then it is possibly a base64 encoded string
+ 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)));
+
+ } catch (Exception e) {
+ // If exception is caught, then it is not a base64 encoded string
+ isEncoded = false;
+ }
+ return isEncoded;
+ }
+
+
+ public static Either<List<String>, IDistributionClientResult> convertToValidHostName(List<String> msgBusAddresses) {
+ List<String> uebLocalHostsNames = new ArrayList<>();
+ for (String name : msgBusAddresses) {
+ try {
+ uebLocalHostsNames.add(InetAddress.getByName(name).getHostName());
+ } catch (UnknownHostException e) {
+ LOGGER.debug("UnknownHost: {}", e.getMessage(), e);
+ }
+ }
+ Either<List<String>, IDistributionClientResult> response;
+ if (uebLocalHostsNames.isEmpty()) {
+ response = Either.right(new DistributionClientResultImpl(DistributionActionResultEnum.CONF_INVALID_MSG_BUS_ADDRESS, "configuration is invalid: " + DistributionActionResultEnum.CONF_INVALID_MSG_BUS_ADDRESS.name()));
+
+ } else {
+ response = Either.left(uebLocalHostsNames);
+ }
+ return response;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Pair.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Pair.java
index 097cafb..c2a60ba 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Pair.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Pair.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,19 +21,19 @@
package org.onap.sdc.utils;
public final class Pair<F, S> {
- private final F first;
- private final S second;
-
- public Pair(F first, S second){
- this.first = first;
- this.second = second;
- }
+ private final F first;
+ private final S second;
- public F getFirst() {
- return first;
- }
+ public Pair(F first, S second) {
+ this.first = first;
+ this.second = second;
+ }
- public S getSecond() {
- return second;
- }
+ public F getFirst() {
+ return first;
+ }
+
+ public S getSecond() {
+ return second;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Wrapper.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Wrapper.java
index d1d799c..bb02ce3 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Wrapper.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/Wrapper.java
@@ -7,9 +7,9 @@
* 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.
@@ -19,27 +19,33 @@
*/
package org.onap.sdc.utils;
+
/**
* Very Basic Wrapper class.
- * @author mshitrit
- *
+ *
* @param <T>
+ * @author mshitrit
*/
-public class Wrapper<T>{
- private T innerElement;
- public Wrapper(T innerElement){
- this.innerElement = innerElement;
- }
- public Wrapper(){
- this.innerElement = null;
- }
- public T getInnerElement() {
- return innerElement;
- }
- public void setInnerElement(T innerElement) {
- this.innerElement = innerElement;
- }
- public boolean isEmpty(){
- return innerElement == null;
- }
+public class Wrapper<T> {
+ private T innerElement;
+
+ public Wrapper(T innerElement) {
+ this.innerElement = innerElement;
+ }
+
+ public Wrapper() {
+ this.innerElement = null;
+ }
+
+ public T getInnerElement() {
+ return innerElement;
+ }
+
+ public void setInnerElement(T innerElement) {
+ this.innerElement = innerElement;
+ }
+
+ public boolean isEmpty() {
+ return innerElement == null;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/YamlToObjectConverter.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/YamlToObjectConverter.java
index 9c294d2..add82bc 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/YamlToObjectConverter.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/YamlToObjectConverter.java
@@ -7,9 +7,9 @@
* 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.
@@ -39,117 +39,117 @@ import org.yaml.snakeyaml.introspector.PropertyUtils;
public class YamlToObjectConverter {
- private static Logger log = LoggerFactory
- .getLogger(YamlToObjectConverter.class.getName());
+ private static Logger log = LoggerFactory
+ .getLogger(YamlToObjectConverter.class.getName());
- private static HashMap<String, Yaml> yamls = new HashMap<String, Yaml>();
+ private static HashMap<String, Yaml> yamls = new HashMap<String, Yaml>();
- private static Yaml defaultYaml = new Yaml();
+ private static Yaml defaultYaml = new Yaml();
- static {
+ static {
- org.yaml.snakeyaml.constructor.Constructor heatConstructor = new org.yaml.snakeyaml.constructor.Constructor(HeatConfiguration.class);
- TypeDescription heatDescription = new TypeDescription(HeatConfiguration.class);
- //heatDescription.putListPropertyType("parameters", HeatParameterConfiguration.class);
- heatConstructor.addTypeDescription(heatDescription);
- PropertyUtils propertyUtils = new PropertyUtils() {
- @Override
- //This is in order to workaround "default" field in HeatParameterEntry, since default is Java keyword
- public Property getProperty(Class<? extends Object> type, String name, BeanAccess bAccess)
- throws IntrospectionException {
- name = name.substring(0, 1).toLowerCase() + name.substring(1);
- return super.getProperty(type, name, bAccess);
- }
+ org.yaml.snakeyaml.constructor.Constructor heatConstructor = new org.yaml.snakeyaml.constructor.Constructor(HeatConfiguration.class);
+ TypeDescription heatDescription = new TypeDescription(HeatConfiguration.class);
+ //heatDescription.putListPropertyType("parameters", HeatParameterConfiguration.class);
+ heatConstructor.addTypeDescription(heatDescription);
+ PropertyUtils propertyUtils = new PropertyUtils() {
+ @Override
+ //This is in order to workaround "default" field in HeatParameterEntry, since default is Java keyword
+ public Property getProperty(Class<? extends Object> type, String name, BeanAccess bAccess)
+ throws IntrospectionException {
+ name = name.substring(0, 1).toLowerCase() + name.substring(1);
+ return super.getProperty(type, name, bAccess);
+ }
- };
- //Skip properties which are not found - we only are interested in "parameters"
- propertyUtils.setSkipMissingProperties(true);
- heatConstructor.setPropertyUtils(propertyUtils);
+ };
+ //Skip properties which are not found - we only are interested in "parameters"
+ propertyUtils.setSkipMissingProperties(true);
+ heatConstructor.setPropertyUtils(propertyUtils);
- Yaml yaml = new Yaml(heatConstructor);
+ Yaml yaml = new Yaml(heatConstructor);
- yamls.put(HeatConfiguration.class.getName(), yaml);
+ yamls.put(HeatConfiguration.class.getName(), yaml);
- }
+ }
- private static <T> Yaml getYamlByClassName(Class<T> className) {
+ private static <T> Yaml getYamlByClassName(Class<T> className) {
- Yaml yaml = yamls.get(className.getName());
- if (yaml == null) {
- yaml = defaultYaml;
- }
+ Yaml yaml = yamls.get(className.getName());
+ if (yaml == null) {
+ yaml = defaultYaml;
+ }
- return yaml;
- }
+ return yaml;
+ }
- public <T> T convert(String dirPath, Class<T> className,
- String configFileName) {
+ public <T> T convert(String dirPath, Class<T> className,
+ String configFileName) {
- T config = null;
+ T config = null;
- try {
+ try {
- String fullFileName = dirPath + File.separator + configFileName;
+ String fullFileName = dirPath + File.separator + configFileName;
- config = convert(fullFileName, className);
+ config = convert(fullFileName, className);
- } catch (Exception e) {
- log.error("Failed to convert yaml file " + configFileName
- + " to object.", e);
- }
+ } catch (Exception e) {
+ log.error("Failed to convert yaml file " + configFileName
+ + " to object.", e);
+ }
- return config;
- }
+ return config;
+ }
- public <T> T convert(String fullFileName, Class<T> className) {
+ public <T> T convert(String fullFileName, Class<T> className) {
- T config = null;
+ T config = null;
- Yaml yaml = getYamlByClassName(className);
+ Yaml yaml = getYamlByClassName(className);
- InputStream in = null;
- try {
+ InputStream in = null;
+ try {
- File f = new File(fullFileName);
- if (false == f.exists()) {
- log.warn("The file " + fullFileName
- + " cannot be found. Ignore reading configuration.");
- return null;
- }
- in = Files.newInputStream(Paths.get(fullFileName));
+ File f = new File(fullFileName);
+ if (!f.exists()) {
+ log.warn("The file " + fullFileName
+ + " cannot be found. Ignore reading configuration.");
+ return null;
+ }
+ in = Files.newInputStream(Paths.get(fullFileName));
- config = yaml.loadAs(in, className);
+ config = yaml.loadAs(in, className);
- // System.out.println(config.toString());
- } catch (Exception e) {
- log.error("Failed to convert yaml file " + fullFileName
- + " to object.", e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
+ // System.out.println(config.toString());
+ } catch (Exception e) {
+ log.error("Failed to convert yaml file " + fullFileName
+ + " to object.", e);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
- return config;
- }
+ return config;
+ }
- public <T> T convertFromString(String yamlContents, Class<T> className) {
+ public <T> T convertFromString(String yamlContents, Class<T> className) {
- T config = null;
+ T config = null;
- Yaml yaml = getYamlByClassName(className);
+ Yaml yaml = getYamlByClassName(className);
- try {
- config = yaml.loadAs(yamlContents, className);
- } catch (Exception e){
- log.error("Failed to convert YAML {} to object." , yamlContents, e);
- }
+ try {
+ config = yaml.loadAs(yamlContents, className);
+ } catch (Exception e) {
+ log.error("Failed to convert YAML {} to object.", yamlContents, e);
+ }
- return config;
- }
+ return config;
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatConfiguration.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatConfiguration.java
index ee272f4..f9d60d4 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatConfiguration.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatConfiguration.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,20 +23,19 @@ package org.onap.sdc.utils.heat;
import java.util.Map;
public class HeatConfiguration {
-
- //All the rest of heat file is not needed for now...
- Map<String, HeatParameter> parameters;
-
- public Map<String, HeatParameter> getParameters() {
- return parameters;
- }
+ //All the rest of heat file is not needed for now...
+ private Map<String, HeatParameter> parameters;
- public void setParameters(Map<String, HeatParameter> parameters) {
- this.parameters = parameters;
- }
+ public Map<String, HeatParameter> getParameters() {
+ return parameters;
+ }
+
+
+ public void setParameters(Map<String, HeatParameter> parameters) {
+ this.parameters = parameters;
+ }
-
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java
index 3638bcf..731e3e9 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,185 +23,194 @@ package org.onap.sdc.utils.heat;
import java.util.ArrayList;
import java.util.List;
-public class HeatParameter{
-
- String type;
- String label;
- String description;
- //This is in order to workaround "default" field in HeatParameterEntry, since default is Java keyword
- //YAML constructor will lowercase it during parsing
- String Default;
- String hidden = "false";//Default value according to OpenStack spec
- List<HeatParameterConstraint> constraints;
-
-
-
- public String getHidden() {
- return hidden;
- }
- public void setHidden(String hidden) {
- this.hidden = hidden;
- }
-
- public List<HeatParameterConstraint> getConstraints() {
- return constraints;
- }
- public void setConstraints(List<HeatParameterConstraint> constraints) {
- this.constraints = constraints;
- }
- public String getType() {
- return type;
- }
- public void setType(String type) {
- this.type = type;
- }
- public String getLabel() {
- return label;
- }
- public void setLabel(String label) {
- this.label = label;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public String getDefault() {
- return Default;
- }
- public void setDefault(String default1) {
- Default = default1;
- }
-
-
-
- // Getting specific constraints
- /**
- * Get the first "length" constraint from HEAT parameter.
- * No additional "length" constraint is searched for.
- *
- * @return first "length" constraint found for this parameter,
- * or null if no such constraint exists.
- */
- public HeatParameterConstraint getLengthConstraint(){
- HeatParameterConstraint res = null;
- if (constraints != null){
- for (HeatParameterConstraint entry : constraints){
- if (entry.getLength() != null){
- res = entry;
- break;
- }
- }
- }
- return res;
- }
-
-
- /**
- * Get the first "range" constraint from HEAT parameter.
- * No additional "range" constraint is searched for.
- *
- * @return first "range" constraint found for this parameter,
- * or null if no such constraint exists.
- */
- public HeatParameterConstraint getRangeConstraint(){
- HeatParameterConstraint res = null;
- if (constraints != null){
- for (HeatParameterConstraint entry : constraints){
- if (entry.getRange() != null){
- res = entry;
- break;
- }
- }
- }
- return res;
- }
-
- /**
- * Get the first "allowed_values" constraint from HEAT parameter.
- * No additional "allowed_values" constraint is searched for.
- *
- * @return first "allowed_values" constraint found for this parameter,
- * or null if no such constraint exists.
- */
- public HeatParameterConstraint getAllowedValuesConstraint(){
- HeatParameterConstraint res = null;
- if (constraints != null){
- for (HeatParameterConstraint entry : constraints){
- if (entry.getAllowed_values() != null){
- res = entry;
- break;
- }
- }
- }
- return res;
- }
-
- /**
- * Get the "allowed_pattern" constraint list from HEAT parameter.
- *
- * @return "allowed_pattern" constraint list found for this parameter,
- * or null if no such constraint exists.
- */
- public List<HeatParameterConstraint> getAllowedPatternConstraint(){
- List<HeatParameterConstraint> res = null;
- if (constraints != null){
- for (HeatParameterConstraint entry : constraints){
- if (entry.getAllowed_pattern() != null){
- if (res == null){
- res = new ArrayList<>();
- }
- res.add(entry);
- }
- }
- }
- return res;
- }
-
- /**
- * Get the "custom_constraint" constraint list from HEAT parameter.
- *
- * @return "custom_constraint" constraint list found for this parameter,
- * or null if no such constraint exists.
- */
- public List<HeatParameterConstraint> getCustomConstraintConstraint(){
- List<HeatParameterConstraint> res = null;
- if (constraints != null){
- for (HeatParameterConstraint entry : constraints){
- if (entry.getCustom_constraint() != null){
- if (res == null){
- res = new ArrayList<>();
- }
- res.add(entry);
- }
- }
- }
- return res;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- if (type != null){
- sb.append("type:"+type+", ");
- }
- if (label != null){
- sb.append("label:"+label+", ");
- }
- if (Default != null){
- sb.append("default:"+Default+", ");
- }
- if (hidden != null){
- sb.append("hidden:"+hidden+", ");
- }
- if (constraints != null){
- sb.append("constraints:"+constraints+", ");
- }
- if (description != null){
- sb.append("description:"+description);
- }
- return sb.toString();
- }
+public class HeatParameter {
+
+ private String type;
+ private String label;
+ private String description;
+ //This is in order to workaround "default" field in HeatParameterEntry, since default is Java keyword
+ //YAML constructor will lowercase it during parsing
+ private String Default;
+ private String hidden = "false"; //defaultParameters value according to OpenStack spec
+ private List<HeatParameterConstraint> constraints;
+
+
+ public String getHidden() {
+ return hidden;
+ }
+
+ public void setHidden(String hidden) {
+ this.hidden = hidden;
+ }
+
+ public List<HeatParameterConstraint> getConstraints() {
+ return constraints;
+ }
+
+ public void setConstraints(List<HeatParameterConstraint> constraints) {
+ this.constraints = constraints;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDefault() {
+ return Default;
+ }
+
+ public void setDefault(String default1) {
+ Default = default1;
+ }
+
+
+ // Getting specific constraints
+
+ /**
+ * Get the first "length" constraint from HEAT parameter.
+ * No additional "length" constraint is searched for.
+ *
+ * @return first "length" constraint found for this parameter,
+ * or null if no such constraint exists.
+ */
+ public HeatParameterConstraint getLengthConstraint() {
+ HeatParameterConstraint res = null;
+ if (constraints != null) {
+ for (HeatParameterConstraint entry : constraints) {
+ if (entry.getLength() != null) {
+ res = entry;
+ break;
+ }
+ }
+ }
+ return res;
+ }
+
+
+ /**
+ * Get the first "range" constraint from HEAT parameter.
+ * No additional "range" constraint is searched for.
+ *
+ * @return first "range" constraint found for this parameter,
+ * or null if no such constraint exists.
+ */
+ public HeatParameterConstraint getRangeConstraint() {
+ HeatParameterConstraint res = null;
+ if (constraints != null) {
+ for (HeatParameterConstraint entry : constraints) {
+ if (entry.getRange() != null) {
+ res = entry;
+ break;
+ }
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Get the first "allowed_values" constraint from HEAT parameter.
+ * No additional "allowed_values" constraint is searched for.
+ *
+ * @return first "allowed_values" constraint found for this parameter,
+ * or null if no such constraint exists.
+ */
+ public HeatParameterConstraint getAllowedValuesConstraint() {
+ HeatParameterConstraint res = null;
+ if (constraints != null) {
+ for (HeatParameterConstraint entry : constraints) {
+ if (entry.getAllowed_values() != null) {
+ res = entry;
+ break;
+ }
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Get the "allowed_pattern" constraint list from HEAT parameter.
+ *
+ * @return "allowed_pattern" constraint list found for this parameter,
+ * or null if no such constraint exists.
+ */
+ public List<HeatParameterConstraint> getAllowedPatternConstraint() {
+ List<HeatParameterConstraint> res = null;
+ if (constraints != null) {
+ for (HeatParameterConstraint entry : constraints) {
+ if (entry.getAllowed_pattern() != null) {
+ if (res == null) {
+ res = new ArrayList<>();
+ }
+ res.add(entry);
+ }
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Get the "custom_constraint" constraint list from HEAT parameter.
+ *
+ * @return "custom_constraint" constraint list found for this parameter,
+ * or null if no such constraint exists.
+ */
+ public List<HeatParameterConstraint> getCustomConstraintConstraint() {
+ List<HeatParameterConstraint> res = null;
+ if (constraints != null) {
+ for (HeatParameterConstraint entry : constraints) {
+ if (entry.getCustom_constraint() != null) {
+ if (res == null) {
+ res = new ArrayList<>();
+ }
+ res.add(entry);
+ }
+ }
+ }
+ return res;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if (type != null) {
+ sb.append("type:" + type + ", ");
+ }
+ if (label != null) {
+ sb.append("label:" + label + ", ");
+ }
+ if (Default != null) {
+ sb.append("default:" + Default + ", ");
+ }
+ if (hidden != null) {
+ sb.append("hidden:" + hidden + ", ");
+ }
+ if (constraints != null) {
+ sb.append("constraints:" + constraints + ", ");
+ }
+ if (description != null) {
+ sb.append("description:" + description);
+ }
+ return sb.toString();
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameterConstraint.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameterConstraint.java
index d618caf..6d7eb26 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameterConstraint.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameterConstraint.java
@@ -7,9 +7,9 @@
* 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.
@@ -25,69 +25,81 @@ import java.util.Map;
public class HeatParameterConstraint {
- Map<String, String> length;
- Map<String, String> range;
- List<String> allowed_values;
- String allowed_pattern;
- String custom_constraint;
- String description;
-
-
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public Map<String, String> getLength() {
- return length;
- }
- public void setLength(Map<String, String> length) {
- this.length = length;
- }
- public Map<String, String> getRange() {
- return range;
- }
- public void setRange(Map<String, String> range) {
- this.range = range;
- }
- public List<String> getAllowed_values() {
- return allowed_values;
- }
- public void setAllowed_values(List<String> allowed_values) {
- this.allowed_values = allowed_values;
- }
- public String getAllowed_pattern() {
- return allowed_pattern;
- }
- public void setAllowed_pattern(String allowed_pattern) {
- this.allowed_pattern = allowed_pattern;
- }
- public String getCustom_constraint() {
- return custom_constraint;
- }
- public void setCustom_constraint(String custom_constraint) {
- this.custom_constraint = custom_constraint;
- }
-
- @Override
- public String toString() {
- String constraintTypeValue = "<empty>";
- String descriptionStr = "<empty>";
- if (length != null){
- constraintTypeValue = "length:"+length;
- } else if (range != null){
- constraintTypeValue = "range:"+range;
- } else if (allowed_values != null){
- constraintTypeValue = "allowed_values:"+allowed_values;
- } else if (allowed_pattern != null){
- constraintTypeValue = "allowed_pattern:"+allowed_pattern;
- } else if (custom_constraint != null){
- constraintTypeValue = "custom_constraint:"+custom_constraint;
- }
- if (description != null){
- descriptionStr = "description:"+description;
- }
- return new StringBuilder().append(constraintTypeValue).append(", ").append(descriptionStr).toString();
- }
+ private Map<String, String> length;
+ private Map<String, String> range;
+ private List<String> allowed_values;
+ private String allowed_pattern;
+ private String custom_constraint;
+
+ private String description;
+
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Map<String, String> getLength() {
+ return length;
+ }
+
+ public void setLength(Map<String, String> length) {
+ this.length = length;
+ }
+
+ public Map<String, String> getRange() {
+ return range;
+ }
+
+ public void setRange(Map<String, String> range) {
+ this.range = range;
+ }
+
+ public List<String> getAllowed_values() {
+ return allowed_values;
+ }
+
+ public void setAllowed_values(List<String> allowed_values) {
+ this.allowed_values = allowed_values;
+ }
+
+ public String getAllowed_pattern() {
+ return allowed_pattern;
+ }
+
+ public void setAllowed_pattern(String allowed_pattern) {
+ this.allowed_pattern = allowed_pattern;
+ }
+
+ public String getCustom_constraint() {
+ return custom_constraint;
+ }
+
+ public void setCustom_constraint(String custom_constraint) {
+ this.custom_constraint = custom_constraint;
+ }
+
+ @Override
+ public String toString() {
+ String constraintTypeValue = "<empty>";
+ String descriptionStr = "<empty>";
+ if (length != null) {
+ constraintTypeValue = "length:" + length;
+ } else if (range != null) {
+ constraintTypeValue = "range:" + range;
+ } else if (allowed_values != null) {
+ constraintTypeValue = "allowed_values:" + allowed_values;
+ } else if (allowed_pattern != null) {
+ constraintTypeValue = "allowed_pattern:" + allowed_pattern;
+ } else if (custom_constraint != null) {
+ constraintTypeValue = "custom_constraint:" + custom_constraint;
+ }
+ if (description != null) {
+ descriptionStr = "description:" + description;
+ }
+ return new StringBuilder().append(constraintTypeValue).append(", ").append(descriptionStr).toString();
+ }
}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParser.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParser.java
index 340a59d..2dcda92 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParser.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParser.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,49 +27,48 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HeatParser {
-
- private static Logger log = LoggerFactory.getLogger(HeatParser.class.getName());
+ private static Logger log = LoggerFactory.getLogger(HeatParser.class.getName());
- /**
- * Parses and returns the contents of the "parameters" section of YAML-formatted HEAT template.
- *
- * @param heatFileContents - the string contents of HEAT template
- * @return map of parameter name to HeatParameter object.
- * For the following YAML snippet:
- * <b>parameters:
- * image_name_1:
- * type: string
- * label: Image Name
- * description: SCOIMAGE Specify an image name for instance1
- * default: cirros-0.3.1-x86_64
- * </b>
- * the map with one entry will be returned, the key will be "image_name_1".
- * For a HeatParameter object, getConstraints() returns the list of all constraints,
- * regardless of constraint type.
- * For that reason, for each constraint type a sugaring function were added on the HeatParameter type,
- * for example getLengthConstraint(). A correct way to fetch the "length" constraint values map would be
- * parameter.getLengthConstraint().getLength(). Same logic was implemented for all other constraint types.
- *
- * In case of parse error, null will be returned.
- *
- */
- public Map<String, HeatParameter> getHeatParameters(String heatFileContents){
- log.debug("Start of extracting HEAT parameters from file, file contents: {}", heatFileContents);
- Map<String, HeatParameter> heatParameters = null;
- YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
- HeatConfiguration heatConfiguration = yamlToObjectConverter.convertFromString(heatFileContents, HeatConfiguration.class);
- if (heatConfiguration != null){
- heatParameters = heatConfiguration.getParameters();
- } else {
- log.error("Couldn't parse HEAT template.");
- }
- if (heatParameters != null && heatParameters.size() > 0){
- System.out.println("Found HEAT parameters: "+heatParameters.toString());
- log.debug("Found HEAT parameters: {}", heatParameters.toString());
- } else {
- log.warn("HEAT template parameters section wasn't found or is empty.");
- }
- return heatParameters;
- }
+
+ /**
+ * Parses and returns the contents of the "parameters" section of YAML-formatted HEAT template.
+ *
+ * @param heatFileContents - the string contents of HEAT template
+ * @return map of parameter name to HeatParameter object.
+ * For the following YAML snippet:
+ * <b>parameters:
+ * image_name_1:
+ * type: string
+ * label: Image Name
+ * description: SCOIMAGE Specify an image name for instance1
+ * default: cirros-0.3.1-x86_64
+ * </b>
+ * the map with one entry will be returned, the key will be "image_name_1".
+ * For a HeatParameter object, getConstraints() returns the list of all constraints,
+ * regardless of constraint type.
+ * For that reason, for each constraint type a sugaring function were added on the HeatParameter type,
+ * for example getLengthConstraint(). A correct way to fetch the "length" constraint values map would be
+ * parameter.getLengthConstraint().getLength(). Same logic was implemented for all other constraint types.
+ * <p>
+ * In case of parse error, null will be returned.
+ */
+ public Map<String, HeatParameter> getHeatParameters(String heatFileContents) {
+ log.debug("Start of extracting HEAT parameters from file, file contents: {}", heatFileContents);
+ Map<String, HeatParameter> heatParameters = null;
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+ HeatConfiguration heatConfiguration = yamlToObjectConverter.convertFromString(heatFileContents, HeatConfiguration.class);
+ if (heatConfiguration != null) {
+ heatParameters = heatConfiguration.getParameters();
+ } else {
+ log.error("Couldn't parse HEAT template.");
+ }
+ if (heatParameters != null && heatParameters.size() > 0) {
+ System.out.println("Found HEAT parameters: " + heatParameters.toString());
+ log.debug("Found HEAT parameters: {}", heatParameters.toString());
+ } else {
+ log.warn("HEAT template parameters section wasn't found or is empty.");
+ }
+ return heatParameters;
+ }
}