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

Fxed conf and certificate bugs

parent 8e2940de
...@@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.dao.ToscaDao; import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.rpc.DRIPCaller; import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller; import nl.uva.sne.drip.api.rpc.ProvisionerCaller;
import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.types.CloudCredentials; import nl.uva.sne.drip.commons.types.CloudCredentials;
import nl.uva.sne.drip.commons.types.LoginKey; import nl.uva.sne.drip.commons.types.LoginKey;
...@@ -70,6 +71,8 @@ public class PlannerController { ...@@ -70,6 +71,8 @@ public class PlannerController {
@Autowired @Autowired
private CloudCredentialsDao cloudCredentialsDao; private CloudCredentialsDao cloudCredentialsDao;
// @Autowired
// PlannerService plannerService;
@RequestMapping(value = "/plan/{tosca_id}", method = RequestMethod.POST) @RequestMapping(value = "/plan/{tosca_id}", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody public @ResponseBody
...@@ -157,14 +160,13 @@ public class PlannerController { ...@@ -157,14 +160,13 @@ public class PlannerController {
} }
private Parameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException { private Parameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Parameter conf = new Parameter(); Parameter conf = null;
String charset = "UTF-8";
Properties prop = Converter.Object2Properties(cred); switch (cred.getCloudProviderName().toLowerCase()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); case "ec2":
prop.store(baos, null); conf = buildEC2Conf(cred);
byte[] bytes = baos.toByteArray(); break;
conf.setName("ec2.conf"); }
conf.setValue(new String(bytes, charset));
return conf; return conf;
} }
...@@ -212,4 +214,18 @@ public class PlannerController { ...@@ -212,4 +214,18 @@ public class PlannerController {
} }
return parameters; return parameters;
} }
private Parameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Properties prop = Converter.getEC2Properties(cred);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
prop.store(baos, null);
byte[] bytes = baos.toByteArray();
Parameter conf = new Parameter();
conf.setName("ec2.conf");
String charset = "UTF-8";
conf.setValue(new String(bytes, charset));
return conf;
}
} }
/*
* 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.api.service;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class PlannerService {
}
...@@ -19,11 +19,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; ...@@ -19,11 +19,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -35,6 +37,8 @@ import org.yaml.snakeyaml.Yaml; ...@@ -35,6 +37,8 @@ import org.yaml.snakeyaml.Yaml;
*/ */
public class Converter { public class Converter {
private static Map<String, String> EC2_NAME_MAP = new HashMap();
public static String ymlString2Json(String yamlString) { public static String ymlString2Json(String yamlString) {
JSONObject jsonObject = new JSONObject(ymlString2Map(yamlString)); JSONObject jsonObject = new JSONObject(ymlString2Map(yamlString));
return jsonObject.toString(); return jsonObject.toString();
...@@ -110,4 +114,27 @@ public class Converter { ...@@ -110,4 +114,27 @@ public class Converter {
return Property.toProperties(new JSONObject(jsonInString)); return Property.toProperties(new JSONObject(jsonInString));
} }
public static Properties getEC2Properties(CloudCredentials cred) throws JsonProcessingException, JSONException {
Properties prop = Object2Properties(cred);
Enumeration<String> names = (Enumeration<String>) prop.propertyNames();
Properties ec2Props = new Properties();
if (EC2_NAME_MAP.isEmpty()) {
initEC2_NAME_MAP();
}
while (names.hasMoreElements()) {
String name = names.nextElement();
String ec2Name = EC2_NAME_MAP.get(name);
if (ec2Name != null) {
ec2Props.setProperty(ec2Name, prop.getProperty(name));
}
}
return ec2Props;
}
private static void initEC2_NAME_MAP() {
EC2_NAME_MAP.put("keyIdAlias", "AWSAccessKeyId");
EC2_NAME_MAP.put("key", "AWSSecretKey");
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<artifactId>drip</artifactId> <artifactId>drip</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>drip-provisioner</artifactId> <artifactId>drip-provisioner</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
......
...@@ -23,6 +23,7 @@ import java.io.BufferedReader; ...@@ -23,6 +23,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
...@@ -32,6 +33,7 @@ import java.nio.file.Files; ...@@ -32,6 +33,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -55,8 +57,10 @@ public class Consumer extends DefaultConsumer { ...@@ -55,8 +57,10 @@ public class Consumer extends DefaultConsumer {
private final Channel channel; private final Channel channel;
private final String propertiesPath = "etc/consumer.properties"; private final String propertiesPath = "etc/consumer.properties";
// private String jarFilePath;
Map<String, String> em = new HashMap<String, String>();
// private String jarFilePath;
public class topologyElement { public class topologyElement {
String topologyName = ""; String topologyName = "";
...@@ -77,6 +81,18 @@ public class Consumer extends DefaultConsumer { ...@@ -77,6 +81,18 @@ public class Consumer extends DefaultConsumer {
// } else { // } else {
// jarFilePath = jarFile.getAbsolutePath(); // jarFilePath = jarFile.getAbsolutePath();
// } // }
em.put("Virginia", "ec2.us-east-1.amazonaws.com");
em.put("California", "ec2.us-west-1.amazonaws.com");
em.put("Oregon", "ec2.us-west-2.amazonaws.com");
em.put("Mumbai", "ec2.ap-south-1.amazonaws.com");
em.put("Singapore", "ec2.ap-southeast-1.amazonaws.com");
em.put("Seoul", "ec2.ap-northeast-2.amazonaws.com");
em.put("Sydney", "ec2.ap-southeast-2.amazonaws.com");
em.put("Tokyo", "ec2.ap-northeast-1.amazonaws.com");
em.put("Frankfurt", "ec2.eu-central-1.amazonaws.com");
em.put("Ireland", "ec2.eu-west-1.amazonaws.com");
em.put("Paulo", "ec2.sa-east-1.amazonaws.com");
} }
@Override @Override
...@@ -128,6 +144,7 @@ public class Consumer extends DefaultConsumer { ...@@ -128,6 +144,7 @@ public class Consumer extends DefaultConsumer {
//loop through the parameters in a message to find the input files //loop through the parameters in a message to find the input files
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();
for (int i = 0; i < parameters.length(); i++) { for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i); JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get(Parameter.NAME); String name = (String) param.get(Parameter.NAME);
...@@ -187,8 +204,9 @@ public class Consumer extends DefaultConsumer { ...@@ -187,8 +204,9 @@ public class Consumer extends DefaultConsumer {
} }
} else if (name.equals("certificate")) { } else if (name.equals("certificate")) {
JSONObject attribute = param.getJSONObject("attributes"); JSONObject attribute = param.getJSONObject("attributes");
String fileName = (String) attribute.get("filename"); ////This file name does not contain suffix of '.yml' for example String fileName = (String) attribute.get("filename");
File certificate = new File(tempInputDirPath + fileName + ".pem"); certificateNames.add(fileName);
File certificate = new File(tempInputDirPath + File.separator + fileName + ".pem");
if (certificate.createNewFile()) { if (certificate.createNewFile()) {
writeValueToFile((String) param.get(Parameter.VALUE), certificate); writeValueToFile((String) param.get(Parameter.VALUE), certificate);
} }
...@@ -235,9 +253,30 @@ public class Consumer extends DefaultConsumer { ...@@ -235,9 +253,30 @@ public class Consumer extends DefaultConsumer {
String geniConfFilePath = "null"; String geniConfFilePath = "null";
if (ec2ConfFile != null) { if (ec2ConfFile != null) {
ec2ConfFilePath = ec2ConfFile.getAbsolutePath(); ec2ConfFilePath = ec2ConfFile.getAbsolutePath();
Properties prop = new Properties();
prop.load(new FileInputStream(ec2ConfFile));
StringBuilder supportDomains = new StringBuilder();
String prefix = "";
for (String certName : certificateNames) {
String supported = this.em.get(certName);
if (supported != null) {
supportDomains.append(prefix);
prefix = ", ";
supportDomains.append(supported);
}
}
prop.setProperty("KeyDir", tempInputDirPath);
prop.setProperty("SupportDomains", supportDomains.toString());
prop.store(new FileOutputStream(ec2ConfFile), null);
} }
if (geniConfFile != null) { if (geniConfFile != null) {
geniConfFilePath = geniConfFile.getAbsolutePath(); geniConfFilePath = geniConfFile.getAbsolutePath();
Properties prop = new Properties();
prop.load(new FileInputStream(geniConfFile));
prop.propertyNames();
prop.setProperty("KeyDir", tempInputDirPath);
prop.store(new FileOutputStream(geniConfFile), null);
} }
if (logDir.equals("null")) { if (logDir.equals("null")) {
logDir = System.getProperty("java.io.tmpdir"); logDir = System.getProperty("java.io.tmpdir");
......
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