Skip to content

Commit

Permalink
bugfix: Resolves parsing of Policy Trigger Action
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjones-cisco committed Oct 17, 2016
1 parent a892ac7 commit 2155a7b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
8 changes: 4 additions & 4 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ func (i *OperationDefinition) UnmarshalYAML(unmarshal func(interface{}) error) e
return nil
}
var str struct {
Inputs map[string]PropertyAssignment `yaml:"inputs,omitempty"`
//Implementation string `yaml:"implementation,omitempty"`
Description string `yaml:"description,omitempty"`
Implementation string `yaml:"implementation,omitempty"`
Inputs map[string]PropertyAssignment `yaml:"inputs,omitempty"`
Description string `yaml:"description,omitempty"`
Implementation string `yaml:"implementation,omitempty"`
}
if err := unmarshal(&str); err != nil {
return err
Expand All @@ -62,6 +61,7 @@ type InterfaceDef struct {
Inputs map[string]PropertyAssignment `yaml:"inputs,omitempty"`
Description string `yaml:"description,omitempty"`
Implementation string `yaml:"implementation,omitempty"`
// FIXME(kenjones): Missing OperationDefinition here
}

// UnmarshalYAML converts YAML text to a type
Expand Down
12 changes: 6 additions & 6 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (t *TriggerCondition) UnmarshalYAML(unmarshal func(interface{}) error) erro

// TriggerDefinition provides the base structure for defining a Trigger for a Policy
type TriggerDefinition struct {
Description string `yaml:"description,omitempty" json:"description"`
EventType string `yaml:"event_type" json:"event_type"`
Schedule TimeInterval `yaml:"schedule,omitempty" json:"schedule"`
TargetFilter EventFilterDefinition `yaml:"target_filter,omitempty" json:"target_filter"`
Condition TriggerCondition `yaml:"condition,omitempty" json:"condition"`
Action OperationDefinition `yaml:"action" json:"action"`
Description string `yaml:"description,omitempty" json:"description"`
EventType string `yaml:"event_type" json:"event_type"`
Schedule TimeInterval `yaml:"schedule,omitempty" json:"schedule"`
TargetFilter EventFilterDefinition `yaml:"target_filter,omitempty" json:"target_filter"`
Condition TriggerCondition `yaml:"condition,omitempty" json:"condition"`
Action map[string]OperationDefinition `yaml:"action" json:"action"`
}

// PolicyType provides the base structure for defining what a Policy is
Expand Down
1 change: 1 addition & 0 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import "fmt"
// The value of a property can be retrieved using the
// get_property function within TOSCA Service Templates
type PropertyDefinition struct {
// FIXME(kenjones): Value is not part of any version of the specs going back to the original in April 2014
Value string `yaml:"value,omitempty"`
Type string `yaml:"type" json:"type"` // The required data type for the property
Description string `yaml:"description,omitempty" json:"description,omitempty"` // The optional description for the property.
Expand Down
9 changes: 5 additions & 4 deletions service_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ func (s *ServiceTemplateDefinition) Merge(u ServiceTemplateDefinition) ServiceTe
// GetNodeTemplate returns a pointer to a node template given its name
// its returns nil if not found
func (s *ServiceTemplateDefinition) GetNodeTemplate(nodeName string) *NodeTemplate {
nt, ok := s.TopologyTemplate.NodeTemplates[nodeName]
if !ok {
return nil
if nt, ok := s.TopologyTemplate.NodeTemplates[nodeName]; ok {
return &nt
}
return &nt
return nil
}

// PA holds a PropertyAssignment and the original
Expand All @@ -88,6 +87,8 @@ func (s *ServiceTemplateDefinition) GetProperty(node, prop string) PA {

// GetAttribute returns the attribute of a Node
func (s *ServiceTemplateDefinition) GetAttribute(node, attr string) PA {
// FIXME(kenjones): Should be AttributeAssignment or a single type that works for
// both Property and Attribute
var paa PropertyAssignment
nt := s.GetNodeTemplate(node)
if nt != nil {
Expand Down
43 changes: 43 additions & 0 deletions service_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,49 @@ func TestParseVerifyRelationshipTypes(t *testing.T) {
}
}

func TestParseVerifyPolicyTypes(t *testing.T) {
fname := "./tests/tosca_container_policies.yaml"
var s ServiceTemplateDefinition
o, err := os.Open(fname)
if err != nil {
t.Fatal(err)
}
err = s.Parse(o)
if err != nil {
t.Log("Error in processing", fname)
t.Fatal(err)
}

pt := s.PolicyTypes["my.policies.types.Performance"]

if pt.DerivedFrom != "tosca.policies.Performance" {
t.Log(fname, "missing PolicyTypes `my.policies.types.Performance`")
t.Fail()
}

if pt.Properties["metric_name"].Type != "string" {
t.Log(fname, "missing PolicyTypes Property `metric_name`")
t.Fail()
}

if len(pt.Triggers) != 2 {
t.Log(fname, "missing PolicyTypes Triggers")
t.Fail()
}

if pt.Triggers["scale_up"].EventType != "UpperThresholdExceeded" {
t.Log(fname, "missing PolicyTypes Trigger `scale_up`")
t.Fail()
}

tr := pt.Triggers["scale_up"]

if tr.Action["scale_up"].Implementation != "scale_up_workflow" {
t.Log(fname, "missing PolicyTypes Trigger Action `scale_up`")
t.Fail()
}
}

func TestParseCsar(t *testing.T) {

testsko := []string{
Expand Down

0 comments on commit 2155a7b

Please sign in to comment.