From e8d8a37da95c6fea435e0b3e93a477b5aa45b9b1 Mon Sep 17 00:00:00 2001 From: Yuli Shlosberg Date: Wed, 7 Mar 2018 16:29:57 +0200 Subject: update distribution-client package names Change-Id: Ic6f81bc8fdd3b021033c7c68e44f876a6ee1d21a Issue-ID: SDC-952 Signed-off-by: Yuli Shlosberg --- .../java/org/openecomp/test/AdvanceCallBack.java | 70 ---- .../java/org/openecomp/test/ArtifactTypeEnum.java | 111 ------- .../main/java/org/openecomp/test/ClientTest.java | 113 ------- .../java/org/openecomp/test/CsarToscaTester.java | 121 ------- .../src/main/java/org/openecomp/test/Decoder.java | 58 ---- .../org/openecomp/test/NotificationCallback.java | 39 --- .../java/org/openecomp/test/SimpleCallback.java | 356 --------------------- .../org/openecomp/test/SimpleConfiguration.java | 204 ------------ 8 files changed, 1072 deletions(-) delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/AdvanceCallBack.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/ArtifactTypeEnum.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java delete mode 100644 sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java (limited to 'sdc-distribution-ci/src/main/java/org/openecomp/test') diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/AdvanceCallBack.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/AdvanceCallBack.java deleted file mode 100644 index faabaeb..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/AdvanceCallBack.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============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.openecomp.test; - -import java.io.FileOutputStream; -import java.io.IOException; - -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.utils.DistributionActionResultEnum; - -/** - * - * @author tg851x - * This is class used in testing and run locally in the IDE - * logging not needed it is monitored through the IDE console. - */ -public class AdvanceCallBack extends SimpleCallback{ - - public AdvanceCallBack(IDistributionClient client) { - super(client); - } - - @Override - protected void postDownloadLogic( IDistributionClientDownloadResult downloadResult) { - if( downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS){ - saveArtifactPayloadToDisk(downloadResult); - } - - } - - protected void saveFile(byte[] bs, String fileName) { - String downloadPath = SimpleConfiguration.downloadPath(); - try(FileOutputStream fileOuputStream = new FileOutputStream(downloadPath + fileName);) { - fileOuputStream.write(bs); - fileOuputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - protected void saveArtifactPayloadToDisk(IDistributionClientDownloadResult downloadResult) { - System.out.println("################ Downloaded Artifact Payload Start ################"); - String fileName = downloadResult.getArtifactFilename(); - saveFile(downloadResult.getArtifactPayload(), fileName); - System.out.println("################ Downloaded Artifact Payload End ################"); - } - - - - -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/ArtifactTypeEnum.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/ArtifactTypeEnum.java deleted file mode 100644 index 5c4c9e2..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/ArtifactTypeEnum.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============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.openecomp.test; - -import java.util.ArrayList; -import java.util.List; - -/** - * Enum That Represents possible Artifacts Types. - * - */ -public enum ArtifactTypeEnum { - - CHEF("CHEF"), - PUPPET("PUPPET"), - YANG("YANG"), - SHELL_SCRIPT("SHELL_SCRIPT"), - ICON("ICON"), - UNKNOWN("UNKNOWN"), - HEAT("HEAT"), - DG_XML("DG_XML"), - MURANO_PKG("MURANO_PKG"), - HEAT_ENV("HEAT_ENV"), - YANG_XML("YANG_XML"), - HEAT_VOL("HEAT_VOL"), - HEAT_NET("HEAT_NET"), - OTHER("OTHER"), - WORKFLOW("WORKFLOW"), - NETWORK_CALL_FLOW("NETWORK_CALL_FLOW"), - TOSCA_TEMPLATE("TOSCA_TEMPLATE"), - TOSCA_CSAR("TOSCA_CSAR"), - VNF_CATALOG("VNF_CATALOG"), - VF_LICENSE("VF_LICENSE"), - VENDOR_LICENSE("VENDOR_LICENSE"), - MODEL_INVENTORY_PROFILE("MODEL_INVENTORY_PROFILE"), - MODEL_QUERY_SPEC("MODEL_QUERY_SPEC"), - APPC_CONFIG("APPC_CONFIG"), - HEAT_NESTED("HEAT_NESTED"), - HEAT_ARTIFACT("HEAT_ARTIFACT"), - VF_MODULES_METADATA("VF_MODULES_METADATA"), - - // DCAE Artifacts - DCAE_TOSCA("DCAE_TOSCA"), - DCAE_JSON("DCAE_JSON"), - DCAE_POLICY("DCAE_POLICY"), - DCAE_DOC("DCAE_DOC"), - DCAE_EVENT("DCAE_EVENT"), - DCAE_INVENTORY_TOSCA("DCAE_INVENTORY_TOSCA"), - DCAE_INVENTORY_JSON("DCAE_INVENTORY_JSON"), - DCAE_INVENTORY_POLICY("DCAE_INVENTORY_POLICY"), - DCAE_INVENTORY_DOC("DCAE_INVENTORY_DOC"), - DCAE_INVENTORY_BLUEPRINT("DCAE_INVENTORY_BLUEPRINT"), - DCAE_INVENTORY_EVENT("DCAE_INVENTORY_EVENT"), - - // AAI Artifacts - AAI_SERVICE_MODEL("AAI_SERVICE_MODEL"), - AAI_VF_MODEL("AAI_VF_MODEL"), - AAI_VF_MODULE_MODEL("AAI_VF_MODULE_MODEL"), - AAI_VF_INSTANCE_MODEL("AAI_VF_INSTANCE_MODEL"), - - // MIB artifacts - SNMP_POLL("SNMP_POLL"), - SNMP_TRAP("SNMP_TRAP"), - GUIDE("GUIDE"); - - ArtifactTypeEnum(String type) { - this.type = type; - } - - private String type; - - public String getType() { - return type; - } - - public static ArtifactTypeEnum findType(final String type) { - for (ArtifactTypeEnum ate : ArtifactTypeEnum.values()) { - // According to Pavel/Ella - if (ate.getType().equalsIgnoreCase(type)) { - return ate; - } - } - return null; - } - - public static List getAllTypes() { - List types = new ArrayList<>(); - for (ArtifactTypeEnum ate : ArtifactTypeEnum.values()) { - types.add(ate.getType()); - } - return types; - } -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java deleted file mode 100644 index 872240b..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============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.openecomp.test; - -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IComponentDoneStatusMessage; -import org.openecomp.sdc.api.consumer.IStatusCallback; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IStatusData; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.impl.DistributionClientFactory; -import org.openecomp.sdc.utils.DistributionStatusEnum; - -public class ClientTest { - public static void main(String[] args) throws Exception { - - soWdListner(); - clientSender(); - - } - - private static void clientSender() { - IDistributionClient client = DistributionClientFactory.createDistributionClient(); - IDistributionClientResult result = client.init(new SimpleConfiguration(), new SimpleCallback(client)); - System.err.println("Init Status: " + result.toString()); - - IDistributionClientResult start = client.start(); - - System.err.println("Start Status: " + start.toString()); - for( int i = 0; i < 2; i++ ){ - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - client.sendComponentDoneStatus(new IComponentDoneStatusMessage() { - - @Override - public long getTimestamp() { - return System.currentTimeMillis(); - } - - @Override - public DistributionStatusEnum getStatus() { - return DistributionStatusEnum.COMPONENT_DONE_OK; - } - - @Override - public String getDistributionID() { - // TODO Auto-generated method stub - return ""; - } - - @Override - public String getConsumerID() { - return client.getConfiguration().getConsumerID(); - } - - @Override - public String getComponentName() { - return "MSO"; - } - }); - } - - } - - private static void soWdListner() { - IDistributionClient client = DistributionClientFactory.createDistributionClient(); - IDistributionClientResult result = client.init(new SimpleConfiguration() { - @Override - public boolean isConsumeProduceStatusTopic() { - return true; - } - }, new SimpleCallback(client) { - @Override - public void activateCallback(INotificationData data) { - System.err.println("Monitor Recieved Notification: " + data.toString()); - - } - }, new IStatusCallback() { - - @Override - public void activateCallback(IStatusData data) { - System.err.println("Monitor Recieved Status: " + data.toString()); - - } - }); - System.err.println("Init Status: " + result.toString()); - IDistributionClientResult start = client.start(); - - System.err.println("Start Status: " + start.toString()); - } - -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java deleted file mode 100644 index 98072fa..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.openecomp.test; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.tosca.parser.impl.SdcTypes; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; -import org.openecomp.sdc.toscaparser.api.parameters.Input; -import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; - -public class CsarToscaTester { - public static void main(String[] args) throws Exception { - System.out.println("CsarToscaParser - path to CSAR's Directory is " + Arrays.toString(args)); - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - - File folder = new File(args[0]); - File[] listOfFiles = folder.listFiles(); - Date now = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("d-MM-y-HH_mm_ss"); - String time = dateFormat.format(now); - String csarsDir = args[1] + "/csar-reports-" + time; - File dir = new File(csarsDir); - dir.mkdir(); - - - for (File file : listOfFiles) { - if (file.isFile()) { - System.out.println("File " + file.getAbsolutePath()); - String name = file.getName(); - String currentCsarDir = csarsDir+"/"+name+"-"+time; - dir = new File(currentCsarDir); - dir.mkdir(); - try { - processCsar(factory, file); - } catch (SdcToscaParserException e){ - System.out.println("SdcToscaParserException caught. Code: "+e.getCode()+", message: "+ e.getMessage()); - } - List validationIssueReport = ThreadLocalsHolder.getCollector().getValidationIssueReport(); - System.out.println("Validation issues during CSAR parsing are: " + (validationIssueReport != null ? validationIssueReport.toString() : "none")); - - try { - generateReport(time, name, currentCsarDir, validationIssueReport, "validationIssues"); - - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - } - } - - private static void processCsar(SdcToscaParserFactory factory, File file) throws SdcToscaParserException { - ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file.getAbsolutePath()); - //Service level - System.out.println("Invoking sdc-tosca methods on this CSAR...."); - String conformanceLevel = sdcCsarHelper.getConformanceLevel(); - System.out.println("getConformanceLevel() - conformance level is "+conformanceLevel); - String serviceSubstitutionMappingsTypeName = sdcCsarHelper.getServiceSubstitutionMappingsTypeName(); - System.out.println("serviceSubstitutionMappingsTypeName() - subst mappings type of service is "+serviceSubstitutionMappingsTypeName); - List serviceInputs = sdcCsarHelper.getServiceInputs(); - System.out.println("getServiceInputs() - service inputs are "+serviceInputs); - Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); - System.out.println("getServiceMetadata() - service metadata is "+serviceMetadata); - Map serviceMetadataProperties = sdcCsarHelper.getServiceMetadataProperties(); - System.out.println("getServiceMetadataProperties() - service metadata properties is "+serviceMetadataProperties); - List allottedResources = sdcCsarHelper.getAllottedResources(); - System.out.println("getAllottedResources() - service allotted resources are "+allottedResources); - List serviceVfList = sdcCsarHelper.getServiceVfList(); - System.out.println("getServiceVfList() - VF list is "+serviceVfList); - List serviceNodeTemplateBySdcType = sdcCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF); - System.out.println("getServiceNodeTemplateBySdcType() - VF list is "+serviceNodeTemplateBySdcType); - List serviceNodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); - System.out.println("getServiceNodeTemplates() - all node templates list of service is "+serviceNodeTemplates); - - serviceVfList.forEach(x -> { - String nodeTemplateCustomizationUuid = sdcCsarHelper.getNodeTemplateCustomizationUuid(x); - System.out.println("getNodeTemplateCustomizationUuid() - VF ID is "+nodeTemplateCustomizationUuid); - String typeOfNodeTemplate = sdcCsarHelper.getTypeOfNodeTemplate(x); - System.out.println("getTypeOfNodeTemplate() - VF tosca type is "+typeOfNodeTemplate); - List vfModulesByVf = sdcCsarHelper.getVfModulesByVf(nodeTemplateCustomizationUuid); - System.out.println("getVfModulesByVf() - VF modules list is "+vfModulesByVf); - vfModulesByVf.forEach(y -> { - List membersOfVfModule = sdcCsarHelper.getMembersOfVfModule(x, y); - System.out.println("getMembersOfVfModule() - members of VfModule are "+membersOfVfModule); - }); - List vfcListByVf = sdcCsarHelper.getVfcListByVf(nodeTemplateCustomizationUuid); - System.out.println("getVfcListByVf() - VFC list is "+vfcListByVf); - vfcListByVf.forEach(z -> { - List nodeTemplateBySdcType = sdcCsarHelper.getNodeTemplateBySdcType(z, SdcTypes.CP); - System.out.println("getNodeTemplateBySdcType() - CP children node templates of this VFC are "+nodeTemplateBySdcType); - Map> cpPropertiesFromVfcAsObject = sdcCsarHelper.getCpPropertiesFromVfcAsObject(z); - System.out.println("getCpPropertiesFromVfcAsObject() - consolidated CP properties for this VFC are "+cpPropertiesFromVfcAsObject); - boolean hasTopology = sdcCsarHelper.hasTopology(z); - System.out.println("hasTopology() - this VFC is "+(hasTopology ? "nested" : "not nested")); - }); - }); - - } - - private static void generateReport(String time, String name, String currentCsarDir, List criticalsReport, String type) - throws IOException { - FileWriter fw; - fw = new FileWriter(new File(currentCsarDir + "/" + criticalsReport.size() + "-"+type+"-" + name +"-"+time + ".txt")); - for (String exception : criticalsReport) { - fw.write(exception); - fw.write("\r\n"); - } - fw.close(); - } -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java deleted file mode 100644 index 434952b..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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.openecomp.test; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import org.apache.commons.codec.binary.Base64; - -public class Decoder { - - public static String encode(byte[] byteArrayToEncode) { - return new String(Base64.encodeBase64(byteArrayToEncode)); - } - - public static String decode(String strEncoded) { - return new String(Base64.decodeBase64(strEncoded)); - } - - public static String readFileToString(String file) throws IOException { - - try (FileReader fileReader = new FileReader(file); - BufferedReader reader = new BufferedReader(fileReader)) { - String line; - StringBuilder stringBuilder = new StringBuilder(); - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - - reader.close(); - fileReader.close(); - return stringBuilder.toString(); - } catch (IOException e) { - throw new IOException(e); - } - } -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java deleted file mode 100644 index 3b2d772..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============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.openecomp.test; - -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.INotificationData; - -public class NotificationCallback extends SimpleCallback{ - INotificationData latestCallbackData; - public INotificationData getData() { - return latestCallbackData; - } - public NotificationCallback(IDistributionClient client) { - super(client); - } - - public void activateCallback(INotificationData data) { - this.latestCallbackData = data; - super.activateCallback(data); - } -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java deleted file mode 100644 index 0c03bb0..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java +++ /dev/null @@ -1,356 +0,0 @@ -/*- - * ============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.openecomp.test; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.api.consumer.INotificationCallback; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; -import org.openecomp.sdc.api.notification.IVfModuleMetadata; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.utils.ArtifactTypeEnum; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.openecomp.sdc.utils.DistributionStatusEnum; - -/** - * - * @author tg851x - * This is class used in testing and run locally in the IDE - * logging not needed it is monitored through the IDE console. - */ -public class SimpleCallback implements INotificationCallback { - protected IDistributionClient client; - public List iArtifactInfo; - - public final Map simpleCallbackResults = new HashMap(); - - public Map getSimpleCallbackResults() { - return simpleCallbackResults; - } - - public List getIArtifactInfo(){ - return iArtifactInfo; - } - public SimpleCallback(IDistributionClient client) { - this.client = client; - } - - - - - - public void activateCallback(INotificationData data) { - - List artifacts = getArtifacts(data); - - - for (IArtifactInfo iArtifactInfo : artifacts) { - - IArtifactInfo artifactMetadataByUUID = data.getArtifactMetadataByUUID(iArtifactInfo.getArtifactUUID()); - assertEquals("check artifact checksum", iArtifactInfo.getArtifactChecksum(), artifactMetadataByUUID.getArtifactChecksum()); - System.out.println(artifactMetadataByUUID.getArtifactURL()); - if (artifactMetadataByUUID.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA)){ - IDistributionClientDownloadResult download = client.download(iArtifactInfo); - if (download.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS){ - List decodeVfModuleArtifact = client.decodeVfModuleArtifact(download.getArtifactPayload()); -// assertEquals("decoded not equal to actual group amount ", decodeVfModuleArtifact.size(), 2); - if (!decodeVfModuleArtifact.isEmpty()){ - for (IVfModuleMetadata moduleMetadata : decodeVfModuleArtifact) { - List moduleArtifacts = moduleMetadata.getArtifacts(); - if (moduleArtifacts != null) { - - for (String artifactId : moduleArtifacts) { - - IArtifactInfo artifactInfo = data.getArtifactMetadataByUUID(artifactId); - IDistributionClientDownloadResult downloadArt = client.download(artifactInfo); - assertEquals(downloadArt.getDistributionActionResult(), DistributionActionResultEnum.SUCCESS); - - } - - } - } - } - } - } - } - - - for (IArtifactInfo relevantArtifact : artifacts){ - // Download Artifact - IDistributionClientDownloadResult downloadResult = client.download(relevantArtifact); - - postDownloadLogic(downloadResult); - - - - simpleCallbackResults.put("downloadResult", downloadResult); - System.out.println("downloadResult: " + downloadResult.toString()); - System.out.println("<<<<<<<<<<< Artifact content >>>>>>>>>>"); - System.out.println(Decoder.encode(downloadResult.getArtifactPayload())); - - /////Print artifact content to console/////// - -// byte[] contentInBytes = BaseEncoding.base64().decode(Decoder.encode(downloadResult.getArtifactPayload())); -// try { -// System.out.println("Source content: " + new String(contentInBytes, "UTF-8")); -// } catch (UnsupportedEncodingException e1) { -// // TODO Auto-generated catch block -// e1.printStackTrace(); -// } - System.out.println("ArtInfo_timeout: "+ relevantArtifact.getArtifactTimeout()); - System.out.println("ArtInfo_Art_description: "+ relevantArtifact.getArtifactDescription()); - System.out.println("ArtInfo_Art_CheckSum: "+ relevantArtifact.getArtifactChecksum()); - System.out.println("ArtInfo_Art_Url: "+ relevantArtifact.getArtifactURL()); - System.out.println("ArtInfo_Art_Type: "+ relevantArtifact.getArtifactType()); - System.out.println("ArtInfo_Art_Name: "+ relevantArtifact.getArtifactName()); - System.out.println("ArtInfo_UUID: " + relevantArtifact.getArtifactUUID()); - System.out.println("ArtInfo_Version: " + relevantArtifact.getArtifactVersion()); - System.out.println("ArtInfo_RelatedArtifacts: "+ relevantArtifact.getRelatedArtifacts()); - - System.out.println("ArtInfo_Serv_description: " + data.getServiceDescription()); - System.out.println("ArtInfo_Serv_Name: " + data.getServiceName()); - System.out.println("Get_serviceVersion: " + data.getServiceVersion()); - System.out.println("Get_Service_UUID: " + data.getServiceUUID()); - System.out.println("ArtInfo_DistributionId: " + data.getDistributionID()); - System.out.println("ArtInfo_ServiceInvariantUUID: " + data.getServiceInvariantUUID()); - - - // assertTrue("response code is not 200, returned :" + downloadResult.getDistributionActionResult(), downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS ); - - try { - String payload = new String(downloadResult.getArtifactPayload()); -// System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); -// System.out.println(payload); -// System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); - - } catch (Exception e) { - System.out.println("catch"); -// break; - // TODO: handle exception - } - - - - - if (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { - handleSuccessfullDownload(data, relevantArtifact, downloadResult.getArtifactPayload()); - } else { - handleFailedDownload(data, relevantArtifact); - } - } -// if (data != null){ -// iArtifactInfo.addAll(artifacts); -// } - - } - - private List getArtifacts(INotificationData data) { - List ret = new ArrayList(); - List resources = data.getResources(); -// data.getArtifactMetadataByUUID(arg0) - List relevantArtifactTypes = client.getConfiguration().getRelevantArtifactTypes(); - - List collect = resources.stream().flatMap( e -> e.getArtifacts().stream()).filter(p -> relevantArtifactTypes.contains(p.getArtifactType() )).collect(Collectors.toList()); -// if( resources != null ){ -// for( IResourceInstance resourceInstance : resources){ -// if( resourceInstance.getArtifacts() != null ){ -// -// -// -// ret.addAll(resourceInstance.getArtifacts()); -// -// -// } -// } -// } - ret.addAll(collect); - - List servicesArt = data.getServiceArtifacts(); - if( servicesArt != null ){ - ret.addAll(servicesArt); - } - - System.out.println("I am here: " + ret.toString()); - return ret; - } - - - - private void handleFailedDownload(INotificationData data, - IArtifactInfo relevantArtifact) { - // Send Download Status - IDistributionClientResult sendDownloadStatus = client.sendDownloadStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); - postDownloadStatusSendLogic(sendDownloadStatus); - } - - private void handleSuccessfullDownload(INotificationData data, IArtifactInfo relevantArtifact, byte[] payload) { - // Send Download Status - IDistributionClientResult sendDownloadStatus = client.sendDownloadStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.DOWNLOAD_OK)); - - simpleCallbackResults.put("sendDownloadStatus", sendDownloadStatus); -// assertTrue("response code is not 200, returned :" + sendDownloadStatus.getDistributionActionResult(), sendDownloadStatus.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS ); - - // Doing deployment ... - postDownloadStatusSendLogic(sendDownloadStatus); - boolean isDeployedSuccessfully = handleDeployment(data, relevantArtifact, payload); - IDistributionClientResult deploymentStatus; - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - if (isDeployedSuccessfully) { - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.DEPLOY_OK)); - - simpleCallbackResults.put("sendDeploymentStatus", deploymentStatus); -// assertTrue("response code is not 200, returned :" + deploymentStatus.getDistributionActionResult(), deploymentStatus.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS ); - - } else { - deploymentStatus = handleFailedDeployment(data, relevantArtifact); - } - - postDeploymentStatusSendLogic(deploymentStatus); - } - - private IDistributionClientResult handleFailedDeployment(INotificationData data, IArtifactInfo relevantArtifact) { - IDistributionClientResult deploymentStatus; - boolean isAlreadyDeployed = checkIsDeployed(); - if (isAlreadyDeployed) { - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.ALREADY_DEPLOYED)); - } else { - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.DEPLOY_ERROR)); - } - return deploymentStatus; - } - - protected void postDownloadLogic(IDistributionClientDownloadResult downloadResult) { - // TODO Auto-generated method stub - - } - - private void postDownloadStatusSendLogic( - IDistributionClientResult sendDownloadStatus) { - // TODO Auto-generated method stub - - } - - private void postDeploymentStatusSendLogic( - IDistributionClientResult deploymentStatus) { - // TODO Auto-generated method stub - - } - - private boolean checkIsDeployed() { - return false; - } - - private boolean handleDeployment(INotificationData data, IArtifactInfo relevantArtifact, byte[] payload) { - if (relevantArtifact.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.name())) { - - try { - List serviceArtifacts = data.getServiceArtifacts(); - List resourcesArtifacts = data.getResources(); - - JSONArray jsonData = new JSONArray(new String(payload)); - boolean artifactIsFound = true; - for (int index = 0 ; index < jsonData.length(); index++) { - - JSONObject jsonObject = (JSONObject) jsonData.get(index); - JSONArray artifacts = (JSONArray) jsonObject.get("artifacts"); - for (int i = 0 ; i < artifacts.length(); i++) { - String artifact = artifacts.getString(i).toString(); - - Optional serviceArtifactFound = serviceArtifacts.stream().filter(x -> x.getArtifactUUID().equals(artifact)).findFirst(); - - boolean isResourceFound = false; - for (int j = 0 ; j < resourcesArtifacts.size(); j++) { - Optional resourceArtifactFound = resourcesArtifacts.get(j).getArtifacts().stream().filter(x -> x.getArtifactUUID().equals(artifact)).findFirst(); - isResourceFound = resourceArtifactFound.isPresent() || isResourceFound; - } - - if (!serviceArtifactFound.isPresent() && !isResourceFound) { - artifactIsFound = false; - System.out.println("################ Artifact: " + artifact + " NOT FOUND in Notification Data ################"); - } - } - } - return artifactIsFound; - - } catch (Exception e) { - System.out.println("################ Couldn't convert vf_modules_metadata.json to json : " + e.getMessage()); - return false; - } - } - else { - return true; - } - -// to return deploy_error use return false -// return false; - } - - public static IDistributionStatusMessage buildStatusMessage( - final IDistributionClient client, final INotificationData data, - final IArtifactInfo relevantArtifact, - final DistributionStatusEnum status) { - IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { - - public long getTimestamp() { - long currentTimeMillis = System.currentTimeMillis(); - return currentTimeMillis; - } - - public DistributionStatusEnum getStatus() { - return status; - } - - public String getDistributionID() { - return data.getDistributionID(); - } - - public String getConsumerID() { - return client.getConfiguration().getConsumerID(); - } - - public String getArtifactURL() { - return relevantArtifact.getArtifactURL(); - } - }; - return statusMessage; - } - - -} diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java deleted file mode 100644 index 417f564..0000000 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java +++ /dev/null @@ -1,204 +0,0 @@ -/*- - * ============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.openecomp.test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdc.api.consumer.IConfiguration; - -public class SimpleConfiguration implements IConfiguration{ - - /*public String getUser() - { - return System.getProperty("user"); - } - - public List getRelevantArtifactTypes() { - return ArtifactTypeEnum.getAllTypes(); - } - - public int getPollingTimeout() - { - return 20; - } - - public int getPollingInterval() - { - return 20; - } - - public String getPassword() - { - return System.getProperty("password"); - } - - public String getEnvironmentName() - { - return System.getProperty("env"); - } - - public String getConsumerID() - { - return System.getProperty("consumerID"); - } - - public String getConsumerGroup() - { - return System.getProperty("groupID"); - } - - public String getAsdcAddress() - { - return System.getProperty("beAddress"); - } - - public String getKeyStorePath() - { - return ""; - } - - public String getKeyStorePassword() - { - return "Aa123456"; - } - - public boolean activateServerTLSAuth() - { - return Boolean.parseBoolean(System.getProperty("auth")); -// res.add(ArtifactTypeEnum.HEAT_ARTIFACT); -// res.add(ArtifactTypeEnum.HEAT_ENV); -// res.add(ArtifactTypeEnum.MURANO_PKG); -// res.add(ArtifactTypeEnum.VF_LICENSE); -// res.add(ArtifactTypeEnum.APPC_CONFIG); -// res.add(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE); -// res.add(ArtifactTypeEnum.VNF_CATALOG); -// res.add(ArtifactTypeEnum.APPC_CONFIG); -// res.add(ArtifactTypeEnum.VF_MODULES_METADATA); -// return "PROD-Tedy-Only"; -// return "A-AI"; -// return "A-AI"; - } - - @Override - public boolean isFilterInEmptyResources() { - return false; - } - - public static String downloadPath() { - return "c:\\temp\\"; - } - - public static Boolean toDownload() { - return false; - }*/ - - public String getUser() { - return "ci"; - } - - public List getRelevantArtifactTypes() { - -// List res = new ArrayList(); -// for (ArtifactTypeEnum type : AssetTypeEnum.values()){ -// res.add(type.name()); -// } - return ArtifactTypeEnum.getAllTypes(); - } - - - public int getPollingTimeout() { - return 20; - } - - public int getPollingInterval() { - return 20; - } - - public String getPassword() { - return "123456"; - } - - public String getEnvironmentName() { - return "PROD"; - } - - public String getConsumerID() { - return "consumerVasya"; - } - - public String getConsumerGroup() { - return "groupVasya"; - - } - - public static Boolean toDownload() { - return true; - } - - public static String downloadPath() { - return "c:\\temp\\"; - } - - public String getAsdcAddress() { - return "127.0.0.1:8443"; - } - - @Override - public List getMsgBusAddress() { - return new ArrayList<>(); - } - - @Override - public String getKeyStorePath() { - return StringUtils.EMPTY; - } - - @Override - public String getKeyStorePassword() { - - return "Aa123456"; - } - - @Override - public boolean activateServerTLSAuth() { - - return false; - } - - @Override - public boolean isFilterInEmptyResources() { - return false; - } - - @Override - public Boolean isUseHttpsWithDmaap() { - return true; - } - - @Override - public boolean isConsumeProduceStatusTopic() { - return false; - } - -} -- cgit 1.2.3-korg