diff options
Diffstat (limited to 'distribution-ci/src/main')
12 files changed, 934 insertions, 0 deletions
diff --git a/distribution-ci/src/main/java/org/openecomp/test/BaseInit.java b/distribution-ci/src/main/java/org/openecomp/test/BaseInit.java new file mode 100644 index 0000000000..b056b35b75 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/BaseInit.java @@ -0,0 +1,122 @@ +package org.openecomp.test; + +//import static org.junit.Assert.assertNotNull; +//import static org.junit.Assert.assertTrue; +// +//import java.io.IOException; +// +//import org.junit.Before; +//import org.junit.rules.TestName; +// +//import org.openecomp.sdc.be.model.User; +//import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +//import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails; +//import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum; +//import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails; +//import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum; +//import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; +////import org.openecomp.sdc.ci.tests.execute.lifecycle.LCSbaseTest; +//import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +//import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails; +//import org.openecomp.sdc.ci.tests.utils.ArtifactUtils; +//import org.openecomp.sdc.ci.tests.utils.DbUtils; +////import org.openecomp.sdc.ci.tests.utils.ResourceUtils; +////import org.openecomp.sdc.ci.tests.utils.ServiceUtils; +//import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +//import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +//import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils; +//import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils; +//import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils; +//import org.openecomp.sdc.common.api.ArtifactTypeEnum; + +public abstract class BaseInit { + + +// protected ResourceReqDetails resourceDetails; +// protected ResourceReqDetails resourceDetails1; +// protected ServiceReqDetails serviceDetails; +// protected ServiceReqDetails serviceDetails2; +// protected ComponentInstanceReqDetails resourceInstanceReqDetails; +// protected ComponentInstanceReqDetails resourceInstanceReqDetails2; +// protected User sdncDesignerDetails1; +// protected User sdncTesterDeatails1; +// protected User sdncAdminDetails1; +// protected ArtifactReqDetails heatArtifactDetails; +// +// protected ArtifactReqDetails defaultArtifactDetails; +// //protected ResourceUtils resourceUtils; +// protected ArtifactUtils artifactUtils; +// +// +// //static ServiceUtils serviceUtils = new ServiceUtils(); +// public BaseInit(TestName testName, String className) { +// super(testName, className); +// } +// @Before +// public void before() throws Exception{ +// +// initializeMembers(); +// +// createComponents(); +// +// } +// public void initializeMembers() throws IOException, Exception { +// +// resourceDetails = ElementFactory.getDefaultResource(); +// resourceDetails1 = ElementFactory.getDefaultResource("secondResource", NormativeTypesEnum.ROOT); +// serviceDetails = ElementFactory.getDefaultService(); +// serviceDetails2 = ElementFactory.getDefaultService("newTestService2", ServiceCategoriesEnum.MOBILITY, "al1976"); +// sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); +// sdncTesterDeatails1 = ElementFactory.getDefaultUser(UserRoleEnum.TESTER); +// sdncAdminDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); +// heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType()); +// resourceInstanceReqDetails = ElementFactory.getDefaultComponentInstance(); +// resourceInstanceReqDetails2 = ElementFactory.getDefaultComponentInstance(); +// +// } +// protected void createComponents() throws Exception{ +// +//// Create resources +// RestResponse response = ResourceRestUtils.createResource(resourceDetails, sdncDesignerDetails1); +// assertTrue("create request returned status:" + response.getErrorCode(),response.getErrorCode() == 201); +// assertNotNull("resource uniqueId is null:", resourceDetails.getUniqueId()); +// +// response = ResourceRestUtils.createResource(resourceDetails1, sdncDesignerDetails1); +// assertTrue("create request returned status:" + response.getErrorCode(),response.getErrorCode() == 201); +// assertNotNull("resource uniqueId is null:", resourceDetails1.getUniqueId()); +// +//// Create services +// response = ServiceRestUtils.createService(serviceDetails, sdncDesignerDetails1); +// assertTrue("create request returned status:" + response.getErrorCode(),response.getErrorCode() == 201); +// assertNotNull("service uniqueId is null:", serviceDetails.getUniqueId()); +// +// response = ServiceRestUtils.createService(serviceDetails2, sdncDesignerDetails1); +// assertTrue("create request returned status:" + response.getErrorCode(),response.getErrorCode() == 201); +// assertNotNull("service uniqueId is null:", serviceDetails2.getUniqueId()); +// +// ArtifactReqDetails heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType()); +// response = ArtifactRestUtils.addInformationalArtifactToResource(heatArtifactDetails, sdncDesignerDetails1, resourceDetails.getUniqueId()); +// assertTrue("add HEAT artifact to resource request returned status:" + response.getErrorCode(),response.getErrorCode() == 200); +// +// ArtifactReqDetails heatArtifactDetails1 = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType()); +// response = ArtifactRestUtils.addInformationalArtifactToResource(heatArtifactDetails1, sdncDesignerDetails1, resourceDetails1.getUniqueId()); +// assertTrue("add HEAT artifact to resource request returned status:" + response.getErrorCode(),response.getErrorCode() == 200); +// +// // certified resources +//// response = LCSbaseTest.certifyResource(resourceDetails); +//// assertTrue("certify resource request returned status:" + response.getErrorCode(),response.getErrorCode() == 200); +//// +//// response = LCSbaseTest.certifyResource(resourceDetails1); +//// assertTrue("certify resource request returned status:" + response.getErrorCode(),response.getErrorCode() == 200); +//// +//// add resource instance with HEAT deployment artifact to the service +// resourceInstanceReqDetails.setUniqueId(resourceDetails.getUniqueId()); +//// response = ServiceUtils.createResourceInstance(resourceInstanceReqDetails, sdncDesignerDetails1, serviceDetails.getUniqueId()); +//// assertTrue("response code is not 200, returned: " + response.getErrorCode(),response.getErrorCode() == 200); +// +// DbUtils.cleanAllAudits(); +// +// +// } + +} diff --git a/distribution-ci/src/main/java/org/openecomp/test/CallableTask.java b/distribution-ci/src/main/java/org/openecomp/test/CallableTask.java new file mode 100644 index 0000000000..814fe9ae46 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/CallableTask.java @@ -0,0 +1,57 @@ +package org.openecomp.test; + +//import java.util.concurrent.Callable; +// +//import org.openecomp.sdc.api.IDistributionClient; +//import org.openecomp.sdc.api.results.IDistributionClientResult; +//import org.openecomp.sdc.impl.DistributionClientFactory; +//import org.openecomp.sdc.be.model.Service; +//import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; + +public class CallableTask { + +// NotificationCallback notifCallback = null; +// //private ServiceUtils serviceUtils; +// private Service service; +// +// //public CallableTask(ServiceUtils serviceUtils, Service service) { +// public CallableTask(Service service) { +// //this.serviceUtils = serviceUtils; +// this.service = service; +// } +// +// public NotificationCallback getNotifCallback() { +// return notifCallback; +// } +// +// @Override +// public Boolean call() throws Exception { +// +// IDistributionClient client = DistributionClientFactory.createDistributionClient(); +// +// notifCallback = new NotificationCallback(client); +// IDistributionClientResult result = client.init(new SimpleConfiguration(), notifCallback); +// +// System.out.println("result.getDistributionMessageResult: " + result.getDistributionMessageResult()); +// +// System.out.println("Starting client..."); +// IDistributionClientResult start = client.start(); +// System.out.println(start.getDistributionMessageResult()); +// +//// RestResponse changeStateToDISTRIBUTED = serviceUtils.changeStateToDISTRIBUTED(service, UserUtils.getGovernorDetails1()); +// ServiceReqDetails serviceDetails = new ServiceReqDetails(); +// serviceDetails.setUniqueId(service.getUniqueId()); +// //RestResponse changeStateToDISTRIBUTED = serviceUtils.changeDistributionStatus(serviceDetails, "1.0", UserUtils.getGovernorDetails1(), "change", DistributionStatusEnum.DISTRIBUTED); +// //assertTrue("response code is not 200, returned :" + changeStateToDISTRIBUTED.getErrorCode(), changeStateToDISTRIBUTED.getErrorCode() == 200); +// +// +//// while (simpleCallback.getSimpleCallbackResults().size()<3){ +// System.err.println("Sleeping..."); +// Thread.sleep(5000); +// System.err.println("Finished Sleeping..."); +//// } +// +// return true; +// } + +} diff --git a/distribution-ci/src/main/java/org/openecomp/test/ClientTest.java b/distribution-ci/src/main/java/org/openecomp/test/ClientTest.java new file mode 100644 index 0000000000..1a10860828 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/ClientTest.java @@ -0,0 +1,33 @@ +package org.openecomp.test; + +import org.slf4j.LoggerFactory; + +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.impl.DistributionClientFactory; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.LoggerContext; + +public class ClientTest { + public static void main(String[] args) throws InterruptedException { + + LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + lc.getLogger("org.apache.http").setLevel(Level.INFO); + + IDistributionClient client = DistributionClientFactory.createDistributionClient(); + + IDistributionClientResult result = client.init(new SimpleConfiguration(), new NotificationCallback(client)); + System.out.println(result.getDistributionMessageResult()); + + System.out.println("Starting client..."); + IDistributionClientResult startResult = client.start(); + + // Thread.sleep(10000); + // client.stop(); + + System.out.println(startResult.getDistributionMessageResult()); + + } + +} diff --git a/distribution-ci/src/main/java/org/openecomp/test/E2eFlows.java b/distribution-ci/src/main/java/org/openecomp/test/E2eFlows.java new file mode 100644 index 0000000000..521fc21312 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/E2eFlows.java @@ -0,0 +1,108 @@ +package org.openecomp.test; + +import org.junit.rules.TestName; + +//import static org.junit.Assert.assertTrue; +// +//import java.util.concurrent.ExecutorService; +//import java.util.concurrent.Executors; +//import java.util.concurrent.Future; +//import java.util.concurrent.TimeUnit; +// +//import org.junit.After; +//import org.junit.Test; +//import org.junit.rules.TestName; +// +//import org.openecomp.sdc.api.IDistributionClient; +//import org.openecomp.sdc.api.notification.IArtifactInfo; +//import org.openecomp.sdc.api.notification.INotificationData; +//import org.openecomp.sdc.api.results.IDistributionClientResult; +//import org.openecomp.sdc.impl.DistributionClientFactory; +//import org.openecomp.sdc.utils.DistributionActionResultEnum; +//import org.openecomp.sdc.be.model.DistributionStatusEnum; +//import org.openecomp.sdc.be.model.Service; +//import org.openecomp.sdc.ci.tests.execute.lifecycle.LCSbaseTest; +//import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +////import org.openecomp.sdc.ci.tests.users.UserUtils; +//import org.openecomp.sdc.ci.tests.utils.DbUtils; +//import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; + +public class E2eFlows { + + + +// private IDistributionClient client = DistributionClientFactory.createDistributionClient(); +// private ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor(); +// +// private CallableTask callableTask; +// private NotificationCallback notifCallback; +// private IArtifactInfo iArtifactInfo; +// + + +// +// @After +// public void after() throws Exception { +// client.stop(); +// Thread.sleep(5000); +// } +// +// // ---------------------------------Success +// // scenario-------------------------------------------------------------------------------- +// +// @Test +// public void distributeService() throws Exception{ +// createServiceReadyForDistribution(); +// //RestResponse changeStateToDISTRIBUTED = serviceUtils.changeDistributionStatus(serviceDetails, "1.0", UserUtils.getGovernorDetails1(), "change", DistributionStatusEnum.DISTRIBUTED); +// //assertTrue("response code is not 200, returned :" + changeStateToDISTRIBUTED.getErrorCode(), changeStateToDISTRIBUTED.getErrorCode() == 200); +// +// } +// @Test +// public void E2E_Success() throws Exception { +// Service service = createServiceReadyForDistribution(); +// +//// clean audit +// DbUtils.cleanAllAudits(); +// +// //Create task to run in BG +// callableTask = new CallableTask(service); +// +// //Run the task in BG +// System.err.println("Executing Task..."); +// Future<Boolean> f = newSingleThreadExecutor.submit(callableTask); +// +// //Wait for task to complete and return with result +// +//// while (!f.isDone()){ +// System.err.println("Waiting for result..."); +// // Thread.sleep(30000); +//// } +// Boolean result = f.get(15, TimeUnit.SECONDS); +// +// System.out.println("future:" + result); +// +// //Check Results +// notifCallback = callableTask.getNotifCallback(); +// +// INotificationData data = notifCallback.getData(); +// +// System.out.println("result map size = "+ notifCallback.getSimpleCallbackResults().size()); +// IDistributionClientResult downloadResult = notifCallback.getSimpleCallbackResults().get("downloadResult"); +// assertTrue("response code is not SUCCESS, returned :"+ downloadResult.getDistributionActionResult(),downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS); +// +// } +// +// +// private Service createServiceReadyForDistribution() throws Exception { +//// RestResponse response = LCSbaseTest.certifyService(serviceDetails); +//// assertTrue("response code is not 200, returned :" + response.getErrorCode(), response.getErrorCode() == 200); +//// Service service = ResponseParser.convertServiceResponseToJavaObject(response.getResponse()); +//// +//// RestResponse changeDistributionStateToApprove = serviceUtils.changeDistributionStateToApprove(service,UserUtils.getGovernorDetails1()); +//// assertTrue("response code is not 200, returned :" + changeDistributionStateToApprove.getErrorCode(), changeDistributionStateToApprove.getErrorCode() == 200); +//// service = ResponseParser.convertServiceResponseToJavaObject(changeDistributionStateToApprove.getResponse()); +//// return service; +// return null; +// } + +} diff --git a/distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java b/distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java new file mode 100644 index 0000000000..247b9a9984 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/NotificationCallback.java @@ -0,0 +1,19 @@ +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/distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java b/distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java new file mode 100644 index 0000000000..a7b2311867 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/SimpleCallback.java @@ -0,0 +1,275 @@ +package org.openecomp.test; + +import static org.junit.Assert.*; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.commons.codec.binary.Base64; + +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; +import org.openecomp.sdc.ci.tests.utils.Decoder; +import org.openecomp.sdc.ci.tests.utils.general.FileUtils; +import com.google.common.io.BaseEncoding; + +public class SimpleCallback implements INotificationCallback { + private IDistributionClient client; + public List<IArtifactInfo> iArtifactInfo; + + public final Map<String, IDistributionClientResult> simpleCallbackResults = new HashMap<String, IDistributionClientResult>(); + + public Map<String, IDistributionClientResult> getSimpleCallbackResults() { + return simpleCallbackResults; + } + + public List<IArtifactInfo> getIArtifactInfo() { + return iArtifactInfo; + } + + public SimpleCallback(IDistributionClient client) { + this.client = client; + } + + public void activateCallback(INotificationData data) { + + List<IArtifactInfo> 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<IVfModuleMetadata> decodeVfModuleArtifact = client.decodeVfModuleArtifact(download.getArtifactPayload()); + // assertEquals("decoded not equal to actual group amount ", decodeVfModuleArtifact.size(), 2); + if (!decodeVfModuleArtifact.isEmpty()) { + for (IVfModuleMetadata moduleMetadata : decodeVfModuleArtifact) { + List<String> 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); + } else { + handleFailedDownload(data, relevantArtifact); + } + } + // if (data != null){ + // iArtifactInfo.addAll(artifacts); + // } + + } + + private List<IArtifactInfo> getArtifacts(INotificationData data) { + List<IArtifactInfo> ret = new ArrayList<IArtifactInfo>(); + List<IResourceInstance> resources = data.getResources(); + // data.getArtifactMetadataByUUID(arg0) + List<String> relevantArtifactTypes = client.getConfiguration().getRelevantArtifactTypes(); + + List<IArtifactInfo> 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<IArtifactInfo> 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) { + // 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(); + 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; + } + + private 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() { + 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/distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java b/distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java new file mode 100644 index 0000000000..7f2ff91906 --- /dev/null +++ b/distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java @@ -0,0 +1,149 @@ +package org.openecomp.test; + +import java.util.List; + +import org.openecomp.sdc.api.consumer.IConfiguration; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; + +public class SimpleConfiguration implements IConfiguration{ + +// public String getUser() +// { +// return System.getProperty("user"); +// } +// +// public List<String> getRelevantArtifactTypes() { +// List<String> res = new ArrayList<String>(); +// for (ArtifactTypeEnum type : ArtifactTypeEnum.values()){ +// res.add(type.name()); +// } +// return res; +// } +// +// 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"; +// } + + + + public String getUser() { + return "ci"; + } + + public List<String> getRelevantArtifactTypes() { + +// List<String> res = new ArrayList<String>(); +// 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-Rom"; + } + + public String getConsumerID() { + return "ys9693-groupVasya"; + } + + public String getConsumerGroup() { +// return "mso-groupTedy"; + return "ys9693-consumerVasya"; + } + + public String getAsdcAddress() { + return "127.0.0.1:8443"; + + } + + @Override + public String getKeyStorePath() { + //return ""; + return "etc/asdc-client.jks"; + } + + @Override + public String getKeyStorePassword() { + + return "Aa123456"; + } + + @Override + public boolean activateServerTLSAuth() { + + return false; + } + +} diff --git a/distribution-ci/src/main/resources/ci/conf/log4j.properties b/distribution-ci/src/main/resources/ci/conf/log4j.properties new file mode 100644 index 0000000000..3e159ec8df --- /dev/null +++ b/distribution-ci/src/main/resources/ci/conf/log4j.properties @@ -0,0 +1,34 @@ +# Define the root logger with appender file +log4j.rootLogger = DEBUG, FILE, stdout + +# Define the file appender +log4j.appender.FILE=org.apache.log4j.RollingFileAppender +log4j.appender.FILE.File=${targetlog}logs/ci-log.out + +# Define the layout for file appender +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p [%10c] : %m%n + +# Set the maximum file size before rollover +log4j.appender.FILE.maxFileSize=5MB + +# Set the the backup index +log4j.appender.FILE.maxBackupIndex=10 + + +############################################################# + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +#log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p %10c:%L - %m%n + +log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG +log4j.logger.com.thinkaurelius.titan.diskstorage.cassandra.CassandraTransaction=INFO, FILE, stdout + +log4j.logger.org.openecomp.sdc.ci.tests.utils=TRACE, FILE, stdout +log4j.additivity.org.openecomp.sdc.ci.tests.utils=false + + diff --git a/distribution-ci/src/main/resources/ci/conf/sdc-packages.yaml b/distribution-ci/src/main/resources/ci/conf/sdc-packages.yaml new file mode 100644 index 0000000000..34a78d9275 --- /dev/null +++ b/distribution-ci/src/main/resources/ci/conf/sdc-packages.yaml @@ -0,0 +1,10 @@ +packages: + - org.openecomp.sdc.ci.tests.execute.general + - org.openecomp.sdc.ci.tests.execute.user + - org.openecomp.sdc.ci.tests.execute.property + - org.openecomp.sdc.ci.tests.execute.lifecycle + - org.openecomp.sdc.ci.tests.execute.resource + - org.openecomp.sdc.ci.tests.execute.service + - org.openecomp.sdc.ci.tests.execute.artifacts + - org.openecomp.sdc.ci.tests.execute.imports + - org.openecomp.sdc.ci.tests.execute.category
\ No newline at end of file diff --git a/distribution-ci/src/main/resources/ci/conf/sdc.yaml b/distribution-ci/src/main/resources/ci/conf/sdc.yaml new file mode 100644 index 0000000000..a9c449e672 --- /dev/null +++ b/distribution-ci/src/main/resources/ci/conf/sdc.yaml @@ -0,0 +1,35 @@ +outputFolder: target +reportName: index.html +catalogBeHost: behost +catalogFeHost: fehost +esHost: eshost +disributionClientHost: disClient +catalogFePort: 8181 +catalogBePort: 8080 +disributionClientPort: 8181 +esPort: 9200 +neoHost: neoHost +neoPort: 7474 +neoDBusername: neo4j +neoDBpassword: 123456 + +resourceConfigDir: src/test/resources/CI/tests +componentsConfigDir: src/test/resources/CI/components +importResourceConfigDir: src/test/resources/CI/importResource +importResourceTestsConfigDir: src/test/resources/CI/importResourceTests +errorConfigurationFile: ../catalog-be/src/main/resources/config/error-configuration.yaml + +titanPropertiesFile: src/main/resources/ci/conf/titan.properties + +stopOnClassFailure: false + +#List of non-abstract resources to keep during titan cleanup between tests +#Only 1.0 version will be kept +resourcesNotToDelete: + - tosca.nodes.Compute + - tosca.nodes.Database + - tosca.nodes.ObjectStorage + - tosca.nodes.BlockStorage + - tosca.nodes.LoadBalancer + - org.openecomp.resource.cp.Port + - org.openecomp.resource.vl.Network
\ No newline at end of file diff --git a/distribution-ci/src/main/resources/ci/conf/titan.properties b/distribution-ci/src/main/resources/ci/conf/titan.properties new file mode 100644 index 0000000000..691f4d6877 --- /dev/null +++ b/distribution-ci/src/main/resources/ci/conf/titan.properties @@ -0,0 +1,5 @@ +storage.backend=cassandra +storage.hostname=cassandrahost +storage.port=9160 + +cache.db-cache = false
\ No newline at end of file diff --git a/distribution-ci/src/main/resources/ci/scripts/startTest.sh b/distribution-ci/src/main/resources/ci/scripts/startTest.sh new file mode 100644 index 0000000000..88659a80b6 --- /dev/null +++ b/distribution-ci/src/main/resources/ci/scripts/startTest.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +function usage { + echo "Usage: $0 <jar file>" +} + +function exitOnError() { + if [ $1 -ne 0 ] + then + echo "Failed running task $2" + exit 2 + fi +} + +if [ $# -lt 1 ] +then + usage + exit 2 +fi + +CURRENT_DIR=`pwd` +BASEDIR=$(dirname $0) + +if [ ${BASEDIR:0:1} = "/" ] +then + FULL_PATH=$BASEDIR +else + FULL_PATH=$CURRENT_DIR/$BASEDIR +fi + +LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j.properties +############################################# +TARGET_DIR=${FULL_PATH}/target +CONF_FILE=${FULL_PATH}/conf/sdc.yaml +DEBUG=true +MainClass=org.openecomp.sdc.ci.tests.run.StartTest + +JAR_FILE=$1 + +#TARGET_DIR=`echo ${TARGET_DIR} | sed 's/\//\//g'` +#echo $TARGET_DIR + +TESTS_DIR=/opt/app/sdc/ci/resources/tests +COMPONENTS_DIR=/opt/app/sdc/ci/resources/components + +#sed -i 's#\(outputFolder:\).*#\1 '${TARGET_DIR}'#g' $CONF_FILE +#sed -i 's#\(resourceConfigDir:\).*#\1 '${TESTS_DIR}'#g' $CONF_FILE +#sed -i 's#\(componentsConfigDir:\).*#\1 '${COMPONENTS_DIR}'#g' $CONF_FILE +TARGET_LOG_DIR="${TARGET_DIR}/" + +mkdir -p ${TARGET_DIR} +if [ -d ${TARGET_DIR} ] +then + rm -rf ${TARGET_DIR}/* + exitOnError $? "Failed_to_delete_target_dir" +fi + +debug_port=8800 +#JAVA_OPTION="-javaagent:/var/tmp/jacoco/lib/jacocoagent.jar=destfile=jacoco-it.exec" +JAVA_OPTION="" +case "$2" in + -debug) echo "Debug mode, Listen on port $debug_port"; JAVA_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug_port}" ;; + "") echo "Standard mode";; + *) echo "USAGE: startTest.sh [-debug]";; +esac + +cmd="java $JAVA_OPTION -DdisplayException=true -Dtargetlog=${TARGET_LOG_DIR} -Dconfig.resource=${CONF_FILE} -Ddebug=${DEBUG} -Dlog4j.configuration=${LOGS_PROP_FILE} -cp $JAR_FILE ${MainClass}" + +#echo $cmd +#console=`$cmd` + +if [ $DEBUG == "true" ] +then + $cmd +else + $cmd >> /dev/null +fi +status=`echo $?` + + + +echo "##################################################" +echo "################# status is ${status} #################" +echo "##################################################" + +exit $status + |