Commit 21c571a1 authored by Spiros Koulouzis's avatar Spiros Koulouzis

try to attach outputs to TOSCA. Attach all keys to TOSCA outputs

parent 7f94f332
...@@ -420,12 +420,12 @@ public class ProvisionService { ...@@ -420,12 +420,12 @@ public class ProvisionService {
provisionResponse = new ProvisionResponse(); provisionResponse = new ProvisionResponse();
} }
Map<String, Object> kvMap = null; // Map<String, Object> kvMap = null;
KeyPair userKey = new KeyPair(); // KeyPair userKey = new KeyPair();
KeyPair deployerKey = new KeyPair(); // KeyPair deployerKey = new KeyPair();
Map<String, Key> privateCloudKeys = new HashMap<>(); // Map<String, Key> privateCloudKeys = new HashMap<>();
Map<String, Key> publicCloudKeys = new HashMap<>(); // Map<String, Key> publicCloudKeys = new HashMap<>();
PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest); PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest);
Map<String, Object> toscaPlan = plan.getKeyValue(); Map<String, Object> toscaPlan = plan.getKeyValue();
...@@ -442,94 +442,97 @@ public class ProvisionService { ...@@ -442,94 +442,97 @@ public class ProvisionService {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
throw ex; throw ex;
} }
switch (name) { if (name.equals("deploy_parameters")) {
case "deploy_parameters": String value = p.getValue();
String value = p.getValue(); String[] lines = value.split("\n");
String[] lines = value.split("\n"); if (value.length() < 2) {
if (value.length() < 2) { throw new Exception("Provision failed");
throw new Exception("Provision failed");
// this.deleteProvisionedResources(provisionResponse); // this.deleteProvisionedResources(provisionResponse);
} }
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
// DeployParameter deployParam = new DeployParameter(); // DeployParameter deployParam = new DeployParameter();
String[] parts = lines[i].split(" "); String[] parts = lines[i].split(" ");
String deployIP = parts[0]; String deployIP = parts[0];
String deployUser = parts[1]; String deployUser = parts[1];
// String deployCertPath = parts[2]; // String deployCertPath = parts[2];
// String cloudCertificateName = FilenameUtils.removeExtension(FilenameUtils.getBaseName(deployCertPath)); // String cloudCertificateName = FilenameUtils.removeExtension(FilenameUtils.getBaseName(deployCertPath));
String deployRole = parts[2]; String deployRole = parts[2];
String nodeName = nodeNames.get(i); String nodeName = nodeNames.get(i);
Map<String, Object> ipOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployIP); Map<String, Object> ipOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployIP);
Map<String, Object> roleOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployRole); Map<String, Object> roleOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployRole);
outputs.put("ip", ipOutput); outputs.put("ip", ipOutput);
outputs.put("role", roleOutput); outputs.put("role", roleOutput);
Map<String, Object> properties = (Map<String, Object>) vmList.get(i).get("properties"); Map<String, Object> properties = (Map<String, Object>) vmList.get(i).get("properties");
properties.put("user_name", deployUser); properties.put("user_name", deployUser);
} }
if (name.contains("_key")) {
break; for (String nodeName : nodeNames) {
case "public_user_key": Map<String, Object> keyOutput = TOSCAUtils.buildTOSCAOutput(nodeName, p.getValue());
Key key = new Key(); outputs.put(name, keyOutput);
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PUBLIC);
userKey.setPublicKey(key);
break;
case "private_user_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PRIVATE);
userKey.setPrivateKey(key);
break;
case "private_deployer_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PRIVATE);
deployerKey.setPrivateKey(key);
break;
case "public_deployer_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PUBLIC);
deployerKey.setPublicKey(key);
break;
case "public_cloud_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PUBLIC);
key.setAttributes(p.getAttributes());
publicCloudKeys.put(p.getAttributes().get("key_pair_id"), key);
break;
case "private_cloud_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PRIVATE);
key.setAttributes(p.getAttributes());
privateCloudKeys.put(p.getAttributes().get("key_pair_id"), key);
break;
default:
value = p.getValue();
if (kvMap == null) {
kvMap = new HashMap();
} }
kvMap.put(name, Converter.ymlString2Map(value)); }
break;
}
for (String nodeName : nodeNames) {
Map<String, Object> keyOutput = TOSCAUtils.buildTOSCAOutput(nodeName, p.getValue());
outputs.put(name, keyOutput);
} }
// switch (name) {
// case "deploy_parameters":
// break;
// case "public_user_key":
// Key key = new Key();
// key.setKey(p.getValue());
// key.setName(p.getAttributes().get("name"));
// key.setType(Key.KeyType.PUBLIC);
// userKey.setPublicKey(key);
// break;
// case "private_user_key":
// key = new Key();
// key.setKey(p.getValue());
// key.setName(p.getAttributes().get("name"));
// key.setType(Key.KeyType.PRIVATE);
// userKey.setPrivateKey(key);
// break;
// case "private_deployer_key":
// key = new Key();
// key.setKey(p.getValue());
// key.setName(p.getAttributes().get("name"));
// key.setType(Key.KeyType.PRIVATE);
// deployerKey.setPrivateKey(key);
// break;
// case "public_deployer_key":
// key = new Key();
// key.setKey(p.getValue());
// key.setName(p.getAttributes().get("name"));
// key.setType(Key.KeyType.PUBLIC);
// deployerKey.setPublicKey(key);
// break;
// case "public_cloud_key":
// key = new Key();
// key.setKey(p.getValue());
// key.setName(p.getAttributes().get("name"));
// key.setType(Key.KeyType.PUBLIC);
// key.setAttributes(p.getAttributes());
// publicCloudKeys.put(p.getAttributes().get("key_pair_id"), key);
// break;
//
// case "private_cloud_key":
// key = new Key();
// key.setKey(p.getValue());
// key.setName(p.getAttributes().get("name"));
// key.setType(Key.KeyType.PRIVATE);
// key.setAttributes(p.getAttributes());
// privateCloudKeys.put(p.getAttributes().get("key_pair_id"), key);
// break;
//
// default:
// value = p.getValue();
// if (kvMap == null) {
// kvMap = new HashMap();
// }
// kvMap.put(name, Converter.ymlString2Map(value));
// break;
// }
} }
topologyTemplate.put("outputs", outputs); topologyTemplate.put("outputs", outputs);
...@@ -540,49 +543,48 @@ public class ProvisionService { ...@@ -540,49 +543,48 @@ public class ProvisionService {
// userKeyIds = provisionResponse.getUserKeyPairIDs(); // userKeyIds = provisionResponse.getUserKeyPairIDs();
} }
if (saveUserKeys) { // if (saveUserKeys) {
if (userKeyIds != null && !userKeyIds.isEmpty()) { // if (userKeyIds != null && !userKeyIds.isEmpty()) {
} else { // } else {
userKeyIds = new ArrayList<>(); // userKeyIds = new ArrayList<>();
if (userKey.getPublicKey() != null) { // if (userKey.getPublicKey() != null) {
userKey = keyPairService.save(userKey); // userKey = keyPairService.save(userKey);
userKeyIds.add(userKey.getId()); // userKeyIds.add(userKey.getId());
} // }
} // }
} // }
ArrayList<String> deployerKeyIds = null; // ArrayList<String> deployerKeyIds = null;
if (saveDeployerKeyI) { // if (saveDeployerKeyI) {
deployerKeyIds = new ArrayList<>(); // deployerKeyIds = new ArrayList<>();
if (deployerKey.getPublicKey() != null) { // if (deployerKey.getPublicKey() != null) {
deployerKey = keyPairService.save(deployerKey); // deployerKey = keyPairService.save(deployerKey);
deployerKeyIds.add(deployerKey.getId()); // deployerKeyIds.add(deployerKey.getId());
} // }
} // }
// ArrayList<String> cloudKeyPairIDs = new ArrayList<>();
ArrayList<String> cloudKeyPairIDs = new ArrayList<>(); // List<KeyPair> allPirs = keyPairService.findAll();
List<KeyPair> allPirs = keyPairService.findAll(); // for (String id : publicCloudKeys.keySet()) {
for (String id : publicCloudKeys.keySet()) { // boolean save = true;
boolean save = true; // String key_pair_id = privateCloudKeys.get(id).getAttributes().get("key_pair_id");
String key_pair_id = privateCloudKeys.get(id).getAttributes().get("key_pair_id"); // for (KeyPair p : allPirs) {
for (KeyPair p : allPirs) { // Key pk = p.getPrivateKey();
Key pk = p.getPrivateKey(); // if (pk != null && pk.getAttributes() != null && pk.getAttributes().containsKey("key_pair_id")) {
if (pk != null && pk.getAttributes() != null && pk.getAttributes().containsKey("key_pair_id")) { // if (key_pair_id.equals(pk.getAttributes().get("key_pair_id"))) {
if (key_pair_id.equals(pk.getAttributes().get("key_pair_id"))) { // save = false;
save = false; // break;
break; // }
} // }
} // }
} // if (save) {
if (save) { // KeyPair cloudPair = new KeyPair();
KeyPair cloudPair = new KeyPair(); // cloudPair.setPrivateKey(privateCloudKeys.get(id));
cloudPair.setPrivateKey(privateCloudKeys.get(id)); // cloudPair.setPublicKey(publicCloudKeys.get(id));
cloudPair.setPublicKey(publicCloudKeys.get(id)); // cloudPair.setKeyPairId(id);
cloudPair.setKeyPairId(id); // cloudPair = keyPairService.save(cloudPair);
cloudPair = keyPairService.save(cloudPair); // cloudKeyPairIDs.add(cloudPair.getId());
cloudKeyPairIDs.add(cloudPair.getId()); // }
} //
// }
}
// ArrayList<String> existingCloudKeyPairIDs = provisionResponse.getCloudKeyPairIDs(); // ArrayList<String> existingCloudKeyPairIDs = provisionResponse.getCloudKeyPairIDs();
// if (existingCloudKeyPairIDs != null) { // if (existingCloudKeyPairIDs != null) {
// existingCloudKeyPairIDs.addAll(cloudKeyPairIDs); // existingCloudKeyPairIDs.addAll(cloudKeyPairIDs);
...@@ -594,17 +596,17 @@ public class ProvisionService { ...@@ -594,17 +596,17 @@ public class ProvisionService {
// provisionResponse.setDeployParameters(deployParameters); // provisionResponse.setDeployParameters(deployParameters);
// provisionResponse.setKvMap(kvMap); // provisionResponse.setKvMap(kvMap);
provisionResponse.setKvMap(toscaPlan); provisionResponse.setKvMap(toscaPlan);
if (provisionRequest != null) { // if (provisionRequest != null) {
// provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs()); //// provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
provisionResponse.setPlanID(provisionRequest.getPlanID()); // provisionResponse.setPlanID(provisionRequest.getPlanID());
} // }
//
if (userKeyIds != null) { // if (userKeyIds != null) {
// provisionResponse.setUserKeyPairIDs(userKeyIds); //// provisionResponse.setUserKeyPairIDs(userKeyIds);
} // }
if (deployerKeyIds != null) { // if (deployerKeyIds != null) {
// provisionResponse.setDeployerKeyPairIDs(deployerKeyIds); //// provisionResponse.setDeployerKeyPairIDs(deployerKeyIds);
} // }
provisionResponse = save(provisionResponse); provisionResponse = save(provisionResponse);
return provisionResponse; return provisionResponse;
......
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