Skip to content

Commit

Permalink
Added separate UIs and tests for them, ready for integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Perez Belmonte committed Sep 4, 2017
1 parent 9e4ca75 commit 8e4fd02
Show file tree
Hide file tree
Showing 13 changed files with 523 additions and 195 deletions.
7 changes: 4 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ The version 0.1 of the ElasTest Cost Engine, provides the following features:

When the ECE is started correctly, a basic UI will be exposed at http://localhost:8888

The 0.0.2 version of ECE initializes the databases and includes two different Cost Models as initial values. The T-Jobs are mocked up until the DSL is correctly defined.
The 0.1 version of ECE initializes the databases and includes two different Cost Models as initial values. The T-Jobs are
mocked up until the DSL is correctly defined.

The ECE UI offers the functionality to estimate the price of running a specified T-Job running under a Cost Model.
![ElasTest Cost Engine Demo Interface v0.0.2](imgs/CostEngine002Demo.png)
![ElasTest Cost Engine Demo Interface v0.1](imgs/CostEngine002Demo.png)

The ECE UI also ofers a simple way to manage all the Cost Models, creating, deleting and requesting for the json structure.

Expand All @@ -55,7 +56,7 @@ ECE will be in contact with the following ElasTest services:

![ElasTest Cost Engine final architecture](imgs/ECEArch.png)

For now, the 0.0.2 version is using Mock up values to simmulate the interaction with the rest of the ElasTest Components.
For now, the 0.1 version is using Mock up values to simmulate the interaction with the rest of the ElasTest Components.


![ElasTest Cost Engine Mock up architecture](imgs/MockECE.png)
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>material-design-lite</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>

<repositories>
Expand Down
88 changes: 75 additions & 13 deletions src/main/java/io/elastest/ece/application/APIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class APIController {

@PostConstruct
public void init() {
//TODO: Communicate with TORM to get all the TJobs
testCostModelValues();
testTestValues();
}
Expand All @@ -64,17 +65,63 @@ public String getIndex(Model model) {
return "index";
}

@RequestMapping(value = "/estimate", method = RequestMethod.GET)
public String getEstimateCostModels(Model model) {
logger.info("Creating test values.");
HibernateClient hibernateClient = HibernateClient.getInstance();
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
List<TJob> tJobs = hibernateClient.executeQuery(QueryHelper.createListQuery(TJob.class));

logger.info("Adding attributes to the model.");
model.addAttribute("tests", tJobs);
model.addAttribute("costModels", costModels);
logger.info("Redirecting to the ECE's Cost Estimation Page.");
return "estimate";
}

@RequestMapping(value = "/deletecostmodel", method = RequestMethod.GET)
public String getDeleteCostModel(Model model) {
logger.info("Creating test values.");
HibernateClient hibernateClient = HibernateClient.getInstance();
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));

logger.info("Adding attributes to the model.");
model.addAttribute("costModels", costModels);
logger.info("Redirecting to the ECE's Delete Cost Model Page.");
return "deletecostmodel";
}

@RequestMapping(value = "/costmodeldetails", method = RequestMethod.GET)
public String getCostModelDetails(Model model) {
logger.info("Creating test values.");
HibernateClient hibernateClient = HibernateClient.getInstance();
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));

logger.info("Adding attributes to the model.");
model.addAttribute("costModels", costModels);
logger.info("Redirecting to the ECE's Cost Model Details Page.");
return "costmodeldetails";
}

@RequestMapping(value = "/createcostmodel", method = RequestMethod.GET)
public String getCreateCostModel() {
logger.info("Redirecting to the ECE's Cost Model Creation Page.");
return "createcostmodel";
}

@RequestMapping(value = "/costmodel", method = RequestMethod.POST)
public String addCostModel(@RequestParam String name, @RequestParam String description, @RequestParam String fixName, @RequestParam Double fixValue, @RequestParam double cpus, @RequestParam double memory, @RequestParam double disk, Model model) {
public String addCostModel(@RequestParam String name, @RequestParam String description, @RequestParam String[] fixNames, @RequestParam Double[] fixValues, @RequestParam String[] varNames, @RequestParam Double[] varValues, Model model) {
logger.info("Creating Cost Model.");
HashMap<String, Double> varCosts = new HashMap<>();
varCosts.put("cpus", cpus);
varCosts.put("memory", memory);
varCosts.put("disk", disk);

HashMap<String, Double> fixCosts = new HashMap<>();
fixCosts.put(fixName, fixValue);

for (int i = 0; i < fixNames.length; i++) {
fixCosts.put(fixNames[i], fixValues[i]);
}

for (int i = 0; i < varNames.length; i++) {
varCosts.put(varNames[i], varValues[i]);
}

CostModel costModel = new CostModel(name, "ONDEMAND", fixCosts, varCosts, null, description);
logger.info("Persisting the created Cost Model into the DB");
Expand Down Expand Up @@ -104,40 +151,45 @@ public String deleteCostModel(@RequestParam String costModelId) {
return "costModelDeleted";
}

@RequestMapping(value = "/estimate", method = RequestMethod.POST)
@RequestMapping(value = "/estimation", method = RequestMethod.GET)
public String getEstimate(@RequestParam("tJobId") String tJobId, @RequestParam("costModelId") String costModelId, Model model) {
return estimatePost(tJobId, costModelId, model);
}

@RequestMapping(value = "/estimation", method = RequestMethod.POST)
public String estimatePost(@RequestParam String testId, @RequestParam String costModelId, Model model) {
HibernateClient hibernateClient = HibernateClient.getInstance();
CostModel costModel = (CostModel) hibernateClient.getObject(CostModel.class, Long.valueOf(costModelId));
TJob tJob = (TJob) hibernateClient.getObject(TJob.class, Long.valueOf(testId));
double totalCost = 0;
String costModelType = costModel.getType();
if(costModelType.equalsIgnoreCase("ONDEMAND")){
if (costModelType.equalsIgnoreCase("ONDEMAND")) {
Map<String, Double> fixCost = costModel.getFix_cost();
Map<String, Double> varRate = costModel.getVar_rate();
Map<String, String> components = costModel.getComponents();
Map<String, String> metadata = tJob.getMetadata();

logger.info("Adding all fix costs from the cost model.");
for(Object key : fixCost.keySet()){
for (Object key : fixCost.keySet()) {
totalCost += fixCost.get(key);
}

logger.info("Adding all the accounted variable costs in the model");
for(Object key : varRate.keySet()){
if(tJob.getMetadata().containsKey(key)){
for (Object key : varRate.keySet()) {
if (tJob.getMetadata().containsKey(key)) {
totalCost += (Double.parseDouble(metadata.get(key)) * (varRate.get(key)));
}
}

//TODO:add component costs.
logger.info("Adding all the component costs.");
}else if(costModelType.equalsIgnoreCase("PAYG")){
} else if (costModelType.equalsIgnoreCase("PAYG")) {
//TODO: implement
}

model.addAttribute("estimate", totalCost);
logger.info("Returning an estimate for the test jobs: " + testId + " and the Cost Model: " + costModelId);
return "estimate";
return "estimation";
}

private ArrayList testCostModelValues() {
Expand Down Expand Up @@ -165,6 +217,11 @@ private ArrayList testCostModelValues() {

logger.info("Persisting demo values");
HibernateClient hibernateClient = HibernateClient.getInstance();

List<CostModel> oldCostModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
for (CostModel oldCostModel : oldCostModels)
hibernateClient.deleteObject(oldCostModel);

hibernateClient.persistObject(costModel);
hibernateClient.persistObject(costModel1);
return result;
Expand Down Expand Up @@ -192,6 +249,11 @@ private ArrayList testTestValues() {

logger.info("Persisting demo values");
HibernateClient hibernateClient = HibernateClient.getInstance();

List<TJob> oldTJobs = hibernateClient.executeQuery(QueryHelper.createListQuery(TJob.class));
for (TJob oldTJob : oldTJobs)
hibernateClient.deleteObject(oldTJob);

hibernateClient.persistObject(tJob);
hibernateClient.persistObject(tJob1);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/costModelCreated.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

</head>
<body>
<form method="get" action="/">
<form method="get" action="/createcostmodel">
<table>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/costModelDeleted.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

</head>
<body>
<form method="get" action="/">
<form method="get" action="/deletecostmodel">
<table>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/costModelInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

</head>
<body>
<form method="get" action="/">
<form method="get" action="/costmodeldetails">
<table>
<thead>
<tr>
Expand Down
33 changes: 33 additions & 0 deletions src/main/resources/templates/costmodeldetails.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>ElasTest | ECE</title>
</head>
<body>
<form method="get" action="/costmodel">
<table>
<thead>
<tr>
<th>Get Cost Model Info</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<tr th:each="costModel: ${costModels}">
<td th:text="${costModel.description}">planId</td>
<td>
<input type="radio" name="costModelId" th:value="${costModel.id}">
</td>
</tr>
</td>
<td>
<button id="getCostModelButton">Get Cost Model</button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
85 changes: 85 additions & 0 deletions src/main/resources/templates/createcostmodel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ElasTest | ECE</title>
</head>
<body>
<form method="post" action="/costmodel">
<table>
<tbody>
<tr>
<th>Create Cost Model</th>
<th></th>
<br>
</tr>
<tr>
<td>Cost Model Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Cost Model Description</td>
<td><input type="text" name="description"></td>
</tr>
</tbody>
</table>
<table id="fixTable">
<tbody>
<tr>
<th>
Fix Costs
</th>
<th>
<button type="button" onclick="addFixRow()">Add Row</button>
</th>
</tr>
<tr>
<td><input type="text" name="fixNames"></td>
<td><input type="number" name="fixValues"></td>
</tr>
</tbody>
</table>
<table id="varTable">
<tbody>

<tr>
<th>
Variable Costs
</th>
<th>
<button type="button" onclick="addVarRow()">Add Row</button>
</th>
</tr>
<tr>
<td><input type="text" name="varNames"></td>
<td><input type="number" name="varValues"></td>
</tr>
</tr>
</tbody>
</table>
<button id="createCostModel">Add Cost Model</button>
</form>

<script>
function addFixRow() {
var table = document.getElementById("fixTable");
var row = table.insertRow(table.size);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);

cell1.innerHTML = "<input type=\"text\" name=\"fixNames\">";
cell2.innerHTML = "<input type=\"number\" name=\"fixValues\">";
}

function addVarRow() {
var table = document.getElementById("varTable");
var row = table.insertRow(table.size);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);

cell1.innerHTML = "<input type=\"text\" name=\"varNames\">";
cell2.innerHTML = "<input type=\"number\" name=\"varValues\">";
}
</script>
</body>
</html>
33 changes: 33 additions & 0 deletions src/main/resources/templates/deletecostmodel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>ElasTest | ECE</title>
</head>
<body>
<form method="post" action="/deleteCostModel">
<table>
<thead>
<tr>
<th>Delete Cost Model</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<tr th:each="costModel: ${costModels}">
<td th:text="${costModel.description}">planId</td>
<td>
<input type="radio" name="costModelId" th:value="${costModel.id}">
</td>
</tr>
</td>
<td>
<button id="deleteButton">Delete</button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Loading

0 comments on commit 8e4fd02

Please # to comment.