Commit 8e2940de authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added cloud certs in the message

parent 8f0cfc5f
...@@ -108,7 +108,6 @@ public class PlannerController { ...@@ -108,7 +108,6 @@ public class PlannerController {
return null; return null;
} }
private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException, IOException { private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException, IOException {
ToscaRepresentation t2 = dao.findOne(toscaId); ToscaRepresentation t2 = dao.findOne(toscaId);
Map<String, Object> map = t2.getKvMap(); Map<String, Object> map = t2.getKvMap();
...@@ -141,26 +140,56 @@ public class PlannerController { ...@@ -141,26 +140,56 @@ public class PlannerController {
private Message buildProvisionerMessage(Message plannerReturnedMessage, String cloudConfID) throws IOException, JsonProcessingException, JSONException { private Message buildProvisionerMessage(Message plannerReturnedMessage, String cloudConfID) throws IOException, JsonProcessingException, JSONException {
Message invokationMessage = new Message(); Message invokationMessage = new Message();
List<Parameter> parameters = new ArrayList(); List<Parameter> parameters = new ArrayList();
CloudCredentials cred = cloudCredentialsDao.findOne(cloudConfID);
Parameter conf = buildCloudConfParam(cred);
parameters.add(conf);
List<Parameter> certs = buildCertificatesParam(cred);
parameters.addAll(certs);
List<Parameter> topologies = buildTopologyParams(plannerReturnedMessage);
parameters.addAll(topologies);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
}
private Parameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Parameter conf = new Parameter(); Parameter conf = new Parameter();
String charset = "UTF-8"; String charset = "UTF-8";
CloudCredentials cred = cloudCredentialsDao.findOne(cloudConfID);
Properties prop = Converter.Object2Properties(cred); Properties prop = Converter.Object2Properties(cred);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
prop.store(baos, null); prop.store(baos, null);
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
conf.setName("ec2.conf"); conf.setName("ec2.conf");
conf.setValue(new String(bytes, charset)); conf.setValue(new String(bytes, charset));
parameters.add(conf); return conf;
}
private List<Parameter> buildCertificatesParam(CloudCredentials cred) {
List<LoginKey> loginKeys = cred.getLogineKys(); List<LoginKey> loginKeys = cred.getLogineKys();
for(LoginKey lk : loginKeys){ List<Parameter> parameters = new ArrayList<>();
for (LoginKey lk : loginKeys) {
String domainName = lk.getAttributes().get("domain_name"); String domainName = lk.getAttributes().get("domain_name");
if (domainName == null) {
domainName = lk.getAttributes().get("domain_name ");
}
Parameter cert = new Parameter(); Parameter cert = new Parameter();
cert.setName("certificate"); cert.setName("certificate");
cert.setValue(charset); cert.setValue(lk.getKey());
Map<String, String> attributes = new HashMap<>();
attributes.put("filename", domainName);
cert.setAttributes(attributes);
parameters.add(cert);
}
return parameters;
} }
private List<Parameter> buildTopologyParams(Message plannerReturnedMessage) {
List<Parameter> returnedParams = plannerReturnedMessage.getParameters(); List<Parameter> returnedParams = plannerReturnedMessage.getParameters();
List<Parameter> parameters = new ArrayList();
for (Parameter param : returnedParams) { for (Parameter param : returnedParams) {
Parameter topology = new Parameter(); Parameter topology = new Parameter();
String name = param.getName(); String name = param.getName();
...@@ -181,9 +210,6 @@ public class PlannerController { ...@@ -181,9 +210,6 @@ public class PlannerController {
} }
parameters.add(topology); parameters.add(topology);
} }
return parameters;
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
} }
} }
...@@ -160,11 +160,9 @@ public class Consumer extends DefaultConsumer { ...@@ -160,11 +160,9 @@ public class Consumer extends DefaultConsumer {
int fileLevel = Integer.valueOf((String) attribute_level.get("level")); int fileLevel = Integer.valueOf((String) attribute_level.get("level"));
if (fileLevel == 0) /////if the file level is 0, it means that this is the top level description if (fileLevel == 0) /////if the file level is 0, it means that this is the top level description
{ {
File topologyFile = new File(tempInputDirPath + "topology_main"); File topologyFile = new File(tempInputDirPath + "topology_main");
if (topologyFile.createNewFile()) { if (topologyFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), topologyFile); writeValueToFile((String) param.get(Parameter.VALUE), topologyFile);
mainTopologyPath = topologyFile.getAbsolutePath(); mainTopologyPath = topologyFile.getAbsolutePath();
} else { } else {
return null; return null;
...@@ -187,6 +185,13 @@ public class Consumer extends DefaultConsumer { ...@@ -187,6 +185,13 @@ public class Consumer extends DefaultConsumer {
} }
} }
} else if (name.equals("certificate")) {
JSONObject attribute = param.getJSONObject("attributes");
String fileName = (String) attribute.get("filename"); ////This file name does not contain suffix of '.yml' for example
File certificate = new File(tempInputDirPath + fileName + ".pem");
if (certificate.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), certificate);
}
} else if (name.equals("logdir")) { } else if (name.equals("logdir")) {
logDir = (String) param.get(Parameter.VALUE); logDir = (String) param.get(Parameter.VALUE);
} else if (name.equals("sshkey")) { } else if (name.equals("sshkey")) {
......
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