Commit 7f94f332 authored by Spiros Koulouzis's avatar Spiros Koulouzis

try to attach outputs to TOSCA

parent 446c8c13
...@@ -200,27 +200,22 @@ public class DeployService { ...@@ -200,27 +200,22 @@ public class DeployService {
if (pro == null) { if (pro == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
List<String> loginKeysIDs = pro.getDeployerKeyPairIDs(); // List<String> loginKeysIDs = pro.getDeployerKeyPairIDs();
List<Message> messages = new ArrayList<>(); List<Message> messages = new ArrayList<>();
// if (loginKeysIDs == null || loginKeysIDs.isEmpty()) {
// List<String> cloudConfIDs = pro.getCloudCredentialsIDs();
// CloudCredentials cCred = cloudCredentialsService.findOne(cloudConfIDs.get(0));
// loginKeysIDs = cCred.getkeyPairIDs();
// }
List<KeyPair> loginKeys = new ArrayList<>(); List<KeyPair> loginKeys = new ArrayList<>();
for (String keyID : loginKeysIDs) { // for (String keyID : loginKeysIDs) {
KeyPair key = keyDao.findOne(keyID); // KeyPair key = keyDao.findOne(keyID);
loginKeys.add(key); // loginKeys.add(key);
} // }
List<DeployParameter> deployParams = pro.getDeployParameters(); // List<DeployParameter> deployParams = pro.getDeployParameters();
List<MessageParameter> parameters = new ArrayList<>(); List<MessageParameter> parameters = new ArrayList<>();
for (DeployParameter dp : deployParams) { // for (DeployParameter dp : deployParams) {
MessageParameter messageParameter = createCredentialPartameter(dp, loginKeys); // MessageParameter messageParameter = createCredentialPartameter(dp, loginKeys);
parameters.add(messageParameter); // parameters.add(messageParameter);
} // }
MessageParameter managerTypeParameter = createManagerTypeParameter(managerType); MessageParameter managerTypeParameter = createManagerTypeParameter(managerType);
parameters.add(managerTypeParameter); parameters.add(managerTypeParameter);
...@@ -258,17 +253,12 @@ public class DeployService { ...@@ -258,17 +253,12 @@ public class DeployService {
} }
private MessageParameter createCredentialPartameter(DeployParameter dp, List<KeyPair> loginKeys) { private MessageParameter createCredentialPartameter(DeployParameter dp, List<KeyPair> loginKeys) {
// String cName = dp.getCloudCertificateName();
MessageParameter messageParameter = new MessageParameter(); MessageParameter messageParameter = new MessageParameter();
messageParameter.setName("credential"); messageParameter.setName("credential");
messageParameter.setEncoding("UTF-8"); messageParameter.setEncoding("UTF-8");
String key = null; String key = null;
for (KeyPair lk : loginKeys) { for (KeyPair lk : loginKeys) {
// String lkName = lk.getPrivateKey().getAttributes().get("domain_name");
// if (lkName.equals(cName)) {
key = lk.getPrivateKey().getKey(); key = lk.getPrivateKey().getKey();
// break;
// }
} }
messageParameter.setValue(key); messageParameter.setValue(key);
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
...@@ -474,114 +464,9 @@ public class DeployService { ...@@ -474,114 +464,9 @@ public class DeployService {
} }
private BenchmarkResult parseSaveBenchmarkResult(AnsibleOutput ansOut) { private BenchmarkResult parseSaveBenchmarkResult(AnsibleOutput ansOut) {
// KeyValueHolder res = ansOut.getAnsibleResult();
// if (res != null) {
// List<String> cmdList = res.getCmd();
// if (cmdList != null) {
//
// switch (cmdList.get(0)) {
// case "sysbench":
// String[] out = res.getStdout().split("\n");
// String version = getSysbeanchVersion(out[0]);
// int numOfThreads = getNumberOfThreads(out[3]);
// Double executionTime = getExecutionTime(out[14]);
// int totalNumberOfEvents = getTotalNumberOfEvents(out[15]);
//
// double minExecutionTimePerRequest = getMinExecutionTimePerRequest(out[18]);
// double avgExecutionTimePerRequest = getAvgExecutionTimePerRequest(out[19]);
// double maxExecutionTimePerRequest = getMaxExecutionTimePerRequest(out[20]);
// double approx95Percentile = getApprox95Percentile(out[21]);
//
// double avgEventsPerThread = getAvgEventsPerThread(out[24]);
// double stddevEventsPerThread = getStddevEventsPerThread(out[24]);
//
// double avgExecTimePerThread = getAvgExecTimePerThread(out[25]);
// double stddevExecTimePerThread = getStddevExecTimePerThread(out[25]);
//
// SysbenchCPUBenchmark b = new SysbenchCPUBenchmark();
// b.setSysbenchVersion(version);
//
// b.setNumberOfThreads(numOfThreads);
// b.setExecutionTime(executionTime * 1000);
//
// b.setTotalNumberOfEvents(totalNumberOfEvents);
//
// b.setAvgEventsPerThread(avgEventsPerThread);
// b.setStddevEventsPerThread(stddevEventsPerThread);
//
// b.setAvgExecTimePerThread(avgExecTimePerThread * 1000);
// b.setStddevExecTimePerThread(stddevExecTimePerThread);
// b.setApprox95Percentile(approx95Percentile);
//
// b.setMinExecutionTimePerRequest(minExecutionTimePerRequest);
// b.setAvgExecutionTimePerRequest(avgExecutionTimePerRequest);
// b.setMaxExecutionTimePerRequest(maxExecutionTimePerRequest);
//
// b.setAnsibleOutputID(ansOut.getId());
//
// b.setCloudDeploymentDomain(ansOut.getCloudDeploymentDomain());
// b.setHost(ansOut.getHost());
// b.setVmType(ansOut.getVmType());
// b = (SysbenchCPUBenchmark) benchmarkResultService.save(b);
// return b;
//
// default:
// return null;
//
// }
// }
// }
return null; return null;
} }
private String getSysbeanchVersion(String string) {
return string.replaceAll("sysbench", "").replaceAll(": multi-threaded system evaluation benchmark", "");
}
private int getNumberOfThreads(String string) {
return Integer.valueOf(string.replaceAll("Number of threads: ", ""));
}
private Double getExecutionTime(String string) {
return Double.valueOf(string.replaceAll("total time:", "").replaceAll("s", "").trim());
}
private int getTotalNumberOfEvents(String string) {
return Integer.valueOf(string.replaceAll("total number of events:", "").replaceAll("s", "").trim());
}
private Double getAvgEventsPerThread(String string) {
return Double.valueOf(string.replaceAll("events \\(avg/stddev\\):", "").trim().split("/")[0]);
}
private Double getStddevEventsPerThread(String string) {
return Double.valueOf(string.replaceAll("events \\(avg/stddev\\):", "").trim().split("/")[1]);
}
private Double getAvgExecTimePerThread(String string) {
return Double.valueOf(string.replaceAll("execution time \\(avg/stddev\\):", "").trim().split("/")[0]);
}
private Double getStddevExecTimePerThread(String string) {
return Double.valueOf(string.replaceAll("execution time \\(avg/stddev\\):", "").trim().split("/")[1]);
}
private double getMinExecutionTimePerRequest(String string) {
return Double.valueOf(string.replaceAll("min:", "").replaceAll("ms", "").trim());
}
private double getAvgExecutionTimePerRequest(String string) {
return Double.valueOf(string.replaceAll("avg:", "").replaceAll("ms", "").trim());
}
private double getMaxExecutionTimePerRequest(String string) {
return Double.valueOf(string.replaceAll("max:", "").replaceAll("ms", "").trim());
}
private double getApprox95Percentile(String string) {
return Double.valueOf(string.replaceAll("approx. 95 percentile:", "").replaceAll("ms", "").trim());
}
private String parseValue(String value) throws JSONException { private String parseValue(String value) throws JSONException {
JSONArray ja = new JSONArray(value); JSONArray ja = new JSONArray(value);
JSONArray newJa = new JSONArray(); JSONArray newJa = new JSONArray();
......
...@@ -58,6 +58,9 @@ import org.springframework.security.core.context.SecurityContextHolder; ...@@ -58,6 +58,9 @@ import org.springframework.security.core.context.SecurityContextHolder;
import nl.uva.sne.drip.api.dao.ProvisionResponseDao; import nl.uva.sne.drip.api.dao.ProvisionResponseDao;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller1; import nl.uva.sne.drip.api.rpc.ProvisionerCaller1;
import nl.uva.sne.drip.commons.utils.DRIPLogHandler; import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import nl.uva.sne.drip.commons.utils.TOSCAUtils;
import static nl.uva.sne.drip.commons.utils.TOSCAUtils.getVMsFromTopology;
import static nl.uva.sne.drip.commons.utils.TOSCAUtils.getVMsNodeNamesFromTopology;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key; import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
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.ScaleRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
...@@ -343,7 +346,6 @@ public class ProvisionService { ...@@ -343,7 +346,6 @@ public class ProvisionService {
parameters.add(action); parameters.add(action);
PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest); PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest);
List<MessageParameter> topologies = buildTopologyParams(plan); List<MessageParameter> topologies = buildTopologyParams(plan);
parameters.addAll(topologies); parameters.addAll(topologies);
invokationMessage.setParameters(parameters); invokationMessage.setParameters(parameters);
...@@ -418,7 +420,6 @@ public class ProvisionService { ...@@ -418,7 +420,6 @@ public class ProvisionService {
provisionResponse = new ProvisionResponse(); provisionResponse = new ProvisionResponse();
} }
List<DeployParameter> deployParameters = new ArrayList<>();
Map<String, Object> kvMap = null; Map<String, Object> kvMap = null;
KeyPair userKey = new KeyPair(); KeyPair userKey = new KeyPair();
KeyPair deployerKey = new KeyPair(); KeyPair deployerKey = new KeyPair();
...@@ -426,6 +427,14 @@ public class ProvisionService { ...@@ -426,6 +427,14 @@ public class ProvisionService {
Map<String, Key> privateCloudKeys = new HashMap<>(); Map<String, Key> privateCloudKeys = new HashMap<>();
Map<String, Key> publicCloudKeys = new HashMap<>(); Map<String, Key> publicCloudKeys = new HashMap<>();
PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest);
Map<String, Object> toscaPlan = plan.getKeyValue();
Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaPlan.get("topology_template"));
List<Map<String, Object>> vmList = getVMsFromTopology(toscaPlan);
List<String> nodeNames = getVMsNodeNamesFromTopology(toscaPlan);
Map<String, Object> outputs = new HashMap<>();
for (MessageParameter p : parameters) { for (MessageParameter p : parameters) {
String name = p.getName(); String name = p.getName();
if (name.toLowerCase().contains("exception")) { if (name.toLowerCase().contains("exception")) {
...@@ -441,21 +450,27 @@ public class ProvisionService { ...@@ -441,21 +450,27 @@ public class ProvisionService {
throw new Exception("Provision failed"); throw new Exception("Provision failed");
// this.deleteProvisionedResources(provisionResponse); // this.deleteProvisionedResources(provisionResponse);
} }
for (String line : lines) {
DeployParameter deployParam = new DeployParameter(); for (int i = 0; i < lines.length; i++) {
String[] parts = line.split(" "); // DeployParameter deployParam = new DeployParameter();
String[] parts = lines[i].split(" ");
String deployIP = parts[0]; String deployIP = parts[0];
String deployUser = parts[1]; String deployUser = parts[1];
// String deployCertPath = parts[2]; // String deployCertPath = parts[2];
// String cloudCertificateName = FilenameUtils.removeExtension(FilenameUtils.getBaseName(deployCertPath)); // String cloudCertificateName = FilenameUtils.removeExtension(FilenameUtils.getBaseName(deployCertPath));
String deployRole = parts[2]; String deployRole = parts[2];
deployParam.setIP(deployIP); String nodeName = nodeNames.get(i);
deployParam.setRole(deployRole);
deployParam.setUser(deployUser); Map<String, Object> ipOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployIP);
// deployParam.setCloudCertificateName(cloudCertificateName); Map<String, Object> roleOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployRole);
deployParameters.add(deployParam); outputs.put("ip", ipOutput);
outputs.put("role", roleOutput);
Map<String, Object> properties = (Map<String, Object>) vmList.get(i).get("properties");
properties.put("user_name", deployUser);
} }
break; break;
case "public_user_key": case "public_user_key":
Key key = new Key(); Key key = new Key();
...@@ -511,7 +526,13 @@ public class ProvisionService { ...@@ -511,7 +526,13 @@ public class ProvisionService {
kvMap.put(name, Converter.ymlString2Map(value)); kvMap.put(name, Converter.ymlString2Map(value));
break; break;
} }
for (String nodeName : nodeNames) {
Map<String, Object> keyOutput = TOSCAUtils.buildTOSCAOutput(nodeName, p.getValue());
outputs.put(name, keyOutput);
}
} }
topologyTemplate.put("outputs", outputs);
List<String> userKeyIds = null; List<String> userKeyIds = null;
if (provisionRequest != null) { if (provisionRequest != null) {
userKeyIds = provisionRequest.getUserKeyPairIDs(); userKeyIds = provisionRequest.getUserKeyPairIDs();
...@@ -571,7 +592,8 @@ public class ProvisionService { ...@@ -571,7 +592,8 @@ public class ProvisionService {
// provisionResponse.setCloudKeyPairIDs(existingCloudKeyPairIDs); // provisionResponse.setCloudKeyPairIDs(existingCloudKeyPairIDs);
// provisionResponse.setDeployParameters(deployParameters); // provisionResponse.setDeployParameters(deployParameters);
provisionResponse.setKvMap(kvMap); // provisionResponse.setKvMap(kvMap);
provisionResponse.setKvMap(toscaPlan);
if (provisionRequest != null) { if (provisionRequest != null) {
// provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs()); // provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
provisionResponse.setPlanID(provisionRequest.getPlanID()); provisionResponse.setPlanID(provisionRequest.getPlanID());
......
/*
* Copyright 2019 S. Koulouzis
*
* 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.commons.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
*
* @author S. Koulouzis
*/
public class TOSCAUtils {
public static List<Map<String, Object>> getVMsFromTopology(Map<String, Object> toscaPlan) {
List<String> vmNames = getVMsNodeNamesFromTopology(toscaPlan);
Map<String, Object> topologyTemplate = (Map<String, Object>) toscaPlan.get("topology_template");
List<Map<String, Object>> vmList = new ArrayList<>();
for (String vmName : vmNames) {
Map<String, Object> vm = (Map<String, Object>) topologyTemplate.get(vmName);
// Map<String, Object> properties = (Map<String, Object>) vm.get("properties");
vmList.add(vm);
}
return vmList;
}
public static List<String> getVMsNodeNamesFromTopology(Map<String, Object> toscaPlan) {
Map<String, Object> topologyTemplate = (Map<String, Object>) toscaPlan.get("topology_template");
Map<String, Object> nodeTemplates = (Map<String, Object>) (topologyTemplate).get("node_templates");
Iterator it = nodeTemplates.entrySet().iterator();
List<String> vmNames = new ArrayList<>();
while (it.hasNext()) {
Map.Entry node = (Map.Entry) it.next();
Map<String, Object> nodeValue = (Map<String, Object>) node.getValue();
String type = (String) nodeValue.get("type");
if (type.equals("tosca.nodes.ARTICONF.VM.topology")) {
List<Map<String, Object>> requirements = (List<Map<String, Object>>) nodeValue.get("requirements");
for (Map<String, Object> req : requirements) {
Map.Entry<String, Object> requirementEntry = req.entrySet().iterator().next();
String nodeName = (String) ((Map<String, Object>) req.get(requirementEntry.getKey())).get("node");
vmNames.add(nodeName);
}
}
}
return vmNames;
}
public static Map<String, Object> buildTOSCAOutput(String nodeName, String value) {
Map<String, Object> output = new HashMap();
Map<String, Object> outputValue = new HashMap();
List<String> att = new ArrayList<>();
att.add(nodeName);
att.add(value);
outputValue.put("get_attribute", att);
output.put("value", outputValue);
return output;
}
}
...@@ -57,7 +57,7 @@ public class P2PConverter { ...@@ -57,7 +57,7 @@ public class P2PConverter {
break; break;
} }
} }
List<Object> vmList = new ArrayList<>(); List<Map<String, Object>> vmList = new ArrayList<>();
for (String vmName : vmNames) { for (String vmName : vmNames) {
Map<String, Object> vm = (Map<String, Object>) topologyTemplate.get(vmName); Map<String, Object> vm = (Map<String, Object>) topologyTemplate.get(vmName);
Map<String, Object> properties = (Map<String, Object>) vm.get("properties"); Map<String, Object> properties = (Map<String, Object>) vm.get("properties");
......
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error"> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change beforePath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" />
......
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