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

add credentials to TOSCA

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