Commit 46ef9c49 authored by Spiros Koulouzis's avatar Spiros Koulouzis

try to match VM types

parent b17d26c0
......@@ -13,7 +13,7 @@ topology_template:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
os: ubuntu 16.04
type: tosca.nodes.ARTICONF.VM.Compute
compute_1:
interfaces:
......@@ -23,7 +23,7 @@ topology_template:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
os: ubuntu 16.04
type: tosca.nodes.ARTICONF.VM.Compute
compute_2:
interfaces:
......@@ -33,7 +33,7 @@ topology_template:
disk_size: 50000 MB
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
os: ubuntu 16.04.04
type: tosca.nodes.ARTICONF.VM.Compute
kubernetes:
interfaces:
......
......@@ -44,7 +44,7 @@ topology_template:
required: true
type: integer
os:
default: ubuntu 16
default: ubuntu 16.04
required: true
type: string
private_ip:
......@@ -74,7 +74,7 @@ topology_template:
host_name: vm
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
os: ubuntu 16.04
role: worker
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
......@@ -87,7 +87,7 @@ topology_template:
host_name: vm
mem_size: 6000 MB
num_cores: 2
os: ubuntu 16
os: ubuntu 16.04
role: worker
user_name: vm_user
type: tosca.nodes.ARTICONF.VM.Compute
......
......@@ -42,6 +42,10 @@ public class ToscaHelper {
private final ObjectMapper objectMapper;
public static final String VM_CAPABILITY = "tosca.capabilities.ARTICONF.VM";
private static final String VM_TYPE = "tosca.nodes.ARTICONF.VM.Compute";
private static final String VM_NUM_OF_CORES = "num_cores";
private static final String MEM_SIZE = "mem_size";
private static final String VM_OS = "os";
/**
* @return the id
......@@ -101,4 +105,47 @@ public class ToscaHelper {
}
public Double getVMNumOfCores(NodeTemplate vm) throws Exception {
if (vm.getType().equals(VM_TYPE)) {
return (Double) vm.getProperties().get(VM_NUM_OF_CORES);
} else {
throw new Exception("NodeTemplate is not of type: " + VM_TYPE + " it is of type: " + vm.getType());
}
}
public Double getVMNMemSize(NodeTemplate vm) throws Exception {
if (vm.getType().equals(VM_TYPE)) {
String memScalar = (String) vm.getProperties().get(MEM_SIZE);
String[] memScalarArray = memScalar.split(" ");
String memSize = memScalarArray[0];
String memUnit = memScalarArray[1];
Double memSizeInGB = convertToGB(Integer.valueOf(memSize), memUnit);
return memSizeInGB;
} else {
throw new Exception("NodeTemplate is not of type: " + VM_TYPE + " it is of type: " + vm.getType());
}
}
public String getVMNOS(NodeTemplate vm) throws Exception {
if (vm.getType().equals(VM_TYPE)) {
return (String) vm.getProperties().get(VM_OS);
} else {
throw new Exception("NodeTemplate is not of type: " + VM_TYPE + " it is of type: " + vm.getType());
}
}
private Double convertToGB(Integer value, String memUnit) {
switch (memUnit) {
case "GB":
return Double.valueOf(value);
case "MB":
return value * 0.001;
case "KB":
return value * 0.000001;
default:
return null;
}
}
}
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import nl.uva.sne.drip.model.cloud.storm.DCMetaInfo;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
......@@ -16,93 +17,95 @@ import javax.validation.constraints.*;
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-11T15:13:55.016Z")
public class DBInfo {
@JsonProperty("GlobalEntry")
private String globalEntry = null;
public class DBInfo {
@JsonProperty("DCMetaInfo")
private DCMetaInfo dcMetaInfo = null;
@JsonProperty("GlobalEntry")
private String globalEntry = null;
public DBInfo globalEntry(String globalEntry) {
this.globalEntry = globalEntry;
return this;
}
@JsonProperty("DCMetaInfo")
private List<DCMetaInfo> dcMetaInfo = null;
/**
* Get globalEntry
* @return globalEntry
**/
@ApiModelProperty(value = "")
public DBInfo globalEntry(String globalEntry) {
this.globalEntry = globalEntry;
return this;
}
/**
* Get globalEntry
*
* @return globalEntry
*
*/
@ApiModelProperty(value = "")
public String getGlobalEntry() {
return globalEntry;
}
public String getGlobalEntry() {
return globalEntry;
}
public void setGlobalEntry(String globalEntry) {
this.globalEntry = globalEntry;
}
public void setGlobalEntry(String globalEntry) {
this.globalEntry = globalEntry;
}
public DBInfo dcMetaInfo(DCMetaInfo dcMetaInfo) {
this.dcMetaInfo = dcMetaInfo;
return this;
}
public DBInfo dcMetaInfo(List<DCMetaInfo> dcMetaInfo) {
this.dcMetaInfo = dcMetaInfo;
return this;
}
/**
* Get dcMetaInfo
* @return dcMetaInfo
**/
@ApiModelProperty(value = "")
/**
* Get dcMetaInfo
*
* @return dcMetaInfo
*
*/
@ApiModelProperty(value = "")
@Valid
@Valid
public DCMetaInfo getDcMetaInfo() {
return dcMetaInfo;
}
public List<DCMetaInfo> getDcMetaInfo() {
return dcMetaInfo;
}
public void setDcMetaInfo(DCMetaInfo dcMetaInfo) {
this.dcMetaInfo = dcMetaInfo;
}
public void setDcMetaInfo(List<DCMetaInfo> dcMetaInfo) {
this.dcMetaInfo = dcMetaInfo;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DBInfo dbInfo = (DBInfo) o;
return Objects.equals(this.globalEntry, dbInfo.globalEntry)
&& Objects.equals(this.dcMetaInfo, dbInfo.dcMetaInfo);
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
@Override
public int hashCode() {
return Objects.hash(globalEntry, dcMetaInfo);
}
if (o == null || getClass() != o.getClass()) {
return false;
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DBInfo {\n");
sb.append(" globalEntry: ").append(toIndentedString(globalEntry)).append("\n");
sb.append(" dcMetaInfo: ").append(toIndentedString(dcMetaInfo)).append("\n");
sb.append("}");
return sb.toString();
}
DBInfo dbInfo = (DBInfo) o;
return Objects.equals(this.globalEntry, dbInfo.globalEntry) &&
Objects.equals(this.dcMetaInfo, dbInfo.dcMetaInfo);
}
@Override
public int hashCode() {
return Objects.hash(globalEntry, dcMetaInfo);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DBInfo {\n");
sb.append(" globalEntry: ").append(toIndentedString(globalEntry)).append("\n");
sb.append(" dcMetaInfo: ").append(toIndentedString(dcMetaInfo)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
return o.toString().replace("\n", "\n ");
}
}
......@@ -19,8 +19,25 @@ import javax.validation.constraints.*;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-11T15:13:55.016Z")
public class VMMetaInfo {
/**
* @return the vmType
*/
public String getVmType() {
return vmType;
}
/**
* @param vmType the vmType to set
*/
public void setVmType(String vmType) {
this.vmType = vmType;
}
@JsonProperty("OS")
private String OS = null;
@JsonProperty("VMType")
private String vmType = null;
@JsonProperty("CPU")
private String CPU = null;
......
......@@ -11,10 +11,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.cloud.storm.CloudDB;
import nl.uva.sne.drip.model.cloud.storm.DB;
import nl.uva.sne.drip.model.cloud.storm.DBInfo;
import nl.uva.sne.drip.model.cloud.storm.DCMetaInfo;
import nl.uva.sne.drip.model.cloud.storm.VMMetaInfo;
/**
......@@ -32,7 +36,8 @@ class CloudStormDAO {
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
VMMetaInfo findVmMetaInfoByProvider(String provider) throws IOException {
List<VMMetaInfo> findVmMetaInfoByProvider(String provider) throws IOException {
DB db = objectMapper.readValue(new File(cloudStormDBPath + File.separator + "db.yml"), DB.class);
List<CloudDB> cloudDBs = db.getCloudDBs();
......@@ -44,10 +49,18 @@ class CloudStormDAO {
}
}
if (targetCloudDB != null) {
List<VMMetaInfo> vMMetaInfos = new ArrayList<>();
DBInfo dbInfo = objectMapper.readValue(new File(cloudStormDBPath + File.separator + targetCloudDB.getDbInfoFile()), DBInfo.class);
return dbInfo.getDcMetaInfo().getVmMetaInfo();
List<DCMetaInfo> metaInfos = dbInfo.getDcMetaInfo();
for (DCMetaInfo metaInfo : metaInfos) {
vMMetaInfos.addAll(metaInfo.getVmMetaInfo());
}
return vMMetaInfos;
}
return null;
}
}
......@@ -15,6 +15,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormVM;
......@@ -46,7 +47,7 @@ class CloudStormService {
this.helper = new ToscaHelper(toscaTemplate, sureToscaBasePath);
}
public ToscaTemplate execute() throws FileNotFoundException, JSchException, IOException, ApiException {
public ToscaTemplate execute() throws FileNotFoundException, JSchException, IOException, ApiException, Exception {
tempInputDirPath = System.getProperty("java.io.tmpdir") + File.separator + "Input-" + Long.toString(System.nanoTime()) + File.separator;
File tempInputDir = new File(tempInputDirPath);
if (!(tempInputDir.mkdirs())) {
......@@ -58,7 +59,7 @@ class CloudStormService {
return toscaTemplate;
}
private CloudsStormTopTopology buildCloudStormTopTopology(ToscaTemplate toscaTemplate) throws JSchException, IOException, ApiException {
private CloudsStormTopTopology buildCloudStormTopTopology(ToscaTemplate toscaTemplate) throws JSchException, IOException, ApiException, Exception {
CloudsStormTopTopology topTopology = new CloudsStormTopTopology();
String publicKeyPath = buildSSHKeyPair();
topTopology.setPublicKeyPath(publicKeyPath);
......@@ -86,7 +87,7 @@ class CloudStormService {
return "vm_user";
}
private List<CloudsStormSubTopology> getCloudsStormSubTopologies(ToscaTemplate toscaTemplate) throws ApiException, IOException {
private List<CloudsStormSubTopology> getCloudsStormSubTopologies(ToscaTemplate toscaTemplate) throws ApiException, IOException, Exception {
List<NodeTemplate> vmTopologyTemplates = helper.getVMTopologyTemplates();
List<CloudsStormSubTopology> cloudsStormSubTopologies = new ArrayList<>();
int i = 0;
......@@ -115,15 +116,20 @@ class CloudStormService {
return cloudsStormSubTopologies;
}
private String getVMType(NodeTemplate vm, String provider) throws IOException {
VMMetaInfo vmInfo = cloudStormDAO.findVmMetaInfoByProvider(provider);
String cpu = vmInfo.getCPU();
String mem = vmInfo.getMEM();
vmInfo.get
int numOfCores = helper.getVMNumOfCores(vm);
int memSize = helper.getVMNMemSize(vm);
private String getVMType(NodeTemplate vm, String provider) throws IOException, Exception {
Double numOfCores = helper.getVMNumOfCores(vm);
Double memSize = helper.getVMNMemSize(vm);
String os = helper.getVMNOS(vm);
List<VMMetaInfo> vmInfos = cloudStormDAO.findVmMetaInfoByProvider(provider);
for (VMMetaInfo vmInfo : vmInfos) {
System.err.println("numOfCores: " + numOfCores + " = " + vmInfo.getCPU());
System.err.println("memSize: " + numOfCores + " = " + vmInfo.getMEM());
System.err.println("os: " + os + " = " + vmInfo.getOS());
if (Objects.equals(numOfCores, Double.valueOf(vmInfo.getCPU())) && Objects.equals(memSize, Double.valueOf(vmInfo.getMEM())) && os.toLowerCase().equals(vmInfo.getOS().toLowerCase())) {
return vmInfo.getVmType();
}
}
return null;
}
......
......@@ -4,4 +4,6 @@
GlobalEntry:
type: "string"
DCMetaInfo:
$ref: "https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/openAPI/schema/CloudStorm/DCMetaInfo.yml#/DCMetaInfo"
type: "array"
items:
$ref: "https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/openAPI/schema/CloudStorm/DCMetaInfo.yml#/DCMetaInfo"
......@@ -7,6 +7,8 @@
type: "string"
MEM:
type: "string"
VMType:
type: "string"
Price:
type: "string"
DefaultSSHAccount:
......
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