Commit 446c8c13 authored by Spiros Koulouzis's avatar Spiros Koulouzis

add credentials to TOSCA

parent 03b20b8c
...@@ -153,7 +153,7 @@ public class ProvisionController { ...@@ -153,7 +153,7 @@ public class ProvisionController {
List<String> getIds() { List<String> getIds() {
List<ProvisionResponse> all = provisionService.findAll(); List<ProvisionResponse> all = provisionService.findAll();
List<String> ids = new ArrayList<>(all.size()); List<String> ids = new ArrayList<>(all.size());
for (ProvisionRequest pi : all) { for (ProvisionResponse pi : all) {
ids.add(pi.getId()); ids.add(pi.getId());
} }
return ids; return ids;
...@@ -181,9 +181,9 @@ public class ProvisionController { ...@@ -181,9 +181,9 @@ public class ProvisionController {
throw new BadRequestException(); throw new BadRequestException();
} }
try { try {
req = provisionService.provisionResources(req, 1); ProvisionResponse resp = provisionService.provisionResources(req, 1);
return req.getId(); return resp.getId();
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof nl.uva.sne.drip.api.exception.PlanNotFoundException if (ex instanceof nl.uva.sne.drip.api.exception.PlanNotFoundException
...@@ -210,16 +210,16 @@ public class ProvisionController { ...@@ -210,16 +210,16 @@ public class ProvisionController {
}) })
public @ResponseBody public @ResponseBody
String postProvisionResponse(@RequestBody ProvisionResponse resp) { String postProvisionResponse(@RequestBody ProvisionResponse resp) {
if (resp.getCloudCredentialsIDs() == null || resp.getCloudCredentialsIDs().get(0) == null // if (resp.getCloudCredentialsIDs() == null || resp.getCloudCredentialsIDs().get(0) == null
|| resp.getCloudCredentialsIDs().get(0).length() < 2) { // || resp.getCloudCredentialsIDs().get(0).length() < 2) {
throw new BadRequestException(); // throw new BadRequestException();
} // }
if (resp.getPlanID() == null || resp.getPlanID().length() < 2) { // if (resp.getPlanID() == null || resp.getPlanID().length() < 2) {
throw new BadRequestException(); // throw new BadRequestException();
} // }
if (resp.getDeployParameters() == null || resp.getDeployParameters().get(0) == null) { // if (resp.getDeployParameters() == null || resp.getDeployParameters().get(0) == null) {
throw new BadRequestException(); // throw new BadRequestException();
} // }
resp = provisionService.save(resp); resp = provisionService.save(resp);
return resp.getId(); return resp.getId();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package nl.uva.sne.drip.drip.commons.data.v1.external; package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -25,36 +26,55 @@ import java.util.List; ...@@ -25,36 +26,55 @@ import java.util.List;
* @author S. Koulouzis * @author S. Koulouzis
*/ */
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class ProvisionResponse extends ProvisionRequest { public class ProvisionResponse extends KeyValueHolder {
private List<DeployParameter> deployParameters; private String planID;
private ArrayList<String> cloudKeyPairIDs;
/**
/** * The ID of the plan <code>PlanResponse</code> to provision for.
* The deploy parameters.
* *
* @return the deployParameters * @return the planID
*/ */
public List<DeployParameter> getDeployParameters() { @DocumentationExample("ASedsfd46b4fDFd83ba1q")
return deployParameters; public String getPlanID() {
return planID;
} }
/** /**
* @param deployParameters the deployParameters to set * @param planID the planID to set
*/ */
public void setDeployParameters(List<DeployParameter> deployParameters) { public void setPlanID(String planID) {
this.deployParameters = deployParameters; this.planID = planID;
}
public void setCloudKeyPairIDs(ArrayList<String> cloudKeyPairIDs) {
this.cloudKeyPairIDs = cloudKeyPairIDs;
} }
/** // private List<DeployParameter> deployParameters;
* @return the cloudKeyPairIDs // private ArrayList<String> cloudKeyPairIDs;
*/ //
public ArrayList<String> getCloudKeyPairIDs() { // /**
return cloudKeyPairIDs; // * The deploy parameters.
} // *
// * @return the deployParameters
// */
// public List<DeployParameter> getDeployParameters() {
// return deployParameters;
// }
//
// /**
// * @param deployParameters the deployParameters to set
// */
// public void setDeployParameters(List<DeployParameter> deployParameters) {
// this.deployParameters = deployParameters;
// }
//
// public void setCloudKeyPairIDs(ArrayList<String> cloudKeyPairIDs) {
// this.cloudKeyPairIDs = cloudKeyPairIDs;
// }
//
// /**
// * @return the cloudKeyPairIDs
// */
// public ArrayList<String> getCloudKeyPairIDs() {
// return cloudKeyPairIDs;
// }
} }
...@@ -4,7 +4,6 @@ import java.io.IOException; ...@@ -4,7 +4,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
...@@ -25,24 +24,28 @@ import org.json.JSONException; ...@@ -25,24 +24,28 @@ import org.json.JSONException;
public class P2PConverter { public class P2PConverter {
public static SimplePlanContainer transfer( Map<String, Object> toscaPlanMap, public static SimplePlanContainer transfer(Map<String, Object> toscaPlanMap,
String userName, String domainName, String cloudProvider) throws JsonParseException, JsonMappingException, IOException, JSONException { String userName, String domainName, String cloudProvider) throws JsonParseException, JsonMappingException, IOException, JSONException {
if (cloudProvider != null) { if (cloudProvider != null) {
cloudProvider = cloudProvider.toUpperCase(); cloudProvider = cloudProvider.toUpperCase();
} }
Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaPlanMap.get("topology_template")).get("node_templates"); Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaPlanMap.get("topology_template")).get("node_templates");
//Get the domain provider and vm list //Get the domain provider and vm list
Map<String, Object> topologyNode = null;
String topologyNodeName = null;
List<String> vmNames = new ArrayList<>(); List<String> vmNames = new ArrayList<>();
for (Map.Entry<String, Object> entry : topologyTemplate.entrySet()) { for (Map.Entry<String, Object> entry : topologyTemplate.entrySet()) {
Map<String, Object> node = (Map<String, Object>) entry.getValue(); Map<String, Object> node = (Map<String, Object>) entry.getValue();
String type = (String) node.get("type"); String type = (String) node.get("type");
if (type.equals("tosca.nodes.ARTICONF.VM.topology")) { if (type.equals("tosca.nodes.ARTICONF.VM.topology")) {
Map<String, Object> properties = (Map<String, Object>) node.get("properties"); topologyNode = node;
topologyNodeName = entry.getKey();
Map<String, Object> properties = (Map<String, Object>) topologyNode.get("properties");
domainName = (String) properties.get("domain"); domainName = (String) properties.get("domain");
cloudProvider = (String) properties.get("provider"); cloudProvider = (String) properties.get("provider");
List<Object> requirements = (List<Object>) node.get("requirements"); List<Object> requirements = (List<Object>) topologyNode.get("requirements");
for (Object requirement : requirements) { for (Object requirement : requirements) {
Map<String, Object> requirementMap = (Map<String, Object>) requirement; Map<String, Object> requirementMap = (Map<String, Object>) requirement;
...@@ -51,13 +54,16 @@ public class P2PConverter { ...@@ -51,13 +54,16 @@ public class P2PConverter {
String nodeName = (String) ((Map<String, Object>) requirementMap.get(requirementEntry.getKey())).get("node"); String nodeName = (String) ((Map<String, Object>) requirementMap.get(requirementEntry.getKey())).get("node");
vmNames.add(nodeName); vmNames.add(nodeName);
} }
break;
} }
} }
List<Object> vmList = new ArrayList<>(); List<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);
userName = (String) ((Map<String, Object>)vm.get("properties")).get("user_name"); Map<String, Object> properties = (Map<String, Object>) vm.get("properties");
vm.put("name", vmName); userName = (String) properties.get("user_name");
String hostName = (String) properties.get("host_name");
vm.put("name", hostName);
vmList.add(vm); vmList.add(vm);
} }
...@@ -71,23 +77,24 @@ public class P2PConverter { ...@@ -71,23 +77,24 @@ public class P2PConverter {
String provisionerScalingMode = "fixed"; String provisionerScalingMode = "fixed";
SubTopology subTopology = createSubTopology(cloudProvider); SubTopology subTopology = createSubTopology(cloudProvider);
subTopologyInfo.cloudProvider = cloudProvider; subTopologyInfo.cloudProvider = cloudProvider;
subTopologyInfo.topology = UUID.randomUUID().toString(); subTopologyInfo.topology = topologyNodeName.replaceAll("_", "");
subTopologyInfo.domain = domainName; subTopologyInfo.domain = domainName;
subTopologyInfo.status = "fresh"; subTopologyInfo.status = "fresh";
subTopologyInfo.statusInfo = null; subTopologyInfo.statusInfo = null;
subTopologyInfo.tag = provisionerScalingMode; subTopologyInfo.tag = provisionerScalingMode;
Map<String, SubTopologyInfo> subTopologyInfos = new HashMap<>(); Map<String, SubTopologyInfo> subTopologyInfos = new HashMap<>();
int counter = 0;
for (Object element : vmList) { for (Object element : vmList) {
VM vm = createVM(element, cloudProvider, firstVM); VM vm = createVM(element, cloudProvider, firstVM);
firstVM = false; firstVM = false;
counter++;
if (isScalable(element)) { if (isScalable(element)) {
subTopologyInfo = new SubTopologyInfo(); subTopologyInfo = new SubTopologyInfo();
subTopology = createSubTopology(cloudProvider); subTopology = createSubTopology(cloudProvider);
provisionerScalingMode = "scaling"; provisionerScalingMode = "scaling";
subTopologyInfo.cloudProvider = cloudProvider; subTopologyInfo.cloudProvider = cloudProvider;
subTopologyInfo.topology = UUID.randomUUID().toString(); subTopologyInfo.topology = "subTopology"+counter;
subTopologyInfo.domain = domainName; subTopologyInfo.domain = domainName;
subTopologyInfo.status = "fresh"; subTopologyInfo.status = "fresh";
subTopologyInfo.tag = provisionerScalingMode; subTopologyInfo.tag = provisionerScalingMode;
......
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