Commit 3310ed45 authored by Spiros Koulouzis's avatar Spiros Koulouzis

get available credentials

parent 959f4a83
...@@ -31,6 +31,9 @@ import nl.uva.sne.drip.sure.tosca.client.DefaultApi; ...@@ -31,6 +31,9 @@ import nl.uva.sne.drip.sure.tosca.client.DefaultApi;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import nl.uva.sne.drip.sure.tosca.client.ApiException; import nl.uva.sne.drip.sure.tosca.client.ApiException;
import nl.uva.sne.drip.sure.tosca.client.Configuration; import nl.uva.sne.drip.sure.tosca.client.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/** /**
* *
...@@ -38,15 +41,21 @@ import nl.uva.sne.drip.sure.tosca.client.Configuration; ...@@ -38,15 +41,21 @@ import nl.uva.sne.drip.sure.tosca.client.Configuration;
*/ */
public class ToscaHelper { public class ToscaHelper {
private final DefaultApi api; private DefaultApi api;
private final ObjectMapper objectMapper; private ObjectMapper objectMapper;
public static final String VM_CAPABILITY = "tosca.capabilities.ARTICONF.VM"; 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_TYPE = "tosca.nodes.ARTICONF.VM.Compute";
private static final String VM_NUM_OF_CORES = "num_cores"; private static final String VM_NUM_OF_CORES = "num_cores";
private static final String MEM_SIZE = "mem_size"; private static final String MEM_SIZE = "mem_size";
private static final String VM_OS = "os"; private static final String VM_OS = "os";
private static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology"; private static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology";
private Integer id;
@Autowired
public ToscaHelper(String sureToscaBasePath) {
init(sureToscaBasePath);
}
/** /**
* @return the id * @return the id
...@@ -55,23 +64,23 @@ public class ToscaHelper { ...@@ -55,23 +64,23 @@ public class ToscaHelper {
return id; return id;
} }
private final Integer id; // public ToscaHelper(ToscaTemplate toscaTemplate, String sureToscaBasePath) throws JsonProcessingException, IOException, ApiException {
// init(sureToscaBasePath);
public ToscaHelper(ToscaTemplate toscaTemplate, String sureToscaBasePath) throws JsonProcessingException, IOException, ApiException { // uploadToscaTemplate(toscaTemplate);
// }
private void init(String sureToscaBasePath) {
Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath); Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath);
api = new DefaultApi(Configuration.getDefaultApiClient()); api = new DefaultApi(Configuration.getDefaultApiClient());
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
id = uploadToscaTemplate(toscaTemplate);
} }
private Integer uploadToscaTemplate(ToscaTemplate toscaTemplate) throws JsonProcessingException, IOException, ApiException { public void uploadToscaTemplate(ToscaTemplate toscaTemplate) throws JsonProcessingException, IOException, ApiException {
String ymlStr = objectMapper.writeValueAsString(toscaTemplate); String ymlStr = objectMapper.writeValueAsString(toscaTemplate);
File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml"); File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml");
FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes()); FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes());
String resp = api.uploadToscaTemplate(toscaTemplateFile); String resp = api.uploadToscaTemplate(toscaTemplateFile);
return Integer.valueOf(resp); id = Integer.valueOf(resp);
} }
public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException { public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException {
...@@ -90,7 +99,7 @@ public class ToscaHelper { ...@@ -90,7 +99,7 @@ public class ToscaHelper {
return vmTopologyTemplates; return vmTopologyTemplates;
} }
public List<NodeTemplate> getTopologyTemplateVMs(NodeTemplate nodeTemplate) throws ApiException { public List<NodeTemplate> getTemplateVMsForVMTopology(NodeTemplate nodeTemplate) throws ApiException {
List<Map<String, Object>> requirements = nodeTemplate.getRequirements(); List<Map<String, Object>> requirements = nodeTemplate.getRequirements();
List<NodeTemplate> vms = new ArrayList<>(); List<NodeTemplate> vms = new ArrayList<>();
for (Map<String, Object> req : requirements) { for (Map<String, Object> req : requirements) {
......
...@@ -65,11 +65,12 @@ public class VMMetaInfo { ...@@ -65,11 +65,12 @@ public class VMMetaInfo {
/** /**
* Get OS * Get OS
*
* @return OS * @return OS
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getOS() { public String getOS() {
return OS; return OS;
} }
...@@ -85,11 +86,12 @@ public class VMMetaInfo { ...@@ -85,11 +86,12 @@ public class VMMetaInfo {
/** /**
* Get CPU * Get CPU
*
* @return CPU * @return CPU
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getCPU() { public String getCPU() {
return CPU; return CPU;
} }
...@@ -105,11 +107,12 @@ public class VMMetaInfo { ...@@ -105,11 +107,12 @@ public class VMMetaInfo {
/** /**
* Get MEM * Get MEM
*
* @return MEM * @return MEM
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getMEM() { public String getMEM() {
return MEM; return MEM;
} }
...@@ -125,11 +128,12 @@ public class VMMetaInfo { ...@@ -125,11 +128,12 @@ public class VMMetaInfo {
/** /**
* Get price * Get price
*
* @return price * @return price
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getPrice() { public String getPrice() {
return price; return price;
} }
...@@ -145,11 +149,12 @@ public class VMMetaInfo { ...@@ -145,11 +149,12 @@ public class VMMetaInfo {
/** /**
* Get defaultSSHAccount * Get defaultSSHAccount
*
* @return defaultSSHAccount * @return defaultSSHAccount
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getDefaultSSHAccount() { public String getDefaultSSHAccount() {
return defaultSSHAccount; return defaultSSHAccount;
} }
...@@ -165,11 +170,12 @@ public class VMMetaInfo { ...@@ -165,11 +170,12 @@ public class VMMetaInfo {
/** /**
* Get availability * Get availability
*
* @return availability * @return availability
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getAvailability() { public String getAvailability() {
return availability; return availability;
} }
...@@ -193,11 +199,12 @@ public class VMMetaInfo { ...@@ -193,11 +199,12 @@ public class VMMetaInfo {
/** /**
* Get extraInfo * Get extraInfo
*
* @return extraInfo * @return extraInfo
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getExtraInfo() { public Map<String, Object> getExtraInfo() {
return extraInfo; return extraInfo;
} }
...@@ -206,7 +213,6 @@ public class VMMetaInfo { ...@@ -206,7 +213,6 @@ public class VMMetaInfo {
this.extraInfo = extraInfo; this.extraInfo = extraInfo;
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {
...@@ -216,13 +222,13 @@ public class VMMetaInfo { ...@@ -216,13 +222,13 @@ public class VMMetaInfo {
return false; return false;
} }
VMMetaInfo vmMetaInfo = (VMMetaInfo) o; VMMetaInfo vmMetaInfo = (VMMetaInfo) o;
return Objects.equals(this.OS, vmMetaInfo.OS) && return Objects.equals(this.OS, vmMetaInfo.OS)
Objects.equals(this.CPU, vmMetaInfo.CPU) && && Objects.equals(this.CPU, vmMetaInfo.CPU)
Objects.equals(this.MEM, vmMetaInfo.MEM) && && Objects.equals(this.MEM, vmMetaInfo.MEM)
Objects.equals(this.price, vmMetaInfo.price) && && Objects.equals(this.price, vmMetaInfo.price)
Objects.equals(this.defaultSSHAccount, vmMetaInfo.defaultSSHAccount) && && Objects.equals(this.defaultSSHAccount, vmMetaInfo.defaultSSHAccount)
Objects.equals(this.availability, vmMetaInfo.availability) && && Objects.equals(this.availability, vmMetaInfo.availability)
Objects.equals(this.extraInfo, vmMetaInfo.extraInfo); && Objects.equals(this.extraInfo, vmMetaInfo.extraInfo);
} }
@Override @Override
...@@ -257,4 +263,3 @@ public class VMMetaInfo { ...@@ -257,4 +263,3 @@ public class VMMetaInfo {
return o.toString().replace("\n", "\n "); return o.toString().replace("\n", "\n ");
} }
} }
...@@ -11,12 +11,12 @@ import javax.validation.Valid; ...@@ -11,12 +11,12 @@ import javax.validation.Valid;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
/** /**
* Credentials * Credential
*/ */
@Validated @Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-10T15:39:04.296Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-10T15:39:04.296Z")
public class Credentials { public class Credential {
/** /**
* @return the id * @return the id
*/ */
...@@ -55,7 +55,7 @@ public class Credentials { ...@@ -55,7 +55,7 @@ public class Credentials {
@JsonProperty("cloud_provider_name") @JsonProperty("cloud_provider_name")
private String cloudProviderName = null; private String cloudProviderName = null;
public Credentials protocol(String protocol) { public Credential protocol(String protocol) {
this.protocol = protocol; this.protocol = protocol;
return this; return this;
} }
...@@ -76,7 +76,7 @@ public class Credentials { ...@@ -76,7 +76,7 @@ public class Credentials {
this.protocol = protocol; this.protocol = protocol;
} }
public Credentials tokenType(String tokenType) { public Credential tokenType(String tokenType) {
this.tokenType = tokenType; this.tokenType = tokenType;
return this; return this;
} }
...@@ -97,7 +97,7 @@ public class Credentials { ...@@ -97,7 +97,7 @@ public class Credentials {
this.tokenType = tokenType; this.tokenType = tokenType;
} }
public Credentials token(String token) { public Credential token(String token) {
this.token = token; this.token = token;
return this; return this;
} }
...@@ -118,12 +118,12 @@ public class Credentials { ...@@ -118,12 +118,12 @@ public class Credentials {
this.token = token; this.token = token;
} }
public Credentials keys(Map<String, String> keys) { public Credential keys(Map<String, String> keys) {
this.keys = keys; this.keys = keys;
return this; return this;
} }
public Credentials putKeysItem(String key, String keysItem) { public Credential putKeysItem(String key, String keysItem) {
if (this.keys == null) { if (this.keys == null) {
this.keys = new HashMap<String, String>(); this.keys = new HashMap<String, String>();
} }
...@@ -147,7 +147,7 @@ public class Credentials { ...@@ -147,7 +147,7 @@ public class Credentials {
this.keys = keys; this.keys = keys;
} }
public Credentials user(String user) { public Credential user(String user) {
this.user = user; this.user = user;
return this; return this;
} }
...@@ -168,7 +168,7 @@ public class Credentials { ...@@ -168,7 +168,7 @@ public class Credentials {
this.user = user; this.user = user;
} }
public Credentials cloudProviderName(String cloudProviderName) { public Credential cloudProviderName(String cloudProviderName) {
this.cloudProviderName = cloudProviderName; this.cloudProviderName = cloudProviderName;
return this; return this;
} }
...@@ -197,7 +197,7 @@ public class Credentials { ...@@ -197,7 +197,7 @@ public class Credentials {
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
Credentials credentials = (Credentials) o; Credential credentials = (Credential) o;
return Objects.equals(this.protocol, credentials.protocol) return Objects.equals(this.protocol, credentials.protocol)
&& Objects.equals(this.tokenType, credentials.tokenType) && Objects.equals(this.tokenType, credentials.tokenType)
&& Objects.equals(this.token, credentials.token) && Objects.equals(this.token, credentials.token)
......
...@@ -73,7 +73,8 @@ public class ToscaHelperTest { ...@@ -73,7 +73,8 @@ public class ToscaHelperTest {
String serviceBasePath = prop.getProperty("sure-tosca.base.path"); String serviceBasePath = prop.getProperty("sure-tosca.base.path");
serviceUp = isServiceUp(serviceBasePath); serviceUp = isServiceUp(serviceBasePath);
if (serviceUp) { if (serviceUp) {
instance = new ToscaHelper(toscaTemplate, serviceBasePath); instance = new ToscaHelper(serviceBasePath);
instance.uploadToscaTemplate(toscaTemplate);
} }
} }
......
...@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import nl.uva.sne.drip.model.tosca.Credentials; import nl.uva.sne.drip.model.tosca.Credential;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
...@@ -39,7 +39,7 @@ public interface CredentialApi { ...@@ -39,7 +39,7 @@ public interface CredentialApi {
produces = {"application/json"}, produces = {"application/json"},
consumes = {"application/json"}, consumes = {"application/json"},
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<String> createCredentials(@ApiParam(value = "Created user object", required = true) @Valid @RequestBody Credentials body); ResponseEntity<String> createCredentials(@ApiParam(value = "Created user object", required = true) @Valid @RequestBody Credential body);
@ApiOperation(value = "Get all credential IDs", nickname = "getCredentialIDs", notes = "Returns all IDss ", response = String.class, responseContainer = "List", authorizations = { @ApiOperation(value = "Get all credential IDs", nickname = "getCredentialIDs", notes = "Returns all IDss ", response = String.class, responseContainer = "List", authorizations = {
@Authorization(value = "auth", scopes = { @Authorization(value = "auth", scopes = {
......
package nl.uva.sne.drip.api; package nl.uva.sne.drip.api;
import nl.uva.sne.drip.model.tosca.Credentials; import nl.uva.sne.drip.model.tosca.Credential;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -38,7 +38,7 @@ public class CredentialApiController implements CredentialApi { ...@@ -38,7 +38,7 @@ public class CredentialApiController implements CredentialApi {
@Override @Override
public ResponseEntity<String> createCredentials(@ApiParam( public ResponseEntity<String> createCredentials(@ApiParam(
value = "Created user object", required = true) value = "Created user object", required = true)
@Valid @RequestBody Credentials body) { @Valid @RequestBody Credential body) {
String accept = request.getHeader("Accept"); String accept = request.getHeader("Accept");
if (accept != null && accept.contains("application/json")) { if (accept != null && accept.contains("application/json")) {
String id = credentialService.save(body); String id = credentialService.save(body);
......
...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api; ...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -10,6 +11,7 @@ import org.springframework.stereotype.Controller; ...@@ -10,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import nl.uva.sne.drip.service.DRIPService; import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -39,9 +41,15 @@ public class PlannerApiController implements PlannerApi { ...@@ -39,9 +41,15 @@ public class PlannerApiController implements PlannerApi {
@PathVariable("id") String id) { @PathVariable("id") String id) {
String accept = request.getHeader("Accept"); String accept = request.getHeader("Accept");
if (accept != null && accept.contains("text/plain")) { if (accept != null && accept.contains("text/plain")) {
try {
dripService.setRequestQeueName(queueName); dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.execute(id); String planedYemplateId = dripService.execute(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
} }
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
......
...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api; ...@@ -2,6 +2,7 @@ package nl.uva.sne.drip.api;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.util.logging.Level;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -10,6 +11,7 @@ import org.springframework.stereotype.Controller; ...@@ -10,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import nl.uva.sne.drip.service.DRIPService; import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -42,9 +44,15 @@ public class ProvisionerApiController implements ProvisionerApi { ...@@ -42,9 +44,15 @@ public class ProvisionerApiController implements ProvisionerApi {
@PathVariable("id") String id) { @PathVariable("id") String id) {
String accept = request.getHeader("Accept"); String accept = request.getHeader("Accept");
if (accept != null && accept.contains("text/plain")) { if (accept != null && accept.contains("text/plain")) {
try {
dripService.setRequestQeueName(queueName); dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.execute(id); String planedYemplateId = dripService.execute(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
} }
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
......
/*
* 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.configuration;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
/**
*
* @author S. Koulouzis
*/
@Configuration
@PropertySources({
@PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)
})
@ComponentScan(basePackages = {"nl.uva.sne.drip", "nl.uva.sne.drip.api", "nl.uva.sne.drip.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.model", "nl.uva.sne.drip.service", "nl.uva.sne.drip.commons.utils"})
public class ToscaHelperConfig {
@Value("${sure-tosca.base.path}")
private String sureToscaBasePath;
@Bean
public ToscaHelper toscaHelper() {
return new ToscaHelper(sureToscaBasePath);
}
}
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
*/ */
package nl.uva.sne.drip.dao; package nl.uva.sne.drip.dao;
import nl.uva.sne.drip.model.tosca.Credentials; import java.util.List;
import nl.uva.sne.drip.model.tosca.Credential;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -14,6 +15,7 @@ import org.springframework.stereotype.Repository; ...@@ -14,6 +15,7 @@ import org.springframework.stereotype.Repository;
* @author S. Koulouzis * @author S. Koulouzis
*/ */
@Repository @Repository
public interface CredentialDAO extends MongoRepository<Credentials, String> { public interface CredentialDAO extends MongoRepository<Credential, String> {
List<Credential> findBycloudProviderName(String cloudProviderName);
} }
...@@ -11,7 +11,7 @@ import java.util.List; ...@@ -11,7 +11,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import nl.uva.sne.drip.dao.CredentialDAO; import nl.uva.sne.drip.dao.CredentialDAO;
import nl.uva.sne.drip.model.tosca.Credentials; import nl.uva.sne.drip.model.tosca.Credential;
/** /**
* *
...@@ -23,13 +23,13 @@ public class CredentialService { ...@@ -23,13 +23,13 @@ public class CredentialService {
@Autowired @Autowired
private CredentialDAO dao; private CredentialDAO dao;
public String save(Credentials document) { public String save(Credential document) {
dao.save(document); dao.save(document);
return document.getId(); return document.getId();
} }
public Credentials findByID(String id) throws JsonProcessingException { public Credential findByID(String id) throws JsonProcessingException {
Credentials credentials = dao.findById(id).get(); Credential credentials = dao.findById(id).get();
return credentials; return credentials;
} }
...@@ -39,8 +39,8 @@ public class CredentialService { ...@@ -39,8 +39,8 @@ public class CredentialService {
public List<String> getAllIds() { public List<String> getAllIds() {
List<String> allIds = new ArrayList<>(); List<String> allIds = new ArrayList<>();
List<Credentials> all = dao.findAll(); List<Credential> all = dao.findAll();
for (Credentials tt : all) { for (Credential tt : all) {
allIds.add(tt.getId()); allIds.add(tt.getId());
} }
return allIds; return allIds;
...@@ -50,4 +50,8 @@ public class CredentialService { ...@@ -50,4 +50,8 @@ public class CredentialService {
dao.deleteAll(); dao.deleteAll();
} }
List<Credential> findByProvider(String provider) {
return dao.findBycloudProviderName(provider);
}
} }
...@@ -5,13 +5,19 @@ ...@@ -5,13 +5,19 @@
*/ */
package nl.uva.sne.drip.service; package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.model.Message; import nl.uva.sne.drip.model.Message;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller; import nl.uva.sne.drip.rpc.DRIPCaller;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -28,14 +34,27 @@ public class DRIPService { ...@@ -28,14 +34,27 @@ public class DRIPService {
@Autowired @Autowired
DRIPCaller caller; DRIPCaller caller;
@Autowired
CredentialService credentialService;
private String requestQeueName; private String requestQeueName;
public String execute(String id) { @Autowired
private ToscaHelper helper;
public String execute(String id) throws JsonProcessingException, ApiException, Exception {
try { try {
caller.init(); caller.init();
String ymlToscaTemplate = toscaTemplateService.findByID(id); String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate); ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplate> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplate vmTopology : vmTopologies) {
String provider = helper.getTopologyProvider(vmTopology);
List<Credential> credentials = credentialService.findByProvider(provider);
}
Message message = new Message(); Message message = new Message();
message.setOwner("user"); message.setOwner("user");
message.setCreationDate(System.currentTimeMillis()); message.setCreationDate(System.currentTimeMillis());
......
...@@ -36,7 +36,7 @@ import java.util.logging.Level; ...@@ -36,7 +36,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.Swagger2SpringBoot; import nl.uva.sne.drip.Swagger2SpringBoot;
import nl.uva.sne.drip.configuration.MongoConfig; import nl.uva.sne.drip.configuration.MongoConfig;
import nl.uva.sne.drip.model.tosca.Credentials; import nl.uva.sne.drip.model.tosca.Credential;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
...@@ -266,7 +266,7 @@ public class ServiceTests { ...@@ -266,7 +266,7 @@ public class ServiceTests {
public String saveCredential() { public String saveCredential() {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "saveCredential"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "saveCredential");
Credentials document = new Credentials(); Credential document = new Credential();
document.setCloudProviderName("exogeni"); document.setCloudProviderName("exogeni");
Map<String, String> keys = new HashMap<>(); Map<String, String> keys = new HashMap<>();
keys.put("keystore", "/qTlqams0Ppq2rnaOgL5am7ExGO2nMsOZYM61kiAnsvkOixUuoPy9r4d4OfhwQXXg3lZmeRITjNz4ps+hIDKuxodIQXgBtfMy9Kx8Syb9bIl/MQQls5hWyp9yHAl6vAampoxYu0170lceT1sds4OCz3tM9eF7/UoBQwXBPo94QhO1/vSbtICyVsm3Z2HeGKcBWobT3opZV2w30GqX/7OBmNeIG7RBMPuxLsUxJ9Alahi1zXOUjLkd2bmmVFREngmeubgCzPFxxCQQrZK6WratTzJKc1sRVNK5GJzTwi9BlcZSQSgprum9yVHUgQc6Ylmvdrkhn2g9SlluY2JAZyCZvHYaRBKE4o5bXBDumTy1YAPMNPTfpeeLz+YmH0GMfVwKkxtIBpjb045QseoIWcqxke60WWfJguaTqymXknmcqcLNz+UzUdfVfyurOy9X8xmTGCW5V4N"); keys.put("keystore", "/qTlqams0Ppq2rnaOgL5am7ExGO2nMsOZYM61kiAnsvkOixUuoPy9r4d4OfhwQXXg3lZmeRITjNz4ps+hIDKuxodIQXgBtfMy9Kx8Syb9bIl/MQQls5hWyp9yHAl6vAampoxYu0170lceT1sds4OCz3tM9eF7/UoBQwXBPo94QhO1/vSbtICyVsm3Z2HeGKcBWobT3opZV2w30GqX/7OBmNeIG7RBMPuxLsUxJ9Alahi1zXOUjLkd2bmmVFREngmeubgCzPFxxCQQrZK6WratTzJKc1sRVNK5GJzTwi9BlcZSQSgprum9yVHUgQc6Ylmvdrkhn2g9SlluY2JAZyCZvHYaRBKE4o5bXBDumTy1YAPMNPTfpeeLz+YmH0GMfVwKkxtIBpjb045QseoIWcqxke60WWfJguaTqymXknmcqcLNz+UzUdfVfyurOy9X8xmTGCW5V4N");
...@@ -286,7 +286,7 @@ public class ServiceTests { ...@@ -286,7 +286,7 @@ public class ServiceTests {
public void testCredentialServiceFindByID() throws Exception { public void testCredentialServiceFindByID() throws Exception {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "findByID"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "findByID");
String id = saveCredential(); String id = saveCredential();
Credentials result = credentialService.findByID(id); Credential result = credentialService.findByID(id);
assertNotNull(result); assertNotNull(result);
} }
...@@ -299,7 +299,7 @@ public class ServiceTests { ...@@ -299,7 +299,7 @@ public class ServiceTests {
String id = saveCredential(); String id = saveCredential();
credentialService.deleteByID(id); credentialService.deleteByID(id);
try { try {
Credentials res = credentialService.findByID(id); Credential res = credentialService.findByID(id);
} catch (Exception ex) { } catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) { if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage()); fail(ex.getMessage());
......
#http://geni-images.renci.org/images/standard/ubuntu-comet/
#https://wiki.exogeni.net/doku.php?id=public:experimenters:resource_types:start
GlobalEntry: "https://geni.renci.org:11443/orca/xmlrpc" GlobalEntry: "https://geni.renci.org:11443/orca/xmlrpc"
DCMetaInfo: DCMetaInfo:
- domain: "UvA (Amsterdam, The Netherlands) XO Rack" - domain: "UvA (Amsterdam, The Netherlands) XO Rack"
...@@ -833,3 +835,23 @@ DCMetaInfo: ...@@ -833,3 +835,23 @@ DCMetaInfo:
OS_URL: "http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.4.xml" OS_URL: "http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.4.xml"
OS_GUID: "9394ca154aa35eb55e604503ae7943ddaecc6ca5" OS_GUID: "9394ca154aa35eb55e604503ae7943ddaecc6ca5"
DiskSize: 75 DiskSize: 75
- OS: "Ubuntu 16.04"
CPU: 4
MEM: 12
VMType: "XOXLarge"
Price: null
DefaultSSHAccount: "root"
extraInfo:
OS_URL: "http://geni-images.renci.org/images/standard/ubuntu-comet/ubuntu-18.04/ubuntu-18.04.xml"
OS_GUID: "fe66b08bffa14c385ad64edd124350a2da826af9"
DiskSize: 75
- OS: "Ubuntu 16.04"
CPU: 2
MEM: 6
VMType: "XOLarge"
Price: null
DefaultSSHAccount: "root"
extraInfo:
OS_URL: "http://geni-images.renci.org/images/standard/ubuntu-comet/ubuntu-18.04/ubuntu-18.04.xml"
OS_GUID: "fe66b08bffa14c385ad64edd124350a2da826af9"
DiskSize: 50
...@@ -51,7 +51,8 @@ class CloudStormService { ...@@ -51,7 +51,8 @@ class CloudStormService {
String cloudStormDBPath = properties.getProperty("cloud.storm.db.path"); String cloudStormDBPath = properties.getProperty("cloud.storm.db.path");
cloudStormDAO = new CloudStormDAO(cloudStormDBPath); cloudStormDAO = new CloudStormDAO(cloudStormDBPath);
String sureToscaBasePath = properties.getProperty("sure-tosca.base.path"); String sureToscaBasePath = properties.getProperty("sure-tosca.base.path");
this.helper = new ToscaHelper(toscaTemplate, sureToscaBasePath); this.helper = new ToscaHelper(sureToscaBasePath);
this.helper.uploadToscaTemplate(toscaTemplate);
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
} }
...@@ -75,15 +76,13 @@ class CloudStormService { ...@@ -75,15 +76,13 @@ class CloudStormService {
if (!(credentialsTempInputDir.mkdirs())) { if (!(credentialsTempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath()); throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath());
} }
writeCloudcredentialsTopologyFiles(toscaTemplate, credentialsTempInputDirPath); writeCloudStormCredentialsFiles(toscaTemplate, credentialsTempInputDirPath);
String infrasCodeTempInputDirPath = File.separator + "infrasCodes"; String infrasCodeTempInputDirPath = File.separator + "infrasCodes";
File infrasCodeTempInputDir = new File(infrasCodeTempInputDirPath); File infrasCodeTempInputDir = new File(infrasCodeTempInputDirPath);
if (!(infrasCodeTempInputDir.mkdirs())) { if (!(infrasCodeTempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath()); throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath());
} }
return toscaTemplate; return toscaTemplate;
} }
...@@ -136,7 +135,7 @@ class CloudStormService { ...@@ -136,7 +135,7 @@ class CloudStormService {
List<CloudsStormVM> vms = new ArrayList<>(); List<CloudsStormVM> vms = new ArrayList<>();
cloudsStormVMs.setName("vm_topology" + i); cloudsStormVMs.setName("vm_topology" + i);
List<NodeTemplate> vmTemplates = helper.getTopologyTemplateVMs(nodeTemplate); List<NodeTemplate> vmTemplates = helper.getTemplateVMsForVMTopology(nodeTemplate);
int j = 0; int j = 0;
for (NodeTemplate vm : vmTemplates) { for (NodeTemplate vm : vmTemplates) {
CloudsStormVM cloudsStormVM = new CloudsStormVM(); CloudsStormVM cloudsStormVM = new CloudsStormVM();
...@@ -173,8 +172,8 @@ class CloudStormService { ...@@ -173,8 +172,8 @@ class CloudStormService {
return null; return null;
} }
private void writeCloudcredentialsTopologyFiles(ToscaTemplate toscaTemplate, String credentialsTempInputDirPath) { private void writeCloudStormCredentialsFiles(ToscaTemplate toscaTemplate, String credentialsTempInputDirPath) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }
} }
Credentials: Credential:
type: "object" type: "object"
properties: properties:
protocol: protocol:
......
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