alien4cloud / alien4cloud

Application LIfecycle ENablement for Cloud
http://alien4cloud.org
Apache License 2.0
76 stars 68 forks source link

Inheritance is not working in types on different levels. #103

Open yuranich opened 7 years ago

yuranich commented 7 years ago

Issue for alien4cloud-tosca module of @lucboutier team.

Test 1: Create test file with following content and use it as input to ToscaArchiveParser:

tosca_definitions_version: alien_dsl_1_3_0

metadata:
  template_name: inheritance test
  template_author: yuranich
  template_version: 1.0.0

imports:
  - my-types-extended:1.0.0

node_types:
  tosca.tests.nodes.MyType:
    derived_from: tosca.tests.nodes.ParentType
    description: Sample empty type
    properties:
      component_version:
        description: component version
        type: string
        required: false
        default: 2342

topology_template:
  node_templates:
    my_node:
      type: tosca.tests.nodes.MyType
      description: Template for an instance of tosca.tests.nodes.MyType defined in the imported file

Here I imported CSAR with following file:

tosca_definitions_version: alien_dsl_1_3_0

imports:
  - my-types:1.0.0

node_types:
  tosca.tests.nodes.ParentType:
    derived_from: tosca.tests.nodes.ParentOfParentType
    description: Sample empty type
    properties:
      sample_prop:
        description: sample property
        type: string
        required: false
        default: another_val

and here in import I have another csar with file:

tosca_definitions_version: alien_dsl_1_3_0

imports:
  - tosca-normative-types:1.0.0

node_types:
  tosca.tests.nodes.ParentOfParentType:
    derived_from: tosca.nodes.Root
    description: Sample empty type
    properties:
      wow_wow_prop:
        description: sample property
        type: string
        required: false
        default: wow wow value

After parsing I got this JSON:

{
  "archive" : {
    "name" : "inheritance test",
    "version" : "1.0.0",
    "nestedVersion" : {
      "majorVersion" : 1,
      "minorVersion" : 0,
      "incrementalVersion" : 0,
      "buildNumber" : 0
    },
    "workspace" : null,
    "hash" : null,
    "definitionHash" : null,
    "delegateId" : null,
    "delegateType" : null,
    "yamlFilePath" : "test.yaml",
    "toscaDefinitionsVersion" : "alien_dsl_1_3_0",
    "toscaDefaultNamespace" : null,
    "templateAuthor" : "yuranich",
    "description" : null,
    "dependencies" : [ {
      "name" : "my-types",
      "version" : "1.0.0",
      "hash" : null
    }, {
      "name" : "my-types-extended",
      "version" : "1.0.0",
      "hash" : null
    }, {
      "name" : "tosca-normative-types",
      "version" : "1.0.0",
      "hash" : null
    } ],
    "license" : null,
    "tags" : [ ],
    "importSource" : null,
    "importDate" : null,
    "id" : "inheritance test:1.0.0"
  },
  "topology" : {
    "archiveName" : "parse_test",
    "archiveVersion" : "1.0.0",
    "nestedVersion" : {
      "majorVersion" : 1,
      "minorVersion" : 0,
      "incrementalVersion" : 0,
      "buildNumber" : 0
    },
    "lastUpdateDate" : 1487346399031,
    "dependencies" : [ {
      "name" : "my-types",
      "version" : "1.0.0",
      "hash" : null
    }, {
      "name" : "my-types-extended",
      "version" : "1.0.0",
      "hash" : null
    }, {
      "name" : "tosca-normative-types",
      "version" : "1.0.0",
      "hash" : null
    } ],
    "nodeTemplates" : {
      "my_node" : {
        "name" : "my_node",
        "type" : "tosca.tests.nodes.MyType",
        "properties" : {
          "component_version" : {
            "value" : "2342",
            "definition" : false
          },
          "sample_prop" : {
            "value" : "another_val",
            "definition" : false
          }
        },
        "attributes" : null,
        "artifacts" : null,
        "interfaces" : null,
        "requirements" : { },
        "relationships" : { },
        "capabilities" : { },
        "groups" : null,
        "directives" : null
      }
    },
    "empty" : false,
    "id" : "parse_test:1.0.0"
  },
  "topologyTemplateDescription" : null,
  "localImports" : null,
  "repositories" : { },
  "dataTypes" : { },
  "artifactTypes" : { },
  "capabilityTypes" : { },
  "interfaceTypes" : { },
  "relationshipTypes" : { },
  "nodeTypes" : {
    "tosca.tests.nodes.MyType" : {
      "archiveName" : "inheritance test",
      "archiveVersion" : "1.0.0",
      "nestedVersion" : {
        "majorVersion" : 1,
        "minorVersion" : 0,
        "incrementalVersion" : 0,
        "buildNumber" : 0
      },
      "elementId" : "tosca.tests.nodes.MyType",
      "description" : "Sample empty type",
      "derivedFrom" : [ "tosca.tests.nodes.ParentType", "tosca.tests.nodes.ParentOfParentType" ],
      "properties" : {
        "component_version" : {
          "type" : "string",
          "entrySchema" : null,
          "required" : false,
          "description" : "component version",
          "status" : null,
          "suggestionId" : null,
          "constraints" : null,
          "default" : {
            "value" : "2342",
            "definition" : false
          },
          "password" : false,
          "definition" : true
        },
        "sample_prop" : {
          "type" : "string",
          "entrySchema" : null,
          "required" : false,
          "description" : "sample property",
          "status" : null,
          "suggestionId" : null,
          "constraints" : null,
          "default" : {
            "value" : "another_val",
            "definition" : false
          },
          "password" : false,
          "definition" : true
        }
      },
      "capabilities" : [ ],
      "requirements" : [ ],
      "alienScore" : 0,
      "abstract" : false,
      "id" : "tosca.tests.nodes.MyType:1.0.0"
    }
  },
  "groupTypes" : { },
  "policyTypes" : { }
}

Expected result: properties from type tosca.tests.nodes.ParentOfParentType must be in parsing result. Actual result: properties from type tosca.tests.nodes.ParentOfParentType not in parsing result.

But if I merge my-types and my-types-extended files together in one file everything will be OK.

Test 2: With data types: I created following file for input:

tosca_definitions_version: alien_dsl_1_3_0

metadata:
  template_name: inheritance test
  template_author: yuranich
  template_version: 1.0.0

imports:
  - my-types:1.0.0

data_types:
  tosca.tests.data.MyTypeExtended:
    derived_from: tosca.tests.data.MyType
    description: Sample empty type inhereted

In import I have:

tosca_definitions_version: alien_dsl_1_3_0

imports:
  - tosca-normative-types:1.0.0

data_types:
  tosca.tests.data.MyType:
    derived_from: tosca.datatypes.network.PortSpec
    description: Sample empty type
    properties:
      type_version:
        description: type version
        type: string
        required: false
        default: 2342

Normative types from here https://github.com/oasis-open/tosca-test-assertions/blob/master/Normative-types/normative-types.yml PortSpec type has some properties on it, but they is not coming to final result, even if I remove all constraints and leave only 'protocol' property. E.g:

tosca.datatypes.network.PortSpec:
  derived_from: tosca.datatypes.Root
  properties:
    protocol:
      type: string
      required: true
      default: tcp

In result I got:

{
  "archive" : {
    "name" : "inheritance test",
    "version" : "1.0.0",
    "nestedVersion" : {
      "majorVersion" : 1,
      "minorVersion" : 0,
      "incrementalVersion" : 0,
      "buildNumber" : 0
    },
    "workspace" : null,
    "hash" : null,
    "definitionHash" : null,
    "delegateId" : null,
    "delegateType" : null,
    "yamlFilePath" : "test.yaml",
    "toscaDefinitionsVersion" : "alien_dsl_1_3_0",
    "toscaDefaultNamespace" : null,
    "templateAuthor" : "yuranich",
    "description" : null,
    "dependencies" : [ {
      "name" : "my-types",
      "version" : "1.0.0",
      "hash" : null
    }, {
      "name" : "tosca-normative-types",
      "version" : "1.0.0",
      "hash" : null
    } ],
    "license" : null,
    "tags" : [ ],
    "importSource" : null,
    "importDate" : null,
    "id" : "inheritance test:1.0.0"
  },
  "topology" : null,
  "topologyTemplateDescription" : null,
  "localImports" : null,
  "repositories" : { },
  "dataTypes" : {
    "tosca.tests.data.MyTypeExtended" : {
      "archiveName" : "inheritance test",
      "archiveVersion" : "1.0.0",
      "nestedVersion" : {
        "majorVersion" : 1,
        "minorVersion" : 0,
        "incrementalVersion" : 0,
        "buildNumber" : 0
      },
      "elementId" : "tosca.tests.data.MyTypeExtended",
      "description" : "Sample empty type inhereted",
      "derivedFrom" : [ "tosca.tests.data.MyType", "tosca.datatypes.network.PortSpec" ],
      "properties" : {
        "type_version" : {
          "type" : "string",
          "entrySchema" : null,
          "required" : false,
          "description" : "type version",
          "status" : null,
          "suggestionId" : null,
          "constraints" : null,
          "default" : {
            "value" : "2342",
            "definition" : false
          },
          "password" : false,
          "definition" : true
        }
      },
      "deriveFromSimpleType" : false,
      "abstract" : false,
      "id" : "tosca.tests.data.MyTypeExtended:1.0.0"
    }
  },
  "artifactTypes" : { },
  "capabilityTypes" : { },
  "interfaceTypes" : { },
  "relationshipTypes" : { },
  "nodeTypes" : { },
  "groupTypes" : { },
  "policyTypes" : { }
}

Expected result: type_version and protocol properties displayed in the final result. Actual result: Only type_version property displayed.

This issue repeats for other types too. E. g. artifacts.

yuranich commented 7 years ago

I've explored the issue myself and found that my problem lays here https://github.com/alien4cloud/alien4cloud/blob/develop/alien4cloud-tosca/src/main/java/alien4cloud/tosca/parser/ToscaArchiveParser.java

For every dependency new ToscaContext is created. If I remove "requiresNew = true" parameter, these tests work fine.

lucboutier commented 7 years ago

Thanks Yuri,

I will check if there are impacts related to that. There is probably indeed no good reasons for a new ToscaContext here but this may have impacts on other elements of alien (editor eventually) and I need to check that first.

Luc