Documentation ¶
Index ¶
- Constants
- func IsVersionString(expr string) bool
- type ConstraintExpression
- func (c *ConstraintExpression) Add_Constraint(newconstr string)
- func (c *ConstraintExpression) GetLanguageHandler() (plugin_registry.ConstraintLanguagePlugin, error)
- func (self *ConstraintExpression) GetStrings() []string
- func (c ConstraintExpression) IsSame(other ConstraintExpression) bool
- func (self *ConstraintExpression) IsSatisfiedBy(props []Property) error
- func (c *ConstraintExpression) MergeWith(other *ConstraintExpression)
- func (c *ConstraintExpression) Validate() ([]string, error)
- type ExternalPolicy
- type Property
- type PropertyExpression
- type PropertyList
- func (self *PropertyList) Add_Property(new_ele *Property, replaceExisting bool) error
- func (self *PropertyList) Compatible_With(other *PropertyList, ignoreBuiltIn bool) error
- func (self PropertyList) HasProperty(name string) bool
- func (p PropertyList) IsSame(compare PropertyList) bool
- func (self *PropertyList) MergeWith(new_list *PropertyList, replaceExsiting bool)
- func (self *PropertyList) Validate() error
- type RequiredProperty
- func (self *RequiredProperty) Initialize(exp *map[string]interface{}) error
- func (self *RequiredProperty) IsSatisfiedBy(props []Property) error
- func (self *RequiredProperty) IsValid() error
- func (self *RequiredProperty) Merge(other *RequiredProperty) *RequiredProperty
- func (rp *RequiredProperty) TopLevelElements() []interface{}
Constants ¶
const ( // for node policy PROP_NODE_CPU = "openhorizon.cpu" //The number of CPUs PROP_NODE_MEMORY = "openhorizon.memory" //The amount of memory in MBs PROP_NODE_ARCH = "openhorizon.arch" //The hardware architecture of the node (e.g. amd64, armv6, etc) // for service policy PROP_SVC_URL = "openhorizon.service.url" // The unique name of the service. PROP_SVC_NAME = "openhorizon.service.name" // The unique name of the service. PROP_SVC_ORG = "openhorizon.service.org" // The multi-tenant org where the service is defined. If service.url is specified but this property is omitted, the org defaults to the org of the node, service or policy which is referring to the service. PROP_SVC_VERSION = "openhorizon.service.version" // The version of a service using the same semantic version syntax. PROP_SVC_ARCH = "openhorizon.service.arch" // The hardware architecture of the node this service can run on. )
These are built-in property names that can be used in the policies. anax will fill in the properties during the agreement negotiation process. The user defined policies (business policy, node policy) need to add constrains on these properties if needed.
const ( STRING_TYPE = "string" VERSION_TYPE = "version" BOOLEAN_TYPE = "boolean" INTEGER_TYPE = "int" FLOAT_TYPE = "float" LIST_TYPE = "list of string" UNDECLARED_TYPE = "" )
const MAX_MEMEORY = 1048576 // the unit is MB. This is 1000G
const OP_AND = "and"
These are the boolean operators that can be used to construct a RequiredProperties expression
const OP_NOT = "not"
const OP_OR = "or"
Variables ¶
This section is empty.
Functions ¶
func IsVersionString ¶
IsVersionString will return true if the input version string is a valid version according to the version string schema outlined in anax/policy/version.go. A number with leading 0's, for example 1.02.1, is not a valid version string.
Types ¶
type ConstraintExpression ¶
type ConstraintExpression []string
This type implements all the ConstraintLanguage Plugin methods and delegates to plugin system.
func Constraint_Factory ¶
func Constraint_Factory() *ConstraintExpression
Create a simple, empty ConstraintExpression Object.
func (*ConstraintExpression) Add_Constraint ¶
func (c *ConstraintExpression) Add_Constraint(newconstr string)
Add a new constriant
func (*ConstraintExpression) GetLanguageHandler ¶
func (c *ConstraintExpression) GetLanguageHandler() (plugin_registry.ConstraintLanguagePlugin, error)
func (*ConstraintExpression) GetStrings ¶
func (self *ConstraintExpression) GetStrings() []string
func (ConstraintExpression) IsSame ¶
func (c ConstraintExpression) IsSame(other ConstraintExpression) bool
This function checks if the 2 constraints are the same. In order to be same, they must have the same constraints. The order can be different.
func (*ConstraintExpression) IsSatisfiedBy ¶
func (self *ConstraintExpression) IsSatisfiedBy(props []Property) error
This function is used to determine if an input set of properties and values will satisfy the ConstraintExpression expression.
func (*ConstraintExpression) MergeWith ¶
func (c *ConstraintExpression) MergeWith(other *ConstraintExpression)
merge two constraint into one, remove the duplicates.
func (*ConstraintExpression) Validate ¶
func (c *ConstraintExpression) Validate() ([]string, error)
type ExternalPolicy ¶
type ExternalPolicy struct { // The properties this node wishes to expose about itself. These properties can be referred to by constraint expressions in other policies, // (e.g. service policy, model policy, business policy). Properties PropertyList `json:"properties,omitempty"` // A textual expression indicating requirements on the other party in order to make an agreement. Constraints ConstraintExpression `json:"constraints,omitempty"` }
func CreateNodeBuiltInPolicy ¶
func CreateNodeBuiltInPolicy(availableMem bool) *ExternalPolicy
get the node's built-in ptoperties to be used in the node policy availableMem -- the total memory vs. the available memory size
func CreateServiceBuiltInPolicy ¶
func CreateServiceBuiltInPolicy(svcName, svcOrg, svcVersion, svcArch string) *ExternalPolicy
create the built-in properties
func (*ExternalPolicy) MergeWith ¶
func (e *ExternalPolicy) MergeWith(newPol *ExternalPolicy, replaceExsiting bool)
merge the two policies. If the newPol contains the same properties, ignore them unless replaceExsiting is true.
func (ExternalPolicy) String ¶
func (e ExternalPolicy) String() string
func (*ExternalPolicy) Validate ¶
func (e *ExternalPolicy) Validate() error
The validate function returns errors if the policy does not validate. It uses the constraint language plugins to handle the constraints field.
type Property ¶
type Property struct { Name string `json:"name"` // The Property name Value interface{} `json:"value"` // The Property value Type string `json:"type,omitempty"` // The type of the Property value }
func Property_Factory ¶
This function creates Property objects
type PropertyExpression ¶
type PropertyExpression struct { Name string `json:"name"` // The Property name Value interface{} `json:"value"` // The Property value Op string `json:"op"` // The operator to apply to the property value }
This struct represents property value expressions to be satisfied
func PropertyExpression_Factory ¶
func PropertyExpression_Factory(name string, value interface{}, op string) *PropertyExpression
func (PropertyExpression) String ¶
func (p PropertyExpression) String() string
type PropertyList ¶
type PropertyList []Property
This struct represents property values advertised by the policy
func (*PropertyList) Add_Property ¶
func (self *PropertyList) Add_Property(new_ele *Property, replaceExisting bool) error
This function adds a Property to the list. Return an error if there are duplicates and replaceExisting is false.
func (*PropertyList) Compatible_With ¶
func (self *PropertyList) Compatible_With(other *PropertyList, ignoreBuiltIn bool) error
This function compares 2 property lists to determine if they set different values on the same property. This would make them incompatible.
func (PropertyList) HasProperty ¶
func (self PropertyList) HasProperty(name string) bool
This function checks the property list to see if the given property is present.
func (PropertyList) IsSame ¶
func (p PropertyList) IsSame(compare PropertyList) bool
func (*PropertyList) MergeWith ¶
func (self *PropertyList) MergeWith(new_list *PropertyList, replaceExsiting bool)
This function merges two PropertyList into one list. If both have the same property, ignore the ones from new_list unless replaceExsiting is true.
func (*PropertyList) Validate ¶
func (self *PropertyList) Validate() error
Validate will return an error if any property in the list has an invalid format or a value that does not match a declared type
type RequiredProperty ¶
type RequiredProperty map[string]interface{}
func RequiredPropertyFromConstraint ¶
func RequiredPropertyFromConstraint(extConstraint *ConstraintExpression) (*RequiredProperty, error)
Create a RequiredProperty Object based on the constraint expression in an external policy. The constraint expression contains references to properties and provides a comparison operator and value on that property. These can be converted into our internal format.
func RequiredProperty_Factory ¶
func RequiredProperty_Factory() *RequiredProperty
Create a simple, empty RequiredProperty Object.
func (*RequiredProperty) Initialize ¶
func (self *RequiredProperty) Initialize(exp *map[string]interface{}) error
Initialize a RequiredProperty object from a plain map
func (*RequiredProperty) IsSatisfiedBy ¶
func (self *RequiredProperty) IsSatisfiedBy(props []Property) error
This function is used to determine if an input set of properties and values will satisfy the RequiredProperty expression.
func (*RequiredProperty) IsValid ¶
func (self *RequiredProperty) IsValid() error
This function is used to verify that the RequiredProperty expression is syntactically valid.
func (*RequiredProperty) Merge ¶
func (self *RequiredProperty) Merge(other *RequiredProperty) *RequiredProperty
This function will merge 2 RequiredProperty expressions together by ANDing them.
func (*RequiredProperty) TopLevelElements ¶
func (rp *RequiredProperty) TopLevelElements() []interface{}
Return the top level elements in the requiredProperty.