Skip to content

Commit

Permalink
Rename TOSCA "unit" to "file"
Browse files Browse the repository at this point in the history
  • Loading branch information
tliron committed Jun 14, 2022
1 parent a9409c1 commit 1b14294
Show file tree
Hide file tree
Showing 37 changed files with 292 additions and 186 deletions.
3 changes: 3 additions & 0 deletions clout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ fit all. Puccini instead comes with examples: see [storing in Neo4j](examples/ne
Structure
---------

Note that *all* map keys in Clout must be strings. This is in order to ensure widest compatibility
with programming languages and implementations.

### `version` (string)

Must be "1.0" to conform with this document.
Expand Down
19 changes: 0 additions & 19 deletions clout/js/coerce.go

This file was deleted.

19 changes: 0 additions & 19 deletions clout/js/resolve.go

This file was deleted.

36 changes: 36 additions & 0 deletions clout/js/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package js

import (
problemspkg "github.com/tliron/kutil/problems"
urlpkg "github.com/tliron/kutil/url"
cloutpkg "github.com/tliron/puccini/clout"
)

func Resolve(clout *cloutpkg.Clout, problems *problemspkg.Problems, urlContext *urlpkg.Context, history bool, format string, strict bool, pretty bool) {
var arguments map[string]string
if !history {
arguments = make(map[string]string)
arguments["history"] = "false"
}
Exec("tosca.resolve", arguments, clout, problems, urlContext, format, strict, pretty)
}

func Coerce(clout *cloutpkg.Clout, problems *problemspkg.Problems, urlContext *urlpkg.Context, history bool, format string, strict bool, pretty bool) {
var arguments map[string]string
if !history {
arguments = make(map[string]string)
arguments["history"] = "false"
}
Exec("tosca.coerce", arguments, clout, problems, urlContext, format, strict, pretty)
}

func Outputs(clout *cloutpkg.Clout, problems *problemspkg.Problems, urlContext *urlpkg.Context, format string, strict bool, pretty bool) {
Exec("tosca.outputs", nil, clout, problems, urlContext, format, strict, pretty)
}

func Exec(scriptletName string, arguments map[string]string, clout *cloutpkg.Clout, problems *problemspkg.Problems, urlContext *urlpkg.Context, format string, strict bool, pretty bool) {
context := NewContext(scriptletName, log, arguments, true, format, strict, pretty, "", urlContext)
if _, err := context.Require(clout, scriptletName, map[string]any{"problems": problems}); err != nil {
problems.ReportError(err)
}
}
14 changes: 14 additions & 0 deletions clout/util/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package util

import (
"github.com/tliron/kutil/ard"
)

func Put(key string, value ard.Value, entity ard.Value, names ...string) bool {
if map_, ok := ard.NewNode(entity).Get(names...).StringMap(); ok {
map_[key] = value
return true
} else {
return false
}
}
21 changes: 21 additions & 0 deletions clout/util/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package util

import (
"github.com/tliron/kutil/ard"
)

func NewList(entryType string, values ard.List) ard.StringMap {
return ard.StringMap{
"$information": NewListInformation(entryType),
"$list": values,
}
}

func NewListInformation(entryType string) ard.StringMap {
return ard.StringMap{
"type": ard.StringMap{"name": "list"},
"entry": ard.StringMap{
"type": ard.StringMap{"name": entryType},
},
}
}
29 changes: 29 additions & 0 deletions clout/util/map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package util

import (
"github.com/tliron/kutil/ard"
)

func NewStringMap(values ard.StringMap, valueType string) ard.StringMap {
entries := make(ard.List, len(values))
index := 0
for key, value := range values {
entries[index] = NewStringMapEntry(key, value, valueType)
index++
}
return ard.StringMap{"$map": entries}
}

func NewStringMapEntry(key string, value ard.Value, valueType string) ard.StringMap {
return ard.StringMap{
"$information": NewValueInformation(valueType),
"$key": ard.StringMap{"$value": key},
"$value": value,
}
}

func NewValueInformation(type_ string) ard.StringMap {
return ard.StringMap{
"type": ard.StringMap{"name": type_},
}
}
40 changes: 40 additions & 0 deletions clout/util/tosca.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package util

import (
"github.com/tliron/kutil/ard"
)

func IsTosca(metadata ard.Value, kind string) bool {
var metadata_ struct {
Puccini struct {
Version string `ard:"version"`
Kind string `ard:"kind"`
} `ard:"puccini"`
}

if err := ard.NewReflector().ToComposite(metadata, &metadata_); err == nil {
if metadata_.Puccini.Version == "1.0" {
if kind != "" {
return metadata_.Puccini.Kind == kind
} else {
return true
}
}
}

return false
}

func IsToscaType(entity ard.Value, type_ string) bool {
if types, ok := ard.NewNode(entity).Get("types").StringMap(); ok {
if _, ok := types[type_]; ok {
return true
}
}
return false
}

func GetToscaOutputs(properties ard.Value) (ard.StringMap, bool) {
outputs, ok := ard.NewNode(properties).Get("tosca", "outputs").StringMap()
return outputs, ok
}
4 changes: 2 additions & 2 deletions puccini-tosca/commands/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/spf13/cobra"
"github.com/tliron/kutil/terminal"
formatpkg "github.com/tliron/kutil/transcribe"
"github.com/tliron/kutil/transcribe"
"github.com/tliron/kutil/util"
"github.com/tliron/puccini/tosca/csar"

Expand Down Expand Up @@ -52,7 +52,7 @@ func Meta(url string) {
util.FailOnError(err)

if !terminal.Quiet || (output != "") {
err = formatpkg.WriteOrPrint(meta, format, terminal.Stdout, strict, pretty, output)
err = transcribe.WriteOrPrint(meta, format, terminal.Stdout, strict, pretty, output)
util.FailOnError(err)
}
}
1 change: 1 addition & 0 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
gofmt -w -s -e \
"$ROOT/clout" \
"$ROOT/clout/js" \
"$ROOT/clout/util" \
"$ROOT/puccini-clout" \
"$ROOT/puccini-clout/commands" \
"$ROOT/puccini-tosca" \
Expand Down
6 changes: 3 additions & 3 deletions tosca/QUIRKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ These are activated via the `--quirk/-x` switch for
* **imports.implicit.disable**: In TOSCA 1.0-1.3 the Simple Profile is implicitly imported by
default. This quirk will disable implicit imports.

* **imports.version.permissive**: By default Puccini will report an error if a unit imports
another unit with an incompatible grammar. This quirk will disable the check.
* **imports.version.permissive**: By default Puccini will report an error if a file imports
another file with an incompatible grammar. This quirk will disable the check.

* **imports.topology_template.ignore**: Allows imported units to contain a `topology_template`
* **imports.topology_template.ignore**: Allows imported files to contain a `topology_template`
section, which is ignored.

* **imports.sequencedlist**: Allows the "import" syntax to be a sequenced list, in which the
Expand Down
4 changes: 2 additions & 2 deletions tosca/grammars/cloudify_v1_3/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (
//

type Blueprint struct {
*Unit `name:"blueprint"`
*File `name:"blueprint"`

Description *string `read:"description"` // not in spec, but in code
Groups Groups `read:"groups,Group"`
}

func NewBlueprint(context *tosca.Context) *Blueprint {
return &Blueprint{Unit: NewUnit(context)}
return &Blueprint{File: NewFile(context)}
}

// tosca.Reader signature
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/cloudify_v1_3/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
Grammar.RegisterVersion("tosca_definitions_version", "cloudify_dsl_1_3", "/cloudify/5.0.5/profile.yaml")

Grammar.RegisterReader("$Root", ReadBlueprint)
Grammar.RegisterReader("$Unit", ReadUnit)
Grammar.RegisterReader("$File", ReadFile)

Grammar.RegisterReader("Blueprint", ReadBlueprint)
Grammar.RegisterReader("DataType", ReadDataType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
)

//
// Unit
// File
//
// See Blueprint
//

type Unit struct {
*Entity `name:"unit"`
type File struct {
*Entity `name:"file"`

ToscaDefinitionsVersion *string `read:"tosca_definitions_version" mandatory:""`
Metadata Metadata `read:"metadata,!Metadata"` // not in spec, but in code
Expand All @@ -31,24 +31,24 @@ type Unit struct {
UploadResources *UploadResources `read:"upload_resources,UploadResources"`
}

func NewUnit(context *tosca.Context) *Unit {
return &Unit{
func NewFile(context *tosca.Context) *File {
return &File{
Entity: NewEntity(context),
Inputs: make(Inputs),
Outputs: make(ValueDefinitions),
}
}

// tosca.Reader signature
func ReadUnit(context *tosca.Context) tosca.EntityPtr {
self := NewUnit(context)
func ReadFile(context *tosca.Context) tosca.EntityPtr {
self := NewFile(context)
context.ScriptletNamespace.Merge(DefaultScriptletNamespace)
context.ValidateUnsupportedFields(append(context.ReadFields(self), "dsl_definitions"))
return self
}

// tosca.Importer interface
func (self *Unit) GetImportSpecs() []*tosca.ImportSpec {
func (self *File) GetImportSpecs() []*tosca.ImportSpec {
var importSpecs = make([]*tosca.ImportSpec, 0, len(self.Imports))
for _, import_ := range self.Imports {
if importSpec, ok := import_.NewImportSpec(self); ok {
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/cloudify_v1_3/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ReadImport(context *tosca.Context) tosca.EntityPtr {
return self
}

func (self *Import) NewImportSpec(unit *Unit) (*tosca.ImportSpec, bool) {
func (self *Import) NewImportSpec(unit *File) (*tosca.ImportSpec, bool) {
if self.File == nil {
return nil, false
}
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/tosca_v1_0/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
Grammar.RegisterVersion("tosca_definitions_version", "tosca_simple_yaml_1_0", "/tosca/simple/1.0/profile.yaml")

Grammar.RegisterReader("$Root", tosca_v1_1.ReadServiceTemplate) // 1.1
Grammar.RegisterReader("$Unit", tosca_v1_1.ReadUnit) // 1.1
Grammar.RegisterReader("$File", tosca_v1_1.ReadFile) // 1.1

Grammar.RegisterReader("Artifact", tosca_v1_2.ReadArtifact) // 1.2
Grammar.RegisterReader("ArtifactDefinition", tosca_v1_2.ReadArtifactDefinition) // 1.2
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/tosca_v1_1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
Grammar.RegisterVersion("tosca_definitions_version", "tosca_simple_yaml_1_1", "/tosca/simple/1.1/profile.yaml")

Grammar.RegisterReader("$Root", ReadServiceTemplate) // override
Grammar.RegisterReader("$Unit", ReadUnit) // override
Grammar.RegisterReader("$File", ReadFile) // override

Grammar.RegisterReader("Artifact", tosca_v1_2.ReadArtifact) // 1.2
Grammar.RegisterReader("ArtifactDefinition", tosca_v1_2.ReadArtifactDefinition) // 1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
)

//
// Unit
// File
//
// [TOSCA-Simple-Profile-YAML-v1.1] @ 3.9
// [TOSCA-Simple-Profile-YAML-v1.0] @ 3.9
//

// tosca.Reader signature
func ReadUnit(context *tosca.Context) tosca.EntityPtr {
func ReadFile(context *tosca.Context) tosca.EntityPtr {
context.SetReadTag("Profile", "")

self := tosca_v2_0.NewUnit(context)
self := tosca_v2_0.NewFile(context)
context.ScriptletNamespace.Merge(DefaultScriptletNamespace)
ignore := []string{"dsl_definitions"}
if context.HasQuirk(tosca.QuirkImportsTopologyTemplateIgnore) {
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/tosca_v1_2/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
Grammar.RegisterVersion("tosca_definitions_version", "tosca_simple_profile_for_nfv_1_0", "/tosca/simple-for-nfv/1.0/profile.yaml")

Grammar.RegisterReader("$Root", ReadServiceTemplate) // override
Grammar.RegisterReader("$Unit", ReadUnit) // override
Grammar.RegisterReader("$File", ReadFile) // override

Grammar.RegisterReader("Artifact", ReadArtifact) // override
Grammar.RegisterReader("ArtifactDefinition", ReadArtifactDefinition) // override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
)

//
// Unit
// File
//
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.10
// [TOSCA-Simple-Profile-YAML-v1.1] @ 3.9
// [TOSCA-Simple-Profile-YAML-v1.0] @ 3.9
//

// tosca.Reader signature
func ReadUnit(context *tosca.Context) tosca.EntityPtr {
func ReadFile(context *tosca.Context) tosca.EntityPtr {
context.SetReadTag("Profile", "namespace")

self := tosca_v2_0.NewUnit(context)
self := tosca_v2_0.NewFile(context)
context.ScriptletNamespace.Merge(DefaultScriptletNamespace)
ignore := []string{"dsl_definitions"}
if context.HasQuirk(tosca.QuirkImportsTopologyTemplateIgnore) {
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 @@ -16,7 +16,7 @@ func init() {
Grammar.RegisterVersion("tosca_definitions_version", "tosca_simple_yaml_1_3", "/tosca/simple/1.3/profile.yaml")

Grammar.RegisterReader("$Root", ReadServiceTemplate)
Grammar.RegisterReader("$Unit", ReadUnit)
Grammar.RegisterReader("$File", ReadFile)

Grammar.RegisterReader("Artifact", tosca_v2_0.ReadArtifact)
Grammar.RegisterReader("ArtifactDefinition", tosca_v2_0.ReadArtifactDefinition)
Expand Down
Loading

0 comments on commit 1b14294

Please sign in to comment.