Commit 4e3f7474 authored by Spiros Koulouzis's avatar Spiros Koulouzis

replaced Ansible data type with keyvalue

parent f1105ccd
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package nl.uva.sne.drip.api.dao; package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse; import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult; import nl.uva.sne.drip.drip.commons.data.v1.external.KeyValueHolder;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query; import org.springframework.data.mongodb.repository.Query;
...@@ -27,5 +27,5 @@ import org.springframework.data.mongodb.repository.Query; ...@@ -27,5 +27,5 @@ import org.springframework.data.mongodb.repository.Query;
public interface DeployDao extends MongoRepository<DeployResponse, String> { public interface DeployDao extends MongoRepository<DeployResponse, String> {
@Query(value = "{'statusHistories':{$elemMatch:{'status':{$in:['PROCESSABLE']}}},'created' : { '$gt' : { '$date' : ':?0' } , '$lt' : { '$date' : ':?1'}}}", count = true) @Query(value = "{'statusHistories':{$elemMatch:{'status':{$in:['PROCESSABLE']}}},'created' : { '$gt' : { '$date' : ':?0' } , '$lt' : { '$date' : ':?1'}}}", count = true)
public Iterable<AnsibleResult> findByCommand(String cmd); public Iterable<KeyValueHolder> findByCommand(String cmd);
} }
...@@ -21,9 +21,9 @@ import java.util.List; ...@@ -21,9 +21,9 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import nl.uva.sne.drip.api.dao.AnsibleOutputDao; import nl.uva.sne.drip.api.dao.AnsibleOutputDao;
import nl.uva.sne.drip.api.exception.NotFoundException; import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyValueHolder;
import nl.uva.sne.drip.drip.commons.data.v1.external.User; import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize; import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PostFilter;
...@@ -79,35 +79,4 @@ public class AnsibleOutputService { ...@@ -79,35 +79,4 @@ public class AnsibleOutputService {
ansibleOutputDao.deleteAll(); ansibleOutputDao.deleteAll();
} }
public List<String> findAllCommands() {
List<AnsibleOutput> all = findAll();
Set<String> hashset = new HashSet<>();
for (AnsibleOutput ans : all) {
AnsibleResult res = ans.getAnsibleResult();
if (res != null) {
List<String> commandList = res.getCmd();
if (commandList != null) {
hashset.add(commandList.get(0));
}
}
}
return new ArrayList<>(hashset);
}
public List<AnsibleOutput> findByCommand(String command) {
List<AnsibleOutput> all = findAll();
List<AnsibleOutput> filtered = new ArrayList<>();
for (AnsibleOutput ans : all) {
AnsibleResult res = ans.getAnsibleResult();
if (res != null) {
List<String> commandList = res.getCmd();
if (commandList != null && commandList.get(0).equals(command)) {
filtered.add(ans);
}
}
}
return filtered;
}
} }
...@@ -54,11 +54,11 @@ import nl.uva.sne.drip.commons.utils.Converter; ...@@ -54,11 +54,11 @@ import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.DRIPLogHandler; import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation; import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair; import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyValueHolder;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse; import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation; import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.SysbenchCPUBenchmark; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.SysbenchCPUBenchmark;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -398,7 +398,7 @@ public class DeployService { ...@@ -398,7 +398,7 @@ public class DeployService {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
value = parseValue(value); value = parseValue(value);
System.err.println(value);
List<AnsibleOutput> outputList = mapper.readValue(value, new TypeReference<List<AnsibleOutput>>() { List<AnsibleOutput> outputList = mapper.readValue(value, new TypeReference<List<AnsibleOutput>>() {
}); });
...@@ -476,66 +476,63 @@ public class DeployService { ...@@ -476,66 +476,63 @@ public class DeployService {
} }
private BenchmarkResult parseSaveBenchmarkResult(AnsibleOutput ansOut) { private BenchmarkResult parseSaveBenchmarkResult(AnsibleOutput ansOut) {
AnsibleResult res = ansOut.getAnsibleResult(); // KeyValueHolder res = ansOut.getAnsibleResult();
if (res != null) { // if (res != null) {
List<String> cmdList = res.getCmd(); // List<String> cmdList = res.getCmd();
if (cmdList != null) { // if (cmdList != null) {
//
switch (cmdList.get(0)) { // switch (cmdList.get(0)) {
case "sysbench": // case "sysbench":
String[] out = res.getStdout().split("\n"); // String[] out = res.getStdout().split("\n");
String version = getSysbeanchVersion(out[0]); // String version = getSysbeanchVersion(out[0]);
int numOfThreads = getNumberOfThreads(out[3]); // int numOfThreads = getNumberOfThreads(out[3]);
Double executionTime = getExecutionTime(out[14]); // Double executionTime = getExecutionTime(out[14]);
int totalNumberOfEvents = getTotalNumberOfEvents(out[15]); // int totalNumberOfEvents = getTotalNumberOfEvents(out[15]);
//
double minExecutionTimePerRequest = getMinExecutionTimePerRequest(out[18]); // double minExecutionTimePerRequest = getMinExecutionTimePerRequest(out[18]);
double avgExecutionTimePerRequest = getAvgExecutionTimePerRequest(out[19]); // double avgExecutionTimePerRequest = getAvgExecutionTimePerRequest(out[19]);
double maxExecutionTimePerRequest = getMaxExecutionTimePerRequest(out[20]); // double maxExecutionTimePerRequest = getMaxExecutionTimePerRequest(out[20]);
double approx95Percentile = getApprox95Percentile(out[21]); // double approx95Percentile = getApprox95Percentile(out[21]);
//
double avgEventsPerThread = getAvgEventsPerThread(out[24]); // double avgEventsPerThread = getAvgEventsPerThread(out[24]);
double stddevEventsPerThread = getStddevEventsPerThread(out[24]); // double stddevEventsPerThread = getStddevEventsPerThread(out[24]);
//
double avgExecTimePerThread = getAvgExecTimePerThread(out[25]); // double avgExecTimePerThread = getAvgExecTimePerThread(out[25]);
double stddevExecTimePerThread = getStddevExecTimePerThread(out[25]); // double stddevExecTimePerThread = getStddevExecTimePerThread(out[25]);
//
SysbenchCPUBenchmark b = new SysbenchCPUBenchmark(); // SysbenchCPUBenchmark b = new SysbenchCPUBenchmark();
b.setSysbenchVersion(version); // b.setSysbenchVersion(version);
//
b.setNumberOfThreads(numOfThreads); // b.setNumberOfThreads(numOfThreads);
b.setExecutionTime(executionTime * 1000); // b.setExecutionTime(executionTime * 1000);
//
b.setTotalNumberOfEvents(totalNumberOfEvents); // b.setTotalNumberOfEvents(totalNumberOfEvents);
//
b.setAvgEventsPerThread(avgEventsPerThread); // b.setAvgEventsPerThread(avgEventsPerThread);
b.setStddevEventsPerThread(stddevEventsPerThread); // b.setStddevEventsPerThread(stddevEventsPerThread);
//
b.setAvgExecTimePerThread(avgExecTimePerThread * 1000); // b.setAvgExecTimePerThread(avgExecTimePerThread * 1000);
b.setStddevExecTimePerThread(stddevExecTimePerThread); // b.setStddevExecTimePerThread(stddevExecTimePerThread);
b.setApprox95Percentile(approx95Percentile); // b.setApprox95Percentile(approx95Percentile);
//
b.setMinExecutionTimePerRequest(minExecutionTimePerRequest); // b.setMinExecutionTimePerRequest(minExecutionTimePerRequest);
b.setAvgExecutionTimePerRequest(avgExecutionTimePerRequest); // b.setAvgExecutionTimePerRequest(avgExecutionTimePerRequest);
b.setMaxExecutionTimePerRequest(maxExecutionTimePerRequest); // b.setMaxExecutionTimePerRequest(maxExecutionTimePerRequest);
//
b.setAnsibleOutputID(ansOut.getId()); // b.setAnsibleOutputID(ansOut.getId());
//
b.setCloudDeploymentDomain(ansOut.getCloudDeploymentDomain()); // b.setCloudDeploymentDomain(ansOut.getCloudDeploymentDomain());
b.setDelta(ansOut.getAnsibleResult().getDelta()); // b.setHost(ansOut.getHost());
b.setStart(ansOut.getAnsibleResult().getStart()); // b.setVmType(ansOut.getVmType());
b.setEnd(ansOut.getAnsibleResult().getEnd()); // b = (SysbenchCPUBenchmark) benchmarkResultService.save(b);
b.setHost(ansOut.getHost()); // return b;
b.setVmType(ansOut.getVmType()); //
b = (SysbenchCPUBenchmark) benchmarkResultService.save(b); // default:
return b; // return null;
//
default: // }
return null; // }
// }
}
}
}
return null; return null;
} }
......
...@@ -69,23 +69,7 @@ public class AnsibleOutputController { ...@@ -69,23 +69,7 @@ public class AnsibleOutputController {
} }
return resp; return resp;
} }
/**
* Query AnsibleOutput by executing command.
*
* @param command
* @return
*/
@RequestMapping(method = RequestMethod.GET, params = {"command"})
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 200, condition = "Successful query")
})
public @ResponseBody
List<AnsibleOutput> getByCommand(@RequestParam(value = "command") String command) {
return ansibleOutputService.findByCommand(command);
}
/** /**
* Returns the ids of stored objects. Empty list if non stored * Returns the ids of stored objects. Empty list if non stored
* *
...@@ -106,21 +90,7 @@ public class AnsibleOutputController { ...@@ -106,21 +90,7 @@ public class AnsibleOutputController {
return ids; return ids;
} }
/**
* Query for used (unique) commands
*
* @return
*/
@RequestMapping(value = "/commands", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 200, condition = "Successful query")
})
public @ResponseBody
List<String> getCommands() {
return ansibleOutputService.findAllCommands();
}
/** /**
* Deletes object * Deletes object
* *
......
...@@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; ...@@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.webcohesion.enunciate.metadata.DocumentationExample; import com.webcohesion.enunciate.metadata.DocumentationExample;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyValueHolder;
import nl.uva.sne.drip.drip.commons.data.v1.external.OwnedObject; import nl.uva.sne.drip.drip.commons.data.v1.external.OwnedObject;
import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
...@@ -42,7 +43,7 @@ public class AnsibleOutput extends OwnedObject { ...@@ -42,7 +43,7 @@ public class AnsibleOutput extends OwnedObject {
@Indexed @Indexed
private String vmType; private String vmType;
private AnsibleResult result; private KeyValueHolder result;
private String provisionID; private String provisionID;
...@@ -72,12 +73,12 @@ public class AnsibleOutput extends OwnedObject { ...@@ -72,12 +73,12 @@ public class AnsibleOutput extends OwnedObject {
* @return the result * @return the result
*/ */
@JsonProperty("result") @JsonProperty("result")
public AnsibleResult getAnsibleResult() { public KeyValueHolder getAnsibleResult() {
return result; return result;
} }
@JsonProperty("result") @JsonProperty("result")
public void setAnsiibleResult(AnsibleResult result) { public void setAnsiibleResult(KeyValueHolder result) {
this.result = result; this.result = result;
} }
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
/**
* This class represents an ansible execution result. This can be used as a
* archive / log of ansible executions for example how much time it took for
* execution, errors etc.
*
* @author S. Koulouzis
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AnsibleResult {
private String msg;
private Boolean changed;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
private Date end;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
private Date start;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss.SSSSSS")
private Date delta;
private String stdout;
private String stderr;
private List<String> cmd;
// @JsonProperty("stdout_lines")
// private List<String> stdout_lines;
// @JsonProperty("results")
// private List<AnsibleResult_> results = null;
@JsonProperty("msg")
public String getMsg() {
return msg;
}
@JsonProperty("msg")
public void setMsg(String msg) {
this.msg = msg;
}
@JsonProperty("changed")
public Boolean getChanged() {
return changed;
}
@JsonProperty("changed")
public void setChanged(Boolean changed) {
this.changed = changed;
}
// @JsonProperty("results")
// public List<AnsibleResult_> getAnsibleResults() {
// return results;
// }
//
// @JsonProperty("results")
// public void setAnsibleResults(List<AnsibleResult_> results) {
// this.results = results;
// }
@JsonProperty("end")
public Date getEnd() {
return end;
}
@JsonProperty("end")
public void setEnd(Date end) {
this.end = end;
}
@JsonProperty("stdout")
public String getStdout() {
return stdout;
}
@JsonProperty("stdout")
public void setStdout(String stdout) {
this.stdout = stdout;
}
@JsonProperty("cmd")
public List<String> getCmd() {
return cmd;
}
@JsonProperty("cmd")
public void setCmd(List<String> cmd) {
this.cmd = cmd;
}
@JsonProperty("start")
public Date getStart() {
return start;
}
@JsonProperty("start")
public void setStart(Date start) {
this.start = start;
}
@JsonProperty("stderr")
public String getStderr() {
return stderr;
}
@JsonProperty("stderr")
public void setStderr(String stderr) {
this.stderr = stderr;
}
@JsonProperty("delta")
public Date getDelta() {
return delta;
}
@JsonProperty("delta")
public void setDelta(Date delta) {
this.delta = delta;
}
// @JsonProperty("stdout_lines")
// public List<String> getStdout_lines() {
// return stdout_lines;
// }
//
// @JsonProperty("stdout_lines")
// public void setStdout_lines(List<String> stdout_lines) {
// this.stdout_lines = stdout_lines;
// }
}
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<ch.qos.logback.version>1.2.3</ch.qos.logback.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>nl.uva.sne.drip</groupId> <groupId>nl.uva.sne.drip</groupId>
...@@ -89,6 +92,23 @@ ...@@ -89,6 +92,23 @@
<version>2.4.4</version> <version>2.4.4</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
</dependencies> </dependencies>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment