Commit 5e5868ec authored by Spiros Koulouzis's avatar Spiros Koulouzis

added Provisioner type

parent 67f74d65
......@@ -84,14 +84,14 @@ public class ToscaHelper {
id = Integer.valueOf(resp);
}
public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException {
public List<Map<String, Object>> getSupportedProvisionInterfaceDefinitions() throws ApiException {
List<Map<String, Object>> interfaceDefinitions = new ArrayList<>();
List<String> toscaInterfaceTypes = getSuportedProvisionInterfaceTypes();
for (String type : toscaInterfaceTypes) {
String derivedFrom = null;
List<Map<String, Object>> interfaces = api.getTypes(String.valueOf(id), "interface_types", null, type, null, null, null, null, null, derivedFrom);
interfaceDefinitions.addAll(interfaces);
}
return interfaceDefinitions;
}
......@@ -223,4 +223,10 @@ public class ToscaHelper {
return toscaTemplate;
}
private List<String> getSuportedProvisionInterfaceTypes() {
List<String> suportedProvisionInterfaceTypes = new ArrayList<>();
suportedProvisionInterfaceTypes.add("tosca.interfaces.ARTICONF.CloudsStorm");
return suportedProvisionInterfaceTypes;
}
}
package nl.uva.sne.drip.model.cloud.storm;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
/**
* CloudCred
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-26T13:19:20.152Z")
public class CloudCred {
@JsonProperty("cloudProvider")
private String cloudProvider = null;
@JsonProperty("credInfoFile")
private String credInfoFile = null;
public CloudCred cloudProvider(String cloudProvider) {
this.cloudProvider = cloudProvider;
return this;
}
/**
* Get cloudProvider
*
* @return cloudProvider
*
*/
@ApiModelProperty(value = "")
public String getCloudProvider() {
return cloudProvider;
}
public void setCloudProvider(String cloudProvider) {
this.cloudProvider = cloudProvider;
}
public CloudCred credInfoFile(String credInfoFile) {
this.credInfoFile = credInfoFile;
return this;
}
/**
* Get credInfoFile
*
* @return credInfoFile
*
*/
@ApiModelProperty(value = "")
public String getCredInfoFile() {
return credInfoFile;
}
public void setCredInfoFile(String credInfoFile) {
this.credInfoFile = credInfoFile;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CloudCred cloudCred = (CloudCred) o;
return Objects.equals(this.cloudProvider, cloudCred.cloudProvider)
&& Objects.equals(this.credInfoFile, cloudCred.credInfoFile);
}
@Override
public int hashCode() {
return Objects.hash(cloudProvider, credInfoFile);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CloudCred {\n");
sb.append(" cloudProvider: ").append(toIndentedString(cloudProvider)).append("\n");
sb.append(" credInfoFile: ").append(toIndentedString(credInfoFile)).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 ");
}
}
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;
/**
* CloudCredentialDB
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-26T13:19:20.152Z")
public class CloudCredentialDB {
@JsonProperty("cloudCreds")
@Valid
private List<CloudCred> cloudCreds = null;
public CloudCredentialDB cloudCreds(List<CloudCred> cloudCreds) {
this.cloudCreds = cloudCreds;
return this;
}
public CloudCredentialDB addCloudCredsItem(CloudCred cloudCredsItem) {
if (this.cloudCreds == null) {
this.cloudCreds = new ArrayList<CloudCred>();
}
this.cloudCreds.add(cloudCredsItem);
return this;
}
/**
* Get cloudCreds
*
* @return cloudCreds
*
*/
@ApiModelProperty(value = "")
@Valid
public List<CloudCred> getCloudCreds() {
return cloudCreds;
}
public void setCloudCreds(List<CloudCred> cloudCreds) {
this.cloudCreds = cloudCreds;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CloudCredentialDB cloudCredentialDB = (CloudCredentialDB) o;
return Objects.equals(this.cloudCreds, cloudCredentialDB.cloudCreds);
}
@Override
public int hashCode() {
return Objects.hash(cloudCreds);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CloudCredentialDB {\n");
sb.append(" cloudCreds: ").append(toIndentedString(cloudCreds)).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 ");
}
}
package nl.uva.sne.drip.model.cloud.storm;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
/**
* CloudDB
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-26T13:19:20.152Z")
public class CloudDB {
@JsonProperty("cloudProvider")
private String cloudProvider = null;
@JsonProperty("dbInfoFile")
private String dbInfoFile = null;
public CloudDB cloudProvider(String cloudProvider) {
this.cloudProvider = cloudProvider;
return this;
}
/**
* Get cloudProvider
*
* @return cloudProvider
*
*/
@ApiModelProperty(value = "")
public String getCloudProvider() {
return cloudProvider;
}
public void setCloudProvider(String cloudProvider) {
this.cloudProvider = cloudProvider;
}
public CloudDB dbInfoFile(String dbInfoFile) {
this.dbInfoFile = dbInfoFile;
return this;
}
/**
* Get dbInfoFile
*
* @return dbInfoFile
*
*/
@ApiModelProperty(value = "")
public String getDbInfoFile() {
return dbInfoFile;
}
public void setDbInfoFile(String dbInfoFile) {
this.dbInfoFile = dbInfoFile;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CloudDB cloudDB = (CloudDB) o;
return Objects.equals(this.cloudProvider, cloudDB.cloudProvider)
&& Objects.equals(this.dbInfoFile, cloudDB.dbInfoFile);
}
@Override
public int hashCode() {
return Objects.hash(cloudProvider, dbInfoFile);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CloudDB {\n");
sb.append(" cloudProvider: ").append(toIndentedString(cloudProvider)).append("\n");
sb.append(" dbInfoFile: ").append(toIndentedString(dbInfoFile)).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 ");
}
}
......@@ -100,7 +100,7 @@ public class ToscaHelperTest {
}
/**
* Test of getProvisionInterfaceDefinitions method, of class ToscaHelper.
* Test of getSupportedProvisionInterfaceDefinitions method, of class ToscaHelper.
*
* @throws nl.uva.sne.drip.sure.tosca.client.ApiException
*/
......@@ -108,13 +108,11 @@ public class ToscaHelperTest {
public void testGetProvisionInterfaceDefinitions() throws ApiException {
if (serviceUp) {
System.out.println("getProvisionInterfaceDefinitions");
List<String> toscaInterfaceTypes = new ArrayList<>();
String expected = "tosca.interfaces.ARTICONF.CloudsStorm";
toscaInterfaceTypes.add(expected);
List<Map<String, Object>> result = instance.getProvisionInterfaceDefinitions(toscaInterfaceTypes);
List<Map<String, Object>> result = instance.getSupportedProvisionInterfaceDefinitions();
assertNotNull(result);
String key = result.get(0).keySet().iterator().next();
assertEquals(expected, key);
// assertEquals(expected, key);
}
}
......
......@@ -2,7 +2,6 @@ package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
......@@ -43,7 +42,7 @@ public class PlannerApiController implements PlannerApi {
if (accept != null && accept.contains("text/plain")) {
try {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.execute(id);
String planedYemplateId = dripService.plan(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
......
......@@ -46,7 +46,7 @@ public class ProvisionerApiController implements ProvisionerApi {
if (accept != null && accept.contains("text/plain")) {
try {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.execute(id);
String planedYemplateId = dripService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
......
......@@ -8,9 +8,11 @@ package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.NotFoundException;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.model.Message;
import nl.uva.sne.drip.model.NodeTemplate;
......@@ -43,16 +45,11 @@ public class DRIPService {
@Autowired
private ToscaHelper helper;
public String execute(String id) throws JsonProcessingException, ApiException, Exception {
private String execute(ToscaTemplate toscaTemplate) throws JsonProcessingException, ApiException, Exception {
try {
caller.init();
String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
if (requestQeueName.equals("provisioner")) {
toscaTemplate = addCredentials(toscaTemplate);
}
Logger.getLogger(DRIPService.class.getName()).log(Level.INFO, "toscaTemplate:\n" + toscaTemplate);
Logger.getLogger(DRIPService.class.getName()).log(Level.INFO, "toscaTemplate:\n{0}", toscaTemplate);
Message message = new Message();
message.setOwner("user");
message.setCreationDate(System.currentTimeMillis());
......@@ -109,4 +106,38 @@ public class DRIPService {
return toscaTemplate;
}
public String plan(String id) throws ApiException, Exception {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
return execute(toscaTemplate);
}
public String provision(String id) throws JsonProcessingException, NotFoundException, IOException, Exception {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
toscaTemplate = addCredentials(toscaTemplate);
toscaTemplate = addProvisionInterface(toscaTemplate);
return execute(toscaTemplate);
}
private ToscaTemplate addProvisionInterface(ToscaTemplate toscaTemplate) throws IOException, JsonProcessingException, ApiException, Exception {
helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
List<Provisioner> provisioners = null;
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
provisioners = provisionerService.findByProvider(provider.toLowerCase());
if (provisioners != null && provisioners.size() > 0) {
Provisioner provisioner = getBestProvisioners(vmTopologyMap.getNodeTemplate(), provisioners);
vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisioner);
toscaTemplate = helper.setVMTopologyInToscaTemplate(toscaTemplate, vmTopologyMap);
}
}
return toscaTemplate;
}
private Map<String, Object> getBestProvisionInterfaceDefinitions(List<Map<String, Object>> result) {
return result.get(0);
}
}
......@@ -28,7 +28,7 @@ import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormVM;
import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.cloud.storm.CloudCred;
import nl.uva.sne.drip.model.cloud.storm.CloudCredentials;
import nl.uva.sne.drip.model.cloud.storm.CloudCredentialDB;
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.CloudsStormVMs;
......@@ -75,7 +75,7 @@ class CloudStormService {
if (!(topologyTempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath());
}
writeCloudStormTopologyFiles(toscaTemplate, topologyTempInputDirPath);
writeCloudStormTopologyFiles(topologyTempInputDirPath);
String credentialsTempInputDirPath = tempInputDirPath + File.separator + "credentials";
File credentialsTempInputDir = new File(credentialsTempInputDirPath);
......@@ -88,11 +88,11 @@ class CloudStormService {
if (!(infrasCodeTempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath());
}
writeCloudStormInfrasCodeFiles(infrasCodeTempInputDirPath);
return toscaTemplate;
}
private void writeCloudStormTopologyFiles(ToscaTemplate toscaTemplate, String tempInputDirPath) throws JSchException, IOException, ApiException, Exception {
private void writeCloudStormTopologyFiles(String tempInputDirPath) throws JSchException, IOException, ApiException, Exception {
CloudsStormTopTopology topTopology = new CloudsStormTopTopology();
String publicKeyPath = buildSSHKeyPair(tempInputDirPath);
topTopology.setPublicKeyPath(publicKeyPath);
......@@ -103,8 +103,6 @@ class CloudStormService {
topTopology.setTopologies(cloudsStormSubTopology);
objectMapper.writeValue(new File(tempInputDirPath + File.separator + "top.yml"), topTopology);
// <CloudsStormVMs > cloudsStormVMsList = (List<CloudsStormVMs>) subTopologiesAndVMs.get("cloud_storm_subtopologies");
}
private String buildSSHKeyPair(String tempInputDirPath) throws JSchException, IOException {
......@@ -187,7 +185,7 @@ class CloudStormService {
CloudCred cloudStormCredential = new CloudCred();
cloudStormCredential.setCloudProvider(toscaCredentials.getCloudProviderName());
String credInfoFile = credentialsTempInputDirPath + File.separator + toscaCredentials.getCloudProviderName() + i + ".yml";
String credInfoFile = toscaCredentials.getCloudProviderName() + i + ".yml";
cloudStormCredential.setCredInfoFile(credInfoFile);
cloudStormCredentialList.add(cloudStormCredential);
......@@ -195,7 +193,7 @@ class CloudStormService {
objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + toscaCredentials.getCloudProviderName() + i + ".yml"), cloudStormCredentialInfo);
i++;
}
CloudCredentials cloudStormCredentials = new CloudCredentials();
CloudCredentialDB cloudStormCredentials = new CloudCredentialDB();
cloudStormCredentials.setCloudCreds(cloudStormCredentialList);
objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + "CloudStormCredentials.yml"), cloudStormCredentials);
}
......@@ -222,4 +220,8 @@ class CloudStormService {
return null;
}
private void writeCloudStormInfrasCodeFiles(String infrasCodeTempInputDirPath) {
}
}
......@@ -7,5 +7,5 @@ Provisioner:
type: "string"
description:
type: "string"
tosca_interface_types:
tosca_interface_type:
type: "string"
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