Commit 4b613bd4 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added os in VM and modified P2PCovnerter for TOSCA

parent 7902a445
...@@ -102,7 +102,10 @@ node_types: ...@@ -102,7 +102,10 @@ node_types:
type: scalar-unit.size type: scalar-unit.size
required: true required: true
constraints: constraints:
- greater_or_equal: 0 MB - greater_or_equal: 0 MB
os:
type: string
required: true
interfaces: interfaces:
Standard: Standard:
create: dumy.yaml create: dumy.yaml
......
...@@ -50,6 +50,7 @@ import org.springframework.security.access.prepost.PostFilter; ...@@ -50,6 +50,7 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Base64;
/** /**
* *
...@@ -90,32 +91,35 @@ public class PlannerService { ...@@ -90,32 +91,35 @@ public class PlannerService {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
List<MessageParameter> messageParams = plannerReturnedMessage.getParameters(); List<MessageParameter> messageParams = plannerReturnedMessage.getParameters();
String toscaPlan = null;
for (MessageParameter mp : messageParams) { for (MessageParameter mp : messageParams) {
String value = mp.getValue(); String value = mp.getValue();
logger.log(Level.INFO, "value: "+value); toscaPlan = new String(Base64.getDecoder().decode(value));
logger.log(Level.INFO, "TOSCA Plann: "+toscaPlan);
} }
String domainName = getBestDomain(cloudProvider); // String domainName = getBestDomain(cloudProvider);
// SimplePlanContainer simplePlan = P2PConverter.transfer(jsonArrayString.toString(), "vm_user", domainName, cloudProvider); SimplePlanContainer simplePlan = P2PConverter.transfer(toscaPlan, null, null, null);
PlanResponse topLevel = new PlanResponse(); PlanResponse topLevel = new PlanResponse();
// topLevel.setLevel(0); topLevel.setLevel(0);
// topLevel.setToscaID(toscaId); topLevel.setToscaID(toscaId);
// topLevel.setName("planner_output_all.yml"); topLevel.setName("planner_output_all.yml");
// topLevel.setKvMap(Converter.ymlString2Map(simplePlan.topLevelContents)); topLevel.setKvMap(Converter.ymlString2Map(simplePlan.topLevelContents));
// Map<String, String> map = simplePlan.lowerLevelContents; Map<String, String> map = simplePlan.lowerLevelContents;
// Set<String> loweLevelPlansIDs = new HashSet<>(); Set<String> loweLevelPlansIDs = new HashSet<>();
// for (String lowLevelNames : map.keySet()) { for (String lowLevelNames : map.keySet()) {
// PlanResponse lowLevelPlan = new PlanResponse(); PlanResponse lowLevelPlan = new PlanResponse();
// lowLevelPlan.setLevel(1); lowLevelPlan.setLevel(1);
// lowLevelPlan.setToscaID(toscaId); lowLevelPlan.setToscaID(toscaId);
// lowLevelPlan.setName(lowLevelNames); lowLevelPlan.setName(lowLevelNames);
// lowLevelPlan.setKvMap(Converter.ymlString2Map(map.get(lowLevelNames))); lowLevelPlan.setKvMap(Converter.ymlString2Map(map.get(lowLevelNames)));
// save(lowLevelPlan); save(lowLevelPlan);
// loweLevelPlansIDs.add(lowLevelPlan.getId()); loweLevelPlansIDs.add(lowLevelPlan.getId());
// } }
//
// topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs); topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs);
save(topLevel); save(topLevel);
logger.log(Level.INFO, "Plan saved"); logger.log(Level.INFO, "Plan saved");
return topLevel; return topLevel;
...@@ -275,21 +279,21 @@ public class PlannerService { ...@@ -275,21 +279,21 @@ public class PlannerService {
return false; return false;
} }
private String getBestCloudProvider() { // private String getBestCloudProvider() {
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":
return "Frankfurt"; // return "Frankfurt";
case "egi": // case "egi":
return "CESNET"; // return "CESNET";
case "exogeni": // case "exogeni":
return "RENCI (Chapel Hill, NC USA) XO Rack"; // return "RENCI (Chapel Hill, NC USA) XO Rack";
} // }
return null; // return null;
} // }
} }
...@@ -25,10 +25,40 @@ import org.json.JSONException; ...@@ -25,10 +25,40 @@ import org.json.JSONException;
public class P2PConverter { public class P2PConverter {
public static SimplePlanContainer transfer(String plannerOutputJson, public static SimplePlanContainer transfer(String toscaPlan,
String userName, String domainName, String cloudProvider) throws JsonParseException, JsonMappingException, IOException, JSONException { String userName, String domainName, String cloudProvider) throws JsonParseException, JsonMappingException, IOException, JSONException {
cloudProvider = cloudProvider.toUpperCase(); if (cloudProvider != null) {
List<Object> vmList = Converter.jsonString2List(plannerOutputJson); cloudProvider = cloudProvider.toUpperCase();
}
Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaPlanMap.get("topology_template")).get("node_templates");
//Get the domain provider and vm list
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");
domainName = (String) properties.get("domain");
cloudProvider = (String) properties.get("provider");
List<Object> requirements = (List<Object>) node.get("requirements");
for (Object requirement : requirements) {
Map<String, Object> requirementMap = (Map<String, Object>) requirement;
Map.Entry<String, Object> requirementEntry = requirementMap.entrySet().iterator().next();
String nodeName = (String) ((Map<String, Object>) requirementMap.get(requirementEntry.getKey())).get("node");
vmNames.add(nodeName);
}
}
}
List<Object> vmList = new ArrayList<>();
for (String vmName : vmNames) {
Map<String, Object> vm = (Map<String, Object>) topologyTemplate.get(vmName);
vm.put("name", vmName);
vmList.add(vm);
}
TopTopology topTopology = new TopTopology(); TopTopology topTopology = new TopTopology();
topTopology.publicKeyPath = "name@id_rsa.pub"; topTopology.publicKeyPath = "name@id_rsa.pub";
...@@ -81,7 +111,6 @@ public class P2PConverter { ...@@ -81,7 +111,6 @@ public class P2PConverter {
} }
sti.subTopology = subTopology; sti.subTopology = subTopology;
subTopologyInfos.put(sti.topology, sti); subTopologyInfos.put(sti.topology, sti);
} }
for (SubTopologyInfo info : subTopologyInfos.values()) { for (SubTopologyInfo info : subTopologyInfos.values()) {
topTopology.topologies.add(info); topTopology.topologies.add(info);
...@@ -116,7 +145,7 @@ public class P2PConverter { ...@@ -116,7 +145,7 @@ public class P2PConverter {
Number memSize = Converter.castToNumber(map.get("mem_size")); Number memSize = Converter.castToNumber(map.get("mem_size"));
Number num_cpus = Converter.castToNumber(map.get("num_cpus")); Number num_cpus = Converter.castToNumber(map.get("num_cpus"));
if (num_cpus.intValue() >= 16 && memSize.intValue() >= 32) { if (num_cpus.intValue() >= 16 && memSize.intValue() >= 32000) {
size = 10; size = 10;
} }
return size; return size;
...@@ -175,7 +204,7 @@ public class P2PConverter { ...@@ -175,7 +204,7 @@ public class P2PConverter {
} }
if (size > 5 && size <= 10) { if (size > 5 && size <= 10) {
return "XOLarge"; return "XOLarge";
} }
default: default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider); Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
return null; return null;
...@@ -194,7 +223,7 @@ public class P2PConverter { ...@@ -194,7 +223,7 @@ public class P2PConverter {
break; break;
case "exogeni": case "exogeni":
curVM = new ExoGeniVM(); curVM = new ExoGeniVM();
break; break;
default: default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider); Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
return null; return null;
...@@ -210,10 +239,12 @@ public class P2PConverter { ...@@ -210,10 +239,12 @@ public class P2PConverter {
curVM.name = "node_vm"; curVM.name = "node_vm";
} }
curVM.type = (String) map.get("type"); curVM.type = (String) map.get("type");
curVM.OStype = ((Map<String, String>) map.get("os")).get("distribution") + " " + ((Map<String, Double>) map.get("os")).get("os_version"); Map<String, String> properties = (Map<String, String>) map.get("properties");
curVM.OStype = (String) properties.get("os");
// curVM.clusterType = clusterType; // curVM.clusterType = clusterType;
// curVM.dockers = curValue.getDocker(); // curVM.dockers = curValue.getDocker();
curVM.nodeType = getSize((Map<String, String>) map.get("host"), cloudProvider); curVM.nodeType = getSize(properties, cloudProvider);
// Eth eth = new Eth(); // Eth eth = new Eth();
// eth.name = "p1"; // eth.name = "p1";
...@@ -246,7 +277,7 @@ public class P2PConverter { ...@@ -246,7 +277,7 @@ public class P2PConverter {
case "exogeni": case "exogeni":
subTopology = new ExoGeniSubTopology(); subTopology = new ExoGeniSubTopology();
((ExoGeniSubTopology) subTopology).components = new ArrayList<>(); ((ExoGeniSubTopology) subTopology).components = new ArrayList<>();
break; break;
default: default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider); Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
return null; return null;
...@@ -264,7 +295,7 @@ public class P2PConverter { ...@@ -264,7 +295,7 @@ public class P2PConverter {
break; break;
case "exogeni": case "exogeni":
((ExoGeniSubTopology) subTopology).components.add((ExoGeniVM) vm); ((ExoGeniSubTopology) subTopology).components.add((ExoGeniVM) vm);
break; break;
default: default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider); Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
// return null; // return null;
...@@ -285,6 +316,6 @@ public class P2PConverter { ...@@ -285,6 +316,6 @@ public class P2PConverter {
return true; return true;
} }
} }
return false; return true;
} }
} }
...@@ -2,24 +2,11 @@ ...@@ -2,24 +2,11 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error"> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example.yaml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/types/nodes.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../TOSCA/application_example_output.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/application_example_output.yaml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/controller/PlannerController.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/controller/ProvisionController.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/service/CloudStormService.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/service/PlannerService.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/Artifact.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/Attribute.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/Constraint.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/EntrySchema.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/Interface.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/Property.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/PropertyStatus.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/Requirement.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/capabilities/Capabilities.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/nodes/NodeState.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/model/tosca/nodes/RootNode.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" />
...@@ -171,7 +158,7 @@ ...@@ -171,7 +158,7 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/basic_planner.py</url> <url>file://$PROJECT_DIR$/src/planner/basic_planner.py</url>
<line>95</line> <line>103</line>
<option name="timeStamp" value="2" /> <option name="timeStamp" value="2" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
......
...@@ -36,6 +36,11 @@ def get_mem_size(): ...@@ -36,6 +36,11 @@ def get_mem_size():
return '3000 MB' return '3000 MB'
def get_os_distribution():
return 'Ubuntu 14.04'
def set_VM_properties(node_template_dict): def set_VM_properties(node_template_dict):
node_template_dict['properties'].pop('host_name') node_template_dict['properties'].pop('host_name')
node_template_dict['properties']['host_name'] = 'vm' node_template_dict['properties']['host_name'] = 'vm'
...@@ -48,6 +53,7 @@ def set_VM_properties(node_template_dict): ...@@ -48,6 +53,7 @@ def set_VM_properties(node_template_dict):
node_template_dict['properties']['mem_size'] = get_mem_size() node_template_dict['properties']['mem_size'] = get_mem_size()
node_template_dict['properties'].pop('user_name') node_template_dict['properties'].pop('user_name')
node_template_dict['properties']['user_name'] = 'vm_user' node_template_dict['properties']['user_name'] = 'vm_user'
node_template_dict['properties']['os'] = get_os_distribution()
return node_template_dict return node_template_dict
def set_topology_properties(node_template_dict): def set_topology_properties(node_template_dict):
...@@ -121,7 +127,7 @@ class BasicPlanner: ...@@ -121,7 +127,7 @@ class BasicPlanner:
yaml_str = yaml_str.replace('description: TOSCA example', '') yaml_str = yaml_str.replace('description: TOSCA example', '')
yaml_str = yaml_str.replace('tosca_template', 'topology_template') yaml_str = yaml_str.replace('tosca_template', 'topology_template')
self.formatted_yaml_str = 'tosca_definitions_version: tosca_simple_yaml_1_0\nrepositories:\n docker_hub: https://hub.docker.com/\n'+yaml_str self.formatted_yaml_str = 'tosca_definitions_version: tosca_simple_yaml_1_0\nrepositories:\n docker_hub: https://hub.docker.com/\n'+yaml_str
# logging.info('TOSCA template: \n' + formatted_yaml_str) logging.info('TOSCA template: \n' + self.formatted_yaml_str)
def get_plan(self): def get_plan(self):
return self.formatted_yaml_str return self.formatted_yaml_str
......
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