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

add credentials to TOSCA

parent 03b20b8c
......@@ -23,9 +23,11 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -133,64 +135,7 @@ public class ProvisionService {
return callProvisioner1(provisionRequest);
}
// private Message buildProvisioner0Message(ProvisionRequest pReq) throws JSONException, IOException {
// Message invokationMessage = new Message();
// List<MessageParameter> parameters = new ArrayList();
// CloudCredentials cred = cloudCredentialsService.findOne(pReq.getCloudCredentialsIDs().get(0));
// if (cred == null) {
// throw new CloudCredentialsNotFoundException();
// }
// MessageParameter conf = buildCloudCredentialParam(cred, 0).get(0);
// parameters.add(conf);
//
// List<MessageParameter> certs = buildCertificatesParam(cred);
// parameters.addAll(certs);
//
// List<MessageParameter> topologies = buildTopologyParams(pReq.getPlanID());
// parameters.addAll(topologies);
//
// List<String> userKeyIDs = pReq.getUserKeyPairIDs();
// if (userKeyIDs != null) {
// List<MessageParameter> userKeys = buildUserKeysParams(userKeyIDs.get(0), 0);
// parameters.addAll(userKeys);
// }
//
// invokationMessage.setParameters(parameters);
// invokationMessage.setCreationDate((System.currentTimeMillis()));
// return invokationMessage;
// }
private List<MessageParameter> buildCloudCredentialParam(CloudCredentials cred, int version) throws JsonProcessingException, JSONException, IOException {
List<MessageParameter> cloudCredentialParams = new ArrayList<>();
MessageParameter cloudCred = new MessageParameter();
cloudCred.setName("cloud_credential");
cloudCred.setEncoding("UTF-8");
List<KeyPair> keyPairs = new ArrayList<>();
// List<String> keyPairIds = cred.getkeyPairIDs();
// if (keyPairIds != null) {
// for (String id : cred.getkeyPairIDs()) {
// KeyPair pair = keyDao.findOne(id);
// keyPairs.add(pair);
// }
// cred.setKeyPairs(keyPairs);
// }
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
String jsonInString = mapper.writeValueAsString(cred);
cloudCred.setValue("\"" + jsonInString + "\"");
cloudCredentialParams.add(cloudCred);
return cloudCredentialParams;
}
private List<MessageParameter> buildTopologyParams(String planID) throws JSONException, FileNotFoundException {
PlanResponse plan = simplePlanService.getDao().findOne(planID);
private List<MessageParameter> buildTopologyParams(PlanResponse plan) throws JSONException, FileNotFoundException {
if (plan == null) {
throw new PlanNotFoundException();
}
......@@ -291,99 +236,11 @@ public class ProvisionService {
return parameters;
}
private List<MessageParameter> buildCloudKeyParams(ProvisionResponse provisionInfo) {
List<MessageParameter> parameters = new ArrayList();
List<String> ids = provisionInfo.getCloudKeyPairIDs();
if (ids != null) {
for (String id : ids) {
KeyPair pair = keyPairService.findOne(id);
MessageParameter param = new MessageParameter();
param.setName("private_cloud_key");
param.setValue(pair.getPrivateKey().getKey());
HashMap<String, String> attributes = new HashMap<>();
attributes.putAll(pair.getPrivateKey().getAttributes());
attributes.put("name", pair.getPrivateKey().getName());
attributes.put("key_pair_id", pair.getKeyPairId());
param.setAttributes(attributes);
parameters.add(param);
param = new MessageParameter();
param.setName("public_cloud_key");
param.setValue(pair.getPublicKey().getKey());
attributes = new HashMap<>();
attributes.putAll(pair.getPrivateKey().getAttributes());
attributes.put("name", pair.getPublicKey().getName());
attributes.put("key_pair_id", pair.getKeyPairId());
param.setAttributes(attributes);
parameters.add(param);
}
}
return parameters;
}
private MessageParameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Properties prop = Converter.getEC2Properties(cred);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
prop.store(baos, null);
byte[] bytes = baos.toByteArray();
MessageParameter conf = new MessageParameter();
conf.setName("ec2.conf");
String charset = "UTF-8";
conf.setValue(new String(bytes, charset));
return conf;
}
// private List<MessageParameter> buildScriptParams(String userScriptID) {
// Script script = userScriptService.findOne(userScriptID);
// if (script == null) {
// throw new BadRequestException("User script: " + userScriptID + " was not found");
// }
// List<MessageParameter> parameters = new ArrayList();
// MessageParameter scriptParameter = new MessageParameter();
// scriptParameter.setName("guiscript");
// scriptParameter.setValue(script.getContents());
// scriptParameter.setEncoding("UTF-8");
// parameters.add(scriptParameter);
// return parameters;
// }
private List<MessageParameter> buildUserKeysParams(String userKeyID, int version) {
KeyPair key = keyPairService.findOne(userKeyID);
if (key == null) {
throw new BadRequestException("User key: " + userKeyID + " was not found");
}
List<MessageParameter> parameters = new ArrayList();
MessageParameter keyParameter = new MessageParameter();
if (version == 0) {
keyParameter.setName("sshkey");
}
if (version == 1) {
keyParameter.setName("user_ssh_key");
}
keyParameter.setValue(key.getPublicKey().getKey());
keyParameter.setEncoding("UTF-8");
parameters.add(keyParameter);
return parameters;
}
@PostFilter("(hasRole('ROLE_ADMIN'))")
public void deleteAll() {
provisionDao.deleteAll();
}
// private ProvisionResponse callProvisioner0(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
// try (DRIPCaller provisioner = new ProvisionerCaller0(messageBrokerHost);) {
// Message provisionerInvokationMessage = buildProvisioner0Message(provisionRequest);
// provisionerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
// logger.info("Calling provisioner");
// Message response = (provisioner.call(provisionerInvokationMessage));
// logger.info("Got provisioner response");
// return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null, true, true);
// }
// }
private ProvisionResponse callProvisioner1(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisioner1Message(provisionRequest);
......@@ -485,100 +342,76 @@ public class ProvisionService {
action.setValue("start_topology");
parameters.add(action);
List<MessageParameter> topologies = buildTopologyParams(provisionRequest.getPlanID());
parameters.addAll(topologies);
List<String> userKeyIDs = provisionRequest.getUserKeyPairIDs();
if (userKeyIDs != null) {
for (String keyID : userKeyIDs) {
List<MessageParameter> userKeys = buildUserKeysParams(keyID, 1);
parameters.addAll(userKeys);
}
}
List<String> deployerKeys = provisionRequest.getDeployerKeyPairIDs();
if (userKeyIDs != null) {
for (String keyID : deployerKeys) {
List<MessageParameter> deplyMessageKey = buildDeployKeysParams(keyID);
parameters.addAll(deplyMessageKey);
}
}
for (String id : provisionRequest.getCloudCredentialsIDs()) {
CloudCredentials cred = cloudCredentialsService.findOne(id);
if (cred == null) {
throw new CloudCredentialsNotFoundException();
}
List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1);
parameters.addAll(cloudCredentialParams);
}
PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest);
List<MessageParameter> topologies = buildTopologyParams(plan);
parameters.addAll(topologies);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
}
private Message buildTopoplogyModificationMessage(ProvisionResponse provisionInfo, String actionName, Map<String, String> extraAttributes) throws JSONException, IOException {
Message invokationMessage = new Message();
List<MessageParameter> parameters = new ArrayList();
MessageParameter action = new MessageParameter();
action.setName("action");
action.setValue(actionName);
parameters.add(action);
List<MessageParameter> topologies = buildProvisionedTopologyParams(provisionInfo);
parameters.addAll(topologies);
List<MessageParameter> clusterKeys = buildClusterKeyParams(provisionInfo);
parameters.addAll(clusterKeys);
List<MessageParameter> userKeys = buildUserKeyParams(provisionInfo);
parameters.addAll(userKeys);
List<MessageParameter> cloudKeys = buildCloudKeyParams(provisionInfo);
parameters.addAll(cloudKeys);
for (String id : provisionInfo.getCloudCredentialsIDs()) {
CloudCredentials cred = cloudCredentialsService.findOne(id);
if (cred == null) {
throw new CloudCredentialsNotFoundException();
}
List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1);
parameters.addAll(cloudCredentialParams);
}
if (extraAttributes != null && extraAttributes.containsKey("scale_topology_name")) {
MessageParameter scale = new MessageParameter();
scale.setName("scale_topology_name");
scale.setValue(extraAttributes.get("scale_topology_name"));
Map<String, String> attributes = new HashMap<>();
attributes.put("number_of_instances", extraAttributes.get("number_of_instances"));
attributes.put("cloud_provider", extraAttributes.get("cloud_provider"));
attributes.put("domain", extraAttributes.get("domain"));
scale.setAttributes(attributes);
parameters.add(scale);
}
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate(System.currentTimeMillis());
return invokationMessage;
}
private List<MessageParameter> buildDeployKeysParams(String keyID) {
KeyPair key = keyPairService.findOne(keyID);
if (key == null) {
throw new BadRequestException("User key: " + keyID + " was not found");
}
List<MessageParameter> parameters = new ArrayList();
MessageParameter keyParameter = new MessageParameter();
keyParameter.setName("deployer_ssh_key");
keyParameter.setValue(key.getPublicKey().getKey());
keyParameter.setEncoding("UTF-8");
parameters.add(keyParameter);
return parameters;
// Message invokationMessage = new Message();
// List<MessageParameter> parameters = new ArrayList();
//
// MessageParameter action = new MessageParameter();
// action.setName("action");
// action.setValue(actionName);
// parameters.add(action);
//
// List<MessageParameter> topologies = buildProvisionedTopologyParams(provisionInfo);
// parameters.addAll(topologies);
//
// List<MessageParameter> clusterKeys = buildClusterKeyParams(provisionInfo);
// parameters.addAll(clusterKeys);
//
// List<MessageParameter> userKeys = buildUserKeyParams(provisionInfo);
// parameters.addAll(userKeys);
//
// List<MessageParameter> cloudKeys = buildCloudKeyParams(provisionInfo);
// parameters.addAll(cloudKeys);
//
//
// for (String id : provisionInfo.getCloudCredentialsIDs()) {
// CloudCredentials cred = cloudCredentialsService.findOne(id);
// if (cred == null) {
// throw new CloudCredentialsNotFoundException();
// }
//// List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1);
//// parameters.addAll(cloudCredentialParams);
// }
// if (extraAttributes != null && extraAttributes.containsKey("scale_topology_name")) {
// MessageParameter scale = new MessageParameter();
// scale.setName("scale_topology_name");
// scale.setValue(extraAttributes.get("scale_topology_name"));
// Map<String, String> attributes = new HashMap<>();
// attributes.put("number_of_instances", extraAttributes.get("number_of_instances"));
// attributes.put("cloud_provider", extraAttributes.get("cloud_provider"));
// attributes.put("domain", extraAttributes.get("domain"));
// scale.setAttributes(attributes);
// parameters.add(scale);
// }
// invokationMessage.setParameters(parameters);
// invokationMessage.setCreationDate(System.currentTimeMillis());
return null;
}
// private List<MessageParameter> buildDeployKeysParams(String keyID) {
// KeyPair key = keyPairService.findOne(keyID);
// if (key == null) {
// throw new BadRequestException("User key: " + keyID + " was not found");
// }
// List<MessageParameter> parameters = new ArrayList();
// MessageParameter keyParameter = new MessageParameter();
//
// keyParameter.setName("deployer_ssh_key");
//
// keyParameter.setValue(key.getPublicKey().getKey());
// keyParameter.setEncoding("UTF-8");
// parameters.add(keyParameter);
// return parameters;
// }
private ProvisionResponse parseCreateResourcesResponse(List<MessageParameter> parameters,
ProvisionRequest provisionRequest, ProvisionResponse provisionResponse, boolean saveUserKeys, boolean saveDeployerKeyI) throws Exception {
if (provisionResponse == null) {
......@@ -683,7 +516,7 @@ public class ProvisionService {
if (provisionRequest != null) {
userKeyIds = provisionRequest.getUserKeyPairIDs();
} else {
userKeyIds = provisionResponse.getUserKeyPairIDs();
// userKeyIds = provisionResponse.getUserKeyPairIDs();
}
if (saveUserKeys) {
......@@ -729,26 +562,26 @@ public class ProvisionService {
}
}
ArrayList<String> existingCloudKeyPairIDs = provisionResponse.getCloudKeyPairIDs();
if (existingCloudKeyPairIDs != null) {
existingCloudKeyPairIDs.addAll(cloudKeyPairIDs);
} else {
existingCloudKeyPairIDs = cloudKeyPairIDs;
}
provisionResponse.setCloudKeyPairIDs(existingCloudKeyPairIDs);
// ArrayList<String> existingCloudKeyPairIDs = provisionResponse.getCloudKeyPairIDs();
// if (existingCloudKeyPairIDs != null) {
// existingCloudKeyPairIDs.addAll(cloudKeyPairIDs);
// } else {
// existingCloudKeyPairIDs = cloudKeyPairIDs;
// }
// provisionResponse.setCloudKeyPairIDs(existingCloudKeyPairIDs);
provisionResponse.setDeployParameters(deployParameters);
// provisionResponse.setDeployParameters(deployParameters);
provisionResponse.setKvMap(kvMap);
if (provisionRequest != null) {
provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
// provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
provisionResponse.setPlanID(provisionRequest.getPlanID());
}
if (userKeyIds != null) {
provisionResponse.setUserKeyPairIDs(userKeyIds);
// provisionResponse.setUserKeyPairIDs(userKeyIds);
}
if (deployerKeyIds != null) {
provisionResponse.setDeployerKeyPairIDs(deployerKeyIds);
// provisionResponse.setDeployerKeyPairIDs(deployerKeyIds);
}
provisionResponse = save(provisionResponse);
......@@ -757,4 +590,38 @@ public class ProvisionService {
private void parseDeleteResourcesResponse(List<MessageParameter> parameters, ProvisionResponse provisionInfo) {
}
private PlanResponse addCloudCredentialsOnTOSCAPlan(ProvisionRequest provisionRequest) {
List<Map<String, Object>> credentials = new ArrayList<>();
for (String id : provisionRequest.getCloudCredentialsIDs()) {
CloudCredentials cred = cloudCredentialsService.findOne(id);
if (cred == null) {
throw new CloudCredentialsNotFoundException();
}
Map<String, Object> toscaCredential = new HashMap<>();
Map<String, Object> toscaCredentialProperties = new HashMap<>();
toscaCredentialProperties.put("token_type", "secretKey");
toscaCredentialProperties.put("token", cred.getSecretKey());
toscaCredentialProperties.put("accessKeyId", cred.getAccessKeyId());
toscaCredentialProperties.put("cloud_provider_name", cred.getCloudProviderName());
toscaCredentialProperties.put("attributes", cred.getAttributes());
toscaCredential.put("properties", toscaCredentialProperties);
credentials.add(toscaCredential);
}
PlanResponse plan = simplePlanService.getDao().findOne(provisionRequest.getPlanID());
Map<String, Object> toscaPlan = plan.getKeyValue();
Map<String, Object> nodeTemplates = (Map<String, Object>) ((Map<String, Object>) toscaPlan.get("topology_template")).get("node_templates");
Iterator it = nodeTemplates.entrySet().iterator();
while (it.hasNext()) {
Map.Entry node = (Map.Entry) it.next();
Map<String, Object> value = (Map<String, Object>) node.getValue();
String type = (String) value.get("type");
if (type.equals("tosca.nodes.ARTICONF.VM.topology")) {
Map<String, Object> properties = (Map<String, Object>) value.get("properties");
properties.put("credentials", credentials);
}
}
return plan;
}
}
......@@ -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;
......
......@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -56,6 +57,7 @@ import provisioning.credential.ExoGENICredential;
* @author S. Koulouzis
*/
public class MessageParsing {
private static SimplePlanContainer simplePlan;
public static List<File> getTopologies(JSONArray parameters, String tempInputDirPath, int level) throws JSONException, IOException {
......@@ -66,8 +68,7 @@ public class MessageParsing {
if (name.equals("topology")) {
String toscaPlan = new String(Base64.getDecoder().decode((String) param.get("value")));
Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
if (level == 0) {
simplePlan = P2PConverter.transfer(toscaPlanMap, null, null, null);
String fileName = "planner_output_all.yml";
......@@ -178,79 +179,82 @@ public class MessageParsing {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
MessageParameter messageParam = mapper.readValue(param.toString(), MessageParameter.class);
String name = messageParam.getName();
String value = messageParam.getValue();
if (name.equals("cloud_credential")) {
if (name.equals("topology")) {
Credential credential = null;
value = value.substring(1, value.length() - 1);
CloudCredentials cred = mapper.readValue(value, CloudCredentials.class);
if (cred.getCloudProviderName().toLowerCase().equals("ec2")) {
EC2Credential ec2 = new EC2Credential();
ec2.accessKey = cred.getAccessKeyId();
ec2.secretKey = cred.getSecretKey();
credential = ec2;
}
if (cred.getCloudProviderName().toLowerCase().equals("egi")) {
EGICredential egi = new EGICredential();
Map<String, Object> att = cred.getAttributes();
String trustedCertificatesURL = null;
if (att != null && att.containsKey("trustedCertificatesURL")) {
trustedCertificatesURL = (String) att.get("trustedCertificatesURL");
}
if (trustedCertificatesURL != null) {
downloadCACertificates(new URL(trustedCertificatesURL), PropertyValues.TRUSTED_CERTIFICATE_FOLDER);
} else {
downloadCACertificates(PropertyValues.CA_BUNDLE_URL, PropertyValues.TRUSTED_CERTIFICATE_FOLDER);
String toscaPlan = new String(Base64.getDecoder().decode((String) param.get("value")));
Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
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;
}
String myProxyEndpoint = null;
if (att != null && att.containsKey("myProxyEndpoint")) {
myProxyEndpoint = (String) att.get("myProxyEndpoint");
}
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();
ec2.accessKey = (String) toscaCredentialProperties.get("accessKeyId");
ec2.secretKey = (String) toscaCredentialProperties.get("token");
credential = ec2;
}
if (myProxyEndpoint != null) {
String[] myVOs = null;
List voNames = null;
if (att != null && att.containsKey("voms")) {
myVOs = ((String) att.get("voms")).split(",");
voNames = (List) Arrays.asList(myVOs);
if (cloudProviderName.toLowerCase().equals("egi")) {
EGICredential egi = new EGICredential();
Map<String, Object> att = (Map<String, Object>) toscaCredentialProperties.get("attributes");
String trustedCertificatesURL = null;
if (att != null && att.containsKey("trustedCertificatesURL")) {
trustedCertificatesURL = (String) att.get("trustedCertificatesURL");
}
if (trustedCertificatesURL != null) {
downloadCACertificates(new URL(trustedCertificatesURL), PropertyValues.TRUSTED_CERTIFICATE_FOLDER);
} else {
downloadCACertificates(PropertyValues.CA_BUNDLE_URL, PropertyValues.TRUSTED_CERTIFICATE_FOLDER);
}
String myProxyEndpoint = null;
if (att != null && att.containsKey("myProxyEndpoint")) {
myProxyEndpoint = (String) att.get("myProxyEndpoint");
}
if (myProxyEndpoint != null) {
String[] myVOs = null;
List voNames = null;
if (att != null && att.containsKey("voms")) {
myVOs = ((String) att.get("voms")).split(",");
voNames = (List) Arrays.asList(myVOs);
}
egi.proxyFilePath = AAUtils.generateProxy((String) toscaCredentialProperties.get("accessKeyId"), (String) toscaCredentialProperties.get("token"), SOURCE.MY_PROXY, myProxyEndpoint, voNames);
} else {
egi.proxyFilePath = AAUtils.generateProxy((String) toscaCredentialProperties.get("accessKeyId"), (String) toscaCredentialProperties.get("token"), SOURCE.PROXY_FILE, myProxyEndpoint, null);
}
egi.proxyFilePath = AAUtils.generateProxy(cred.getAccessKeyId(), cred.getSecretKey(), SOURCE.MY_PROXY, myProxyEndpoint, voNames);
} else {
egi.proxyFilePath = AAUtils.generateProxy(cred.getAccessKeyId(), cred.getSecretKey(), SOURCE.PROXY_FILE, myProxyEndpoint, null);
egi.trustedCertPath = PropertyValues.TRUSTED_CERTIFICATE_FOLDER;
credential = egi;
}
egi.trustedCertPath = PropertyValues.TRUSTED_CERTIFICATE_FOLDER;
credential = egi;
}
if (cred.getCloudProviderName().toLowerCase().equals("exogeni")) {
ExoGENICredential exoGeniCredential = new ExoGENICredential();
exoGeniCredential.keyAlias = cred.getAccessKeyId();
exoGeniCredential.keyPassword = cred.getSecretKey();
Map<String, Object> att = cred.getAttributes();
if (att != null && att.containsKey("keystore")) {
String javaKeyStoreEncoded = (String) att.get("keystore");
byte[] decoded = Base64.getDecoder().decode(javaKeyStoreEncoded);
File keyStoreFile = new File(tempInputDirPath + File.separator + "user.jks");
FileUtils.writeByteArrayToFile(keyStoreFile, decoded);
exoGeniCredential.userKeyPath = keyStoreFile.getAbsolutePath();
if (cloudProviderName.toLowerCase().equals("exogeni")) {
ExoGENICredential exoGeniCredential = new ExoGENICredential();
exoGeniCredential.keyAlias = (String) toscaCredentialProperties.get("accessKeyId");
exoGeniCredential.keyPassword = (String) toscaCredentialProperties.get("token");
Map<String, Object> att = (Map<String, Object>) toscaCredentialProperties.get("attributes");
if (att != null && att.containsKey("keystore")) {
String javaKeyStoreEncoded = (String) att.get("keystore");
byte[] decoded = Base64.getDecoder().decode(javaKeyStoreEncoded);
File keyStoreFile = new File(tempInputDirPath + File.separator + "user.jks");
FileUtils.writeByteArrayToFile(keyStoreFile, decoded);
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);
}
}
......
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