Commit c354a862 authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed serialization error

parent a6e38c65
package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -10,29 +11,16 @@ import java.util.List;
import java.util.Map;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* NodeTemplate
*/
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-10T15:39:04.296Z")
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-10T16:27:40.329Z")
public class NodeTemplate {
public String getId() {
return name;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.name = id;
}
@JsonIgnore
private String name;
@JsonProperty("derived_from")
private String derivedFrom = null;
......@@ -79,7 +67,7 @@ public class NodeTemplate {
* Get derivedFrom
*
* @return derivedFrom
*
*
*/
@ApiModelProperty(value = "")
......@@ -108,7 +96,7 @@ public class NodeTemplate {
* Get properties
*
* @return properties
*
*
*/
@ApiModelProperty(value = "")
......@@ -137,7 +125,7 @@ public class NodeTemplate {
* Get requirements
*
* @return requirements
*
*
*/
@ApiModelProperty(value = "")
......@@ -168,7 +156,7 @@ public class NodeTemplate {
* Get interfaces
*
* @return interfaces
*
*
*/
@ApiModelProperty(value = "")
......@@ -197,7 +185,7 @@ public class NodeTemplate {
* Get capabilities
*
* @return capabilities
*
*
*/
@ApiModelProperty(value = "")
......@@ -218,7 +206,7 @@ public class NodeTemplate {
* Get type
*
* @return type
*
*
*/
@ApiModelProperty(value = "")
......@@ -239,7 +227,7 @@ public class NodeTemplate {
* Get description
*
* @return description
*
*
*/
@ApiModelProperty(value = "")
......@@ -268,7 +256,7 @@ public class NodeTemplate {
* Get directives
*
* @return directives
*
*
*/
@ApiModelProperty(value = "")
......@@ -297,7 +285,7 @@ public class NodeTemplate {
* Get attributes
*
* @return attributes
*
*
*/
@ApiModelProperty(value = "")
......@@ -326,7 +314,7 @@ public class NodeTemplate {
* Get artifacts
*
* @return artifacts
*
*
*/
@ApiModelProperty(value = "")
......
......@@ -24,12 +24,17 @@ import java.io.FileInputStream;
import java.nio.file.Files;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.ToscaTemplate;
import org.junit.After;
......@@ -50,12 +55,14 @@ public class ToscaHelperTest {
private static final String testUpdatedApplicationExampleToscaFilePath = ".." + File.separator + "TOSCA" + File.separator + "application_example_2_topologies.yaml";
private static ToscaHelper instance;
private static ToscaTemplate toscaTemplate;
private static Boolean serviceUp;
public ToscaHelperTest() {
}
@BeforeClass
public static void setUpClass() throws UnsupportedEncodingException, JsonProcessingException, IOException, ApiException {
Properties prop = new Properties();
String resourceName = "src/test/resources/application.properties";
prop.load(new FileInputStream(resourceName));
......@@ -63,7 +70,11 @@ public class ToscaHelperTest {
String ymlStr = new String(bytes, "UTF-8");
objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
toscaTemplate = objectMapper.readValue(ymlStr, ToscaTemplate.class);
instance = new ToscaHelper(toscaTemplate, prop.getProperty("sure-tosca.base.path"));
String serviceBasePath = prop.getProperty("sure-tosca.base.path");
serviceUp = isServiceUp(serviceBasePath);
if (serviceUp) {
instance = new ToscaHelper(toscaTemplate, serviceBasePath);
}
}
......@@ -84,37 +95,59 @@ public class ToscaHelperTest {
*/
@Test
public void testGetId() {
System.out.println("getId");
Integer result = instance.getId();
assertNotNull(result);
if (serviceUp) {
System.out.println("getId");
Integer result = instance.getId();
assertNotNull(result);
}
}
/**
* Test of getProvisionInterfaceDefinitions method, of class ToscaHelper.
*
* @throws nl.uva.sne.drip.sure_tosca.client.ApiException
*/
@Test
public void testGetProvisionInterfaceDefinitions() throws Exception {
System.out.println("getProvisionInterfaceDefinitions");
List<String> toscaInterfaceTypes = new ArrayList<>();
String expected = "tosca.interfaces.ARTICONF.CloudsStorm";
toscaInterfaceTypes.add(expected);
List<Map<String, Object>> result = instance.getProvisionInterfaceDefinitions(toscaInterfaceTypes);
assertNotNull(result);
String key = result.get(0).keySet().iterator().next();
assertEquals(expected, key);
public void testGetProvisionInterfaceDefinitions() throws ApiException {
if (serviceUp) {
System.out.println("getProvisionInterfaceDefinitions");
List<String> toscaInterfaceTypes = new ArrayList<>();
String expected = "tosca.interfaces.ARTICONF.CloudsStorm";
toscaInterfaceTypes.add(expected);
List<Map<String, Object>> result = instance.getProvisionInterfaceDefinitions(toscaInterfaceTypes);
assertNotNull(result);
String key = result.get(0).keySet().iterator().next();
assertEquals(expected, key);
}
}
/**
* Test of getVMTopologyTemplates method, of class ToscaHelper.
*
* @throws nl.uva.sne.drip.sure_tosca.client.ApiException
*/
@Test
public void testGetVMTopologyTemplates() throws Exception {
System.out.println("getVMTopologyTemplates");
List<NodeTemplate> result = instance.getVMTopologyTemplates();
assertNotNull(result);
for (NodeTemplate nodeTemplate : result) {
assertEquals(nodeTemplate.getType(), "tosca.nodes.ARTICONF.VM.topology");
public void testGetVMTopologyTemplates() throws ApiException {
if (serviceUp) {
System.out.println("getVMTopologyTemplates");
List<NodeTemplate> result = instance.getVMTopologyTemplates();
assertNotNull(result);
for (NodeTemplate nodeTemplate : result) {
assertEquals(nodeTemplate.getType(), "tosca.nodes.ARTICONF.VM.topology");
}
}
}
public static Boolean isServiceUp(String serviceBasePath) {
try {
URL serviceUrl = new URL(serviceBasePath);
HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection();
//Set request to header to reduce load as Subirkumarsao said.
connection.setRequestMethod("HEAD");
int code = connection.getResponseCode();
} catch (IOException ex) {
return false;
}
return true;
}
}
......@@ -15,15 +15,24 @@ import java.io.File;
import org.junit.Test;
import java.util.List;
import static nl.uva.sne.drip.commons.utils.ToscaHelperTest.isServiceUp;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
/**
* API tests for DefaultApi
*/
@Ignore
public class DefaultApiTest {
// private final DefaultApi api = new DefaultApi();
private String serviceBasePath;
private final Boolean serviceUp;
public DefaultApiTest() {
serviceUp = isServiceUp(serviceBasePath);
}
// private final DefaultApi api = new DefaultApi();
/**
*
*
......@@ -330,5 +339,4 @@ public class DefaultApiTest {
//
// // TODO: test validations
// }
}
This diff is collapsed.
......@@ -746,6 +746,8 @@ definitions:
NodeTemplate:
type: object
properties:
name:
type: string
derived_from:
type: string
properties:
......
NodeTemplate:
type: "object"
properties:
name:
type: "string"
derived_from:
type: "string"
properties:
......
......@@ -64,12 +64,3 @@ class Model(object):
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
# def __hash__(self):
# return hash(self.__dict__.keys())
def __key(self):
return tuple(sorted(self.to_dict()))
def __hash__(self):
return hash(self.__key())
\ No newline at end of file
......@@ -15,8 +15,7 @@ class NodeTemplateModel(Model):
Do not edit the class manually.
"""
def __init__(self, derived_from=None, properties=None, requirements=None, interfaces=None, capabilities=None,
type=None, description=None, directives=None, attributes=None, artifacts=None): # noqa: E501
def __init__(self, derived_from=None, properties=None, requirements=None, interfaces=None, capabilities=None, type=None, description=None, directives=None, attributes=None, artifacts=None): # noqa: E501
"""NodeTemplate - a model defined in Swagger
:param derived_from: The derived_from of this NodeTemplate. # noqa: E501
......@@ -84,10 +83,12 @@ class NodeTemplateModel(Model):
:param dikt: A dict.
:type: dict
:return: The NodeTemplate of this NodeTemplate. # noqa: E501
:rtype: NodeTemplateModel
:rtype: NodeTemplate
"""
return util.deserialize_model(dikt, cls)
@property
def derived_from(self):
"""Gets the derived_from of this NodeTemplate.
......
......@@ -5,9 +5,9 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from sure_tosca.models import NodeTemplateModel
from sure_tosca.models.base_model_ import Model
from sure_tosca import util
from sure_tosca.models.node_template import NodeTemplateModel
class TopologyTemplateModel(Model):
......@@ -22,9 +22,9 @@ class TopologyTemplateModel(Model):
:param description: The description of this TopologyTemplate. # noqa: E501
:type description: str
:param inputs: The inputs of this TopologyTemplate. # noqa: E501
:type inputs: List[Dict[str, object]]
:type inputs: Dict[str, str]
:param node_templates: The node_templates of this TopologyTemplate. # noqa: E501
:type node_templates: Dict[str, NodeTemplateModel]
:type node_templates: Dict[str, NodeTemplate]
:param relationship_templates: The relationship_templates of this TopologyTemplate. # noqa: E501
:type relationship_templates: Dict[str, object]
:param outputs: The outputs of this TopologyTemplate. # noqa: E501
......@@ -38,7 +38,7 @@ class TopologyTemplateModel(Model):
"""
self.swagger_types = {
'description': str,
'inputs': List[Dict[str, object]],
'inputs': Dict[str, str],
'node_templates': Dict[str, NodeTemplateModel],
'relationship_templates': Dict[str, object],
'outputs': Dict[str, object],
......@@ -74,7 +74,7 @@ class TopologyTemplateModel(Model):
:param dikt: A dict.
:type: dict
:return: The TopologyTemplate of this TopologyTemplate. # noqa: E501
:rtype: TopologyTemplateModel
:rtype: TopologyTemplate
"""
return util.deserialize_model(dikt, cls)
......@@ -105,7 +105,7 @@ class TopologyTemplateModel(Model):
:return: The inputs of this TopologyTemplate.
:rtype: List[Dict[str, object]]
:rtype: Dict[str, str]
"""
return self._inputs
......@@ -115,7 +115,7 @@ class TopologyTemplateModel(Model):
:param inputs: The inputs of this TopologyTemplate.
:type inputs: List[Dict[str, object]]
:type inputs: Dict[str, str]
"""
self._inputs = inputs
......@@ -126,7 +126,7 @@ class TopologyTemplateModel(Model):
:return: The node_templates of this TopologyTemplate.
:rtype: Dict[str, NodeTemplateModel]
:rtype: Dict[str, NodeTemplate]
"""
return self._node_templates
......@@ -136,7 +136,7 @@ class TopologyTemplateModel(Model):
:param node_templates: The node_templates of this TopologyTemplate.
:type node_templates: Dict[str, NodeTemplateModel]
:type node_templates: Dict[str, NodeTemplate]
"""
self._node_templates = node_templates
......@@ -168,7 +168,7 @@ class TopologyTemplateModel(Model):
:return: The outputs of this TopologyTemplate.
:rtype: str
:rtype: Dict[str, object]
"""
return self._outputs
......@@ -178,7 +178,7 @@ class TopologyTemplateModel(Model):
:param outputs: The outputs of this TopologyTemplate.
:type outputs: str
:type outputs: Dict[str, object]
"""
self._outputs = outputs
......@@ -245,8 +245,3 @@ class TopologyTemplateModel(Model):
"""
self._policies = policies
def __eq__(self, other):
if isinstance(other, TopologyTemplateModel):
return self.__key() == other.__key()
return NotImplemented
\ No newline at end of file
......@@ -5,9 +5,9 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from sure_tosca.models import TopologyTemplateModel
from sure_tosca.models.base_model_ import Model
from sure_tosca import util
from sure_tosca.models.topology_template import TopologyTemplateModel
class ToscaTemplateModel(Model):
......@@ -16,11 +16,7 @@ class ToscaTemplateModel(Model):
Do not edit the class manually.
"""
def __init__(self, tosca_definitions_version=None, tosca_default_namespace=None, template_name=None,
topology_template=None, template_author=None, template_version=None, description=None, imports=None,
dsl_definitions=None, node_types=None, relationship_types=None, relationship_templates=None,
capability_types=None, artifact_types=None, data_types=None, interface_types=None, policy_types=None,
group_types=None, repositories=None): # noqa: E501
def __init__(self, tosca_definitions_version=None, tosca_default_namespace=None, template_name=None, topology_template=None, template_author=None, template_version=None, description=None, imports=None, dsl_definitions=None, node_types=None, relationship_types=None, relationship_templates=None, capability_types=None, artifact_types=None, data_types=None, interface_types=None, policy_types=None, group_types=None, repositories=None): # noqa: E501
"""ToscaTemplate - a model defined in Swagger
:param tosca_definitions_version: The tosca_definitions_version of this ToscaTemplate. # noqa: E501
......@@ -30,7 +26,7 @@ class ToscaTemplateModel(Model):
:param template_name: The template_name of this ToscaTemplate. # noqa: E501
:type template_name: str
:param topology_template: The topology_template of this ToscaTemplate. # noqa: E501
:type topology_template: TopologyTemplateModel
:type topology_template: TopologyTemplate
:param template_author: The template_author of this ToscaTemplate. # noqa: E501
:type template_author: str
:param template_version: The template_version of this ToscaTemplate. # noqa: E501
......@@ -56,7 +52,7 @@ class ToscaTemplateModel(Model):
:param interface_types: The interface_types of this ToscaTemplate. # noqa: E501
:type interface_types: Dict[str, object]
:param policy_types: The policy_types of this ToscaTemplate. # noqa: E501
:type policy_types: Dict[str, str]
:type policy_types: Dict[str, object]
:param group_types: The group_types of this ToscaTemplate. # noqa: E501
:type group_types: Dict[str, object]
:param repositories: The repositories of this ToscaTemplate. # noqa: E501
......@@ -79,7 +75,7 @@ class ToscaTemplateModel(Model):
'artifact_types': Dict[str, object],
'data_types': Dict[str, object],
'interface_types': Dict[str, object],
'policy_types': Dict[str, str],
'policy_types': Dict[str, object],
'group_types': Dict[str, object],
'repositories': Dict[str, object]
}
......@@ -133,7 +129,7 @@ class ToscaTemplateModel(Model):
:param dikt: A dict.
:type: dict
:return: The ToscaTemplate of this ToscaTemplate. # noqa: E501
:rtype: ToscaTemplateModel
:rtype: ToscaTemplate
"""
return util.deserialize_model(dikt, cls)
......@@ -206,7 +202,7 @@ class ToscaTemplateModel(Model):
:return: The topology_template of this ToscaTemplate.
:rtype: TopologyTemplateModel
:rtype: TopologyTemplate
"""
return self._topology_template
......@@ -216,7 +212,7 @@ class ToscaTemplateModel(Model):
:param topology_template: The topology_template of this ToscaTemplate.
:type topology_template: TopologyTemplateModel
:type topology_template: TopologyTemplate
"""
self._topology_template = topology_template
......@@ -479,7 +475,7 @@ class ToscaTemplateModel(Model):
:return: The policy_types of this ToscaTemplate.
:rtype: Dict[str, str]
:rtype: Dict[str, object]
"""
return self._policy_types
......@@ -489,7 +485,7 @@ class ToscaTemplateModel(Model):
:param policy_types: The policy_types of this ToscaTemplate.
:type policy_types: Dict[str, str]
:type policy_types: Dict[str, object]
"""
self._policy_types = policy_types
......@@ -535,8 +531,3 @@ class ToscaTemplateModel(Model):
"""
self._repositories = repositories
def __eq__(self, other):
if isinstance(other, ToscaTemplateModel):
return self.__key() == other.__key()
return NotImplemented
......@@ -3,6 +3,7 @@ import logging
import os
import tempfile
import uuid
from builtins import print
from functools import reduce
import copy
......@@ -115,6 +116,17 @@ def get_interface_types(id, interface_type=None):
return query_db(queries, db=interface_types_db)
def change_to_nodeTemplateModel(query_results):
res = []
for node_template in query_results:
# copy.deepcopy()
name = next(iter(node_template))
node_template = node_template[name]
node_template['name'] = name
res.append(NodeTemplateModel.from_dict(node_template))
return res
def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, has_properties=None,
has_attributes=None,
has_requirements=None, has_capabilities=None, has_artifacts=None):
......@@ -173,7 +185,8 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
queries.append(query.artifacts != prop)
query_results = query_db(queries, db=node_template_db)
return query_results
return change_to_nodeTemplateModel(query_results)
def get_tosca_template_get_dsl_definitions(id, anchors, derived_from):
......
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