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 deploy parameters. * The ID of the plan <code>PlanResponse</code> to provision for.
* *
* @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) { // private List<DeployParameter> deployParameters;
this.cloudKeyPairIDs = cloudKeyPairIDs; // private ArrayList<String> cloudKeyPairIDs;
} //
// /**
/** // * The deploy parameters.
* @return the cloudKeyPairIDs // *
*/ // * @return the deployParameters
public ArrayList<String> getCloudKeyPairIDs() { // */
return cloudKeyPairIDs; // 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,7 +24,7 @@ import org.json.JSONException; ...@@ -25,7 +24,7 @@ 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();
...@@ -34,15 +33,19 @@ public class P2PConverter { ...@@ -34,15 +33,19 @@ public class P2PConverter {
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;
......
...@@ -28,6 +28,7 @@ import java.util.ArrayList; ...@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -56,6 +57,7 @@ import provisioning.credential.ExoGENICredential; ...@@ -56,6 +57,7 @@ import provisioning.credential.ExoGENICredential;
* @author S. Koulouzis * @author S. Koulouzis
*/ */
public class MessageParsing { public class MessageParsing {
private static SimplePlanContainer simplePlan; private static SimplePlanContainer simplePlan;
public static List<File> getTopologies(JSONArray parameters, String tempInputDirPath, int level) throws JSONException, IOException { public static List<File> getTopologies(JSONArray parameters, String tempInputDirPath, int level) throws JSONException, IOException {
...@@ -67,7 +69,6 @@ public class MessageParsing { ...@@ -67,7 +69,6 @@ public class MessageParsing {
String toscaPlan = new String(Base64.getDecoder().decode((String) param.get("value"))); String toscaPlan = new String(Base64.getDecoder().decode((String) param.get("value")));
Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan); Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
if (level == 0) { if (level == 0) {
simplePlan = P2PConverter.transfer(toscaPlanMap, null, null, null); simplePlan = P2PConverter.transfer(toscaPlanMap, null, null, null);
String fileName = "planner_output_all.yml"; String fileName = "planner_output_all.yml";
...@@ -178,22 +179,39 @@ public class MessageParsing { ...@@ -178,22 +179,39 @@ public class MessageParsing {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
MessageParameter messageParam = mapper.readValue(param.toString(), MessageParameter.class); MessageParameter messageParam = mapper.readValue(param.toString(), MessageParameter.class);
String name = messageParam.getName(); String name = messageParam.getName();
String value = messageParam.getValue();
if (name.equals("cloud_credential")) {
if (name.equals("topology")) {
Credential credential = null; Credential credential = null;
value = value.substring(1, value.length() - 1); String toscaPlan = new String(Base64.getDecoder().decode((String) param.get("value")));
CloudCredentials cred = mapper.readValue(value, CloudCredentials.class); Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
if (cred.getCloudProviderName().toLowerCase().equals("ec2")) { Map<String, Object> nodeTemplates = (Map<String, Object>) ((Map<String, Object>) toscaPlanMap.get("topology_template")).get("node_templates");
Iterator it = nodeTemplates.entrySet().iterator();
List<Map<String, Object>> toscaCredentialsList = new ArrayList<>();
while (it.hasNext()) {
Map.Entry node = (Map.Entry) it.next();
Map<String, Object> nodeValue = (Map<String, Object>) node.getValue();
String type = (String) nodeValue.get("type");
if (type.equals("tosca.nodes.ARTICONF.VM.topology")) {
Map<String, Object> properties = (Map<String, Object>) nodeValue.get("properties");
toscaCredentialsList = (List<Map<String, Object>>) properties.get("credentials");
break;
}
}
for (Map<String, Object> toscaCredential : toscaCredentialsList) {
Map<String, Object> toscaCredentialProperties = (Map<String, Object>) toscaCredential.get("properties");
String cloudProviderName = (String) toscaCredentialProperties.get("cloud_provider_name");
if (cloudProviderName.toLowerCase().equals("ec2")) {
EC2Credential ec2 = new EC2Credential(); EC2Credential ec2 = new EC2Credential();
ec2.accessKey = cred.getAccessKeyId(); ec2.accessKey = (String) toscaCredentialProperties.get("accessKeyId");
ec2.secretKey = cred.getSecretKey(); ec2.secretKey = (String) toscaCredentialProperties.get("token");
credential = ec2; credential = ec2;
} }
if (cred.getCloudProviderName().toLowerCase().equals("egi")) { if (cloudProviderName.toLowerCase().equals("egi")) {
EGICredential egi = new EGICredential(); EGICredential egi = new EGICredential();
Map<String, Object> att = cred.getAttributes(); Map<String, Object> att = (Map<String, Object>) toscaCredentialProperties.get("attributes");
String trustedCertificatesURL = null; String trustedCertificatesURL = null;
if (att != null && att.containsKey("trustedCertificatesURL")) { if (att != null && att.containsKey("trustedCertificatesURL")) {
trustedCertificatesURL = (String) att.get("trustedCertificatesURL"); trustedCertificatesURL = (String) att.get("trustedCertificatesURL");
...@@ -214,18 +232,18 @@ public class MessageParsing { ...@@ -214,18 +232,18 @@ public class MessageParsing {
myVOs = ((String) att.get("voms")).split(","); myVOs = ((String) att.get("voms")).split(",");
voNames = (List) Arrays.asList(myVOs); voNames = (List) Arrays.asList(myVOs);
} }
egi.proxyFilePath = AAUtils.generateProxy(cred.getAccessKeyId(), cred.getSecretKey(), SOURCE.MY_PROXY, myProxyEndpoint, voNames); egi.proxyFilePath = AAUtils.generateProxy((String) toscaCredentialProperties.get("accessKeyId"), (String) toscaCredentialProperties.get("token"), SOURCE.MY_PROXY, myProxyEndpoint, voNames);
} else { } else {
egi.proxyFilePath = AAUtils.generateProxy(cred.getAccessKeyId(), cred.getSecretKey(), SOURCE.PROXY_FILE, myProxyEndpoint, null); egi.proxyFilePath = AAUtils.generateProxy((String) toscaCredentialProperties.get("accessKeyId"), (String) toscaCredentialProperties.get("token"), SOURCE.PROXY_FILE, myProxyEndpoint, null);
} }
egi.trustedCertPath = PropertyValues.TRUSTED_CERTIFICATE_FOLDER; egi.trustedCertPath = PropertyValues.TRUSTED_CERTIFICATE_FOLDER;
credential = egi; credential = egi;
} }
if (cred.getCloudProviderName().toLowerCase().equals("exogeni")) { if (cloudProviderName.toLowerCase().equals("exogeni")) {
ExoGENICredential exoGeniCredential = new ExoGENICredential(); ExoGENICredential exoGeniCredential = new ExoGENICredential();
exoGeniCredential.keyAlias = cred.getAccessKeyId(); exoGeniCredential.keyAlias = (String) toscaCredentialProperties.get("accessKeyId");
exoGeniCredential.keyPassword = cred.getSecretKey(); exoGeniCredential.keyPassword = (String) toscaCredentialProperties.get("token");
Map<String, Object> att = cred.getAttributes(); Map<String, Object> att = (Map<String, Object>) toscaCredentialProperties.get("attributes");
if (att != null && att.containsKey("keystore")) { if (att != null && att.containsKey("keystore")) {
String javaKeyStoreEncoded = (String) att.get("keystore"); String javaKeyStoreEncoded = (String) att.get("keystore");
byte[] decoded = Base64.getDecoder().decode(javaKeyStoreEncoded); byte[] decoded = Base64.getDecoder().decode(javaKeyStoreEncoded);
...@@ -233,24 +251,10 @@ public class MessageParsing { ...@@ -233,24 +251,10 @@ public class MessageParsing {
FileUtils.writeByteArrayToFile(keyStoreFile, decoded); FileUtils.writeByteArrayToFile(keyStoreFile, decoded);
exoGeniCredential.userKeyPath = keyStoreFile.getAbsolutePath(); exoGeniCredential.userKeyPath = keyStoreFile.getAbsolutePath();
} }
credential = exoGeniCredential; credential = exoGeniCredential;
} }
}
// for (KeyPair pair : cred.getKeyPairs()) {
// if (pair != null) {
// File dir = new File(tempInputDirPath + File.separator + pair.getId());
// dir.mkdir();
// Key privateKey = pair.getPrivateKey();
// if (privateKey != null) {
// writeValueToFile(privateKey.getKey(), new File(dir.getAbsolutePath() + File.separator + privateKey.getName()));
// }
// Key publicKey = pair.getPublicKey();
// if (publicKey != null) {
// writeValueToFile(publicKey.getKey(), new File(dir.getAbsolutePath() + File.separator + publicKey.getName()));
// }
// }
// }
credentials.add(credential); credentials.add(credential);
} }
} }
......
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