Commit cff704c4 authored by Spiros Koulouzis's avatar Spiros Koulouzis

implementing provision service

parent 5dbca3ef
...@@ -22,10 +22,17 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; ...@@ -22,10 +22,17 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import nl.uva.sne.drip.commons.sure_tosca.client.ApiClient;
import nl.uva.sne.drip.commons.sure_tosca.client.ApiException; import nl.uva.sne.drip.commons.sure_tosca.client.ApiException;
import nl.uva.sne.drip.commons.sure_tosca.client.Configuration;
import nl.uva.sne.drip.commons.sure_tosca.client.DefaultApi; import nl.uva.sne.drip.commons.sure_tosca.client.DefaultApi;
import nl.uva.sne.drip.model.ToscaTemplate; import nl.uva.sne.drip.model.ToscaTemplate;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/** /**
* *
...@@ -46,11 +53,13 @@ public class ToscaHelper { ...@@ -46,11 +53,13 @@ public class ToscaHelper {
private final Integer id; private final Integer id;
public ToscaHelper(ToscaTemplate toscaTemplate) throws JsonProcessingException, IOException, ApiException { public ToscaHelper(ToscaTemplate toscaTemplate, String sureToscaBasePath) throws JsonProcessingException, IOException, ApiException {
api = new DefaultApi(); Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath);
id = uploadToscaTemplate(toscaTemplate); 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 { private Integer uploadToscaTemplate(ToscaTemplate toscaTemplate) throws JsonProcessingException, IOException, ApiException {
...@@ -58,7 +67,19 @@ public class ToscaHelper { ...@@ -58,7 +67,19 @@ public class ToscaHelper {
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 null; return Integer.valueOf(resp);
}
public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException {
List<Map<String, Object>> interfaceDefinitions = new ArrayList<>();
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;
} }
} }
...@@ -4,6 +4,7 @@ import java.util.Objects; ...@@ -4,6 +4,7 @@ import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap; import java.util.HashMap;
...@@ -18,9 +19,9 @@ import org.springframework.data.annotation.Id; ...@@ -18,9 +19,9 @@ import org.springframework.data.annotation.Id;
* Credentials * Credentials
*/ */
@Validated @Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-11-01T14:10:53.529Z") @JsonInclude(JsonInclude.Include.NON_NULL)
public class Credentials { public class Credentials {
/** /**
* @return the id * @return the id
*/ */
...@@ -65,11 +66,12 @@ public class Credentials { ...@@ -65,11 +66,12 @@ public class Credentials {
/** /**
* Get protocol * Get protocol
*
* @return protocol * @return protocol
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getProtocol() { public String getProtocol() {
return protocol; return protocol;
} }
...@@ -85,11 +87,12 @@ public class Credentials { ...@@ -85,11 +87,12 @@ public class Credentials {
/** /**
* Get tokenType * Get tokenType
*
* @return tokenType * @return tokenType
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getTokenType() { public String getTokenType() {
return tokenType; return tokenType;
} }
...@@ -105,11 +108,12 @@ public class Credentials { ...@@ -105,11 +108,12 @@ public class Credentials {
/** /**
* Get token * Get token
*
* @return token * @return token
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getToken() { public String getToken() {
return token; return token;
} }
...@@ -133,11 +137,12 @@ public class Credentials { ...@@ -133,11 +137,12 @@ public class Credentials {
/** /**
* Get keys * Get keys
*
* @return keys * @return keys
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getKeys() { public Map<String, String> getKeys() {
return keys; return keys;
} }
...@@ -153,11 +158,12 @@ public class Credentials { ...@@ -153,11 +158,12 @@ public class Credentials {
/** /**
* Get user * Get user
*
* @return user * @return user
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getUser() { public String getUser() {
return user; return user;
} }
...@@ -173,11 +179,12 @@ public class Credentials { ...@@ -173,11 +179,12 @@ public class Credentials {
/** /**
* Get cloudProviderName * Get cloudProviderName
*
* @return cloudProviderName * @return cloudProviderName
**/ *
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getCloudProviderName() { public String getCloudProviderName() {
return cloudProviderName; return cloudProviderName;
} }
...@@ -186,7 +193,6 @@ public class Credentials { ...@@ -186,7 +193,6 @@ public class Credentials {
this.cloudProviderName = cloudProviderName; this.cloudProviderName = cloudProviderName;
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {
...@@ -196,12 +202,12 @@ public class Credentials { ...@@ -196,12 +202,12 @@ public class Credentials {
return false; return false;
} }
Credentials credentials = (Credentials) o; Credentials credentials = (Credentials) 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)
Objects.equals(this.keys, credentials.keys) && && Objects.equals(this.keys, credentials.keys)
Objects.equals(this.user, credentials.user) && && Objects.equals(this.user, credentials.user)
Objects.equals(this.cloudProviderName, credentials.cloudProviderName); && Objects.equals(this.cloudProviderName, credentials.cloudProviderName);
} }
@Override @Override
...@@ -235,4 +241,3 @@ public class Credentials { ...@@ -235,4 +241,3 @@ public class Credentials {
return o.toString().replace("\n", "\n "); return o.toString().replace("\n", "\n ");
} }
} }
...@@ -3,6 +3,7 @@ package nl.uva.sne.drip.model; ...@@ -3,6 +3,7 @@ package nl.uva.sne.drip.model;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -17,28 +18,26 @@ import javax.validation.constraints.*; ...@@ -17,28 +18,26 @@ import javax.validation.constraints.*;
* NodeTemplate * NodeTemplate
*/ */
@Validated @Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-11-01T14:10:53.529Z") @JsonInclude(JsonInclude.Include.NON_NULL)
public class NodeTemplate { public class NodeTemplate {
@JsonProperty("derived_from") @JsonProperty("derived_from")
private String derivedFrom = null; private String derivedFrom = null;
@JsonProperty("properties") @JsonProperty("properties")
@Valid @Valid
private Map<String, String> properties = null; private Map<String, Object> properties = null;
@JsonProperty("requirements") @JsonProperty("requirements")
@Valid @Valid
private List<Map<String, String>> requirements = null; private List<Map<String, Object>> requirements = null;
@JsonProperty("interfaces") @JsonProperty("interfaces")
@Valid @Valid
private Map<String, String> interfaces = null; private Map<String, Object> interfaces = null;
@JsonProperty("capabilities") @JsonProperty("capabilities")
@Valid @Valid
private Map<String, String> capabilities = null; private Map<String, Object> capabilities = null;
@JsonProperty("type") @JsonProperty("type")
private String type = null; private String type = null;
...@@ -52,11 +51,11 @@ public class NodeTemplate { ...@@ -52,11 +51,11 @@ public class NodeTemplate {
@JsonProperty("attributes") @JsonProperty("attributes")
@Valid @Valid
private Map<String, String> attributes = null; private Map<String, Object> attributes = null;
@JsonProperty("artifacts") @JsonProperty("artifacts")
@Valid @Valid
private Map<String, String> artifacts = null; private Map<String, Object> artifacts = null;
public NodeTemplate derivedFrom(String derivedFrom) { public NodeTemplate derivedFrom(String derivedFrom) {
this.derivedFrom = derivedFrom; this.derivedFrom = derivedFrom;
...@@ -78,14 +77,14 @@ public class NodeTemplate { ...@@ -78,14 +77,14 @@ public class NodeTemplate {
this.derivedFrom = derivedFrom; this.derivedFrom = derivedFrom;
} }
public NodeTemplate properties(Map<String, String> properties) { public NodeTemplate properties(Map<String, Object> properties) {
this.properties = properties; this.properties = properties;
return this; return this;
} }
public NodeTemplate putPropertiesItem(String key, String propertiesItem) { public NodeTemplate putPropertiesItem(String key, Object propertiesItem) {
if (this.properties == null) { if (this.properties == null) {
this.properties = new HashMap<String, String>(); this.properties = new HashMap<String, Object>();
} }
this.properties.put(key, propertiesItem); this.properties.put(key, propertiesItem);
return this; return this;
...@@ -98,22 +97,22 @@ public class NodeTemplate { ...@@ -98,22 +97,22 @@ public class NodeTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getProperties() { public Map<String, Object> getProperties() {
return properties; return properties;
} }
public void setProperties(Map<String, String> properties) { public void setProperties(Map<String, Object> properties) {
this.properties = properties; this.properties = properties;
} }
public NodeTemplate requirements(List<Map<String, String>> requirements) { public NodeTemplate requirements(List<Map<String, Object>> requirements) {
this.requirements = requirements; this.requirements = requirements;
return this; return this;
} }
public NodeTemplate addRequirementsItem(Map<String, String> requirementsItem) { public NodeTemplate addRequirementsItem(Map<String, Object> requirementsItem) {
if (this.requirements == null) { if (this.requirements == null) {
this.requirements = new ArrayList<Map<String, String>>(); this.requirements = new ArrayList<Map<String, Object>>();
} }
this.requirements.add(requirementsItem); this.requirements.add(requirementsItem);
return this; return this;
...@@ -127,22 +126,22 @@ public class NodeTemplate { ...@@ -127,22 +126,22 @@ public class NodeTemplate {
@Valid @Valid
public List<Map<String, String>> getRequirements() { public List<Map<String, Object>> getRequirements() {
return requirements; return requirements;
} }
public void setRequirements(List<Map<String, String>> requirements) { public void setRequirements(List<Map<String, Object>> requirements) {
this.requirements = requirements; this.requirements = requirements;
} }
public NodeTemplate interfaces(Map<String, String> interfaces) { public NodeTemplate interfaces(Map<String, Object> interfaces) {
this.interfaces = interfaces; this.interfaces = interfaces;
return this; return this;
} }
public NodeTemplate putInterfacesItem(String key, String interfacesItem) { public NodeTemplate putInterfacesItem(String key, Object interfacesItem) {
if (this.interfaces == null) { if (this.interfaces == null) {
this.interfaces = new HashMap<String, String>(); this.interfaces = new HashMap<String, Object>();
} }
this.interfaces.put(key, interfacesItem); this.interfaces.put(key, interfacesItem);
return this; return this;
...@@ -155,22 +154,22 @@ public class NodeTemplate { ...@@ -155,22 +154,22 @@ public class NodeTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getInterfaces() { public Map<String, Object> getInterfaces() {
return interfaces; return interfaces;
} }
public void setInterfaces(Map<String, String> interfaces) { public void setInterfaces(Map<String, Object> interfaces) {
this.interfaces = interfaces; this.interfaces = interfaces;
} }
public NodeTemplate capabilities(Map<String, String> capabilities) { public NodeTemplate capabilities(Map<String, Object> capabilities) {
this.capabilities = capabilities; this.capabilities = capabilities;
return this; return this;
} }
public NodeTemplate putCapabilitiesItem(String key, String capabilitiesItem) { public NodeTemplate putCapabilitiesItem(String key, Object capabilitiesItem) {
if (this.capabilities == null) { if (this.capabilities == null) {
this.capabilities = new HashMap<String, String>(); this.capabilities = new HashMap<String, Object>();
} }
this.capabilities.put(key, capabilitiesItem); this.capabilities.put(key, capabilitiesItem);
return this; return this;
...@@ -183,11 +182,11 @@ public class NodeTemplate { ...@@ -183,11 +182,11 @@ public class NodeTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getCapabilities() { public Map<String, Object> getCapabilities() {
return capabilities; return capabilities;
} }
public void setCapabilities(Map<String, String> capabilities) { public void setCapabilities(Map<String, Object> capabilities) {
this.capabilities = capabilities; this.capabilities = capabilities;
} }
...@@ -259,14 +258,14 @@ public class NodeTemplate { ...@@ -259,14 +258,14 @@ public class NodeTemplate {
this.directives = directives; this.directives = directives;
} }
public NodeTemplate attributes(Map<String, String> attributes) { public NodeTemplate attributes(Map<String, Object> attributes) {
this.attributes = attributes; this.attributes = attributes;
return this; return this;
} }
public NodeTemplate putAttributesItem(String key, String attributesItem) { public NodeTemplate putAttributesItem(String key, Object attributesItem) {
if (this.attributes == null) { if (this.attributes == null) {
this.attributes = new HashMap<String, String>(); this.attributes = new HashMap<String, Object>();
} }
this.attributes.put(key, attributesItem); this.attributes.put(key, attributesItem);
return this; return this;
...@@ -279,22 +278,22 @@ public class NodeTemplate { ...@@ -279,22 +278,22 @@ public class NodeTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getAttributes() { public Map<String, Object> getAttributes() {
return attributes; return attributes;
} }
public void setAttributes(Map<String, String> attributes) { public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes; this.attributes = attributes;
} }
public NodeTemplate artifacts(Map<String, String> artifacts) { public NodeTemplate artifacts(Map<String, Object> artifacts) {
this.artifacts = artifacts; this.artifacts = artifacts;
return this; return this;
} }
public NodeTemplate putArtifactsItem(String key, String artifactsItem) { public NodeTemplate putArtifactsItem(String key, Object artifactsItem) {
if (this.artifacts == null) { if (this.artifacts == null) {
this.artifacts = new HashMap<String, String>(); this.artifacts = new HashMap<String, Object>();
} }
this.artifacts.put(key, artifactsItem); this.artifacts.put(key, artifactsItem);
return this; return this;
...@@ -307,11 +306,11 @@ public class NodeTemplate { ...@@ -307,11 +306,11 @@ public class NodeTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getArtifacts() { public Map<String, Object> getArtifacts() {
return artifacts; return artifacts;
} }
public void setArtifacts(Map<String, String> artifacts) { public void setArtifacts(Map<String, Object> artifacts) {
this.artifacts = artifacts; this.artifacts = artifacts;
} }
......
package nl.uva.sne.drip.model;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import org.springframework.data.annotation.Id;
/**
* Provisioner
*/
@Validated
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Provisioner {
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
@Id
@JsonIgnore
private String id;
@JsonProperty("version")
private String version = null;
@JsonProperty("name")
private String name = null;
@JsonProperty("description")
private String description = null;
@JsonProperty("tosca_interface_types")
@Valid
private List<String> tosca_interface_types = null;
public Provisioner version(String version) {
this.version = version;
return this;
}
/**
* Get version
*
* @return version
*
*/
@ApiModelProperty(value = "")
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Provisioner templateName(String templateName) {
this.name = templateName;
return this;
}
/**
* Get name
*
* @return name
*
*/
@ApiModelProperty(value = "")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* Get description
*
* @return description
*
*/
@ApiModelProperty(value = "")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Provisioner toscaInterfaceTypes(List<String> imports) {
this.tosca_interface_types = imports;
return this;
}
public Provisioner addToscaInterfaceTypes(String importsItem) {
if (this.tosca_interface_types == null) {
this.tosca_interface_types = new ArrayList();
}
this.tosca_interface_types.add(importsItem);
return this;
}
/**
* Get tosca_interface_types
*
* @return tosca_interface_types
*
*/
@ApiModelProperty(value = "")
@Valid
public List<String> getToscaInterfaceTypes() {
return tosca_interface_types;
}
public void setToscaInterfaceTypes(List<String> tosca_interface_types) {
this.tosca_interface_types = tosca_interface_types;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Provisioner toscaTemplate = (Provisioner) o;
return Objects.equals(this.version, toscaTemplate.version)
&& Objects.equals(this.name, toscaTemplate.name)
&& Objects.equals(this.description, toscaTemplate.description)
&& Objects.equals(this.tosca_interface_types, toscaTemplate.tosca_interface_types);
}
@Override
public int hashCode() {
return Objects.hash(version, name, description, tosca_interface_types);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ToscaTemplate {\n");
sb.append(" toscaDefinitionsVersion: ").append(toIndentedString(version)).append("\n");
sb.append(" templateName: ").append(toIndentedString(name)).append("\n");
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" imports: ").append(toIndentedString(tosca_interface_types)).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 ");
}
}
...@@ -2,6 +2,9 @@ package nl.uva.sne.drip.model; ...@@ -2,6 +2,9 @@ package nl.uva.sne.drip.model;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -9,14 +12,15 @@ import java.util.List; ...@@ -9,14 +12,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.*;
/** /**
* TopologyTemplate * TopologyTemplate
*/ */
@Validated @Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-11-01T14:10:53.529Z") @JsonInclude(JsonInclude.Include.NON_NULL)
public class TopologyTemplate { public class TopologyTemplate {
@JsonProperty("description") @JsonProperty("description")
private String description = null; private String description = null;
...@@ -30,23 +34,23 @@ public class TopologyTemplate { ...@@ -30,23 +34,23 @@ public class TopologyTemplate {
@JsonProperty("relationship_templates") @JsonProperty("relationship_templates")
@Valid @Valid
private Map<String, String> relationshipTemplates = null; private Map<String, Object> relationshipTemplates = null;
@JsonProperty("outputs") @JsonProperty("outputs")
@Valid @Valid
private Map<String, String> outputs = null; private Map<String, Object> outputs = null;
@JsonProperty("groups") @JsonProperty("groups")
@Valid @Valid
private Map<String, String> groups = null; private Map<String, Object> groups = null;
@JsonProperty("substitution_mappings") @JsonProperty("substitution_mappings")
@Valid @Valid
private Map<String, String> substitutionMappings = null; private Map<String, Object> substitutionMappings = null;
@JsonProperty("policies") @JsonProperty("policies")
@Valid @Valid
private List<Map<String, String>> policies = null; private List<Map<String, Object>> policies = null;
public TopologyTemplate description(String description) { public TopologyTemplate description(String description) {
this.description = description; this.description = description;
...@@ -125,14 +129,14 @@ public class TopologyTemplate { ...@@ -125,14 +129,14 @@ public class TopologyTemplate {
this.nodeTemplates = nodeTemplates; this.nodeTemplates = nodeTemplates;
} }
public TopologyTemplate relationshipTemplates(Map<String, String> relationshipTemplates) { public TopologyTemplate relationshipTemplates(Map<String, Object> relationshipTemplates) {
this.relationshipTemplates = relationshipTemplates; this.relationshipTemplates = relationshipTemplates;
return this; return this;
} }
public TopologyTemplate putRelationshipTemplatesItem(String key, String relationshipTemplatesItem) { public TopologyTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) {
if (this.relationshipTemplates == null) { if (this.relationshipTemplates == null) {
this.relationshipTemplates = new HashMap<String, String>(); this.relationshipTemplates = new HashMap<String, Object>();
} }
this.relationshipTemplates.put(key, relationshipTemplatesItem); this.relationshipTemplates.put(key, relationshipTemplatesItem);
return this; return this;
...@@ -145,22 +149,22 @@ public class TopologyTemplate { ...@@ -145,22 +149,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getRelationshipTemplates() { public Map<String, Object> getRelationshipTemplates() {
return relationshipTemplates; return relationshipTemplates;
} }
public void setRelationshipTemplates(Map<String, String> relationshipTemplates) { public void setRelationshipTemplates(Map<String, Object> relationshipTemplates) {
this.relationshipTemplates = relationshipTemplates; this.relationshipTemplates = relationshipTemplates;
} }
public TopologyTemplate outputs(Map<String, String> outputs) { public TopologyTemplate outputs(Map<String, Object> outputs) {
this.outputs = outputs; this.outputs = outputs;
return this; return this;
} }
public TopologyTemplate putOutputsItem(String key, String outputsItem) { public TopologyTemplate putOutputsItem(String key, Object outputsItem) {
if (this.outputs == null) { if (this.outputs == null) {
this.outputs = new HashMap<String, String>(); this.outputs = new HashMap<String, Object>();
} }
this.outputs.put(key, outputsItem); this.outputs.put(key, outputsItem);
return this; return this;
...@@ -173,22 +177,22 @@ public class TopologyTemplate { ...@@ -173,22 +177,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getOutputs() { public Map<String, Object> getOutputs() {
return outputs; return outputs;
} }
public void setOutputs(Map<String, String> outputs) { public void setOutputs(Map<String, Object> outputs) {
this.outputs = outputs; this.outputs = outputs;
} }
public TopologyTemplate groups(Map<String, String> groups) { public TopologyTemplate groups(Map<String, Object> groups) {
this.groups = groups; this.groups = groups;
return this; return this;
} }
public TopologyTemplate putGroupsItem(String key, String groupsItem) { public TopologyTemplate putGroupsItem(String key, Object groupsItem) {
if (this.groups == null) { if (this.groups == null) {
this.groups = new HashMap<String, String>(); this.groups = new HashMap<String, Object>();
} }
this.groups.put(key, groupsItem); this.groups.put(key, groupsItem);
return this; return this;
...@@ -201,22 +205,22 @@ public class TopologyTemplate { ...@@ -201,22 +205,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getGroups() { public Map<String, Object> getGroups() {
return groups; return groups;
} }
public void setGroups(Map<String, String> groups) { public void setGroups(Map<String, Object> groups) {
this.groups = groups; this.groups = groups;
} }
public TopologyTemplate substitutionMappings(Map<String, String> substitutionMappings) { public TopologyTemplate substitutionMappings(Map<String, Object> substitutionMappings) {
this.substitutionMappings = substitutionMappings; this.substitutionMappings = substitutionMappings;
return this; return this;
} }
public TopologyTemplate putSubstitutionMappingsItem(String key, String substitutionMappingsItem) { public TopologyTemplate putSubstitutionMappingsItem(String key, Object substitutionMappingsItem) {
if (this.substitutionMappings == null) { if (this.substitutionMappings == null) {
this.substitutionMappings = new HashMap<String, String>(); this.substitutionMappings = new HashMap<String, Object>();
} }
this.substitutionMappings.put(key, substitutionMappingsItem); this.substitutionMappings.put(key, substitutionMappingsItem);
return this; return this;
...@@ -229,22 +233,22 @@ public class TopologyTemplate { ...@@ -229,22 +233,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getSubstitutionMappings() { public Map<String, Object> getSubstitutionMappings() {
return substitutionMappings; return substitutionMappings;
} }
public void setSubstitutionMappings(Map<String, String> substitutionMappings) { public void setSubstitutionMappings(Map<String, Object> substitutionMappings) {
this.substitutionMappings = substitutionMappings; this.substitutionMappings = substitutionMappings;
} }
public TopologyTemplate policies(List<Map<String, String>> policies) { public TopologyTemplate policies(List<Map<String, Object>> policies) {
this.policies = policies; this.policies = policies;
return this; return this;
} }
public TopologyTemplate addPoliciesItem(Map<String, String> policiesItem) { public TopologyTemplate addPoliciesItem(Map<String, Object> policiesItem) {
if (this.policies == null) { if (this.policies == null) {
this.policies = new ArrayList<Map<String, String>>(); this.policies = new ArrayList<Map<String, Object>>();
} }
this.policies.add(policiesItem); this.policies.add(policiesItem);
return this; return this;
...@@ -258,11 +262,11 @@ public class TopologyTemplate { ...@@ -258,11 +262,11 @@ public class TopologyTemplate {
@Valid @Valid
public List<Map<String, String>> getPolicies() { public List<Map<String, Object>> getPolicies() {
return policies; return policies;
} }
public void setPolicies(List<Map<String, String>> policies) { public void setPolicies(List<Map<String, Object>> policies) {
this.policies = policies; this.policies = policies;
} }
......
package nl.uva.sne.drip.model; package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Objects; import java.util.Objects;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -11,8 +12,7 @@ import org.springframework.data.annotation.Id; ...@@ -11,8 +12,7 @@ import org.springframework.data.annotation.Id;
* User * User
*/ */
@Validated @Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-11-01T14:10:53.529Z") @JsonInclude(JsonInclude.Include.NON_NULL)
public class User { public class User {
/** /**
* @return the id * @return the id
......
...@@ -20,8 +20,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -20,8 +20,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
}) })
@EnableMongoRepositories(basePackageClasses = {ToscaTemplateDAO.class}) @EnableMongoRepositories(basePackageClasses = {ToscaTemplateDAO.class})
@ComponentScan(basePackages = {"nl.uva.sne.drip", "nl.uva.sne.drip.api", @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.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.service"})
"nl.uva.sne.drip.service"})
public class Swagger2SpringBoot implements CommandLineRunner { public class Swagger2SpringBoot implements CommandLineRunner {
@Value("${message.broker.host}") @Value("${message.broker.host}")
......
package nl.uva.sne.drip.api; package nl.uva.sne.drip.api;
import com.fasterxml.jackson.core.JsonProcessingException;
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;
...@@ -12,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -12,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import nl.uva.sne.drip.commons.sure_tosca.client.ApiException;
import nl.uva.sne.drip.service.DRIPService; import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.service.ProvisionerService; import nl.uva.sne.drip.service.ProvisionerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -46,7 +48,7 @@ public class ProvisionerApiController implements ProvisionerApi { ...@@ -46,7 +48,7 @@ public class ProvisionerApiController implements ProvisionerApi {
try { try {
String planedYemplateId = provisionerService.provision(id); String planedYemplateId = provisionerService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (IOException ex) { } catch (IOException | ApiException ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
......
/*
* 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.dao;
import nl.uva.sne.drip.model.Provisioner;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
/**
*
* @author S. Koulouzis
*/
@Repository
public interface ProvisionerDAO extends MongoRepository<Provisioner, String> {
}
...@@ -7,6 +7,7 @@ package nl.uva.sne.drip.service; ...@@ -7,6 +7,7 @@ package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -15,8 +16,10 @@ import java.util.logging.Level; ...@@ -15,8 +16,10 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.commons.sure_tosca.client.ApiException; import nl.uva.sne.drip.commons.sure_tosca.client.ApiException;
import nl.uva.sne.drip.commons.utils.ToscaHelper; import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.dao.ProvisionerDAO;
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.NodeTemplate;
import nl.uva.sne.drip.model.Provisioner;
import nl.uva.sne.drip.model.ToscaTemplate; import nl.uva.sne.drip.model.ToscaTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
...@@ -36,9 +39,15 @@ public class ProvisionerService { ...@@ -36,9 +39,15 @@ public class ProvisionerService {
@Value("${tosca.types.interface}") @Value("${tosca.types.interface}")
private String toscaTypesInterface; private String toscaTypesInterface;
@Value("${sure-tosca.base.path}")
private String sureToscaBasePath;
@Autowired @Autowired
private ToscaTemplateService toscaTemplateService; private ToscaTemplateService toscaTemplateService;
@Autowired
private ProvisionerDAO provisionerDao;
ToscaHelper toscaHelper; ToscaHelper toscaHelper;
private Integer toscaHelperID; private Integer toscaHelperID;
...@@ -46,7 +55,7 @@ public class ProvisionerService { ...@@ -46,7 +55,7 @@ public class ProvisionerService {
String ymlToscaTemplate = toscaTemplateService.findByID(id); String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate); ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
toscaHelper = new ToscaHelper(toscaTemplate); toscaHelper = new ToscaHelper(toscaTemplate, sureToscaBasePath);
toscaTemplate = addProvisionInterface(toscaTemplate); toscaTemplate = addProvisionInterface(toscaTemplate);
...@@ -56,8 +65,12 @@ public class ProvisionerService { ...@@ -56,8 +65,12 @@ public class ProvisionerService {
// private List<Map<String, NodeTemplate>> getVmTopologies(ToscaTemplate toscaTemplate) { // private List<Map<String, NodeTemplate>> getVmTopologies(ToscaTemplate toscaTemplate) {
// return ToscaHelper.getNodesByType(toscaTemplate, "tosca.nodes.ARTICONF.VM.topology"); // return ToscaHelper.getNodesByType(toscaTemplate, "tosca.nodes.ARTICONF.VM.topology");
// } // }
protected ToscaTemplate addProvisionInterface(ToscaTemplate toscaTemplate) throws ApiException {
Provisioner provisioner = selectBestProvisioner();
List<Map<String, Object>> definitions = toscaHelper.getProvisionInterfaceDefinitions(provisioner.getToscaInterfaceTypes());
Map<String, Object> def = selectBestInterfaceDefinitions(definitions);
Map<String, Object> provisionInterface = createProvisionInterface(def);
protected ToscaTemplate addProvisionInterface(ToscaTemplate toscaTemplate) {
// List<Map<String, NodeTemplate>> vmTopologies = getVmTopologies(toscaTemplate); // List<Map<String, NodeTemplate>> vmTopologies = getVmTopologies(toscaTemplate);
// for (Map<String, NodeTemplate> vmTopologyMap : vmTopologies) { // for (Map<String, NodeTemplate> vmTopologyMap : vmTopologies) {
// String topologyName = vmTopologyMap.keySet().iterator().next(); // String topologyName = vmTopologyMap.keySet().iterator().next();
...@@ -66,9 +79,31 @@ public class ProvisionerService { ...@@ -66,9 +79,31 @@ public class ProvisionerService {
// Map<String, Object> cloudStormInterface = getCloudStormProvisionInterface(topologyName); // Map<String, Object> cloudStormInterface = getCloudStormProvisionInterface(topologyName);
// interfaces.put("cloudStorm", cloudStormInterface); // interfaces.put("cloudStorm", cloudStormInterface);
// } // }
return toscaTemplate; return toscaTemplate;
} }
private Provisioner selectBestProvisioner() {
if (provisionerDao.count() <= 0) {
Provisioner provisioner = new Provisioner();
provisioner.setDescription("CloudsStorm is a framework for managing an application-defined infrastructure among public IaaS (Infrastructure-as-a-Service) Clouds. It enables the application to customize its underlying infrastructure at software development phase and dynamically control it at operation phase.");
provisioner.setName("CloudsStorm");
provisioner.setVersion("1.0.0");
List<String> toscaInterfaceTypes = new ArrayList<>();
toscaInterfaceTypes.add("tosca.interfaces.ARTICONF.CloudsStorm");
provisioner.setToscaInterfaceTypes(toscaInterfaceTypes);
provisionerDao.save(provisioner);
}
List<Provisioner> all = provisionerDao.findAll();
return all.get(0);
}
private Map<String, Object> selectBestInterfaceDefinitions(List<Map<String, Object>> definitions) {
return definitions.get(0);
}
private Map<String, Object> createProvisionInterface(Map<String, Object> def) {
Map<String, Object> inputs = (Map<String, Object>) def.get("inputs");
return null;
}
} }
...@@ -16,6 +16,8 @@ db.name=drip ...@@ -16,6 +16,8 @@ db.name=drip
db.username=drip-user db.username=drip-user
db.password=drip-pass db.password=drip-pass
sure-tosca.base.path=http://localhost:8081/tosca-sure/1.0.0
spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true
......
...@@ -103,15 +103,23 @@ public class ServiceTests { ...@@ -103,15 +103,23 @@ public class ServiceTests {
@Before @Before
public void setUp() { public void setUp() {
if (mockMvc == null) {
DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.wac); DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.wac);
mockMvc = builder.build(); mockMvc = builder.build();
} }
}
@After @After
public void tearDown() { public void tearDown() {
} }
@Test
public void testPass() {
Assert.assertTrue(true);
}
/** /**
* Test of saveFile method, of class ToscaTemplateService. * Test of saveFile method, of class ToscaTemplateService.
* *
...@@ -259,6 +267,11 @@ public class ServiceTests { ...@@ -259,6 +267,11 @@ public class ServiceTests {
@Test @Test
public void testCredentialServiceSave() { public void testCredentialServiceSave() {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "save"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "save");
saveCredential();
}
public String saveCredential() {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "saveCredential");
Credentials document = new Credentials(); Credentials document = new Credentials();
document.setCloudProviderName("exogeni"); document.setCloudProviderName("exogeni");
Map<String, String> keys = new HashMap<>(); Map<String, String> keys = new HashMap<>();
...@@ -267,8 +280,7 @@ public class ServiceTests { ...@@ -267,8 +280,7 @@ public class ServiceTests {
document.setToken("secret"); document.setToken("secret");
document.setTokenType("password"); document.setTokenType("password");
credentialID = credentialService.save(document); return credentialService.save(document);
assertNotNull(credentialID);
} }
/** /**
...@@ -279,10 +291,7 @@ public class ServiceTests { ...@@ -279,10 +291,7 @@ public class ServiceTests {
@Test @Test
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");
if (credentialID == null) { String id = saveCredential();
testCredentialServiceSave();
}
String id = credentialID;
Credentials result = credentialService.findByID(id); Credentials result = credentialService.findByID(id);
assertNotNull(result); assertNotNull(result);
} }
...@@ -293,12 +302,10 @@ public class ServiceTests { ...@@ -293,12 +302,10 @@ public class ServiceTests {
@Test @Test
public void testCredentialServiceDeleteByID() throws JsonProcessingException { public void testCredentialServiceDeleteByID() throws JsonProcessingException {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "deleteByID"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "deleteByID");
if (credentialID == null) { String id = saveCredential();
testCredentialServiceSave(); credentialService.deleteByID(id);
}
credentialService.deleteByID(credentialID);
try { try {
Credentials res = credentialService.findByID(credentialID); Credentials res = credentialService.findByID(id);
} catch (Exception ex) { } catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) { if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage()); fail(ex.getMessage());
...@@ -315,7 +322,7 @@ public class ServiceTests { ...@@ -315,7 +322,7 @@ public class ServiceTests {
testCredentialServiceDeleteAll(); testCredentialServiceDeleteAll();
int numOfINst = 3; int numOfINst = 3;
for (int i = 1; i <= numOfINst; i++) { for (int i = 1; i <= numOfINst; i++) {
testCredentialServiceSave(); saveCredential();
} }
List<String> result = credentialService.getAllIds(); List<String> result = credentialService.getAllIds();
assertEquals(numOfINst, result.size()); assertEquals(numOfINst, result.size());
...@@ -331,16 +338,14 @@ public class ServiceTests { ...@@ -331,16 +338,14 @@ public class ServiceTests {
assertEquals(0, size); assertEquals(0, size);
} }
@Test @Test
public void testProvisionerServiceProvision() throws FileNotFoundException, IOException, ApiException { public void testProvisionerServiceProvision() throws FileNotFoundException, IOException, ApiException, nl.uva.sne.drip.commons.sure_tosca.client.ApiException {
FileInputStream in = new FileInputStream(testOutputApplicationExampleToscaFilePath); FileInputStream in = new FileInputStream(testOutputApplicationExampleToscaFilePath);
MultipartFile file = new MockMultipartFile("file", in); MultipartFile file = new MockMultipartFile("file", in);
toscaTemplateID = toscaTemplateService.saveFile(file); toscaTemplateID = toscaTemplateService.saveFile(file);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(toscaTemplateService.findByID(toscaTemplateID)); ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(toscaTemplateService.findByID(toscaTemplateID));
provisionService.addProvisionInterface(toscaTemplate); // provisionService.addProvisionInterface(toscaTemplate);
} }
} }
...@@ -15,7 +15,6 @@ import java.util.ArrayList; ...@@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import nl.uva.sne.drip.commons.utils.TOSCAUtils;
import nl.uva.sne.drip.model.ToscaTemplate; import nl.uva.sne.drip.model.ToscaTemplate;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
...@@ -37,57 +36,14 @@ class ProvisionerRPCService { ...@@ -37,57 +36,14 @@ class ProvisionerRPCService {
buildCloudStormTopTopology(toscaTemplate); buildCloudStormTopTopology(toscaTemplate);
return toscaTemplate; return toscaTemplate;
} }
private Map<String, Object> buildCloudStormTopTopology(ToscaTemplate toscaTemplate) throws JSchException, IOException { private Map<String, Object> buildCloudStormTopTopology(ToscaTemplate toscaTemplate) throws JSchException, IOException {
Map<String, Object> topTopology = new HashMap<>(); Map<String, Object> topTopology = new HashMap<>();
topTopology.put("userName", getVMsUSername(toscaTemplate));
String keysPath = buildSSHKeyPair();
topTopology.put("publicKeyPath", keysPath);
List<Map<String, Object>> subnets = new ArrayList<>();
int counter = 0;
for (Map.Entry vmTopology : getVmTopologies(toscaTemplate)) {
String subnetValue = getSubnets(vmTopology);
if (subnetValue != null) {
Map<String, Object> subnetMap = new HashMap<>();
subnetMap.put("name", "subnet" + counter++);
subnetMap.put("subnet", subnetValue.split("/")[0]);
subnetMap.put("netmask", subnetValue.split("/")[1]);
Object members = null;
subnetMap.put("members", members);
subnets.add(subnetMap);
}
}
if (subnets != null) {
topTopology.put("subnets", subnets);
}
List<Map<String, Object>> subTopologies = buildCloudStormSubTopologies(toscaTemplate);
topTopology.put("topologies", subTopologies);
return topTopology; return topTopology;
} }
private String getVMsUSername(ToscaTemplate toscaTemplate) {
List<Map.Entry> topologyVMs = getTopologyVMs(getVmTopologies(toscaTemplate).get(0), toscaTemplate);
return (String) TOSCAUtils.getNodeProperty(topologyVMs.get(0), "user_name");
}
private List<Map.Entry> getTopologyVMs(Map.Entry topology, ToscaTemplate toscaTemplate) {
List<Map.Entry> topologyVMs = new ArrayList<>();
Map<String, Object> topologyMap = new HashMap<>();
topologyMap.put((String) topology.getKey(), topology.getValue());
List<Map.Entry> relatedNodes = TOSCAUtils.getRelatedNodes(topologyMap, toscaTemplate);
for (Map.Entry node : relatedNodes) {
if (TOSCAUtils.nodeIsOfType(node, "tosca.nodes.ARTICONF.VM.Compute")) {
topologyVMs.add(node);
}
}
return topologyVMs;
}
private String buildSSHKeyPair() throws JSchException, IOException { private String buildSSHKeyPair() throws JSchException, IOException {
String userPublicKeyName = "id_rsa.pub"; String userPublicKeyName = "id_rsa.pub";
String publicKeyPath = "name@" + userPublicKeyName; String publicKeyPath = "name@" + userPublicKeyName;
...@@ -100,31 +56,4 @@ class ProvisionerRPCService { ...@@ -100,31 +56,4 @@ class ProvisionerRPCService {
return publicKeyPath; return publicKeyPath;
} }
private String getSubnets(Map.Entry node) {
return (String) TOSCAUtils.getNodeProperty(node, "subnet");
}
/**
* @return the vmTopologies
*/
public List<Map.Entry> getVmTopologies(ToscaTemplate toscaTemplate) {
if (vmTopologies == null) {
vmTopologies = TOSCAUtils.getNodesByType(toscaTemplate, "tosca.nodes.ARTICONF.VM.topology");
}
return vmTopologies;
}
private List<Map<String, Object>> buildCloudStormSubTopologies(ToscaTemplate toscaTemplate) {
List<Map<String, Object>> cloudStormSubTopologies = new ArrayList<>();
for(Map.Entry topology: getVmTopologies(toscaTemplate)){
Map<String, Object> cloudStormSubTopology = new HashMap<>();
cloudStormSubTopology.put("topology", topology.getKey());
cloudStormSubTopology.put("cloudProvider", TOSCAUtils.getNodeProperty(topology, "provider"));
cloudStormSubTopology.put("domain", TOSCAUtils.getNodeProperty(topology, "domain"));
cloudStormSubTopology.put("status", TOSCAUtils.getNodeProperty(topology, "domain"));
}
return cloudStormSubTopologies;
}
} }
User:
type: "object"
properties:
name:
type: "string"
version:
type: "string"
description:
type: "string"
tosca_interface_types:
type: "string"
password:
type: "string"
userStatus:
type: "array"
items:
type: "string"
...@@ -42,10 +42,8 @@ def query_db(queries, db=None): ...@@ -42,10 +42,8 @@ def query_db(queries, db=None):
updated_results = [] updated_results = []
for res in results: for res in results:
if root_key in res: if root_key in res:
key = res.pop(root_key) key = res[root_key]
node = {key: res} node = {key: res}
else:
node = res
updated_results.append(node) updated_results.append(node)
return updated_results return updated_results
return None return None
...@@ -87,15 +85,27 @@ def save(file): ...@@ -87,15 +85,27 @@ def save(file):
def get_interface_types(id, interface_type=None): def get_interface_types(id, interface_type=None):
if len(interface_types_db) <= 1: if len(interface_types_db) <= 1:
interface_types = get_tosca_template_model_by_id(id).interface_types
if interface_types: tosca_template_model = get_tosca_template_model_by_id(id)
for interface_type_name in interface_types: object_list = tosca_template_model.interface_types
if object_list is None:
object_list = {}
tosca_template = get_tosca_template(tosca_template_model.to_dict())
tosca_node_types = tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
all_custom_def = tosca_template.nodetemplates[0].custom_def
object_list.update(tosca_node_types)
object_list.update(all_custom_def)
if object_list:
for interface_type_name in object_list:
if 'tosca.interfaces' in interface_type_name:
interface = {root_key: interface_type_name} interface = {root_key: interface_type_name}
interface.update(interface_types[interface_type_name]) interface.update(object_list[interface_type_name])
interface_types_db.insert(interface)
queries = [] queries = []
if interface_type: if interface_type:
query = Query() query = Query()
queries.append(query._node_nme == interface_type) queries.append(query.root_key == interface_type)
return query_db(queries, db=interface_types_db) return query_db(queries, db=interface_types_db)
...@@ -352,3 +362,10 @@ def set_node_properties(id, properties, node_name): ...@@ -352,3 +362,10 @@ def set_node_properties(id, properties, node_name):
tosca_template_model.topology_template.node_templates[node_name] = node_template_model tosca_template_model.topology_template.node_templates[node_name] = node_template_model
return update(id,tosca_template_model.to_dict()) return update(id,tosca_template_model.to_dict())
return None return None
def get_types(id, kind_of_type, has_interfaces, type_name, has_properties, has_attributes, has_requirements,
has_capabilities, has_artifacts, derived_from):
if kind_of_type == 'interface_types':
return get_interface_types(id, interface_type=type_name)
return None
\ No newline at end of file
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