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:
type: scalar-unit.size
required: true
constraints:
- greater_or_equal: 0 MB
- greater_or_equal: 0 MB
os:
type: string
required: true
interfaces:
Standard:
create: dumy.yaml
......
......@@ -50,6 +50,7 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import java.util.Base64;
/**
*
......@@ -90,32 +91,35 @@ public class PlannerService {
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
List<MessageParameter> messageParams = plannerReturnedMessage.getParameters();
String toscaPlan = null;
for (MessageParameter mp : messageParams) {
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();
// 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());
// }
//
// topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs);
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());
}
topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs);
save(topLevel);
logger.log(Level.INFO, "Plan saved");
return topLevel;
......@@ -275,21 +279,21 @@ public class PlannerService {
return false;
}
private String getBestCloudProvider() {
List<CloudCredentials> creds = credentialService.findAll();
return creds.get(0).getCloudProviderName().toUpperCase();
}
private String getBestDomain(String cloudProvider) {
switch (cloudProvider.trim().toLowerCase()) {
case "ec2":
return "Frankfurt";
case "egi":
return "CESNET";
case "exogeni":
return "RENCI (Chapel Hill, NC USA) XO Rack";
}
return null;
}
// private String getBestCloudProvider() {
// List<CloudCredentials> creds = credentialService.findAll();
// return creds.get(0).getCloudProviderName().toUpperCase();
// }
// private String getBestDomain(String cloudProvider) {
// switch (cloudProvider.trim().toLowerCase()) {
// case "ec2":
// return "Frankfurt";
// case "egi":
// return "CESNET";
// case "exogeni":
// return "RENCI (Chapel Hill, NC USA) XO Rack";
// }
// return null;
// }
}
......@@ -25,10 +25,40 @@ import org.json.JSONException;
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 {
cloudProvider = cloudProvider.toUpperCase();
List<Object> vmList = Converter.jsonString2List(plannerOutputJson);
if (cloudProvider != null) {
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.publicKeyPath = "name@id_rsa.pub";
......@@ -81,7 +111,6 @@ public class P2PConverter {
}
sti.subTopology = subTopology;
subTopologyInfos.put(sti.topology, sti);
}
for (SubTopologyInfo info : subTopologyInfos.values()) {
topTopology.topologies.add(info);
......@@ -116,7 +145,7 @@ public class P2PConverter {
Number memSize = Converter.castToNumber(map.get("mem_size"));
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;
}
return size;
......@@ -175,7 +204,7 @@ public class P2PConverter {
}
if (size > 5 && size <= 10) {
return "XOLarge";
}
}
default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
return null;
......@@ -194,7 +223,7 @@ public class P2PConverter {
break;
case "exogeni":
curVM = new ExoGeniVM();
break;
break;
default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
return null;
......@@ -210,10 +239,12 @@ public class P2PConverter {
curVM.name = "node_vm";
}
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.dockers = curValue.getDocker();
curVM.nodeType = getSize((Map<String, String>) map.get("host"), cloudProvider);
curVM.nodeType = getSize(properties, cloudProvider);
// Eth eth = new Eth();
// eth.name = "p1";
......@@ -246,7 +277,7 @@ public class P2PConverter {
case "exogeni":
subTopology = new ExoGeniSubTopology();
((ExoGeniSubTopology) subTopology).components = new ArrayList<>();
break;
break;
default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
return null;
......@@ -264,7 +295,7 @@ public class P2PConverter {
break;
case "exogeni":
((ExoGeniSubTopology) subTopology).components.add((ExoGeniVM) vm);
break;
break;
default:
Logger.getLogger(P2PConverter.class.getName()).log(Level.WARNING, "The {0} is not supported yet!", cloudProvider);
// return null;
......@@ -285,6 +316,6 @@ public class P2PConverter {
return true;
}
}
return false;
return true;
}
}
......@@ -2,24 +2,11 @@
<project version="4">
<component name="ChangeListManager">
<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/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/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-api/src/main/java/nl/uva/sne/drip/controller/PlannerController.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/controller/ProvisionController.java" beforeDir="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$/../TOSCA/types/nodes.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../TOSCA/types/nodes.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-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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="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$/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/pyparsing.py" beforeDir="false" />
......@@ -171,7 +158,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/basic_planner.py</url>
<line>95</line>
<line>103</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
</breakpoints>
......
......@@ -36,6 +36,11 @@ def get_mem_size():
return '3000 MB'
def get_os_distribution():
return 'Ubuntu 14.04'
def set_VM_properties(node_template_dict):
node_template_dict['properties'].pop('host_name')
node_template_dict['properties']['host_name'] = 'vm'
......@@ -48,6 +53,7 @@ def set_VM_properties(node_template_dict):
node_template_dict['properties']['mem_size'] = get_mem_size()
node_template_dict['properties'].pop('user_name')
node_template_dict['properties']['user_name'] = 'vm_user'
node_template_dict['properties']['os'] = get_os_distribution()
return node_template_dict
def set_topology_properties(node_template_dict):
......@@ -121,7 +127,7 @@ class BasicPlanner:
yaml_str = yaml_str.replace('description: TOSCA example', '')
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
# logging.info('TOSCA template: \n' + formatted_yaml_str)
logging.info('TOSCA template: \n' + self.formatted_yaml_str)
def get_plan(self):
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