Skip to content

Commit

Permalink
Fix problem reporting for implicit imports
Browse files Browse the repository at this point in the history
The issue was that read errors would cause the read unit not to be added
to the context.

This also fixes YAML syntax errors in the implicit 2.0 profile, which
closes #43.

This also improves dump output for "puccini-tosca parse".
  • Loading branch information
tliron committed Dec 10, 2020
1 parent 319ee3f commit e83242a
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 50 deletions.
34 changes: 17 additions & 17 deletions assets/tosca/profiles/implicit/2.0/data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ data_types:
metadata:
puccini.type: ard.boolean
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

integer:
metadata:
puccini.type: ard.integer
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

float:
metadata:
puccini.type: ard.float
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

string:
metadata:
puccini.type: ard.string
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

bytes:
metadata:
puccini.type: bytes
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

nil:
metadata:
puccini.type: ard.null
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

#
# Special
Expand All @@ -56,25 +56,25 @@ data_types:
puccini.type: version
puccini.comparer: tosca.comparer.version
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

timestamp:
metadata:
puccini.type: timestamp
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

range:
metadata:
puccini.type: range
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

tosca.datatypes.json?:
metadata:
puccini.normative: 'true'
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'
# ERRATUM: typo
description: >-
The json type is a TOSCA data Type used to define a string that contains data in the
Expand All @@ -87,7 +87,7 @@ data_types:
metadata:
puccini.normative: 'true'
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'
# ERRATUM: typo
description: >-
The xml type is a TOSCA data Type used to define a string that contains data in the
Expand All @@ -104,25 +104,25 @@ data_types:
metadata:
puccini.type: scalar-unit.size
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

scalar-unit.time:
metadata:
puccini.type: scalar-unit.time
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

scalar-unit.frequency:
metadata:
puccini.type: scalar-unit.frequency
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

scalar-unit.bitrate:
metadata:
puccini.type: scalar-unit.bitrate
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

#
# Collections
Expand All @@ -132,10 +132,10 @@ data_types:
metadata:
puccini.type: ard.list
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'

map:
metadata:
puccini.type: ard.map
specification.citation: '[TOSCA-v2.0]'
specification.location: ?
specification.location: '?'
48 changes: 48 additions & 0 deletions go.sum

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions puccini-tosca/commands/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ func Parse(url string) (parser.Context, *normal.ServiceTemplate) {
if ToPrintPhase(1) {
if len(dumpPhases) > 1 {
fmt.Fprintf(terminal.Stdout, "%s\n", terminal.ColorHeading("Imports"))
context.PrintImports(1)
} else {
context.PrintImports(0)
}
context.PrintImports(1)
}
}

Expand All @@ -108,8 +110,10 @@ func Parse(url string) (parser.Context, *normal.ServiceTemplate) {
if ToPrintPhase(2) {
if len(dumpPhases) > 1 {
fmt.Fprintf(terminal.Stdout, "%s\n", terminal.ColorHeading("Namespaces"))
context.PrintNamespaces(1)
} else {
context.PrintNamespaces(0)
}
context.PrintNamespaces(1)
}
}

Expand All @@ -119,8 +123,10 @@ func Parse(url string) (parser.Context, *normal.ServiceTemplate) {
if ToPrintPhase(3) {
if len(dumpPhases) > 1 {
fmt.Fprintf(terminal.Stdout, "%s\n", terminal.ColorHeading("Hierarchies"))
context.PrintHierarchies(1)
} else {
context.PrintHierarchies(0)
}
context.PrintHierarchies(1)
}
}

Expand All @@ -130,8 +136,10 @@ func Parse(url string) (parser.Context, *normal.ServiceTemplate) {
if ToPrintPhase(4) {
if len(dumpPhases) > 1 {
fmt.Fprintf(terminal.Stdout, "%s\n", terminal.ColorHeading("Inheritance Tasks"))
tasks.Print(1)
} else {
tasks.Print(0)
}
tasks.Print(1)
}
tasks.Drain()
}
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/tosca_v1_3/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func init() {
Grammar.RegisterReader("TriggerDefinitionCondition", tosca_v2_0.ReadTriggerDefinitionCondition)
Grammar.RegisterReader("Value", tosca_v2_0.ReadValue)
Grammar.RegisterReader("version", tosca_v2_0.ReadVersion)
Grammar.RegisterReader("WorkflowActivityCallOperation", tosca_v2_0.ReadWorkflowActivityCallOperation) // TODO: introduced in TOSCA 1.3
Grammar.RegisterReader("WorkflowActivityCallOperation", tosca_v2_0.ReadWorkflowActivityCallOperation) // introduced in TOSCA 1.3
Grammar.RegisterReader("WorkflowActivityDefinition", tosca_v2_0.ReadWorkflowActivityDefinition) // introduced in TOSCA 1.1
Grammar.RegisterReader("WorkflowDefinition", tosca_v2_0.ReadWorkflowDefinition) // introduced in TOSCA 1.1
Grammar.RegisterReader("WorkflowPreconditionDefinition", tosca_v2_0.ReadWorkflowPreconditionDefinition) // introduced in TOSCA 1.1
Expand Down
11 changes: 11 additions & 0 deletions tosca/grammars/tosca_v2_0/bytes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tosca_v2_0

import (
"github.com/tliron/puccini/tosca"
)

// tosca.Reader signature
func ReadBytes(context *tosca.Context) tosca.EntityPtr {
// TODO
return nil
}
1 change: 1 addition & 0 deletions tosca/grammars/tosca_v2_0/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
Grammar.RegisterReader("AttributeDefinition", ReadAttributeDefinition)
Grammar.RegisterReader("AttributeMapping", ReadAttributeMapping) // introduced in TOSCA 1.3
Grammar.RegisterReader("AttributeValue", ReadAttributeValue)
Grammar.RegisterReader("bytes", ReadBytes) // introduced in TOSCA 2.0
Grammar.RegisterReader("CapabilityAssignment", ReadCapabilityAssignment)
Grammar.RegisterReader("CapabilityDefinition", ReadCapabilityDefinition)
Grammar.RegisterReader("CapabilityFilter", ReadCapabilityFilter)
Expand Down
12 changes: 8 additions & 4 deletions tosca/parser/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ func (self *Context) MergeProblems() {
}
}

func (self *Context) AddUnit(entityPtr tosca.EntityPtr, container *Unit, nameTransformer tosca.NameTransformer) *Unit {
func (self *Context) AddUnit(unit *Unit) {
self.unitsLock.Lock()
self.Units = append(self.Units, unit)
self.unitsLock.Unlock()
}

func (self *Context) AddImportUnit(entityPtr tosca.EntityPtr, container *Unit, nameTransformer tosca.NameTransformer) *Unit {
unit := NewUnit(entityPtr, container, nameTransformer)

if container != nil {
Expand All @@ -55,9 +61,7 @@ func (self *Context) AddUnit(entityPtr tosca.EntityPtr, container *Unit, nameTra
}
}

self.unitsLock.Lock()
self.Units = append(self.Units, unit)
self.unitsLock.Unlock()
self.AddUnit(unit)

self.goReadImports(unit)

Expand Down
20 changes: 13 additions & 7 deletions tosca/parser/phase1-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (self *Context) read(promise Promise, toscaContext *tosca.Context, containe
var err error
if toscaContext.URL, err = csar.GetRootURL(toscaContext.URL); err != nil {
toscaContext.ReportError(err)
return NewUnitNoEntity(toscaContext, container, nameTransformer), false
unit := NewUnitNoEntity(toscaContext, container, nameTransformer)
self.AddUnit(unit)
return unit, false
}
}

Expand All @@ -56,12 +58,16 @@ func (self *Context) read(promise Promise, toscaContext *tosca.Context, containe
err = NewYAMLDecodeError(decodeError)
}
toscaContext.ReportError(err)
return NewUnitNoEntity(toscaContext, container, nameTransformer), false
unit := NewUnitNoEntity(toscaContext, container, nameTransformer)
self.AddUnit(unit)
return unit, false
}

// Detect grammar
if !grammars.Detect(toscaContext) {
return NewUnitNoEntity(toscaContext, container, nameTransformer), false
unit := NewUnitNoEntity(toscaContext, container, nameTransformer)
self.AddUnit(unit)
return unit, false
}

// Read entityPtr
Expand All @@ -80,10 +86,10 @@ func (self *Context) read(promise Promise, toscaContext *tosca.Context, containe

readCache.Store(toscaContext.URL.Key(), entityPtr)

return self.AddUnit(entityPtr, container, nameTransformer), true
return self.AddImportUnit(entityPtr, container, nameTransformer), true
}

// From Importer interface
// From tosca.Importer interface
func (self *Context) goReadImports(container *Unit) {
var importSpecs []*tosca.ImportSpec
if importer, ok := container.EntityPtr.(tosca.Importer); ok {
Expand Down Expand Up @@ -129,7 +135,7 @@ func (self *Context) goReadImports(container *Unit) {
default: // entityPtr
// Cache hit
log.Debugf("{read} cache hit: %s", key)
self.AddUnit(cached, container, importSpec.NameTransformer)
self.AddImportUnit(cached, container, importSpec.NameTransformer)
}
} else {
importToscaContext := container.GetContext().NewImportContext(importSpec.URL)
Expand All @@ -153,7 +159,7 @@ func (self *Context) waitForPromise(promise Promise, key string, container *Unit
default: // entityPtr
// Cache hit
log.Debugf("{read} promise kept: %s", key)
self.AddUnit(cached, container, nameTransformer)
self.AddImportUnit(cached, container, nameTransformer)
}
} else {
log.Debugf("{read} promise broken (empty): %s", key)
Expand Down
Loading

0 comments on commit e83242a

Please sign in to comment.