Commit eaece803 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Fixed bug with ymal format

parent e6b13acf
......@@ -81,8 +81,8 @@ public class DeployController {
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
Message deployerInvokationMessage = buildDeployerMessage(provisionID, clusterType.toLowerCase());
// Message response = deployer.unmarshall(deployer.call(deployerInvokationMessage));
Message response = generateFakeResponse();
Message response = (deployer.call(deployerInvokationMessage));
// Message response = generateFakeResponse();
List<MessageParameter> params = response.getParameters();
ClusterCredentials clusterCred = new ClusterCredentials();
for (MessageParameter p : params) {
......@@ -105,7 +105,11 @@ public class DeployController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
ClusterCredentials get(@PathVariable("id") String id) {
return clusterCredentialService.getDao().findOne(id);
ClusterCredentials clusterC = clusterCredentialService.getDao().findOne(id);
if (clusterC == null) {
throw new NotFoundException();
}
return clusterC;
}
@RequestMapping(value = "/ids", method = RequestMethod.GET)
......@@ -134,6 +138,9 @@ public class DeployController {
private Message buildDeployerMessage(String provisionID, String clusterType) {
ProvisionInfo pro = provisionService.getDao().findOne(provisionID);
if (pro == null) {
throw new NotFoundException();
}
String cloudConfID = pro.getCloudConfID();
CloudCredentials cCred = cloudCredentialsDao.findOne(cloudConfID);
List<LoginKey> loginKeys = cCred.getLoginKeys();
......
......@@ -20,6 +20,7 @@ import nl.uva.sne.drip.commons.types.ProvisionInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -46,7 +47,6 @@ import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.CloudCredentialsNotFoundException;
import nl.uva.sne.drip.api.exception.ExceptionHandler;
import nl.uva.sne.drip.api.exception.InternalServerErrorException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.PlanNotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
......@@ -61,6 +61,7 @@ import nl.uva.sne.drip.commons.types.DeployParameter;
import nl.uva.sne.drip.commons.types.LoginKey;
import nl.uva.sne.drip.commons.types.Plan;
import nl.uva.sne.drip.commons.types.UserScript;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -131,10 +132,12 @@ public class ProvisionController {
Message provisionerInvokationMessage = buildProvisionerMessage(req);
Message response = (provisioner.call(provisionerInvokationMessage));
// Message response = generateFakeResponse();
// Message response = generateFakeResponse(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "doc" + File.separator + "json_samples" +
// File.separator + "ec2_provisioner_provisoned2.json");
List<MessageParameter> params = response.getParameters();
for (MessageParameter p : params) {
String name = p.getName();
if (name.toLowerCase().contains("exception")) {
......@@ -170,8 +173,8 @@ public class ProvisionController {
}
req.setDeployParameters(deployParameters);
}
provisionService.getDao().save(req);
}
provisionService.getDao().save(req);
return req.getId();
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
......@@ -321,23 +324,25 @@ public class ProvisionController {
}
private Message generateFakeResponse() throws IOException, TimeoutException, InterruptedException, JSONException {
String strResponse = "{\"creationDate\":1488368936945,\"parameters\":["
+ "{\"name\":\"f293ff03-4b82-49e2-871a-899aadf821ce\","
+ "\"encoding\":\"UTF-8\",\"value\":"
+ "\"publicKeyPath: /tmp/Input-4007028381500/user.pem\\nuserName: "
+ "zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, "
+ "netmask: 255.255.255.0}\\ncomponents:\\n- "
+ "name: faab6756-61b6-4800-bffa-ae9d859a9d6c\\n "
+ "type: Switch.nodes.Compute\\n nodetype: t2.medium\\n "
+ "OStype: Ubuntu 16.04\\n domain: ec2.us-east-1.amazonaws.com\\n "
+ "script: /tmp/Input-4007028381500/guiscipt.sh\\n "
+ "installation: null\\n role: master\\n "
+ "dockers: mogswitch/InputDistributor\\n "
+ "public_address: 54.144.0.91\\n instanceId: i-0e78cbf853328b820\\n "
+ "ethernet_port:\\n - {name: p1, subnet_name: s1, "
+ "address: 192.168.10.10}\\n- name: 1c75eedf-8497-46fe-aeb8-dab6a62154cb\\n "
+ "type: Switch.nodes.Compute\\n nodetype: t2.medium\\n OStype: Ubuntu 16.04\\n domain: ec2.us-east-1.amazonaws.com\\n script: /tmp/Input-4007028381500/guiscipt.sh\\n installation: null\\n role: slave\\n dockers: mogswitch/ProxyTranscoder\\n public_address: 34.207.254.160\\n instanceId: i-0a99ea18fcc77ed7a\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"54.144.0.91 ubuntu /tmp/Input-4007028381500/Virginia.pem master\\n34.207.254.160 ubuntu /tmp/Input-4007028381500/Virginia.pem slave\\n\"}]}";
private Message generateFakeResponse(String path) throws IOException, TimeoutException, InterruptedException, JSONException {
// String strResponse = "{\"creationDate\":1488368936945,\"parameters\":["
// + "{\"name\":\"f293ff03-4b82-49e2-871a-899aadf821ce\","
// + "\"encoding\":\"UTF-8\",\"value\":"
// + "\"publicKeyPath: /tmp/Input-4007028381500/user.pem\\nuserName: "
// + "zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, "
// + "netmask: 255.255.255.0}\\ncomponents:\\n- "
// + "name: faab6756-61b6-4800-bffa-ae9d859a9d6c\\n "
// + "type: Switch.nodes.Compute\\n nodetype: t2.medium\\n "
// + "OStype: Ubuntu 16.04\\n domain: ec2.us-east-1.amazonaws.com\\n "
// + "script: /tmp/Input-4007028381500/guiscipt.sh\\n "
// + "installation: null\\n role: master\\n "
// + "dockers: mogswitch/InputDistributor\\n "
// + "public_address: 54.144.0.91\\n instanceId: i-0e78cbf853328b820\\n "
// + "ethernet_port:\\n - {name: p1, subnet_name: s1, "
// + "address: 192.168.10.10}\\n- name: 1c75eedf-8497-46fe-aeb8-dab6a62154cb\\n "
// + "type: Switch.nodes.Compute\\n nodetype: t2.medium\\n OStype: Ubuntu 16.04\\n domain: ec2.us-east-1.amazonaws.com\\n script: /tmp/Input-4007028381500/guiscipt.sh\\n installation: null\\n role: slave\\n dockers: mogswitch/ProxyTranscoder\\n public_address: 34.207.254.160\\n instanceId: i-0a99ea18fcc77ed7a\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"54.144.0.91 ubuntu /tmp/Input-4007028381500/Virginia.pem master\\n34.207.254.160 ubuntu /tmp/Input-4007028381500/Virginia.pem slave\\n\"}]}";
// String strResponse = "{\"creationDate\":1488805337447,\"parameters\":[{\"name\":\"2e5dafb6-5a1c-4a66-9dca-5841f99ea735\",\"encoding\":\"UTF-8\",\"value\":\"publicKeyPath: /tmp/Input-11594765342486/user.pem\\nuserName: zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\\ncomponents:\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: master\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: slave\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem master\\n34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem slave\\n\"}]}";
String strResponse = FileUtils.readFileToString(new File(path));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
......
......@@ -122,8 +122,10 @@ public abstract class DRIPCaller implements AutoCloseable {
}
});
String resp = response.take();
String clean = resp.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
String clean = resp;
if (resp.contains("'null'")) {
clean = resp.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
}
if (clean.contains("\"value\":{\"")) {
return Converter.string2Message(clean);
}
......
......@@ -78,7 +78,7 @@ public class PlannerService {
}
jsonArrayString.append("]");
SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "zh9314", "Ubuntu 16.04", "swarm");
SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", "swarm");
Plan topLevel = new Plan();
topLevel.setLevel(0);
topLevel.setToscaID(toscaId);
......
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