diff --git a/installer/deployNeoLoadWeb.sh b/installer/deployNeoLoadWeb.sh index 4adc1bf..6d2721a 100644 --- a/installer/deployNeoLoadWeb.sh +++ b/installer/deployNeoLoadWeb.sh @@ -10,7 +10,7 @@ kubectl -n keptn create secret generic neoload --from-literal="NL_WEB_HOST=$NL_W verify_kubectl $? "Creating neoload secret for keptn services failed." # Create dynatrace-service -NL_SERVICE_RELEASE="0.0.4" +NL_SERVICE_RELEASE="0.0.5" print_info "Deploying neoload-service $NL_SERVICE_RELEASE" # to update the link diff --git a/pom.xml b/pom.xml index 45097d7..dbf9c2e 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ 1.8 + 0.1 registry.hub.docker.com/hrexed/keptn_neoload neoload.saas.com neoload-api.saas.com @@ -91,7 +92,12 @@ ${dockerimage} + + ${tag} + latest + + true ${port} diff --git a/src/main/java/com/keptn/neotys/testexecutor/EventSender/NeoLoadEndEvent.java b/src/main/java/com/keptn/neotys/testexecutor/EventSender/NeoLoadEndEvent.java index 610fb19..1ebdeba 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/EventSender/NeoLoadEndEvent.java +++ b/src/main/java/com/keptn/neotys/testexecutor/EventSender/NeoLoadEndEvent.java @@ -8,8 +8,10 @@ import io.cloudevents.CloudEvent; import io.cloudevents.CloudEventBuilder; import io.cloudevents.http.reactivex.vertx.VertxCloudEvents; +import io.vertx.core.VertxOptions; import io.vertx.core.json.JsonObject; import io.vertx.reactivex.core.AbstractVerticle; +import io.vertx.reactivex.core.Vertx; import io.vertx.reactivex.core.http.HttpClientRequest; import java.net.URI; @@ -22,39 +24,67 @@ import static com.keptn.neotys.testexecutor.conf.NeoLoadConfiguration.*; -public class NeoLoadEndEvent extends AbstractVerticle { +public class NeoLoadEndEvent { String eventid; KeptnLogger logger; + Vertx vertx; + private final static String CONTENTYPE="aplicaiton/json"; - public NeoLoadEndEvent(KeptnLogger log,String enventid) { + public NeoLoadEndEvent(KeptnLogger log, String enventid, Vertx rxvertx) { this.eventid=enventid; logger=log; + vertx=rxvertx; } - public void endevent(KeptnEventFinished data,KeptnExtensions extensions) + public void endevent(KeptnEventFinished data, KeptnExtensions extensions, CloudEvent receivedEvent) { - final HttpClientRequest request = vertx.createHttpClient().post(KEPTN_PORT, KEPTN_EVENT_HOST,KEPTN_EVENT_URL); - -// add a client response handler - request.handler(resp -> { - // react on the server response - - }); - -// write the CloudEvent to the given HTTP Post request object - CloudEvent cloudEvent = new CloudEventBuilder() - .type(KEPTN_TEST_FINISHED) - .id(this.eventid) - .source(URI.create(NEOLOAD_SOURCE)) - .time(ZonedDateTime.now(ZoneOffset.UTC)) - .data(data.toJsonObject()) - .extension(extensions) - .build(); - - VertxCloudEvents.create().writeToHttpClientRequest(cloudEvent, request); - request.end(); - logger.info("Request sent " + cloudEvent.getType() +" data "+ cloudEvent.getData().get().toString()); + try { + logger.debug("endevent : Start sending event"); + final HttpClientRequest request = vertx.createHttpClient().post(KEPTN_PORT_EVENT, KEPTN_EVENT_HOST, "/"+KEPTN_EVENT_URL); + + logger.debug("endevent : Defining cloud envet with data:" + data.toJsonObject().toString()); + + logger.debug("endevnet specversion : "+receivedEvent.getSpecVersion()+" : source : "+URI.create(NEOLOAD_SOURCE).toString()+ " id :"+this.eventid); + String id; + if(receivedEvent.getId()==null) + id=extensions.getShkeptncontext(); + else + id=receivedEvent.getId(); + + + String contentype; + if(receivedEvent.getContentType().isPresent()) + contentype=receivedEvent.getContentType().get(); + else + contentype=CONTENTYPE; + + CloudEvent cloudEvent = new CloudEventBuilder() + .type(KEPTN_TEST_FINISHED) + .id(id) + .source(URI.create(NEOLOAD_SOURCE)) + .time(ZonedDateTime.now(ZoneOffset.UTC)) + .data(data.toJsonObject()) + .extension(extensions) + .specVersion(receivedEvent.getSpecVersion()) + .contentType(contentype) + .build(); + + request.handler(resp -> { + logger.info("endevent : received response code "+String.valueOf(resp.statusCode())+ " message "+ resp.statusMessage()); + }); + + + VertxCloudEvents.create().writeToHttpClientRequest(cloudEvent, false,request); + logger.debug("endevent : request write"); + + request.end(); + logger.info("Request sent " + cloudEvent.getType() + " data " + cloudEvent.getData().get().toString()); + } + catch(Exception e) + { + logger.error("end event generate exception",e); + } } diff --git a/src/main/java/com/keptn/neotys/testexecutor/NeoLoadService.java b/src/main/java/com/keptn/neotys/testexecutor/NeoLoadService.java index d8be534..a8d1e69 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/NeoLoadService.java +++ b/src/main/java/com/keptn/neotys/testexecutor/NeoLoadService.java @@ -2,15 +2,20 @@ import com.keptn.neotys.testexecutor.cloudevent.CloudEventNeoload; import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import java.util.concurrent.TimeUnit; -public class NeoLoadService { +public class NeoLoadService { + private static final int MAX=24; public static void main(String[] args) { - Vertx.vertx().deployVerticle(new CloudEventNeoload()); + VertxOptions options=new VertxOptions().setMaxWorkerExecuteTime(MAX).setMaxWorkerExecuteTimeUnit(TimeUnit.HOURS); + + Vertx.vertx(options).deployVerticle(new CloudEventNeoload()); } diff --git a/src/main/java/com/keptn/neotys/testexecutor/cloudevent/CloudEventNeoload.java b/src/main/java/com/keptn/neotys/testexecutor/cloudevent/CloudEventNeoload.java index b6315c1..11729b1 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/cloudevent/CloudEventNeoload.java +++ b/src/main/java/com/keptn/neotys/testexecutor/cloudevent/CloudEventNeoload.java @@ -11,6 +11,7 @@ import io.vertx.reactivex.ext.web.Router; +import java.io.EOFException; import java.util.HashMap; import java.util.Optional; @@ -25,7 +26,7 @@ public class CloudEventNeoload extends AbstractVerticle { private Vertx rxvertx; public void start() { - rxvertx=io.vertx.reactivex.core.Vertx.newInstance(this.getVertx()); + rxvertx= Vertx.newInstance(this.getVertx()); loger=new KeptnLogger(this.getClass().getName()); if(rxvertx ==null) System.out.println("Issues during init"); @@ -78,9 +79,39 @@ public void start() { String keptncontext = keptnExtensions.getShkeptncontext(); loger.setKepncontext(keptncontext); loger.debug("Received data " + eventFinished.toString()); - NeoLoadHandler neoLoadHandler = new NeoLoadHandler(eventFinished, keptnExtensions, receivedEvent.getId()); - neoLoadHandler.runNeoLoadTest(); - req.response().setStatusCode(200).end("test has finished"); + KeptnExtensions finalKeptnExtensions = keptnExtensions; + req.response().setStatusCode(200).putHeader("content-type", "text/plain").end("event received"); + + vertx.executeBlocking( + future -> { + String result; + try { + NeoLoadHandler neoLoadHandler = new NeoLoadHandler(eventFinished, finalKeptnExtensions, receivedEvent.getId()); + + + neoLoadHandler.runNeoLoadTest(rxvertx,receivedEvent); + result="test has finished"; + future.complete(result); + } + catch (Exception e) + { + result="Exception :"+e.getMessage(); + future.fail(result); + } + },res-> + { + if (res.succeeded()) { + + //req.response().setStatusCode(200).putHeader("content-type", "text/plain").end(res.result()); + + } else { + res.cause().printStackTrace(); + } + } + + ); + + } else { diff --git a/src/main/java/com/keptn/neotys/testexecutor/cloudevent/KeptnExtensions.java b/src/main/java/com/keptn/neotys/testexecutor/cloudevent/KeptnExtensions.java index 1a37145..fab20a4 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/cloudevent/KeptnExtensions.java +++ b/src/main/java/com/keptn/neotys/testexecutor/cloudevent/KeptnExtensions.java @@ -7,7 +7,7 @@ public class KeptnExtensions implements Extension { private String shkeptncontext; - private String datacontenttype; + private String contenttype; //Mandatory to let cloud-events lib instatiate class public KeptnExtensions() { @@ -15,7 +15,7 @@ public KeptnExtensions() { public KeptnExtensions(final String shkeptncontext, final String datacontenttype) { this.shkeptncontext = shkeptncontext; - this.datacontenttype = datacontenttype; + this.contenttype = datacontenttype; } public String getShkeptncontext() { return shkeptncontext; @@ -26,11 +26,11 @@ public void setShkeptncontext(String shkeptncontext) { } public String getDatacontenttype() { - return datacontenttype; + return contenttype; } public void setDatacontenttype(String datacontenttype) { - this.datacontenttype = datacontenttype; + this.contenttype = datacontenttype; } @Override @@ -54,7 +54,7 @@ public boolean equals(final Object obj) { public String toString() { return "KeptExtension{" + "shkeptncontext='" + shkeptncontext + '\'' + - ", datacontenttype='" + datacontenttype + '\'' + + ", datacontenttype='" + contenttype + '\'' + '}'; } } diff --git a/src/main/java/com/keptn/neotys/testexecutor/conf/NeoLoadConfiguration.java b/src/main/java/com/keptn/neotys/testexecutor/conf/NeoLoadConfiguration.java index 7df5c97..8e45c74 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/conf/NeoLoadConfiguration.java +++ b/src/main/java/com/keptn/neotys/testexecutor/conf/NeoLoadConfiguration.java @@ -2,12 +2,13 @@ public class NeoLoadConfiguration { public static int PORT = 8080; - + public static final int KUBETIMEOUT=60; public static String HEALTH_PATH="/health"; - public static String NEOLOAD_SOURCE = "NeoLoad"; + public static String NEOLOAD_SOURCE = "neoload-service"; public static String KEPTN_EVENT_HOST = "event-broker.keptn.svc.cluster.local"; public static String KEPTN_EVENT_URL = "keptn"; public static int KEPTN_PORT=8080; + public static int KEPTN_PORT_EVENT=80; public static String GITHUB="https://github.com/"; public static String NEOLOAD_GITFOLDER="Gitfolder"; public static String LOGING_LEVEL_KEY="logging-level"; @@ -25,7 +26,7 @@ public class NeoLoadConfiguration { public static final String SECRET_API_TOKEN="NL_API_TOKEN"; public static final String SECRET_NL_WEB_HOST="NL_WEB_HOST"; public static final String SECRET_NL_API_HOST="NL_API_HOST"; - public static final String SECRET_NL_ZONEID="NL_API_HOST"; + public static final String SECRET_NL_ZONEID="NL_WEB_ZONEID"; public static final String SECRET_NL_UPLOAD_HOST="NL_UPLOAD_HOST"; public static final String NLWEB_PROTOCOL="https://"; diff --git a/src/main/java/com/keptn/neotys/testexecutor/kubernetes/DockerConstants.java b/src/main/java/com/keptn/neotys/testexecutor/kubernetes/DockerConstants.java index 84cd93c..26cd939 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/kubernetes/DockerConstants.java +++ b/src/main/java/com/keptn/neotys/testexecutor/kubernetes/DockerConstants.java @@ -4,9 +4,10 @@ public class DockerConstants { public static final String CONTROLLER="controller"; public static final String LG="LG"; + public static final String LGname="lg"; public static final String NEOLOAD="neoload"; - public static final String NEOLAOD_LG_DOCKER="neotys/neoload-loadgenerator:latest"; - public static final String NEOLAOD_CTL_DOCKER="neotys/neoload-controller:latest"; + public static final String NEOLAOD_LG_DOCKER="neotys/neoload-loadgenerator:6.10"; + public static final String NEOLAOD_CTL_DOCKER="neotys/neoload-controller:6.10"; public static final String ENV_NEOLOADWEB_URL="NEOLOADWEB_URL"; public static final String ENV_NEOLOADWEB_TOKEN="NEOLOADWEB_TOKEN"; public static final String ENV_MODE="MODE"; diff --git a/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesClient.java b/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesClient.java index 8797b65..8150954 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesClient.java +++ b/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesClient.java @@ -2,7 +2,9 @@ import com.keptn.neotys.testexecutor.log.KeptnLogger; +import io.fabric8.kubernetes.api.model.ContainerPort; import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.EnvVarBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; @@ -13,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.TimeUnit; import static com.keptn.neotys.testexecutor.conf.NeoLoadConfiguration.*; import static com.keptn.neotys.testexecutor.kubernetes.DockerConstants.*; @@ -32,7 +35,7 @@ public class NeoLoadKubernetesClient { private String context; private KeptnLogger logger; private static final String DEFAULT_MASTER_URL="https://kubernetes.default.svc"; - + private static final String DEFAULT_API_SAAS="neoload-api.saas.neotys.com"; public NeoLoadKubernetesClient(String masterurl,String kepncontext) { this.masterurl = masterurl; config = new ConfigBuilder().withMasterUrl(masterurl).build(); @@ -131,6 +134,9 @@ public void deployController() .endMetadata() .withNewSpec() .addNewContainer() + .withName(NEOLOAD+context) + .withImagePullPolicy("IfNotPresent") + .withPorts(controllerPort()) .withNewImage(NEOLAOD_CTL_DOCKER) .withEnv(controllerEnv()) .endContainer() @@ -144,15 +150,21 @@ public void deployController() .addToLabels(NEOLOAD+"_"+CONTROLLER,NEOLOAD+context) .endMetadata() .withNewSpec() - .addNewPort().withPort(7400).withNewTargetPort().withIntVal(7400).endTargetPort().endPort() - .addNewPort().withPort(443).withNewTargetPort().withIntVal(443).endTargetPort().endPort() - .addNewPort().withPort(7200).withNewTargetPort().withIntVal(7200).endTargetPort().endPort() - .addNewPort().withPort(4569).withNewTargetPort().withIntVal(4569).endTargetPort().endPort() + .addNewPort().withPort(7400).withName("nlapi").withProtocol("TCP").withNewTargetPort().withIntVal(7400).endTargetPort().endPort() + .addNewPort().withPort(443).withName("nlssl").withProtocol("TCP").withNewTargetPort().withIntVal(443).endTargetPort().endPort() + .addNewPort().withPort(7200).withName("nlmon").withProtocol("TCP").withNewTargetPort().withIntVal(7200).endTargetPort().endPort() + .addNewPort().withPort(4569).withName("nlpoll").withProtocol("TCP").withNewTargetPort().withIntVal(4569).endTargetPort().endPort() .addToSelector(NEOLOAD+"_"+CONTROLLER,NEOLOAD+context) .withType(CLUSTER_IP) .endSpec() .done(); + while(!client.pods().inNamespace(KEPTN_EVENT_URL).withName(NEOLOAD+context).isReady()) + { + logger.debug("deployController - : pods controller not ready "); + Thread.sleep(1000); + } + } catch (Exception e) { @@ -165,17 +177,12 @@ public void deleteLG(String suffix) { this.client = new DefaultKubernetesClient(config); - logger.debug("deleteLG - : delete Servvice with label :"+NEOLOAD+"_"+LG+","+NEOLOAD+context+suffix ); - - client.services().inNamespace(KEPTN_EVENT_URL) - .withName(NEOLOAD+context+suffix) - .delete(); logger.debug("deleteLG - : delete pods with label :"+NEOLOAD+"_"+LG+","+NEOLOAD+context +suffix); client.pods().inNamespace(KEPTN_EVENT_URL) - .withName(NEOLOAD+context+suffix) + .withName(NEOLOAD+LGname+context+suffix) .delete(); @@ -191,33 +198,36 @@ public void deployLG(String suffix) { this.client = new DefaultKubernetesClient(config); - logger.debug("deployLG - : deploying pod with label :"+NEOLOAD+"_"+LG+","+NEOLOAD+context+suffix ); + logger.debug("deployLG - : deploying pod with label :"+NEOLOAD+"_"+LG+","+NEOLOAD+LGname+context+suffix ); client.pods().inNamespace(KEPTN_EVENT_URL).createNew() .withNewMetadata() - .withName(NEOLOAD+context+suffix) - .addToLabels(NEOLOAD+"_"+LG,NEOLOAD+context+suffix) + .withName(NEOLOAD+LGname+context+suffix) + .addToLabels(NEOLOAD+"_"+LG,NEOLOAD+LGname+context+suffix) .endMetadata() .withNewSpec() .addNewContainer() + .withName(NEOLOAD+LGname+context+suffix) .withNewImage(NEOLAOD_LG_DOCKER) - .withEnv(lgenv()) + .withEnv(lgenv(suffix)) + .withImagePullPolicy("IfNotPresent") + .withPorts(lgPort()) .endContainer() + .withHostname(NEOLOAD+LGname+context+suffix) + .withHostNetwork(true) + .withDnsPolicy("ClusterFirstWithHostNet") .endSpec() .done(); - logger.debug("deployLG - : deploying service with label :"+NEOLOAD+"_"+LG+","+NEOLOAD+context +suffix); - client.services().inNamespace(KEPTN_EVENT_URL).createNew() - .withNewMetadata() - .withName(NEOLOAD+context+suffix) - .addToLabels(NEOLOAD+"_"+LG,NEOLOAD+context+suffix) - .endMetadata() - .withNewSpec() - .addNewPort().withPort(7100).withNewTargetPort().withIntVal(7100).endTargetPort().endPort() - .addToSelector(NEOLOAD+"_"+LG,NEOLOAD+context+suffix) - .withType(CLUSTER_IP) - .endSpec() - .done(); + while(!client.pods().inNamespace(KEPTN_EVENT_URL).withName(NEOLOAD+LGname+context+suffix).isReady()) + { + logger.debug("deployLG - : pod LG not ready :"); + Thread.sleep(1000); + } + + logger.debug(client.pods().inNamespace(KEPTN_EVENT_URL).withName(NEOLOAD+LGname+context+suffix).get().getStatus().getPodIP()); + + } catch (Exception e) @@ -226,10 +236,52 @@ public void deployLG(String suffix) } } - public void deleteService(String servicename) + + + private List lgPort() { - //----#TODO delete the LG Services or Controller + List containerPorts=new ArrayList<>(); + ContainerPort port=new ContainerPort(); + port.setContainerPort(7100); + port.setHostPort(7100); + port.setProtocol("TCP"); + port.setName("nllg"); + containerPorts.add(port); + return containerPorts; + } + private List controllerPort() + { + List containerPorts=new ArrayList<>(); + ContainerPort port=new ContainerPort(); + port.setContainerPort(7400); + port.setHostPort(7400); + port.setProtocol("TCP"); + port.setName("nlapi"); + + containerPorts.add(port); + ContainerPort mon=new ContainerPort(); + mon.setContainerPort(7200); + mon.setHostPort(7200); + mon.setProtocol("TCP"); + mon.setName("nlmon"); + containerPorts.add(mon); + + + ContainerPort ssl=new ContainerPort(); + ssl.setContainerPort(443); + ssl.setHostPort(443); + ssl.setProtocol("TCP"); + ssl.setName("nlssl"); + containerPorts.add(ssl); + + ContainerPort poll=new ContainerPort(); + poll.setContainerPort(4569); + poll.setHostPort(4569); + poll.setProtocol("TCP"); + poll.setName("nlpoll"); + containerPorts.add(poll); + return containerPorts; } private List controllerEnv() @@ -239,33 +291,48 @@ private List controllerEnv() createEnvList(list); list.add(new EnvVar(ENV_MODE,ENV_MANAGED,null)); list.add(new EnvVar(ENV_LEASE_SERVER,LEASE_SERVER,null)); + + logger.debug("controllerenv : "+list.toString()); return list; } - private List lgenv() + private List lgenv(String suffix) { List list=new ArrayList<>(); createEnvList(list); list.add(new EnvVar(ENV_MODE,ENV_MANAGED,null)); - list.add(new EnvVar(ENV_LG_HOST,generateServiceName(LG),null)); - list.add(new EnvVar(ENV_LG_PORT,LG_PORT,null)); + // list.add(new EnvVar(ENV_LG_HOST,generateServiceName(LGname,suffix),null)); + EnvVar env=new EnvVarBuilder() + .withName(ENV_LG_HOST) + .withNewValueFrom() + .withNewFieldRef() + .withFieldPath("status.podIP") + .endFieldRef() + .endValueFrom() + .build(); + list.add(env); + list.add(new EnvVar(ENV_LG_PORT,LG_PORT,null)); + + logger.debug("lgenv : "+list.toString()); + return list; } - private String generateServiceName(String type) + private String generateServiceName(String type,String suffix) { - return NEOLOAD+"-"+type+"-"+context+"."+KEPTN_EVENT_URL+".svc"; + return NEOLOAD+type+context+suffix+"."+KEPTN_EVENT_URL+".svc.cluster.local"; } private void createEnvList(final List list ) { - if(neoloadweb_url.isPresent()) - list.add(new EnvVar(ENV_NEOLOADWEB_URL,neoloadweb_url.get(),null)); - + if(neoloadweb_apiurl.isPresent()) { + if(!neoloadweb_apiurl.get().equalsIgnoreCase(DEFAULT_API_SAAS)) + list.add(new EnvVar(ENV_NEOLOADWEB_URL, "https://" + neoloadweb_apiurl.get() + "/v1", null)); + } list.add(new EnvVar(ENV_NEOLOADWEB_TOKEN,neoloadAPitoken,null)); if(neoloadZoneid.isPresent()) diff --git a/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesWather.java b/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesWather.java new file mode 100644 index 0000000..ed0c01e --- /dev/null +++ b/src/main/java/com/keptn/neotys/testexecutor/kubernetes/NeoLoadKubernetesWather.java @@ -0,0 +1,25 @@ +package com.keptn.neotys.testexecutor.kubernetes; + +import com.keptn.neotys.testexecutor.log.KeptnLogger; +import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.Watcher; + +public class NeoLoadKubernetesWather implements Watcher { + KeptnLogger logger; + + public NeoLoadKubernetesWather(KeptnLogger logger) { + this.logger = logger; + } + + @Override + public void eventReceived(Action action, Object o) { + logger.debug(action.name() +" " + o.toString()); + } + + @Override + public void onClose(KubernetesClientException e) { + if (e != null) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLogger.java b/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLogger.java index 76d34b2..84c92ef 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLogger.java +++ b/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLogger.java @@ -19,11 +19,11 @@ public class KeptnLogger { private String kepncontext; private Logger loger; private ConsoleHandler handler; - private static final String INFO="INFO"; - private static final String WARN="WARN"; - private static final String ERROR="ERROR"; - private static final String TRACE="TRACE"; - private static final String DEBUG="DEBUG"; + public static final String INFO="INFO"; + public static final String WARN="WARN"; + public static final String ERROR="ERROR"; + public static final String TRACE="TRACE"; + public static final String DEBUG="DEBUG"; String messageFormat="{\n" + " \"keptnContext\": \"%s\",\n" + @@ -94,7 +94,8 @@ public void error(String s) { loger.log(Level.SEVERE,s); } public void error(String s,Throwable throwable) { - loger.log(Level.SEVERE,s,throwable); + loger.log(Level.SEVERE,s +" exception : "+ throwable.getMessage(),throwable); + throwable.printStackTrace(); } public void info(String s) { @@ -106,8 +107,6 @@ public void warn(String s) { } - - public void debug(String s) { loger.log(Level.FINE,s); } diff --git a/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLoggerFormater.java b/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLoggerFormater.java index 40f4156..25f5e6d 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLoggerFormater.java +++ b/src/main/java/com/keptn/neotys/testexecutor/log/KeptnLoggerFormater.java @@ -1,20 +1,28 @@ package com.keptn.neotys.testexecutor.log; import java.util.logging.Formatter; +import java.util.logging.Level; import java.util.logging.LogRecord; import static com.keptn.neotys.testexecutor.conf.NeoLoadConfiguration.NEOLOAD_SOURCE; +import static com.keptn.neotys.testexecutor.log.KeptnLogger.*; + public class KeptnLoggerFormater extends Formatter { String keptnContext; + private static final String SEVERE="SEVERE"; + private static final String FINE="FINE"; + + private static final String FINEST="FINEST"; + private static final String WARNING="WARNING"; - String messageFormat="{\n" + - " \"keptnContext\": \"%s\",\n" + - " \"logLevel\": \"%s\",\n" + - " \"keptnService\": \""+NEOLOAD_SOURCE+"\",\n" + - " \"message\": \"%s\"\n" + - "}"; + String messageFormat="{" + + " \"keptnContext\": \"%s\"," + + " \"logLevel\": \"%s\"," + + " \"keptnService\": \""+NEOLOAD_SOURCE+"\"," + + " \"message\": \"%s\"" + + "}\n"; public KeptnLoggerFormater(String keptnContext) { this.keptnContext = keptnContext; @@ -22,6 +30,27 @@ public KeptnLoggerFormater(String keptnContext) { @Override public String format(LogRecord record) { - return String.format(messageFormat,keptnContext,record.getLevel().getName(), record.getMillis() +" :" + record.getSourceClassName() +" - " +record.getSourceMethodName() + " - "+ record.getMessage()); + String level; + switch (record.getLevel().getName()) + { + case INFO: + level=INFO; + break; + case SEVERE: + level=ERROR; + break; + case FINE: + level= DEBUG; + break; + case FINEST: + level= TRACE; + break; + case WARNING: + level= WARNING; + break; + default: level= ERROR; + break; + } + return String.format(messageFormat,keptnContext,level, record.getMillis() +" :" + record.getSourceClassName() +" - " +record.getSourceMethodName() + " - "+ record.getMessage()); } } diff --git a/src/main/java/com/keptn/neotys/testexecutor/messageHandler/NeoLoadHandler.java b/src/main/java/com/keptn/neotys/testexecutor/messageHandler/NeoLoadHandler.java index c8d3d6f..29d20a4 100644 --- a/src/main/java/com/keptn/neotys/testexecutor/messageHandler/NeoLoadHandler.java +++ b/src/main/java/com/keptn/neotys/testexecutor/messageHandler/NeoLoadHandler.java @@ -15,6 +15,8 @@ import com.neotys.ascode.swagger.client.api.RuntimeApi; import com.neotys.ascode.swagger.client.model.ProjectDefinition; import com.neotys.ascode.swagger.client.model.RunTestDefinition; +import io.cloudevents.CloudEvent; +import io.vertx.reactivex.core.Vertx; import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; @@ -211,7 +213,11 @@ private NeoLoadWebTest RunTest(File zipfile, NeoLoadTest test, Optional } private void deleteGitFolder() throws IOException { + logger.debug("deleteGitFolder - delete gitfolder "+gitfolder.toAbsolutePath().toString()); boolean delete=deleteDirectory(new File(gitfolder.toAbsolutePath().toString())); + if(delete) + logger.info("deleteGitFolder - deleted gitfolder "+gitfolder.toAbsolutePath().toString()); + } @@ -225,7 +231,7 @@ boolean deleteDirectory(File directoryToBeDeleted) { } return directoryToBeDeleted.delete(); } - private void runNLScenario(NeoLoadTest test) + private void runNLScenario(NeoLoadTest test, Vertx rxvertx, CloudEvent receivedEvent) { final NeoLoadKubernetesClient neoLoadKubernetesClient=new NeoLoadKubernetesClient(keptncontext); List machinelist = null; @@ -242,15 +248,18 @@ private void runNLScenario(NeoLoadTest test) }); + List projectspath=test.getProject().stream().map(project -> project.getPath()).collect(Collectors.toList()); String zipfilepath=createZipFile(projectspath, keptnEventFinished.getProject(),Optional.ofNullable(test.getConstant_variables())); + Thread.sleep(20000); + NeoLoadWebTest loadWebTest=RunTest(new File(zipfilepath),test,neoLoadKubernetesClient.getNeoloadweb_apiurl(),Optional.ofNullable(neoLoadKubernetesClient.getNeoloadAPitoken()),neoLoadKubernetesClient.getNeoloadweb_url(),neoLoadKubernetesClient.getNeoloadweb_uploadurl(),neoLoadKubernetesClient.getNeoloadZoneid(),machinelist.size()); keptnEventFinished.setTestid(loadWebTest.getTestid()); keptnEventFinished.setNeoloadURL(loadWebTest.getTesturl()); ///--- - NeoLoadEndEvent endEvent=new NeoLoadEndEvent(logger,eventid); - endEvent.endevent(keptnEventFinished,extensions); + NeoLoadEndEvent endEvent=new NeoLoadEndEvent(logger,eventid,rxvertx); + endEvent.endevent(keptnEventFinished,extensions,receivedEvent); //--send end event------------- } @@ -264,18 +273,24 @@ private void runNLScenario(NeoLoadTest test) logger.error("runNLScenario exepption ",e); } catch (IOException e) { logger.error("runNLScenario exepption ",e); - } catch (ApiException e) { + } catch (ApiException | InterruptedException e) { logger.error("RUnNLScenario , api exception",e); } finally { if(neoLoadKubernetesClient!=null) { - //delete infra - if(machinelist!=null) { - machinelist.stream().forEach(machine->{ - neoLoadKubernetesClient.deleteLG(machine); - }); + try { + //delete infra + if (machinelist != null) { + machinelist.stream().forEach(machine -> { + neoLoadKubernetesClient.deleteLG(machine); + }); + } + neoLoadKubernetesClient.deleteController(); + } + catch (Exception e) + { + logger.error("Unable to delete services ",e); } - neoLoadKubernetesClient.deleteController(); } try { deletetempfolder(); @@ -285,14 +300,16 @@ private void runNLScenario(NeoLoadTest test) } } - public void runNeoLoadTest() throws NeoLoadJgitExeption, NeoLoadSerialException, IOException { + public void runNeoLoadTest(Vertx rxvertx, CloudEvent receivedEvent) throws NeoLoadJgitExeption, NeoLoadSerialException, IOException { // gitfolder = getNeoLoadTestFolder(); List neoLoadTestStepList=getNeoLoadTest(); //---for each test start test ----- neoLoadTestStepList.stream().filter(neoLoadTestStep -> neoLoadTestStep.getStep().getStage().equalsIgnoreCase(this.stage)).forEach(step->{ - runNLScenario(step.getStep()); + logger.debug("Running step : "+step.getStep().getScenario()); + runNLScenario(step.getStep(),rxvertx,receivedEvent); + logger.debug("end step : "+step.getStep().getScenario()); });