Commit b17d26c0 authored by Spiros Koulouzis's avatar Spiros Koulouzis

change vminfo to array

parent 2d9ace00
package nl.uva.sne.drip.model.cloud.storm;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
/**
* DB
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-11T15:52:11.688Z")
public class DB {
@JsonProperty("cloudDBs")
@Valid
private List<CloudDB> cloudDBs = null;
public DB cloudDBs(List<CloudDB> cloudDBs) {
this.cloudDBs = cloudDBs;
return this;
}
public DB addCloudDBsItem(CloudDB cloudDBsItem) {
if (this.cloudDBs == null) {
this.cloudDBs = new ArrayList<>();
}
this.cloudDBs.add(cloudDBsItem);
return this;
}
/**
* Get cloudDBs
*
* @return cloudDBs
*
*/
@ApiModelProperty(value = "")
@Valid
public List<CloudDB> getCloudDBs() {
return cloudDBs;
}
public void setCloudDBs(List<CloudDB> cloudDBs) {
this.cloudDBs = cloudDBs;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DB DB = (DB) o;
return Objects.equals(this.cloudDBs, DB.cloudDBs);
}
@Override
public int hashCode() {
return Objects.hash(cloudDBs);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DB {\n");
sb.append(" cloudDBs: ").append(toIndentedString(cloudDBs)).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";
}
return o.toString().replace("\n", "\n ");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nl.uva.sne.drip.provisioner;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
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.List;
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.VMMetaInfo;
/**
*
* @author S. Koulouzis
*/
class CloudStormDAO {
private final String cloudStormDBPath;
private final ObjectMapper objectMapper;
public CloudStormDAO(String cloudStormDBPath) {
this.cloudStormDBPath = cloudStormDBPath;
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
VMMetaInfo findVmMetaInfoByProvider(String provider) throws IOException {
DB db = objectMapper.readValue(new File(cloudStormDBPath + File.separator + "db.yml"), DB.class);
List<CloudDB> cloudDBs = db.getCloudDBs();
CloudDB targetCloudDB = null;
for (CloudDB cloudDB : cloudDBs) {
if (cloudDB.getCloudProvider().toLowerCase().equals(provider.toLowerCase())) {
targetCloudDB = cloudDB;
break;
}
}
if (targetCloudDB != null) {
DBInfo dbInfo = objectMapper.readValue(new File(cloudStormDBPath + File.separator + targetCloudDB.getDbInfoFile()), DBInfo.class);
return dbInfo.getDcMetaInfo().getVmMetaInfo();
}
return null;
}
}
......@@ -6,10 +6,6 @@
package nl.uva.sne.drip.provisioner;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.KeyPair;
......@@ -25,6 +21,7 @@ import nl.uva.sne.drip.model.cloud.storm.CloudsStormVM;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormTopTopology;
import nl.uva.sne.drip.model.cloud.storm.VMMetaInfo;
import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.apache.commons.io.FilenameUtils;
......@@ -39,16 +36,14 @@ class CloudStormService {
private String tempInputDirPath;
private final ToscaTemplate toscaTemplate;
private final ToscaHelper helper;
private final String cloudStormDBPath;
private final ObjectMapper objectMapper;
private final CloudStormDAO cloudStormDAO;
CloudStormService(Properties properties, ToscaTemplate toscaTemplate) throws IOException, JsonProcessingException, ApiException {
this.toscaTemplate = toscaTemplate;
this.cloudStormDBPath = properties.getProperty("cloud.storm.db.path");
String cloudStormDBPath = properties.getProperty("cloud.storm.db.path");
cloudStormDAO = new CloudStormDAO(cloudStormDBPath);
String sureToscaBasePath = properties.getProperty("sure-tosca.base.path");
this.helper = new ToscaHelper(toscaTemplate, sureToscaBasePath);
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
public ToscaTemplate execute() throws FileNotFoundException, JSchException, IOException, ApiException {
......@@ -91,7 +86,7 @@ class CloudStormService {
return "vm_user";
}
private List<CloudsStormSubTopology> getCloudsStormSubTopologies(ToscaTemplate toscaTemplate) throws ApiException {
private List<CloudsStormSubTopology> getCloudsStormSubTopologies(ToscaTemplate toscaTemplate) throws ApiException, IOException {
List<NodeTemplate> vmTopologyTemplates = helper.getVMTopologyTemplates();
List<CloudsStormSubTopology> cloudsStormSubTopologies = new ArrayList<>();
int i = 0;
......@@ -120,9 +115,16 @@ class CloudStormService {
return cloudsStormSubTopologies;
}
private String getVMType(NodeTemplate vm, String provider) {
nl.uva.sne.drip.model.cloud.storm.CloudDB
objectMapper.readValue(new File(cloudStormDBPath), DB)
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);
return null;
}
}
......@@ -654,6 +654,13 @@ definitions:
type: array
items:
$ref: '#/definitions/CloudsStormSubnets'
DB:
type: object
properties:
cloudDBs:
type: array
items:
$ref: '#/definitions/CloudDB'
CloudDB:
type: object
properties:
......
......@@ -14,8 +14,10 @@
availability:
type: "string"
VMMetaInfo:
$ref: "https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/openAPI/schema/CloudStorm/VMMetaInfo.yml#/VMMetaInfo"
type: "array"
items:
$ref: "https://raw.githubusercontent.com/skoulouzis/CONF/DRIP_3.0/openAPI/schema/CloudStorm/VMMetaInfo.yml#/VMMetaInfo"
extraInfo:
type: object
additionalProperties:
type: object
type: object
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