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;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.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.Configuration;
import nl.uva.sne.drip.commons.sure_tosca.client.DefaultApi;
import nl.uva.sne.drip.model.ToscaTemplate;
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 {
private final Integer id;
public ToscaHelper(ToscaTemplate toscaTemplate) throws JsonProcessingException, IOException, ApiException {
api = new DefaultApi();
id = uploadToscaTemplate(toscaTemplate);
public ToscaHelper(ToscaTemplate toscaTemplate, String sureToscaBasePath) throws JsonProcessingException, IOException, ApiException {
Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath);
api = new DefaultApi(Configuration.getDefaultApiClient());
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
id = uploadToscaTemplate(toscaTemplate);
}
private Integer uploadToscaTemplate(ToscaTemplate toscaTemplate) throws JsonProcessingException, IOException, ApiException {
......@@ -58,7 +67,19 @@ public class ToscaHelper {
File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml");
FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes());
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;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
......@@ -18,9 +19,9 @@ import org.springframework.data.annotation.Id;
* Credentials
*/
@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 {
/**
* @return the id
*/
......@@ -65,11 +66,12 @@ public class Credentials {
/**
* Get protocol
*
* @return protocol
**/
*
*/
@ApiModelProperty(value = "")
public String getProtocol() {
return protocol;
}
......@@ -85,11 +87,12 @@ public class Credentials {
/**
* Get tokenType
*
* @return tokenType
**/
*
*/
@ApiModelProperty(value = "")
public String getTokenType() {
return tokenType;
}
......@@ -105,11 +108,12 @@ public class Credentials {
/**
* Get token
*
* @return token
**/
*
*/
@ApiModelProperty(value = "")
public String getToken() {
return token;
}
......@@ -133,11 +137,12 @@ public class Credentials {
/**
* Get keys
*
* @return keys
**/
*
*/
@ApiModelProperty(value = "")
public Map<String, String> getKeys() {
return keys;
}
......@@ -153,11 +158,12 @@ public class Credentials {
/**
* Get user
*
* @return user
**/
*
*/
@ApiModelProperty(value = "")
public String getUser() {
return user;
}
......@@ -173,11 +179,12 @@ public class Credentials {
/**
* Get cloudProviderName
*
* @return cloudProviderName
**/
*
*/
@ApiModelProperty(value = "")
public String getCloudProviderName() {
return cloudProviderName;
}
......@@ -186,7 +193,6 @@ public class Credentials {
this.cloudProviderName = cloudProviderName;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
......@@ -196,12 +202,12 @@ public class Credentials {
return false;
}
Credentials credentials = (Credentials) o;
return Objects.equals(this.protocol, credentials.protocol) &&
Objects.equals(this.tokenType, credentials.tokenType) &&
Objects.equals(this.token, credentials.token) &&
Objects.equals(this.keys, credentials.keys) &&
Objects.equals(this.user, credentials.user) &&
Objects.equals(this.cloudProviderName, credentials.cloudProviderName);
return Objects.equals(this.protocol, credentials.protocol)
&& Objects.equals(this.tokenType, credentials.tokenType)
&& Objects.equals(this.token, credentials.token)
&& Objects.equals(this.keys, credentials.keys)
&& Objects.equals(this.user, credentials.user)
&& Objects.equals(this.cloudProviderName, credentials.cloudProviderName);
}
@Override
......@@ -235,4 +241,3 @@ public class Credentials {
return o.toString().replace("\n", "\n ");
}
}
......@@ -3,6 +3,7 @@ package nl.uva.sne.drip.model;
import java.util.Objects;
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 java.util.ArrayList;
......@@ -17,28 +18,26 @@ import javax.validation.constraints.*;
* NodeTemplate
*/
@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 {
@JsonProperty("derived_from")
private String derivedFrom = null;
@JsonProperty("properties")
@Valid
private Map<String, String> properties = null;
private Map<String, Object> properties = null;
@JsonProperty("requirements")
@Valid
private List<Map<String, String>> requirements = null;
private List<Map<String, Object>> requirements = null;
@JsonProperty("interfaces")
@Valid
private Map<String, String> interfaces = null;
private Map<String, Object> interfaces = null;
@JsonProperty("capabilities")
@Valid
private Map<String, String> capabilities = null;
private Map<String, Object> capabilities = null;
@JsonProperty("type")
private String type = null;
......@@ -52,11 +51,11 @@ public class NodeTemplate {
@JsonProperty("attributes")
@Valid
private Map<String, String> attributes = null;
private Map<String, Object> attributes = null;
@JsonProperty("artifacts")
@Valid
private Map<String, String> artifacts = null;
private Map<String, Object> artifacts = null;
public NodeTemplate derivedFrom(String derivedFrom) {
this.derivedFrom = derivedFrom;
......@@ -78,14 +77,14 @@ public class NodeTemplate {
this.derivedFrom = derivedFrom;
}
public NodeTemplate properties(Map<String, String> properties) {
public NodeTemplate properties(Map<String, Object> properties) {
this.properties = properties;
return this;
}
public NodeTemplate putPropertiesItem(String key, String propertiesItem) {
public NodeTemplate putPropertiesItem(String key, Object propertiesItem) {
if (this.properties == null) {
this.properties = new HashMap<String, String>();
this.properties = new HashMap<String, Object>();
}
this.properties.put(key, propertiesItem);
return this;
......@@ -98,22 +97,22 @@ public class NodeTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getProperties() {
public Map<String, Object> getProperties() {
return properties;
}
public void setProperties(Map<String, String> properties) {
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
public NodeTemplate requirements(List<Map<String, String>> requirements) {
public NodeTemplate requirements(List<Map<String, Object>> requirements) {
this.requirements = requirements;
return this;
}
public NodeTemplate addRequirementsItem(Map<String, String> requirementsItem) {
public NodeTemplate addRequirementsItem(Map<String, Object> requirementsItem) {
if (this.requirements == null) {
this.requirements = new ArrayList<Map<String, String>>();
this.requirements = new ArrayList<Map<String, Object>>();
}
this.requirements.add(requirementsItem);
return this;
......@@ -127,22 +126,22 @@ public class NodeTemplate {
@Valid
public List<Map<String, String>> getRequirements() {
public List<Map<String, Object>> getRequirements() {
return requirements;
}
public void setRequirements(List<Map<String, String>> requirements) {
public void setRequirements(List<Map<String, Object>> requirements) {
this.requirements = requirements;
}
public NodeTemplate interfaces(Map<String, String> interfaces) {
public NodeTemplate interfaces(Map<String, Object> interfaces) {
this.interfaces = interfaces;
return this;
}
public NodeTemplate putInterfacesItem(String key, String interfacesItem) {
public NodeTemplate putInterfacesItem(String key, Object interfacesItem) {
if (this.interfaces == null) {
this.interfaces = new HashMap<String, String>();
this.interfaces = new HashMap<String, Object>();
}
this.interfaces.put(key, interfacesItem);
return this;
......@@ -155,22 +154,22 @@ public class NodeTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getInterfaces() {
public Map<String, Object> getInterfaces() {
return interfaces;
}
public void setInterfaces(Map<String, String> interfaces) {
public void setInterfaces(Map<String, Object> interfaces) {
this.interfaces = interfaces;
}
public NodeTemplate capabilities(Map<String, String> capabilities) {
public NodeTemplate capabilities(Map<String, Object> capabilities) {
this.capabilities = capabilities;
return this;
}
public NodeTemplate putCapabilitiesItem(String key, String capabilitiesItem) {
public NodeTemplate putCapabilitiesItem(String key, Object capabilitiesItem) {
if (this.capabilities == null) {
this.capabilities = new HashMap<String, String>();
this.capabilities = new HashMap<String, Object>();
}
this.capabilities.put(key, capabilitiesItem);
return this;
......@@ -183,11 +182,11 @@ public class NodeTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getCapabilities() {
public Map<String, Object> getCapabilities() {
return capabilities;
}
public void setCapabilities(Map<String, String> capabilities) {
public void setCapabilities(Map<String, Object> capabilities) {
this.capabilities = capabilities;
}
......@@ -259,14 +258,14 @@ public class NodeTemplate {
this.directives = directives;
}
public NodeTemplate attributes(Map<String, String> attributes) {
public NodeTemplate attributes(Map<String, Object> attributes) {
this.attributes = attributes;
return this;
}
public NodeTemplate putAttributesItem(String key, String attributesItem) {
public NodeTemplate putAttributesItem(String key, Object attributesItem) {
if (this.attributes == null) {
this.attributes = new HashMap<String, String>();
this.attributes = new HashMap<String, Object>();
}
this.attributes.put(key, attributesItem);
return this;
......@@ -279,22 +278,22 @@ public class NodeTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getAttributes() {
public Map<String, Object> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, String> attributes) {
public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
public NodeTemplate artifacts(Map<String, String> artifacts) {
public NodeTemplate artifacts(Map<String, Object> artifacts) {
this.artifacts = artifacts;
return this;
}
public NodeTemplate putArtifactsItem(String key, String artifactsItem) {
public NodeTemplate putArtifactsItem(String key, Object artifactsItem) {
if (this.artifacts == null) {
this.artifacts = new HashMap<String, String>();
this.artifacts = new HashMap<String, Object>();
}
this.artifacts.put(key, artifactsItem);
return this;
......@@ -307,11 +306,11 @@ public class NodeTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getArtifacts() {
public Map<String, Object> getArtifacts() {
return artifacts;
}
public void setArtifacts(Map<String, String> artifacts) {
public void setArtifacts(Map<String, Object> 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;
import java.util.Objects;
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 java.util.ArrayList;
import java.util.HashMap;
......@@ -9,14 +12,15 @@ import java.util.List;
import java.util.Map;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* TopologyTemplate
*/
@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 {
@JsonProperty("description")
private String description = null;
......@@ -30,23 +34,23 @@ public class TopologyTemplate {
@JsonProperty("relationship_templates")
@Valid
private Map<String, String> relationshipTemplates = null;
private Map<String, Object> relationshipTemplates = null;
@JsonProperty("outputs")
@Valid
private Map<String, String> outputs = null;
private Map<String, Object> outputs = null;
@JsonProperty("groups")
@Valid
private Map<String, String> groups = null;
private Map<String, Object> groups = null;
@JsonProperty("substitution_mappings")
@Valid
private Map<String, String> substitutionMappings = null;
private Map<String, Object> substitutionMappings = null;
@JsonProperty("policies")
@Valid
private List<Map<String, String>> policies = null;
private List<Map<String, Object>> policies = null;
public TopologyTemplate description(String description) {
this.description = description;
......@@ -125,14 +129,14 @@ public class TopologyTemplate {
this.nodeTemplates = nodeTemplates;
}
public TopologyTemplate relationshipTemplates(Map<String, String> relationshipTemplates) {
public TopologyTemplate relationshipTemplates(Map<String, Object> relationshipTemplates) {
this.relationshipTemplates = relationshipTemplates;
return this;
}
public TopologyTemplate putRelationshipTemplatesItem(String key, String relationshipTemplatesItem) {
public TopologyTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) {
if (this.relationshipTemplates == null) {
this.relationshipTemplates = new HashMap<String, String>();
this.relationshipTemplates = new HashMap<String, Object>();
}
this.relationshipTemplates.put(key, relationshipTemplatesItem);
return this;
......@@ -145,22 +149,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getRelationshipTemplates() {
public Map<String, Object> getRelationshipTemplates() {
return relationshipTemplates;
}
public void setRelationshipTemplates(Map<String, String> relationshipTemplates) {
public void setRelationshipTemplates(Map<String, Object> relationshipTemplates) {
this.relationshipTemplates = relationshipTemplates;
}
public TopologyTemplate outputs(Map<String, String> outputs) {
public TopologyTemplate outputs(Map<String, Object> outputs) {
this.outputs = outputs;
return this;
}
public TopologyTemplate putOutputsItem(String key, String outputsItem) {
public TopologyTemplate putOutputsItem(String key, Object outputsItem) {
if (this.outputs == null) {
this.outputs = new HashMap<String, String>();
this.outputs = new HashMap<String, Object>();
}
this.outputs.put(key, outputsItem);
return this;
......@@ -173,22 +177,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getOutputs() {
public Map<String, Object> getOutputs() {
return outputs;
}
public void setOutputs(Map<String, String> outputs) {
public void setOutputs(Map<String, Object> outputs) {
this.outputs = outputs;
}
public TopologyTemplate groups(Map<String, String> groups) {
public TopologyTemplate groups(Map<String, Object> groups) {
this.groups = groups;
return this;
}
public TopologyTemplate putGroupsItem(String key, String groupsItem) {
public TopologyTemplate putGroupsItem(String key, Object groupsItem) {
if (this.groups == null) {
this.groups = new HashMap<String, String>();
this.groups = new HashMap<String, Object>();
}
this.groups.put(key, groupsItem);
return this;
......@@ -201,22 +205,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getGroups() {
public Map<String, Object> getGroups() {
return groups;
}
public void setGroups(Map<String, String> groups) {
public void setGroups(Map<String, Object> groups) {
this.groups = groups;
}
public TopologyTemplate substitutionMappings(Map<String, String> substitutionMappings) {
public TopologyTemplate substitutionMappings(Map<String, Object> substitutionMappings) {
this.substitutionMappings = substitutionMappings;
return this;
}
public TopologyTemplate putSubstitutionMappingsItem(String key, String substitutionMappingsItem) {
public TopologyTemplate putSubstitutionMappingsItem(String key, Object substitutionMappingsItem) {
if (this.substitutionMappings == null) {
this.substitutionMappings = new HashMap<String, String>();
this.substitutionMappings = new HashMap<String, Object>();
}
this.substitutionMappings.put(key, substitutionMappingsItem);
return this;
......@@ -229,22 +233,22 @@ public class TopologyTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getSubstitutionMappings() {
public Map<String, Object> getSubstitutionMappings() {
return substitutionMappings;
}
public void setSubstitutionMappings(Map<String, String> substitutionMappings) {
public void setSubstitutionMappings(Map<String, Object> substitutionMappings) {
this.substitutionMappings = substitutionMappings;
}
public TopologyTemplate policies(List<Map<String, String>> policies) {
public TopologyTemplate policies(List<Map<String, Object>> policies) {
this.policies = policies;
return this;
}
public TopologyTemplate addPoliciesItem(Map<String, String> policiesItem) {
public TopologyTemplate addPoliciesItem(Map<String, Object> policiesItem) {
if (this.policies == null) {
this.policies = new ArrayList<Map<String, String>>();
this.policies = new ArrayList<Map<String, Object>>();
}
this.policies.add(policiesItem);
return this;
......@@ -258,11 +262,11 @@ public class TopologyTemplate {
@Valid
public List<Map<String, String>> getPolicies() {
public List<Map<String, Object>> getPolicies() {
return policies;
}
public void setPolicies(List<Map<String, String>> policies) {
public void setPolicies(List<Map<String, Object>> policies) {
this.policies = policies;
}
......
......@@ -2,9 +2,8 @@ package nl.uva.sne.drip.model;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -12,15 +11,13 @@ import java.util.List;
import java.util.Map;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.*;
import org.springframework.data.annotation.Id;
/**
* ToscaTemplate
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-11-01T14:10:53.529Z")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ToscaTemplate {
/**
* @return the id
......@@ -63,51 +60,51 @@ public class ToscaTemplate {
@JsonProperty("imports")
@Valid
private List<Map<String, String>> imports = null;
private List<Map<String, Object>> imports = null;
@JsonProperty("dsl_definitions")
@Valid
private Map<String, String> dslDefinitions = null;
private Map<String, Object> dslDefinitions = null;
@JsonProperty("node_types")
@Valid
private Map<String, String> nodeTypes = null;
private Map<String, Object> nodeTypes = null;
@JsonProperty("relationship_types")
@Valid
private Map<String, String> relationshipTypes = null;
private Map<String, Object> relationshipTypes = null;
@JsonProperty("relationship_templates")
@Valid
private Map<String, String> relationshipTemplates = null;
private Map<String, Object> relationshipTemplates = null;
@JsonProperty("capability_types")
@Valid
private Map<String, String> capabilityTypes = null;
private Map<String, Object> capabilityTypes = null;
@JsonProperty("artifact_types")
@Valid
private Map<String, String> artifactTypes = null;
private Map<String, Object> artifactTypes = null;
@JsonProperty("data_types")
@Valid
private Map<String, String> dataTypes = null;
private Map<String, Object> dataTypes = null;
@JsonProperty("interface_types")
@Valid
private Map<String, String> interfaceTypes = null;
private Map<String, Object> interfaceTypes = null;
@JsonProperty("policy_types")
@Valid
private Map<String, String> policyTypes = null;
private Map<String, Object> policyTypes = null;
@JsonProperty("group_types")
@Valid
private Map<String, String> groupTypes = null;
private Map<String, Object> groupTypes = null;
@JsonProperty("repositories")
@Valid
private Map<String, String> repositories = null;
private Map<String, Object> repositories = null;
public ToscaTemplate toscaDefinitionsVersion(String toscaDefinitionsVersion) {
this.toscaDefinitionsVersion = toscaDefinitionsVersion;
......@@ -250,14 +247,14 @@ public class ToscaTemplate {
this.description = description;
}
public ToscaTemplate imports(List<Map<String, String>> imports) {
public ToscaTemplate imports(List<Map<String, Object>> imports) {
this.imports = imports;
return this;
}
public ToscaTemplate addImportsItem(Map<String, String> importsItem) {
public ToscaTemplate addImportsItem(Map<String, Object> importsItem) {
if (this.imports == null) {
this.imports = new ArrayList<Map<String, String>>();
this.imports = new ArrayList<Map<String, Object>>();
}
this.imports.add(importsItem);
return this;
......@@ -271,22 +268,22 @@ public class ToscaTemplate {
@Valid
public List<Map<String, String>> getImports() {
public List<Map<String, Object>> getImports() {
return imports;
}
public void setImports(List<Map<String, String>> imports) {
public void setImports(List<Map<String, Object>> imports) {
this.imports = imports;
}
public ToscaTemplate dslDefinitions(Map<String, String> dslDefinitions) {
public ToscaTemplate dslDefinitions(Map<String, Object> dslDefinitions) {
this.dslDefinitions = dslDefinitions;
return this;
}
public ToscaTemplate putDslDefinitionsItem(String key, String dslDefinitionsItem) {
public ToscaTemplate putDslDefinitionsItem(String key, Object dslDefinitionsItem) {
if (this.dslDefinitions == null) {
this.dslDefinitions = new HashMap<String, String>();
this.dslDefinitions = new HashMap<String, Object>();
}
this.dslDefinitions.put(key, dslDefinitionsItem);
return this;
......@@ -299,22 +296,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getDslDefinitions() {
public Map<String, Object> getDslDefinitions() {
return dslDefinitions;
}
public void setDslDefinitions(Map<String, String> dslDefinitions) {
public void setDslDefinitions(Map<String, Object> dslDefinitions) {
this.dslDefinitions = dslDefinitions;
}
public ToscaTemplate nodeTypes(Map<String, String> nodeTypes) {
public ToscaTemplate nodeTypes(Map<String, Object> nodeTypes) {
this.nodeTypes = nodeTypes;
return this;
}
public ToscaTemplate putNodeTypesItem(String key, String nodeTypesItem) {
public ToscaTemplate putNodeTypesItem(String key, Object nodeTypesItem) {
if (this.nodeTypes == null) {
this.nodeTypes = new HashMap<String, String>();
this.nodeTypes = new HashMap<String, Object>();
}
this.nodeTypes.put(key, nodeTypesItem);
return this;
......@@ -327,22 +324,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getNodeTypes() {
public Map<String, Object> getNodeTypes() {
return nodeTypes;
}
public void setNodeTypes(Map<String, String> nodeTypes) {
public void setNodeTypes(Map<String, Object> nodeTypes) {
this.nodeTypes = nodeTypes;
}
public ToscaTemplate relationshipTypes(Map<String, String> relationshipTypes) {
public ToscaTemplate relationshipTypes(Map<String, Object> relationshipTypes) {
this.relationshipTypes = relationshipTypes;
return this;
}
public ToscaTemplate putRelationshipTypesItem(String key, String relationshipTypesItem) {
public ToscaTemplate putRelationshipTypesItem(String key, Object relationshipTypesItem) {
if (this.relationshipTypes == null) {
this.relationshipTypes = new HashMap<String, String>();
this.relationshipTypes = new HashMap<String, Object>();
}
this.relationshipTypes.put(key, relationshipTypesItem);
return this;
......@@ -355,22 +352,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getRelationshipTypes() {
public Map<String, Object> getRelationshipTypes() {
return relationshipTypes;
}
public void setRelationshipTypes(Map<String, String> relationshipTypes) {
public void setRelationshipTypes(Map<String, Object> relationshipTypes) {
this.relationshipTypes = relationshipTypes;
}
public ToscaTemplate relationshipTemplates(Map<String, String> relationshipTemplates) {
public ToscaTemplate relationshipTemplates(Map<String, Object> relationshipTemplates) {
this.relationshipTemplates = relationshipTemplates;
return this;
}
public ToscaTemplate putRelationshipTemplatesItem(String key, String relationshipTemplatesItem) {
public ToscaTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) {
if (this.relationshipTemplates == null) {
this.relationshipTemplates = new HashMap<String, String>();
this.relationshipTemplates = new HashMap<String, Object>();
}
this.relationshipTemplates.put(key, relationshipTemplatesItem);
return this;
......@@ -383,22 +380,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getRelationshipTemplates() {
public Map<String, Object> getRelationshipTemplates() {
return relationshipTemplates;
}
public void setRelationshipTemplates(Map<String, String> relationshipTemplates) {
public void setRelationshipTemplates(Map<String, Object> relationshipTemplates) {
this.relationshipTemplates = relationshipTemplates;
}
public ToscaTemplate capabilityTypes(Map<String, String> capabilityTypes) {
public ToscaTemplate capabilityTypes(Map<String, Object> capabilityTypes) {
this.capabilityTypes = capabilityTypes;
return this;
}
public ToscaTemplate putCapabilityTypesItem(String key, String capabilityTypesItem) {
public ToscaTemplate putCapabilityTypesItem(String key, Object capabilityTypesItem) {
if (this.capabilityTypes == null) {
this.capabilityTypes = new HashMap<String, String>();
this.capabilityTypes = new HashMap<String, Object>();
}
this.capabilityTypes.put(key, capabilityTypesItem);
return this;
......@@ -411,22 +408,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getCapabilityTypes() {
public Map<String, Object> getCapabilityTypes() {
return capabilityTypes;
}
public void setCapabilityTypes(Map<String, String> capabilityTypes) {
public void setCapabilityTypes(Map<String, Object> capabilityTypes) {
this.capabilityTypes = capabilityTypes;
}
public ToscaTemplate artifactTypes(Map<String, String> artifactTypes) {
public ToscaTemplate artifactTypes(Map<String, Object> artifactTypes) {
this.artifactTypes = artifactTypes;
return this;
}
public ToscaTemplate putArtifactTypesItem(String key, String artifactTypesItem) {
public ToscaTemplate putArtifactTypesItem(String key, Object artifactTypesItem) {
if (this.artifactTypes == null) {
this.artifactTypes = new HashMap<String, String>();
this.artifactTypes = new HashMap<String, Object>();
}
this.artifactTypes.put(key, artifactTypesItem);
return this;
......@@ -439,22 +436,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getArtifactTypes() {
public Map<String, Object> getArtifactTypes() {
return artifactTypes;
}
public void setArtifactTypes(Map<String, String> artifactTypes) {
public void setArtifactTypes(Map<String, Object> artifactTypes) {
this.artifactTypes = artifactTypes;
}
public ToscaTemplate dataTypes(Map<String, String> dataTypes) {
public ToscaTemplate dataTypes(Map<String, Object> dataTypes) {
this.dataTypes = dataTypes;
return this;
}
public ToscaTemplate putDataTypesItem(String key, String dataTypesItem) {
public ToscaTemplate putDataTypesItem(String key, Object dataTypesItem) {
if (this.dataTypes == null) {
this.dataTypes = new HashMap<String, String>();
this.dataTypes = new HashMap<String, Object>();
}
this.dataTypes.put(key, dataTypesItem);
return this;
......@@ -467,22 +464,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getDataTypes() {
public Map<String, Object> getDataTypes() {
return dataTypes;
}
public void setDataTypes(Map<String, String> dataTypes) {
public void setDataTypes(Map<String, Object> dataTypes) {
this.dataTypes = dataTypes;
}
public ToscaTemplate interfaceTypes(Map<String, String> interfaceTypes) {
public ToscaTemplate interfaceTypes(Map<String, Object> interfaceTypes) {
this.interfaceTypes = interfaceTypes;
return this;
}
public ToscaTemplate putInterfaceTypesItem(String key, String interfaceTypesItem) {
public ToscaTemplate putInterfaceTypesItem(String key, Object interfaceTypesItem) {
if (this.interfaceTypes == null) {
this.interfaceTypes = new HashMap<String, String>();
this.interfaceTypes = new HashMap<String, Object>();
}
this.interfaceTypes.put(key, interfaceTypesItem);
return this;
......@@ -495,22 +492,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getInterfaceTypes() {
public Map<String, Object> getInterfaceTypes() {
return interfaceTypes;
}
public void setInterfaceTypes(Map<String, String> interfaceTypes) {
public void setInterfaceTypes(Map<String, Object> interfaceTypes) {
this.interfaceTypes = interfaceTypes;
}
public ToscaTemplate policyTypes(Map<String, String> policyTypes) {
public ToscaTemplate policyTypes(Map<String, Object> policyTypes) {
this.policyTypes = policyTypes;
return this;
}
public ToscaTemplate putPolicyTypesItem(String key, String policyTypesItem) {
public ToscaTemplate putPolicyTypesItem(String key, Object policyTypesItem) {
if (this.policyTypes == null) {
this.policyTypes = new HashMap<String, String>();
this.policyTypes = new HashMap<String, Object>();
}
this.policyTypes.put(key, policyTypesItem);
return this;
......@@ -523,22 +520,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getPolicyTypes() {
public Map<String, Object> getPolicyTypes() {
return policyTypes;
}
public void setPolicyTypes(Map<String, String> policyTypes) {
public void setPolicyTypes(Map<String, Object> policyTypes) {
this.policyTypes = policyTypes;
}
public ToscaTemplate groupTypes(Map<String, String> groupTypes) {
public ToscaTemplate groupTypes(Map<String, Object> groupTypes) {
this.groupTypes = groupTypes;
return this;
}
public ToscaTemplate putGroupTypesItem(String key, String groupTypesItem) {
public ToscaTemplate putGroupTypesItem(String key, Object groupTypesItem) {
if (this.groupTypes == null) {
this.groupTypes = new HashMap<String, String>();
this.groupTypes = new HashMap<String, Object>();
}
this.groupTypes.put(key, groupTypesItem);
return this;
......@@ -551,22 +548,22 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getGroupTypes() {
public Map<String, Object> getGroupTypes() {
return groupTypes;
}
public void setGroupTypes(Map<String, String> groupTypes) {
public void setGroupTypes(Map<String, Object> groupTypes) {
this.groupTypes = groupTypes;
}
public ToscaTemplate repositories(Map<String, String> repositories) {
public ToscaTemplate repositories(Map<String, Object> repositories) {
this.repositories = repositories;
return this;
}
public ToscaTemplate putRepositoriesItem(String key, String repositoriesItem) {
public ToscaTemplate putRepositoriesItem(String key, Object repositoriesItem) {
if (this.repositories == null) {
this.repositories = new HashMap<String, String>();
this.repositories = new HashMap<String, Object>();
}
this.repositories.put(key, repositoriesItem);
return this;
......@@ -579,11 +576,11 @@ public class ToscaTemplate {
@ApiModelProperty(value = "")
public Map<String, String> getRepositories() {
public Map<String, Object> getRepositories() {
return repositories;
}
public void setRepositories(Map<String, String> repositories) {
public void setRepositories(Map<String, Object> repositories) {
this.repositories = repositories;
}
......
package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Objects;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
......@@ -11,8 +12,7 @@ import org.springframework.data.annotation.Id;
* User
*/
@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 {
/**
* @return the id
......
......@@ -20,8 +20,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
})
@EnableMongoRepositories(basePackageClasses = {ToscaTemplateDAO.class})
@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.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.service"})
public class Swagger2SpringBoot implements CommandLineRunner {
@Value("${message.broker.host}")
......
package nl.uva.sne.drip.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import org.slf4j.Logger;
......@@ -12,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
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.ProvisionerService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -46,7 +48,7 @@ public class ProvisionerApiController implements ProvisionerApi {
try {
String planedYemplateId = provisionerService.provision(id);
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);
}
}
......
/*
* 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;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -15,8 +16,10 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.sure_tosca.client.ApiException;
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.NodeTemplate;
import nl.uva.sne.drip.model.Provisioner;
import nl.uva.sne.drip.model.ToscaTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -36,9 +39,15 @@ public class ProvisionerService {
@Value("${tosca.types.interface}")
private String toscaTypesInterface;
@Value("${sure-tosca.base.path}")
private String sureToscaBasePath;
@Autowired
private ToscaTemplateService toscaTemplateService;
@Autowired
private ProvisionerDAO provisionerDao;
ToscaHelper toscaHelper;
private Integer toscaHelperID;
......@@ -46,7 +55,7 @@ public class ProvisionerService {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
toscaHelper = new ToscaHelper(toscaTemplate);
toscaHelper = new ToscaHelper(toscaTemplate, sureToscaBasePath);
toscaTemplate = addProvisionInterface(toscaTemplate);
......@@ -56,8 +65,12 @@ public class ProvisionerService {
// private List<Map<String, NodeTemplate>> getVmTopologies(ToscaTemplate toscaTemplate) {
// 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);
// for (Map<String, NodeTemplate> vmTopologyMap : vmTopologies) {
// String topologyName = vmTopologyMap.keySet().iterator().next();
......@@ -66,9 +79,31 @@ public class ProvisionerService {
// Map<String, Object> cloudStormInterface = getCloudStormProvisionInterface(topologyName);
// interfaces.put("cloudStorm", cloudStormInterface);
// }
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
db.username=drip-user
db.password=drip-pass
sure-tosca.base.path=http://localhost:8081/tosca-sure/1.0.0
spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true
......
......@@ -103,15 +103,23 @@ public class ServiceTests {
@Before
public void setUp() {
if (mockMvc == null) {
DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.wac);
mockMvc = builder.build();
}
}
@After
public void tearDown() {
}
@Test
public void testPass() {
Assert.assertTrue(true);
}
/**
* Test of saveFile method, of class ToscaTemplateService.
*
......@@ -259,6 +267,11 @@ public class ServiceTests {
@Test
public void testCredentialServiceSave() {
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();
document.setCloudProviderName("exogeni");
Map<String, String> keys = new HashMap<>();
......@@ -267,8 +280,7 @@ public class ServiceTests {
document.setToken("secret");
document.setTokenType("password");
credentialID = credentialService.save(document);
assertNotNull(credentialID);
return credentialService.save(document);
}
/**
......@@ -279,10 +291,7 @@ public class ServiceTests {
@Test
public void testCredentialServiceFindByID() throws Exception {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "findByID");
if (credentialID == null) {
testCredentialServiceSave();
}
String id = credentialID;
String id = saveCredential();
Credentials result = credentialService.findByID(id);
assertNotNull(result);
}
......@@ -293,12 +302,10 @@ public class ServiceTests {
@Test
public void testCredentialServiceDeleteByID() throws JsonProcessingException {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "deleteByID");
if (credentialID == null) {
testCredentialServiceSave();
}
credentialService.deleteByID(credentialID);
String id = saveCredential();
credentialService.deleteByID(id);
try {
Credentials res = credentialService.findByID(credentialID);
Credentials res = credentialService.findByID(id);
} catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage());
......@@ -315,7 +322,7 @@ public class ServiceTests {
testCredentialServiceDeleteAll();
int numOfINst = 3;
for (int i = 1; i <= numOfINst; i++) {
testCredentialServiceSave();
saveCredential();
}
List<String> result = credentialService.getAllIds();
assertEquals(numOfINst, result.size());
......@@ -331,16 +338,14 @@ public class ServiceTests {
assertEquals(0, size);
}
@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);
MultipartFile file = new MockMultipartFile("file", in);
toscaTemplateID = toscaTemplateService.saveFile(file);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(toscaTemplateService.findByID(toscaTemplateID));
provisionService.addProvisionInterface(toscaTemplate);
// provisionService.addProvisionInterface(toscaTemplate);
}
}
......@@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nl.uva.sne.drip.commons.utils.TOSCAUtils;
import nl.uva.sne.drip.model.ToscaTemplate;
import org.apache.commons.io.FilenameUtils;
......@@ -37,57 +36,14 @@ class ProvisionerRPCService {
buildCloudStormTopTopology(toscaTemplate);
return toscaTemplate;
}
private Map<String, Object> buildCloudStormTopTopology(ToscaTemplate toscaTemplate) throws JSchException, IOException {
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;
}
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 {
String userPublicKeyName = "id_rsa.pub";
String publicKeyPath = "name@" + userPublicKeyName;
......@@ -100,31 +56,4 @@ class ProvisionerRPCService {
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):
updated_results = []
for res in results:
if root_key in res:
key = res.pop(root_key)
key = res[root_key]
node = {key: res}
else:
node = res
updated_results.append(node)
return updated_results
return None
......@@ -87,15 +85,27 @@ def save(file):
def get_interface_types(id, interface_type=None):
if len(interface_types_db) <= 1:
interface_types = get_tosca_template_model_by_id(id).interface_types
if interface_types:
for interface_type_name in interface_types:
tosca_template_model = get_tosca_template_model_by_id(id)
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.update(interface_types[interface_type_name])
interface.update(object_list[interface_type_name])
interface_types_db.insert(interface)
queries = []
if interface_type:
query = Query()
queries.append(query._node_nme == interface_type)
queries.append(query.root_key == interface_type)
return query_db(queries, db=interface_types_db)
......@@ -352,3 +362,10 @@ def set_node_properties(id, properties, node_name):
tosca_template_model.topology_template.node_templates[node_name] = node_template_model
return update(id,tosca_template_model.to_dict())
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