aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-distribution-client/src/main/java/org/onap/sdc/impl
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-distribution-client/src/main/java/org/onap/sdc/impl')
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java192
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java225
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java74
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java34
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java779
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java50
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java113
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java148
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java158
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java181
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java179
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java66
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java95
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java61
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java78
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java37
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java127
17 files changed, 2597 insertions, 0 deletions
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
new file mode 100644
index 0000000..6a3da83
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java
@@ -0,0 +1,192 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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;
+ }
+
+}
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
new file mode 100644
index 0000000..a33f911
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java
@@ -0,0 +1,225 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import java.util.List;
+
+import org.onap.sdc.utils.DistributionClientConstants;
+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
+ }
+
+}
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
new file mode 100644
index 0000000..6323113
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+
+public class DistributionClientDownloadResultImpl extends DistributionClientResultImpl implements IDistributionClientDownloadResult {
+ byte[] artifactPayload;
+ String artifactName;
+
+
+ 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("\""));
+ }
+
+}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java
new file mode 100644
index 0000000..96aabc2
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientFactory.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.impl.mock.DistributionClientStubImpl;
+
+public class DistributionClientFactory {
+ 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
new file mode 100644
index 0000000..5d15046
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java
@@ -0,0 +1,779 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import static java.util.Objects.isNull;
+
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.net.MalformedURLException;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+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.notification.IArtifactInfo;
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.http.SdcConnectorClient;
+import org.onap.sdc.http.TopicRegistrationResponse;
+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;
+
+import com.att.nsa.apiClient.credentials.ApiCredential;
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.att.nsa.cambria.client.CambriaClient.CambriaApiException;
+import com.att.nsa.cambria.client.CambriaClientBuilders.AbstractAuthenticatedManagerBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.IdentityManagerBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.att.nsa.cambria.client.CambriaIdentityManager;
+import com.att.nsa.cambria.client.CambriaPublisher.message;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+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);
+ }
+ }
+
+
+
+
+
+
+}
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
new file mode 100644
index 0000000..0df0b7b
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientResultImpl.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+
+public class DistributionClientResultImpl implements IDistributionClientResult {
+
+ DistributionActionResultEnum responseStatus;
+ String responseMessage;
+
+ public DistributionClientResultImpl(DistributionActionResultEnum responseStatus, String responseMessage) {
+ this.responseStatus = responseStatus;
+ this.responseMessage = responseMessage;
+ }
+
+ @Override
+ public DistributionActionResultEnum getDistributionActionResult() {
+ return responseStatus;
+ }
+
+ @Override
+ public String getDistributionMessageResult() {
+ return 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
new file mode 100644
index 0000000..d5bc4ce
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageImpl.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
+import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+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;
+ }
+
+
+
+}
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
new file mode 100644
index 0000000..d8c722d
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionStatusMessageJsonBuilderFactory.java
@@ -0,0 +1,148 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.IDistributionStatusMessageJsonBuilder;
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
+import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.utils.DistributionStatusEnum;
+
+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
+ }
+
+
+
+
+
+}
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
new file mode 100644
index 0000000..92dad7b
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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;
+ }
+}
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
new file mode 100644
index 0000000..aab1e29
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationConsumer.java
@@ -0,0 +1,181 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.sdc.api.notification.IArtifactInfo;
+import org.onap.sdc.api.notification.IResourceInstance;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.onap.sdc.api.consumer.INotificationCallback;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.utils.ArtifactTypeEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.google.gson.Gson;
+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;
+ }
+
+}
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
new file mode 100644
index 0000000..7b7b532
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java
@@ -0,0 +1,179 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.sdc.api.notification.IResourceInstance;
+import org.onap.sdc.api.notification.IArtifactInfo;
+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;
+ }
+}
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
new file mode 100644
index 0000000..49ba428
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusConsumer.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.consumer.IStatusCallback;
+import org.onap.sdc.api.notification.IStatusData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+class StatusConsumer implements Runnable {
+
+ private static Logger log = LoggerFactory.getLogger(StatusConsumer.class.getName());
+
+ private CambriaConsumer cambriaConsumer;
+ private IStatusCallback clientCallback;
+
+ public StatusConsumer(CambriaConsumer cambriaConsumer, IStatusCallback clientCallback) {
+ this.cambriaConsumer = cambriaConsumer;
+ this.clientCallback = clientCallback;
+ }
+
+ @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);
+
+
+ }
+
+ } 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
new file mode 100644
index 0000000..70513fe
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/StatusDataImpl.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import org.onap.sdc.api.notification.IStatusData;
+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;
+ }
+
+
+
+
+}
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
new file mode 100644
index 0000000..fb745f3
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/VfModuleMetadata.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import 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;
+ }
+}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java
new file mode 100644
index 0000000..e0cd56e
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientDownloadResultStubImpl.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl.mock;
+
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+
+/** Mock Implementation */
+public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements IDistributionClientDownloadResult {
+
+ @Override
+ public byte[] getArtifactPayload() {
+ String mockPayload = "heat_template_version: 2013-05-23\r\n" +
+ "\r\n" +
+ "description: >\r\n" +
+ " HOT template that creates one COR network (direct).\r\n" +
+ "\r\n" +
+ "parameters:\r\n" +
+ " cor_direct_net_name:\r\n" +
+ " type: string\r\n" +
+ " description: Name of COR direct network\r\n" +
+ " cor_direct_net_cidr:\r\n" +
+ " type: string\r\n" +
+ " description: Direct network address (CIDR notation)\r\n" +
+ " cor_direct_net_gateway:\r\n" +
+ " type: string\r\n" +
+ " description: Direct network gateway address\r\n" +
+ " cor_direct_net_RT:\r\n" +
+ " type: string\r\n" +
+ " description: Direct network route-target (RT)\r\n" +
+ "\r\n" +
+ "resources:\r\n" +
+ " cor_direct_net:\r\n" +
+ " type: OS::Contrail::VirtualNetwork\r\n" +
+ " properties:\r\n" +
+ " name: { get_param: cor_direct_net_name }\r\n" +
+ " route_targets: [ get_param: cor_direct_net_RT ]\r\n" +
+ "\r\n" +
+ " cor_direct_ip_subnet:\r\n" +
+ " type: OS::Neutron::Subnet\r\n" +
+ " properties:\r\n" +
+ " network_id: { get_resource: cor_direct_net }\r\n" +
+ " cidr: {get_param: cor_direct_net_cidr}\r\n" +
+ " gateway_ip: { get_param: cor_direct_net_gateway }\r\n";
+
+ return mockPayload.getBytes();
+ }
+
+ @Override
+ public String getArtifactName() {
+ // TODO Auto-generated method stub
+ return "MackArtifactName";
+ }
+
+ @Override
+ public String getArtifactFilename() {
+ // TODO Auto-generated method stub
+ return "MackArtifactName";
+ }
+
+}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java
new file mode 100644
index 0000000..cf0466b
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientResultStubImpl.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl.mock;
+
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+/** Mock Implementation */
+public class DistributionClientResultStubImpl implements IDistributionClientResult {
+ @Override
+ public DistributionActionResultEnum getDistributionActionResult() {
+ return DistributionActionResultEnum.SUCCESS;
+ }
+
+ @Override
+ public String getDistributionMessageResult() {
+ return "Stub Result, method not implemented!";
+ }
+
+}
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java
new file mode 100644
index 0000000..9049215
--- /dev/null
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/mock/DistributionClientStubImpl.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl.mock;
+
+import java.util.List;
+
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.consumer.*;
+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 */
+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;
+ }
+
+
+
+
+
+
+}