Commit 7078e2a9 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Split parameter loop into separate gets. It's less efficient but we know...

Split parameter loop into separate gets. It's less efficient but we know exactly when to get a parameter
parent b8af4915
...@@ -39,6 +39,7 @@ import java.util.Properties; ...@@ -39,6 +39,7 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.Parameter; import nl.uva.sne.drip.commons.types.Parameter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -58,6 +59,50 @@ public class Consumer extends DefaultConsumer { ...@@ -58,6 +59,50 @@ public class Consumer extends DefaultConsumer {
Map<String, String> em = new HashMap<String, String>(); Map<String, String> em = new HashMap<String, String>();
private File getCloudConfigurationFile(JSONArray parameters, String tempInputDirPath) throws JSONException {
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get(Parameter.NAME);
if (name.equals("ec2.conf") || name.equals("geni.conf")) {
try {
File confFile = new File(tempInputDirPath + File.separator + name);
if (confFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), confFile);
return confFile;
} else {
return null;
}
} catch (IOException e) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, e);
return null;
}
}
}
return null;
}
private File getTopology(JSONArray parameters, String tempInputDirPath, int level) throws JSONException, IOException {
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get(Parameter.NAME);
if (name.equals("topology")) {
JSONObject attributes = param.getJSONObject("attributes");
int fileLevel = Integer.valueOf((String) attributes.get("level"));
String fileName = (String) attributes.get("filename");
if (fileLevel == level) {
File topologyFile = new File(tempInputDirPath + File.separator + fileName);
if (topologyFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), topologyFile);
return topologyFile;
} else {
return null;
}
}
}
}
return null;
}
// private String jarFilePath; // private String jarFilePath;
public class topologyElement { public class topologyElement {
...@@ -143,64 +188,88 @@ public class Consumer extends DefaultConsumer { ...@@ -143,64 +188,88 @@ public class Consumer extends DefaultConsumer {
String logDir = "null", mainTopologyPath = "null", sshKeyFilePath = "null", scriptPath = "null"; String logDir = "null", mainTopologyPath = "null", sshKeyFilePath = "null", scriptPath = "null";
ArrayList<topologyElement> topologyInfoArray = new ArrayList(); ArrayList<topologyElement> topologyInfoArray = new ArrayList();
List<String> certificateNames = new ArrayList(); List<String> certificateNames = new ArrayList();
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i); File cloudConfFile = getCloudConfigurationFile(parameters, tempInputDirPath);
String name = (String) param.get(Parameter.NAME); if (cloudConfFile.getName().toLowerCase().contains("ec2")) {
if (name.equals("ec2.conf")) { ec2ConfFile = cloudConfFile;
try { } else if (cloudConfFile.getName().toLowerCase().contains("geni")) {
ec2ConfFile = new File(tempInputDirPath + "ec2.Conf"); geniConfFile = cloudConfFile;
if (ec2ConfFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), ec2ConfFile);
} else {
return null;
}
} catch (IOException e) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, e);
return null;
}
} else if (name.equals("geni.conf")) {
try {
geniConfFile = new File(tempInputDirPath + "geni.Conf");
if (geniConfFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), geniConfFile);
} else {
return null;
}
} catch (IOException ex) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
} else if (name.equals("topology")) {
JSONObject attribute_level = param.getJSONObject("attributes");
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
{
File topologyFile = new File(tempInputDirPath + "topology_main");
if (topologyFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), topologyFile);
mainTopologyPath = topologyFile.getAbsolutePath();
} else {
return null;
} }
} else if (fileLevel == 1) { ////this means that this file is the low level detailed description File topologyFile = getTopology(parameters, tempInputDirPath, 0);
String fileName = (String) attribute_level.get("filename"); ////This file name does not contain suffix of '.yml' for example File mainTopologyFile = new File(tempInputDirPath + "topology_main");
File topologyFile = new File(tempInputDirPath + fileName + ".yml"); FileUtils.moveFile(topologyFile, mainTopologyFile);
String outputFilePath = tempInputDirPath + fileName + "_provisioned.yml"; mainTopologyPath = mainTopologyFile.getAbsolutePath();
if (topologyFile.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), topologyFile);
topologyFile = getTopology(parameters, tempInputDirPath, 1);
File secondaryTopologyFile = new File(tempInputDirPath + File.separator + topologyFile.getName() + ".yml");
String outputFilePath = tempInputDirPath + File.separator + topologyFile.getName() + "_provisioned.yml";
topologyElement x = new topologyElement(); topologyElement x = new topologyElement();
x.topologyName = fileName; x.topologyName = topologyFile.getName();
x.outputFilePath = outputFilePath; x.outputFilePath = outputFilePath;
topologyInfoArray.add(x); topologyInfoArray.add(x);
FileUtils.moveFile(topologyFile, secondaryTopologyFile);
} else { for (int i = 0; i < parameters.length(); i++) {
return null; JSONObject param = (JSONObject) parameters.get(i);
} String name = (String) param.get(Parameter.NAME);
// if (name.equals("ec2.conf")) {
} // try {
} else if (name.equals("certificate")) { // ec2ConfFile = new File(tempInputDirPath + "ec2.Conf");
// if (ec2ConfFile.createNewFile()) {
// writeValueToFile((String) param.get(Parameter.VALUE), ec2ConfFile);
// } else {
// return null;
// }
// } catch (IOException e) {
// Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, e);
// return null;
// }
// } else if (name.equals("geni.conf")) {
// try {
// geniConfFile = new File(tempInputDirPath + "geni.Conf");
// if (geniConfFile.createNewFile()) {
// writeValueToFile((String) param.get(Parameter.VALUE), geniConfFile);
// } else {
// return null;
// }
// } catch (IOException ex) {
// Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
// return null;
// }
// } else
// if (name.equals("topology")) {
// JSONObject attribute_level = param.getJSONObject("attributes");
// 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
// {
// topologyFile = new File(tempInputDirPath + "topology_main");
// if (topologyFile.createNewFile()) {
// writeValueToFile((String) param.get(Parameter.VALUE), topologyFile);
// mainTopologyPath = topologyFile.getAbsolutePath();
// } else {
// return null;
// }
//
// } else if (fileLevel == 1) { ////this means that this file is the low level detailed description
// String fileName = (String) attribute_level.get("filename"); ////This file name does not contain suffix of '.yml' for example
// topologyFile = new File(tempInputDirPath + fileName + ".yml");
// outputFilePath = tempInputDirPath + fileName + "_provisioned.yml";
// if (topologyFile.createNewFile()) {
// writeValueToFile((String) param.get(Parameter.VALUE), topologyFile);
//
// x = new topologyElement();
// x.topologyName = fileName;
// x.outputFilePath = outputFilePath;
// topologyInfoArray.add(x);
//
// } else {
// return null;
// }
//
// }
// } else
if (name.equals("certificate")) {
JSONObject attribute = param.getJSONObject("attributes"); JSONObject attribute = param.getJSONObject("attributes");
String fileName = (String) attribute.get("filename"); String fileName = (String) attribute.get("filename");
certificateNames.add(fileName); certificateNames.add(fileName);
...@@ -224,8 +293,6 @@ public class Consumer extends DefaultConsumer { ...@@ -224,8 +293,6 @@ public class Consumer extends DefaultConsumer {
writeValueToFile(scriptContent, scriptFile); writeValueToFile(scriptContent, scriptFile);
} }
scriptPath = tempInputDirPath + File.separator + "guiscipt.sh"; scriptPath = tempInputDirPath + File.separator + "guiscipt.sh";
} else {
return null;
} }
} }
...@@ -303,7 +370,7 @@ public class Consumer extends DefaultConsumer { ...@@ -303,7 +370,7 @@ public class Consumer extends DefaultConsumer {
// Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, e); // Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, e);
// } // }
topologyElement x = new topologyElement(); x = new topologyElement();
x.topologyName = "kubernetes"; x.topologyName = "kubernetes";
x.outputFilePath = tempInputDirPath + "file_kubernetes"; x.outputFilePath = tempInputDirPath + "file_kubernetes";
topologyInfoArray.add(x); topologyInfoArray.add(x);
......
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