Commit a9cb2403 authored by Spiros Koulouzis's avatar Spiros Koulouzis

move plan creation to provisioner

parent 2bcce877
...@@ -106,6 +106,9 @@ node_types: ...@@ -106,6 +106,9 @@ node_types:
os: os:
type: string type: string
required: true required: true
ssh_key:
type: string
required: false
interfaces: interfaces:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
...@@ -134,7 +137,10 @@ node_types: ...@@ -134,7 +137,10 @@ node_types:
required: true required: true
domain: domain:
type: string type: string
required: true required: true
credential:
type: tosca.datatypes.Credential
required: false
interfaces: interfaces:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
......
...@@ -95,34 +95,19 @@ public class PlannerService { ...@@ -95,34 +95,19 @@ public class PlannerService {
for (MessageParameter mp : messageParams) { for (MessageParameter mp : messageParams) {
String value = mp.getValue(); String value = mp.getValue();
toscaPlan = new String(Base64.getDecoder().decode(value)); toscaPlan = new String(Base64.getDecoder().decode(value));
logger.log(Level.INFO, "TOSCA Plann: "+toscaPlan); logger.log(Level.INFO, "TOSCA Plann: " + toscaPlan);
}
// String domainName = getBestDomain(cloudProvider);
SimplePlanContainer simplePlan = P2PConverter.transfer(toscaPlan, null, null, null);
PlanResponse topLevel = new PlanResponse();
topLevel.setLevel(0);
topLevel.setToscaID(toscaId);
topLevel.setName("planner_output_all.yml");
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.topLevelContents));
Map<String, String> map = simplePlan.lowerLevelContents;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (String lowLevelNames : map.keySet()) {
PlanResponse lowLevelPlan = new PlanResponse();
lowLevelPlan.setLevel(1);
lowLevelPlan.setToscaID(toscaId);
lowLevelPlan.setName(lowLevelNames);
lowLevelPlan.setKvMap(Converter.ymlString2Map(map.get(lowLevelNames)));
save(lowLevelPlan);
loweLevelPlansIDs.add(lowLevelPlan.getId());
} }
Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
// SimplePlanContainer simplePlan = P2PConverter.transfer(toscaPlanMap, null, null, null);
PlanResponse planResponse = new PlanResponse();
planResponse.setToscaID(toscaId);
planResponse.setKvMap(toscaPlanMap);
topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs); save(planResponse);
save(topLevel);
logger.log(Level.INFO, "Plan saved"); logger.log(Level.INFO, "Plan saved");
return topLevel; return planResponse;
} }
} }
...@@ -167,16 +152,6 @@ public class PlannerService { ...@@ -167,16 +152,6 @@ public class PlannerService {
} }
Map<String, Object> map = plan.getKeyValue(); Map<String, Object> map = plan.getKeyValue();
Set<String> ids = plan.getLoweLevelPlanIDs();
if (ids != null) {
for (String lowID : ids) {
PlanResponse ll = findOne(lowID);
Map<String, Object> lowLevelMap = ll.getKeyValue();
if (lowLevelMap != null) {
map.put(ll.getName(), lowLevelMap);
}
}
}
if (fromat != null && fromat.equals("yml")) { if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map); String ymlStr = Converter.map2YmlString(map);
...@@ -200,13 +175,7 @@ public class PlannerService { ...@@ -200,13 +175,7 @@ public class PlannerService {
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<PlanResponse> findAll() { public List<PlanResponse> findAll() {
List<PlanResponse> all = planDao.findAll(); List<PlanResponse> all = planDao.findAll();
List<PlanResponse> topLevel = new ArrayList<>(); return all;
for (PlanResponse p : all) {
if (p.getLevel() == 0) {
topLevel.add(p);
}
}
return topLevel;
} }
public PlanResponse save(PlanResponse ownedObject) { public PlanResponse save(PlanResponse ownedObject) {
...@@ -251,8 +220,6 @@ public class PlannerService { ...@@ -251,8 +220,6 @@ public class PlannerService {
Map<String, Object> map = Converter.cleanStringContents(ymlContents, true); Map<String, Object> map = Converter.cleanStringContents(ymlContents, true);
PlanResponse pr = new PlanResponse(); PlanResponse pr = new PlanResponse();
pr.setKvMap(map); pr.setKvMap(map);
pr.setLevel(level);
pr.setName(name);
save(pr); save(pr);
return pr.getId(); return pr.getId();
} }
...@@ -283,7 +250,6 @@ public class PlannerService { ...@@ -283,7 +250,6 @@ public class PlannerService {
// List<CloudCredentials> creds = credentialService.findAll(); // List<CloudCredentials> creds = credentialService.findAll();
// return creds.get(0).getCloudProviderName().toUpperCase(); // return creds.get(0).getCloudProviderName().toUpperCase();
// } // }
// private String getBestDomain(String cloudProvider) { // private String getBestDomain(String cloudProvider) {
// switch (cloudProvider.trim().toLowerCase()) { // switch (cloudProvider.trim().toLowerCase()) {
// case "ec2": // case "ec2":
...@@ -295,5 +261,4 @@ public class PlannerService { ...@@ -295,5 +261,4 @@ public class PlannerService {
// } // }
// return null; // return null;
// } // }
} }
...@@ -78,14 +78,14 @@ public class SimplePlannerService { ...@@ -78,14 +78,14 @@ public class SimplePlannerService {
String originalFileName = p.getName(); String originalFileName = p.getName();
String name = System.currentTimeMillis() + "_" + originalFileName; String name = System.currentTimeMillis() + "_" + originalFileName;
if (originalFileName.equals("planner_output_all.yml")) { if (originalFileName.equals("planner_output_all.yml")) {
topLevel.setName(name); // topLevel.setName(name);
topLevel.setLevel(0); // topLevel.setLevel(0);
topLevel.setKvMap(Converter.ymlString2Map(p.getValue())); topLevel.setKvMap(Converter.ymlString2Map(p.getValue()));
} else { } else {
lowerLevelPlan = new PlanResponse(); lowerLevelPlan = new PlanResponse();
lowerLevelPlan.setName(name); // lowerLevelPlan.setName(name);
lowerLevelPlan.setKvMap(Converter.ymlString2Map(p.getValue())); lowerLevelPlan.setKvMap(Converter.ymlString2Map(p.getValue()));
lowerLevelPlan.setLevel(1); // lowerLevelPlan.setLevel(1);
planDao.save(lowerLevelPlan); planDao.save(lowerLevelPlan);
ids.add(lowerLevelPlan.getId()); ids.add(lowerLevelPlan.getId());
} }
...@@ -166,12 +166,12 @@ public class SimplePlannerService { ...@@ -166,12 +166,12 @@ public class SimplePlannerService {
public List<PlanResponse> findAll() { public List<PlanResponse> findAll() {
List<PlanResponse> all = planDao.findAll(); List<PlanResponse> all = planDao.findAll();
List<PlanResponse> topLevel = new ArrayList<>(); // List<PlanResponse> topLevel = new ArrayList<>();
for (PlanResponse p : all) { // for (PlanResponse p : all) {
if (p.getLevel() == 0) { // if (p.getLevel() == 0) {
topLevel.add(p); // topLevel.add(p);
} // }
} // }
return topLevel; return all;
} }
} }
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.exception.NullKeyException;
import nl.uva.sne.drip.api.exception.NullKeyIDException;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v0.external.Configure;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
/**
*
* This controller is responsible for handling cloud credentials used by the
* provisoner to request for resources (VMs).
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/account/configure")
@Component
@Deprecated
public class CloudConfigurationController0 {
@Autowired
private CloudCredentialsService cloudCredentialsService;
@Autowired
private KeyPairService keyService;
@RequestMapping(value = "/ec2", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postEC2Conf(@RequestBody Configure configure) throws Exception {
if (configure.key == null) {
throw new NullKeyException();
}
if (configure.keyid == null) {
throw new NullKeyIDException();
}
CloudCredentials cloudCredentials = new CloudCredentials();
cloudCredentials.setAccessKeyId(configure.keyid);
cloudCredentials.setSecretKey(configure.key);
List<String> loginKeyIDs = new ArrayList<>();
for (nl.uva.sne.drip.drip.commons.data.v0.external.LoginKey0 key0 : configure.loginKey) {
try {
nl.uva.sne.drip.drip.commons.data.v1.external.Key key1 = new nl.uva.sne.drip.drip.commons.data.v1.external.Key();
KeyPair pair = new KeyPair();
key1.setKey(key0.content);
Map<String, String> attributes = new HashMap<>();
attributes.put("domain_name", key0.domain_name);
key1.setAttributes(attributes);
pair.setPrivateKey(key1);
pair = keyService.save(pair);
loginKeyIDs.add(pair.getId());
} catch (KeyException ex) {
Logger.getLogger(CloudConfigurationController0.class.getName()).log(Level.SEVERE, null, ex);
}
}
// cloudCredentials.setKeyIDs(loginKeyIDs);
cloudCredentials.setCloudProviderName("ec2");
cloudCredentials = cloudCredentialsService.save(cloudCredentials);
return "Success: " + cloudCredentials.getId();
}
@RequestMapping(value = "/geni", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postGeniConf(@RequestBody Configure configure) throws Exception {
if (configure.geniKey == null) {
throw new NullKeyException();
}
if (configure.geniKeyAlias == null) {
throw new NullKeyIDException();
}
CloudCredentials cloudCredentials = new CloudCredentials();
// cloudCredentials.setKeyIdAlias(configure.geniKeyAlias);
cloudCredentials.setAccessKeyId(configure.geniKey);
cloudCredentials.setSecretKey(configure.geniKeyPass);
List<String> loginKeyIDs = new ArrayList<>();
for (nl.uva.sne.drip.drip.commons.data.v0.external.LoginKey0 key0 : configure.loginPubKey) {
try {
nl.uva.sne.drip.drip.commons.data.v1.external.Key key1 = new nl.uva.sne.drip.drip.commons.data.v1.external.Key();
key1.setKey(key0.content);
key1.setType(Key.KeyType.PUBLIC);
KeyPair pair = new KeyPair();
pair.setPublicKey(key1);
pair = keyService.save(pair);
loginKeyIDs.add(pair.getId());
} catch (KeyException ex) {
Logger.getLogger(CloudConfigurationController0.class.getName()).log(Level.SEVERE, null, ex);
}
}
for (nl.uva.sne.drip.drip.commons.data.v0.external.LoginKey0 key0 : configure.loginPriKey) {
try {
nl.uva.sne.drip.drip.commons.data.v1.external.Key key1 = new nl.uva.sne.drip.drip.commons.data.v1.external.Key();
key1.setKey(key0.content);
key1.setType(Key.KeyType.PRIVATE);
KeyPair pair = new KeyPair();
pair.setPrivateKey(key1);
pair = keyService.save(pair);
loginKeyIDs.add(pair.getId());
} catch (KeyException ex) {
Logger.getLogger(CloudConfigurationController0.class.getName()).log(Level.SEVERE, null, ex);
}
}
// cloudCredentials.setKeyIDs(loginKeyIDs);
cloudCredentials.setCloudProviderName("geni");
cloudCredentialsService.save(cloudCredentials);
return "Success: " + cloudCredentials.getId();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.DeployService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v0.external.Deploy;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Result;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for deploying a cluster on provisioned
* resources.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/deploy")
@Component
@PreAuthorize("isAuthenticated()")
@Deprecated
public class DeployController0 {
@Autowired
private DeployService deployService;
@RequestMapping(value = "/kubernetes", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result deployKubernetes(@RequestBody Deploy deploy) {
try {
DeployRequest deployReq = new DeployRequest();
deployReq.setManagerType("kubernetes");
deployReq.setProvisionID(deploy.action);
return deploy(deployReq);
} catch (Exception ex) {
Logger.getLogger(DeployController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@RequestMapping(value = "/swarm", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result deploySwarm(@RequestBody Deploy deploy) {
try {
DeployRequest deployReq = new DeployRequest();
deployReq.setManagerType("swarm");
deployReq.setProvisionID(deploy.action);
return deploy(deployReq);
} catch (Exception ex) {
Logger.getLogger(DeployController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
private Result deploy(DeployRequest deployReq) throws Exception {
DeployResponse key = deployService.deploySoftware(deployReq);
Result res = new Result();
res.info = "INFO";
res.status = "Success";
List<Attribute> files = new ArrayList<>();
Attribute attribute = new Attribute();
attribute.content = key.getKeyPair().getPrivateKey().getKey();
files.add(attribute);
res.file = files;
return res;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.drip.commons.data.v0.external.Result;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Plan;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for planning the type of resources to be
* provisioned based on a TOSCA description.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/plan")
@Component
@Deprecated
public class PlannerController0 {
@Autowired
private PlannerService plannerService;
@Autowired
private ToscaService toscaService;
@RequestMapping(value = "/planning", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result plan(@RequestBody Plan plan0) {
try {
String yaml = plan0.file;
yaml = yaml.replaceAll("\\\\n", "\n");
String id = toscaService.saveYamlString(yaml, null);
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id, null,-1);
Result r = new Result();
r.info = ("INFO");
r.status = ("Success");
List<Attribute> files = new ArrayList<>();
Attribute e = Converter.plan1toFile(plan1);
files.add(e);
for (String lowiID : plan1.getLoweLevelPlanIDs()) {
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse lowPlan1 = plannerService.findOne(lowiID);
e = Converter.plan1toFile(lowPlan1);
files.add(e);
//Don't save them cause they will be re-uploaded in the provision step
plannerService.delete(lowPlan1.getId());
}
r.file = files;
plannerService.delete(plan1.getId());
return r;
} catch (IOException | JSONException | TimeoutException | InterruptedException ex) {
Logger.getLogger(PlannerController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.io.IOException;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.commons.utils.Converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.ScriptService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v0.external.Execute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Result;
import nl.uva.sne.drip.drip.commons.data.v0.external.Upload;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for obtaining resources from cloud providers
* based the plan generated by the planner and uploaded by the user
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/provision")
@Component
@PreAuthorize("isAuthenticated()")
@Deprecated
public class ProvisionController0 {
@Autowired
private ScriptService userScriptService;
@Autowired
private KeyPairService userKeysService;
@Autowired
private CloudCredentialsService cloudCredentialsService;
@Autowired
private ProvisionService provisionService;
@Autowired
private PlannerService planService;
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String provision(@RequestBody Upload upload) {
ProvisionResponse resp = new ProvisionResponse();
CloudCredentials cloudCred = cloudCredentialsService.findAll().get(0);
String cloudCredID = cloudCred.getId();
List<String> idList = new ArrayList<>();
idList.add(cloudCredID);
resp.setCloudCredentialsIDs(idList);
List<nl.uva.sne.drip.drip.commons.data.v0.external.Attribute> plans = upload.file;
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse topLevelPlan = null;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (nl.uva.sne.drip.drip.commons.data.v0.external.Attribute p : plans) {
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = Converter.File2Plan1(p);
if (plan1.getLevel() == 0) {
topLevelPlan = plan1;
} else {
plan1 = planService.save(plan1);
loweLevelPlansIDs.add(plan1.getId());
}
}
topLevelPlan.setLoweLevelPlansIDs(loweLevelPlansIDs);
topLevelPlan = planService.save(topLevelPlan);
String planID = topLevelPlan.getId();
resp.setPlanID(planID);
List<KeyPair> allKeys = userKeysService.findAll();
List<String> keyPairIDs = new ArrayList<>();
if (allKeys != null && !allKeys.isEmpty()) {
for (KeyPair keyPair : allKeys) {
String userKeyID = keyPair.getId();
keyPairIDs.add(userKeyID);
}
resp.setUserKeyPairIDs(keyPairIDs);
}
resp = provisionService.save(resp);
return "Success: Infrastructure files are uploaded! Action number: "
+ resp.getId();
}
@RequestMapping(value = "/execute", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result execute(@RequestBody Execute exc) {
try {
ProvisionRequest req = provisionService.findOne(exc.action);
req = provisionService.provisionResources(req,0);
Map<String, Object> map = req.getKeyValue();
String yaml = Converter.map2YmlString(map);
yaml = yaml.replaceAll("\n", "\\\\n");
Result res = new Result();
List<Attribute> files = new ArrayList<>();
Attribute e = new Attribute();
e.content = yaml;
e.level = "0";
e.name = "provisioned_" + exc.action;
files.add(e);
res.info = "INFO";
res.status = "Success";
res.file = files;
return res;
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(ProvisionController0.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(ProvisionController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.PasswordNullException;
import nl.uva.sne.drip.api.exception.UserExistsException;
import nl.uva.sne.drip.api.exception.UserNullException;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v0.external.Register;
import org.springframework.http.MediaType;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for handling user accounts
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/manager/v0.0/switch/account")
@Component
@Deprecated
public class UserController0 {
@Autowired
private UserService service;
@RequestMapping(value = "/register", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.ADMIN})
public @ResponseBody
String register(@RequestBody Register register) {
if (register.user == null) {
throw new UserNullException();
}
if (register.pwd == null) {
throw new PasswordNullException();
}
UserDetails registeredUser = service.loadUserByUsername(register.user);
if (registeredUser != null) {
throw new UserExistsException("Username " + register.user + " is used");
}
User user = new User();
user.setUsername(register.user);
user.setAccountNonExpired(true);
user.setAccountNonLocked(true);
user.setEnabled(true);
user.setCredentialsNonExpired(true);
Collection<String> roles = new ArrayList<>();
roles.add("USER");
user.setRoles(roles);
user.setPassword(new BCryptPasswordEncoder().encode(register.pwd));
user = service.save(user);
return "Success: " + user.getId();
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.api.service.ProvisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v0.external.ConfUserKey;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for handling user public keys. These keys can
* be used by the provisoner to allow the user to login to the VMs from the
* machine the keys correspond to.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/provision")
@Component
@Deprecated
public class UserPublicKeysController0 {
@Autowired
private KeyPairService service;
@Autowired
private ProvisionService provisionService;
@RequestMapping(value = "/confuserkey", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserPublicKeys(@RequestBody ConfUserKey confUserKey) throws Exception {
try {
KeyPair pair = new KeyPair();
Key upk = new Key();
upk.setKey(confUserKey.file.get(0).content);
upk.setName(confUserKey.file.get(0).name);
upk.setType(Key.KeyType.PUBLIC);
pair.setPublicKey(upk);
pair = service.save(pair);
ProvisionResponse provPlan = provisionService.findOne(confUserKey.action);
List<String> keyPairIDs = new ArrayList<>();
keyPairIDs.add(pair.getId());
provPlan.setUserKeyPairIDs(keyPairIDs);
provisionService.save(provPlan);
return "Success: " + pair.getId();
} catch (KeyException ex) {
Logger.getLogger(UserPublicKeysController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v0.rest;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.service.ProvisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.ScriptService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v0.external.ConfScript;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* This controller is responsible for handling user scripts. These user can be
* used by the provisioner to run on the created VMs.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/provision")
@Component
@Deprecated
public class UserScriptController0 {
@Autowired
private ScriptService scriptService;
@RequestMapping(value = "/confscript", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserScript(@RequestBody ConfScript confScript) {
Script script = new Script();
script.setContents(confScript.script);
script = scriptService.save(script);
return "Success: script for GUI is uploaded: " + script.getId();
}
}
...@@ -185,9 +185,7 @@ public class PlannerController { ...@@ -185,9 +185,7 @@ public class PlannerController {
List<PlanResponse> all = plannerService.findAll(); List<PlanResponse> all = plannerService.findAll();
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (PlanResponse tr : all) { for (PlanResponse tr : all) {
if (tr.getLevel() == 0) { ids.add(tr.getId());
ids.add(tr.getId());
}
} }
return ids; return ids;
} }
......
...@@ -211,14 +211,14 @@ public class Converter { ...@@ -211,14 +211,14 @@ public class Converter {
public static Attribute plan1toFile(PlanResponse plan1) throws JSONException { public static Attribute plan1toFile(PlanResponse plan1) throws JSONException {
Attribute e = new Attribute(); Attribute e = new Attribute();
e.level = String.valueOf(plan1.getLevel()); // e.level = String.valueOf(plan1.getLevel());
String p1Name = FilenameUtils.getBaseName(plan1.getName()); // String p1Name = FilenameUtils.getBaseName(plan1.getName());
if (p1Name == null) { // if (p1Name == null) {
p1Name = "Planned_tosca_file_" + plan1.getLevel(); // p1Name = "Planned_tosca_file_" + plan1.getLevel();
plan1.setName(p1Name); // plan1.setName(p1Name);
} // }
e.name = p1Name; // e.name = p1Name;
String ymlString = Converter.map2YmlString(plan1.getKeyValue()); String ymlString = Converter.map2YmlString(plan1.getKeyValue());
e.content = ymlString.replaceAll("\n", "\\\\n"); e.content = ymlString.replaceAll("\n", "\\\\n");
return e; return e;
...@@ -226,8 +226,8 @@ public class Converter { ...@@ -226,8 +226,8 @@ public class Converter {
public static PlanResponse File2Plan1(Attribute p0) { public static PlanResponse File2Plan1(Attribute p0) {
PlanResponse p1 = new PlanResponse(); PlanResponse p1 = new PlanResponse();
p1.setLevel(Integer.valueOf(p0.level)); // p1.setLevel(Integer.valueOf(p0.level));
p1.setName(p0.name); // p1.setName(p0.name);
String yaml = p0.content.replaceAll("\\\\n", "\n"); String yaml = p0.content.replaceAll("\\\\n", "\n");
p1.setKvMap(ymlString2Map(yaml)); p1.setKvMap(ymlString2Map(yaml));
......
...@@ -38,23 +38,6 @@ public class PlanResponse extends KeyValueHolder { ...@@ -38,23 +38,6 @@ public class PlanResponse extends KeyValueHolder {
private Set<String> loweLevelPlansIDs; private Set<String> loweLevelPlansIDs;
/**
* The name of the generated plan
*
* @return the name
*/
@DocumentationExample("planner_output_all.yml")
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/** /**
* The id of the TOSCA <code>PlaybookRepresentation</code> description from * The id of the TOSCA <code>PlaybookRepresentation</code> description from
* which this plan was generated * which this plan was generated
...@@ -72,25 +55,7 @@ public class PlanResponse extends KeyValueHolder { ...@@ -72,25 +55,7 @@ public class PlanResponse extends KeyValueHolder {
public void setToscaID(String toscaID) { public void setToscaID(String toscaID) {
this.toscaID = toscaID; this.toscaID = toscaID;
} }
/**
* The level of the plan. Some provisioners use levels to represent a plan.
* In these cases there are two levels of TOSCA descriptions.
*
* @return the level
*/
@DocumentationExample("0")
public Integer getLevel() {
return level;
}
/**
* @param level the level to set
*/
public void setLevel(Integer level) {
this.level = level;
}
/** /**
* The list of the lower level plans attached to this plan. Some * The list of the lower level plans attached to this plan. Some
* provisioners use levels to represent a plan. In these cases there are two * provisioners use levels to represent a plan. In these cases there are two
......
...@@ -56,6 +56,7 @@ public class P2PConverter { ...@@ -56,6 +56,7 @@ public class P2PConverter {
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");
vm.put("name", vmName); vm.put("name", vmName);
vmList.add(vm); vmList.add(vm);
} }
...@@ -66,15 +67,15 @@ public class P2PConverter { ...@@ -66,15 +67,15 @@ public class P2PConverter {
topTopology.topologies = new ArrayList<>(); topTopology.topologies = new ArrayList<>();
boolean firstVM = true; boolean firstVM = true;
SubTopologyInfo sti = new SubTopologyInfo(); SubTopologyInfo subTopologyInfo = new SubTopologyInfo();
String provisionerScalingMode = "fixed"; String provisionerScalingMode = "fixed";
SubTopology subTopology = createSubTopology(cloudProvider); SubTopology subTopology = createSubTopology(cloudProvider);
sti.cloudProvider = cloudProvider; subTopologyInfo.cloudProvider = cloudProvider;
sti.topology = UUID.randomUUID().toString(); subTopologyInfo.topology = UUID.randomUUID().toString();
sti.domain = domainName; subTopologyInfo.domain = domainName;
sti.status = "fresh"; subTopologyInfo.status = "fresh";
sti.statusInfo = null; subTopologyInfo.statusInfo = null;
sti.tag = provisionerScalingMode; subTopologyInfo.tag = provisionerScalingMode;
Map<String, SubTopologyInfo> subTopologyInfos = new HashMap<>(); Map<String, SubTopologyInfo> subTopologyInfos = new HashMap<>();
for (Object element : vmList) { for (Object element : vmList) {
...@@ -82,20 +83,20 @@ public class P2PConverter { ...@@ -82,20 +83,20 @@ public class P2PConverter {
firstVM = false; firstVM = false;
if (isScalable(element)) { if (isScalable(element)) {
sti = new SubTopologyInfo(); subTopologyInfo = new SubTopologyInfo();
subTopology = createSubTopology(cloudProvider); subTopology = createSubTopology(cloudProvider);
provisionerScalingMode = "scaling"; provisionerScalingMode = "scaling";
sti.cloudProvider = cloudProvider; subTopologyInfo.cloudProvider = cloudProvider;
sti.topology = UUID.randomUUID().toString(); subTopologyInfo.topology = UUID.randomUUID().toString();
sti.domain = domainName; subTopologyInfo.domain = domainName;
sti.status = "fresh"; subTopologyInfo.status = "fresh";
sti.tag = provisionerScalingMode; subTopologyInfo.tag = provisionerScalingMode;
sti.statusInfo = null; subTopologyInfo.statusInfo = null;
} else { } else {
for (SubTopologyInfo info : subTopologyInfos.values()) { for (SubTopologyInfo info : subTopologyInfos.values()) {
if (!info.tag.equals("scaling")) { if (!info.tag.equals("scaling")) {
sti = info; subTopologyInfo = info;
subTopology = sti.subTopology; subTopology = subTopologyInfo.subTopology;
break; break;
} }
} }
...@@ -109,8 +110,8 @@ public class P2PConverter { ...@@ -109,8 +110,8 @@ public class P2PConverter {
subTopology.subnets = new ArrayList<>(); subTopology.subnets = new ArrayList<>();
subTopology.subnets.add(s); subTopology.subnets.add(s);
} }
sti.subTopology = subTopology; subTopologyInfo.subTopology = subTopology;
subTopologyInfos.put(sti.topology, sti); subTopologyInfos.put(subTopologyInfo.topology, subTopologyInfo);
} }
for (SubTopologyInfo info : subTopologyInfos.values()) { for (SubTopologyInfo info : subTopologyInfos.values()) {
topTopology.topologies.add(info); topTopology.topologies.add(info);
...@@ -128,7 +129,7 @@ public class P2PConverter { ...@@ -128,7 +129,7 @@ public class P2PConverter {
String yamlString = mapper.writeValueAsString(topTopology); String yamlString = mapper.writeValueAsString(topTopology);
spc.topLevelContents = yamlString.substring(4); spc.topLevelContents = yamlString.substring(4);
Map<String, String> output = new HashMap<>(); Map<String, Object> output = new HashMap<>();
for (int i = 0; i < topTopology.topologies.size(); i++) { for (int i = 0; i < topTopology.topologies.size(); i++) {
String key = topTopology.topologies.get(i).topology; String key = topTopology.topologies.get(i).topology;
String value = mapper.writeValueAsString(topTopology.topologies.get(i).subTopology); String value = mapper.writeValueAsString(topTopology.topologies.get(i).subTopology);
......
...@@ -5,6 +5,6 @@ import java.util.Map; ...@@ -5,6 +5,6 @@ import java.util.Map;
public class SimplePlanContainer { public class SimplePlanContainer {
public String topLevelContents; public String topLevelContents;
public Map<String, String> lowerLevelContents; public Map<String, Object> lowerLevelContents;
} }
...@@ -102,7 +102,13 @@ ...@@ -102,7 +102,13 @@
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId> <artifactId>logback-access</artifactId>
<version>${ch.qos.logback.version}</version> <version>${ch.qos.logback.version}</version>
</dependency> </dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies> </dependencies>
......
...@@ -70,11 +70,11 @@ public class RPCServer { ...@@ -70,11 +70,11 @@ public class RPCServer {
//We define the queue name //We define the queue name
channel.queueDeclare(PropertyValues.RPC_QUEUE_NAME, false, false, false, null); channel.queueDeclare(PropertyValues.RPC_QUEUE_NAME, false, false, false, null);
DefaultConsumer c; DefaultConsumer c;
if (PropertyValues.RPC_QUEUE_NAME.endsWith("v0")) { // if (PropertyValues.RPC_QUEUE_NAME.endsWith("v0")) {
c = new nl.uva.sne.drip.drip.provisioner.v0.Consumer(channel); // c = new nl.uva.sne.drip.drip.provisioner.v0.Consumer(channel);
} else { // } else {
c = new nl.uva.sne.drip.drip.provisioner.v1.Consumer(channel, PropertyValues.HOST); c = new nl.uva.sne.drip.drip.provisioner.v1.Consumer(channel, PropertyValues.HOST);
} // }
//Start listening for messages //Start listening for messages
channel.basicConsume(PropertyValues.RPC_QUEUE_NAME, false, c); channel.basicConsume(PropertyValues.RPC_QUEUE_NAME, false, c);
......
...@@ -27,13 +27,18 @@ import java.security.cert.CertificateEncodingException; ...@@ -27,13 +27,18 @@ import java.security.cert.CertificateEncodingException;
import java.util.ArrayList; 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.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import nl.uva.sne.drip.commons.utils.AAUtils; import nl.uva.sne.drip.commons.utils.AAUtils;
import nl.uva.sne.drip.commons.utils.AAUtils.SOURCE; import nl.uva.sne.drip.commons.utils.AAUtils.SOURCE;
import static nl.uva.sne.drip.commons.utils.AAUtils.downloadCACertificates; import static nl.uva.sne.drip.commons.utils.AAUtils.downloadCACertificates;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter; import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials; import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
//import org.globus.myproxy.MyProxyException; //import org.globus.myproxy.MyProxyException;
import org.ietf.jgss.GSSException; import org.ietf.jgss.GSSException;
...@@ -51,6 +56,7 @@ import provisioning.credential.ExoGENICredential; ...@@ -51,6 +56,7 @@ import provisioning.credential.ExoGENICredential;
* @author S. Koulouzis * @author S. Koulouzis
*/ */
public class MessageParsing { public class MessageParsing {
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 {
List<File> topologyFiles = new ArrayList<>(); List<File> topologyFiles = new ArrayList<>();
...@@ -58,23 +64,35 @@ public class MessageParsing { ...@@ -58,23 +64,35 @@ public class MessageParsing {
JSONObject param = (JSONObject) parameters.get(i); JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get("name"); String name = (String) param.get("name");
if (name.equals("topology")) { if (name.equals("topology")) {
JSONObject attributes = param.getJSONObject("attributes"); String toscaPlan = new String(Base64.getDecoder().decode((String) param.get("value")));
int fileLevel = Integer.valueOf((String) attributes.get("level")); Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
if (fileLevel == level) {
String originalFilename = (String) attributes.get("filename");
String fileName = originalFilename; if (level == 0) {
if (!fileName.endsWith(".yml")) { simplePlan = P2PConverter.transfer(toscaPlanMap, null, null, null);
fileName += ".yml"; String fileName = "planner_output_all.yml";
}
File topologyFile = new File(tempInputDirPath + File.separator + fileName); File topologyFile = new File(tempInputDirPath + File.separator + fileName);
topologyFile.createNewFile(); topologyFile.createNewFile();
String val = (String) param.get("value"); writeValueToFile(simplePlan.topLevelContents, topologyFile);
writeValueToFile(val, topologyFile);
topologyFiles.add(topologyFile); topologyFiles.add(topologyFile);
//We should have only one top level topoloy //We should have only one top level topoloy
if (level == 0) { // if (level == 0) {
return topologyFiles; return topologyFiles;
// }
} else {
Set<String> keys = simplePlan.lowerLevelContents.keySet();
for (String key : keys) {
String fileName = key;
if (!fileName.endsWith(".yml")) {
fileName += ".yml";
}
File topologyFile = new File(tempInputDirPath + File.separator + fileName);
topologyFile.createNewFile();
String topologyContents = (String) simplePlan.lowerLevelContents.get(key);
writeValueToFile(topologyContents, topologyFile);
topologyFiles.add(topologyFile);
} }
} }
} }
} }
......
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