Skip to content

Commit

Permalink
Update the process deploying pods and services on the cluster.
Browse files Browse the repository at this point in the history
REsolve the problem related to sending cloud events
  • Loading branch information
NeotysLab committed Jul 5, 2019
1 parent 53f4e26 commit fde5702
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 105 deletions.
2 changes: 1 addition & 1 deletion installer/deployNeoLoadWeb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<properties>
<java.version>1.8</java.version>
<tag>0.1</tag>
<dockerimage>registry.hub.docker.com/hrexed/keptn_neoload</dockerimage>
<NL_WEB_HOST>neoload.saas.com</NL_WEB_HOST>
<NL_API_HOST>neoload-api.saas.com</NL_API_HOST>
Expand Down Expand Up @@ -91,7 +92,12 @@
<configuration>
<to>
<image>${dockerimage}</image>
<tags>
<tag>${tag}</tag>
<tag>latest</tag>
</tags>
</to>
<allowInsecureRegistries>true</allowInsecureRegistries>
<container>
<ports>
<port>${port}</port>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Object> 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<JsonObject> cloudEvent = new CloudEventBuilder<JsonObject>()
.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<JsonObject> cloudEvent = new CloudEventBuilder<JsonObject>()
.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);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.vertx.reactivex.ext.web.Router;


import java.io.EOFException;
import java.util.HashMap;
import java.util.Optional;

Expand All @@ -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");
Expand Down Expand Up @@ -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.<String>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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
public class KeptnExtensions implements Extension {

private String shkeptncontext;
private String datacontenttype;
private String contenttype;

//Mandatory to let cloud-events lib instatiate class
public KeptnExtensions() {
}

public KeptnExtensions(final String shkeptncontext, final String datacontenttype) {
this.shkeptncontext = shkeptncontext;
this.datacontenttype = datacontenttype;
this.contenttype = datacontenttype;
}
public String getShkeptncontext() {
return shkeptncontext;
Expand All @@ -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
Expand All @@ -54,7 +54,7 @@ public boolean equals(final Object obj) {
public String toString() {
return "KeptExtension{" +
"shkeptncontext='" + shkeptncontext + '\'' +
", datacontenttype='" + datacontenttype + '\'' +
", datacontenttype='" + contenttype + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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://";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading

0 comments on commit fde5702

Please sign in to comment.