Documentation ¶
Index ¶
- Constants
- Variables
- func AllAgreementProtocols() []string
- func Are_Compatible(producer_policy *Policy, consumer_policy *Policy) error
- func ConvertToAgreementProtocolList(list []interface{}) (*[]AgreementProtocol, error)
- func CreatePolicyFile(filepath string, org string, name string, p *Policy) (string, error)
- func DeleteAllPolicyFiles(homePath string, patternBasedOnly bool) error
- func DeletePolicyFile(name string) error
- func DeletePolicyFilesForOrg(policyPath string, org string, patternBasedOnly bool) error
- func DeletePolicyFilesForPattern(policyPath string, org string, pattern string) error
- func GeneratePolicy(sensorUrl string, sensorOrg string, sensorName string, sensorVersion string, ...) (string, error)
- func HasDefaultBCOrg(protocolName string) string
- func MakeExternalPolicyHeaderName(id string) string
- func MarshalPolicy(pol *Policy) (string, error)
- func RenamePolicyFile(filepath string, org string, name string, newSuffix string) error
- func RequiresBlockchainType(protocolName string) string
- func RetrieveAllProperties(policy *Policy) (*externalpolicy.PropertyList, error)
- func Select_Protocol(producer_policy *Policy, consumer_policy *Policy) string
- func SupportedAgreementProtocol(name string) bool
- func UpdateSettingsWithUserInputs(userInputs []UserInput, existingUserSettings map[string]string, svcUrl string, ...) (map[string]string, error)
- func WritePolicyFile(newPolicy *Policy, name string) error
- type APISpecList
- func (self *APISpecList) Add_API_Spec(new_ele *APISpecification) error
- func (self *APISpecList) AsStringArray() []string
- func (self *APISpecList) Concatenate(new_list *APISpecList)
- func (self APISpecList) ContainsSpecRef(url string, org string, version string) bool
- func (self *APISpecList) GetCommonVersionRanges() (*APISpecList, error)
- func (a APISpecList) IsSame(compare APISpecList, checkVersion bool) bool
- func (self *APISpecList) MergeWith(other *APISpecList) APISpecList
- func (self APISpecList) Supports(required APISpecList) error
- type APISpecification
- type AgreementCountEntry
- type AgreementProtocol
- type AgreementProtocolList
- func (self *AgreementProtocolList) Add_Agreement_Protocol(new_ele *AgreementProtocol) error
- func (self AgreementProtocolList) As_String_Array() []string
- func (self *AgreementProtocolList) Concatenate(new_list *AgreementProtocolList)
- func (self *AgreementProtocolList) FindByName(name string) *AgreementProtocol
- func (self *AgreementProtocolList) Intersects_With(other *AgreementProtocolList) (*AgreementProtocolList, error)
- func (a AgreementProtocolList) IsSame(compare AgreementProtocolList) bool
- func (self *AgreementProtocolList) Single_Element() *AgreementProtocolList
- type Blockchain
- type BlockchainList
- func (self *BlockchainList) Add_Blockchain(new_ele *Blockchain) error
- func (self *BlockchainList) Concatenate(new_list *BlockchainList)
- func (self *BlockchainList) Intersects_With(other *BlockchainList, defaultType string, defaultOrg string) (*BlockchainList, error)
- func (a BlockchainList) IsSame(compare BlockchainList) bool
- func (self *BlockchainList) Single_Element() *BlockchainList
- type Contents
- func (c *Contents) AddWatchEntry(org string, fInfo os.FileInfo, pol *Policy)
- func (c *Contents) ConflictsWithAlreadyTracked(org string, pol *Policy) string
- func (c *Contents) GetPolicyName(org, filename string) string
- func (c *Contents) HasFile(org string, filename string) bool
- func (c *Contents) HasOrg(org string) bool
- func (c *Contents) RemoveWatchEntry(org string, filename string)
- func (c *Contents) String() string
- func (c *Contents) UpdateWatchEntry(org string, fInfo os.FileInfo, pol *Policy)
- type DataVerification
- func (d DataVerification) IsCompatibleWith(compare DataVerification) bool
- func (d DataVerification) IsProducerCompatible(compare DataVerification) bool
- func (d DataVerification) IsSame(compare DataVerification) bool
- func (d DataVerification) IsValid() (bool, error)
- func (d DataVerification) MergeWith(other DataVerification, configInterval uint64) DataVerification
- func (d *DataVerification) Obscure()
- func (d DataVerification) ProducerMergeWith(other DataVerification, configInterval uint64) DataVerification
- func (d DataVerification) String() string
- type HighAvailabilityGroup
- type Input
- type Meter
- func (m Meter) IsCompatibleWith(otherMeter Meter) bool
- func (m Meter) IsEmpty() bool
- func (m Meter) IsSame(otherMeter Meter) bool
- func (m Meter) IsSatisfiedBy(otherMeter Meter) bool
- func (m Meter) IsValid() bool
- func (m Meter) MergeWith(otherMeter Meter, dvCheckRate int) Meter
- func (m *Meter) ProducerMergeWith(otherMeter *Meter, dvCheckRate int) Meter
- func (m Meter) String() string
- type NodeHealth
- type Policy
- func Are_Compatible_Producers(producer_policy1 *Policy, producer_policy2 *Policy, defaultNoData uint64) (*Policy, error)
- func Create_Terms_And_Conditions(producer_policy *Policy, consumer_policy *Policy, workload *Workload, ...) (*Policy, error)
- func DemarshalPolicy(policyString string) (*Policy, error)
- func GenPolicyFromExternalPolicy(extPol *externalpolicy.ExternalPolicy, polName string) (*Policy, error)
- func MergePolicyWithExternalPolicy(pol *Policy, extPol *externalpolicy.ExternalPolicy) (*Policy, error)
- func Policy_Factory(name string) *Policy
- func ReadPolicyFile(name string, arch_synonymns config.ArchSynonyms) (*Policy, error)
- func (self *Policy) Add_API_Spec(spec *APISpecification) error
- func (self *Policy) Add_Agreement_Protocol(ap *AgreementProtocol) error
- func (self *Policy) Add_Constraints(c *externalpolicy.ConstraintExpression) error
- func (self *Policy) Add_DataVerification(d *DataVerification) error
- func (self *Policy) Add_HAGroup(g *HighAvailabilityGroup) error
- func (self *Policy) Add_NodeHealth(nh *NodeHealth) error
- func (self *Policy) Add_Property(p *externalpolicy.Property, replaceExisting bool) error
- func (self *Policy) Add_Workload(w *Workload) error
- func (p *Policy) ConvertSpecRefArchToGOARCH(arch_synonymns config.ArchSynonyms)
- func (self *Policy) DeepCopy() *Policy
- func (self *Policy) Get_DataVerification_enabled() bool
- func (self *Policy) IsSameWorkload(compare *Policy) bool
- func (self *Policy) Is_Self_Consistent(keyFileNames []string, ...) error
- func (self *Policy) Is_Version(v string) bool
- func (p *Policy) MinimumProtocolVersion(name string, other *Policy, maxSupportedVersion int) int
- func (self *Policy) NextHighestPriorityWorkload(currentPriority int, retryCount int, retryStartTime uint64) *Workload
- func (self *Policy) ObscureWorkloadPWs(agreementId string, defaultPW string) error
- func (p *Policy) RequiresKnownBC(protocol string) (string, string, string)
- func (self *Policy) ShortString() string
- func (self *Policy) String() string
- type PolicyHeader
- type PolicyManager
- func (self *PolicyManager) AddPolicy(org string, newPolicy *Policy) error
- func (self *PolicyManager) AgreementCountString() string
- func (self *PolicyManager) AttemptingAgreement(policies []Policy, agreement string, org string) error
- func (self *PolicyManager) CancelAgreement(policies []Policy, agreement string, org string) error
- func (self *PolicyManager) DeletePolicy(org string, delPolicy *Policy)
- func (self *PolicyManager) DeletePolicyByName(org string, polName string)
- func (self *PolicyManager) FinalAgreement(policies []Policy, agreement string, org string) error
- func (self *PolicyManager) GetAllAgreementProtocols() map[string]BlockchainList
- func (self *PolicyManager) GetAllAvailablePolicies(org string) []Policy
- func (self *PolicyManager) GetAllPolicies(org string) []Policy
- func (self *PolicyManager) GetAllPolicyNames() map[string][]string
- func (self *PolicyManager) GetAllPolicyOrgs() []string
- func (self *PolicyManager) GetPolicy(org string, name string) *Policy
- func (self *PolicyManager) GetPolicyByURL(homeOrg string, url string, org string, version string) []Policy
- func (self *PolicyManager) GetPolicyList(homeOrg string, inPolicy *Policy) ([]Policy, error)
- func (self *PolicyManager) GetPolicyNamesForOrg(org string) map[string][]string
- func (self *PolicyManager) GetSerializedPolicies(org string) (map[string]string, error)
- func (self *PolicyManager) MatchesMine(org string, matchPolicy *Policy) error
- func (self *PolicyManager) MergeAllProducers(policies *[]Policy, previouslyMerged *Policy) (*Policy, error)
- func (self *PolicyManager) NumberPolicies() int
- func (self *PolicyManager) ReachedMaxAgreements(policies []Policy, org string) (bool, error)
- func (self *PolicyManager) SetNoAgreementTracking()
- func (self *PolicyManager) String() string
- func (self *PolicyManager) UpdatePolicy(org string, newPolicy *Policy)
- type ProposalRejection
- type UserInput
- type ValueExchange
- type WatchEntry
- type Workload
- type WorkloadList
- type WorkloadPriority
Constants ¶
const AGREEMENT_FINAL = "final"
const AGREEMENT_PENDING = "pending"
const BasicProtocol = "Basic"
All known and supported agreement protocols
const CurrentVersion = version2 // Current schema version
Variables ¶
var AllProtocols = []string{BasicProtocol}
var DefaultBCOrg = map[string]string{}
var RequiresBCType = map[string]string{}
Functions ¶
func AllAgreementProtocols ¶
func AllAgreementProtocols() []string
func Are_Compatible ¶
func ConvertToAgreementProtocolList ¶
func ConvertToAgreementProtocolList(list []interface{}) (*[]AgreementProtocol, error)
func CreatePolicyFile ¶
func DeleteAllPolicyFiles ¶
Delete all policy files. This function does not try to update the policy manager, it is a low level function that simply removes all the policy files.
func DeletePolicyFile ¶
func DeletePolicyFilesForOrg ¶
This function deletes all the policy files for the given org. If patternBasedOnly is false, it deletes all policy file under the path. If patternBasedOnly is true, it only deletes the policy files that are pattern based.
func DeletePolicyFilesForPattern ¶
This function deletes all the policy files for the given pattern of the given org.
func GeneratePolicy ¶
func HasDefaultBCOrg ¶
func MakeExternalPolicyHeaderName ¶
Create a header name for the generated policy that should be unique within the org. The input can be a device id or a service id.
func MarshalPolicy ¶
func RenamePolicyFile ¶
func RequiresBlockchainType ¶
func RetrieveAllProperties ¶
func RetrieveAllProperties(policy *Policy) (*externalpolicy.PropertyList, error)
func Select_Protocol ¶
This function will select an agreement protocol to pursue based on the input policies. This function assumes that the input policies are compatible.
func UpdateSettingsWithUserInputs ¶
func UpdateSettingsWithUserInputs(userInputs []UserInput, existingUserSettings map[string]string, svcUrl string, svcOrg string) (map[string]string, error)
Gets the and update the existing settings if the name does not exist.
func WritePolicyFile ¶
This function writes a Policy object into a file. Note that the file is written formatted so that it is human readable.
Types ¶
type APISpecList ¶
type APISpecList []APISpecification
func (*APISpecList) Add_API_Spec ¶
func (self *APISpecList) Add_API_Spec(new_ele *APISpecification) error
This function adds an API spec to the list. Return an error if there are duplicates.
func (*APISpecList) AsStringArray ¶
func (self *APISpecList) AsStringArray() []string
This function extracts the APISpec URLs from a list of API Specs and returns the URLs in an array.
func (*APISpecList) Concatenate ¶
func (self *APISpecList) Concatenate(new_list *APISpecList)
This function merges 2 API spec lists into one list, there should never be duplicates in the input list.
func (APISpecList) ContainsSpecRef ¶
func (self APISpecList) ContainsSpecRef(url string, org string, version string) bool
This function return true if an api spec list contains the input spec ref url
func (*APISpecList) GetCommonVersionRanges ¶
func (self *APISpecList) GetCommonVersionRanges() (*APISpecList, error)
For each microservice url, get the version range intersection among all occurances in the list.
func (APISpecList) IsSame ¶
func (a APISpecList) IsSame(compare APISpecList, checkVersion bool) bool
func (*APISpecList) MergeWith ¶
func (self *APISpecList) MergeWith(other *APISpecList) APISpecList
This function merges 2 APISpecification arrays, returning the merged list.
func (APISpecList) Supports ¶
func (self APISpecList) Supports(required APISpecList) error
This function compares 2 APISpecification arrays, returning no error if the APISpec list meets the requirements of input APISpec list. Usually the self list is from a producer and the required list is from a consumer (i.e. workload).
type APISpecification ¶
type APISpecification struct { SpecRef string `json:"specRef"` // A URL pointing to the definition of the API spec Org string `json:"organization"` // The organization where the microservice is defined Version string `json:"version"` // The version of the API spec in OSGI version format ExclusiveAccess bool `json:"exclusiveAccess"` // Whether or not exclusive access to this API spec is required. True means sharing is one of the single usage options. Arch string `json:"arch"` // The hardware architecture of the API spec impl. Added in version 2. }
func APISpecification_Factory ¶
func APISpecification_Factory(ref string, org string, vers string, arch string) *APISpecification
This function creates API Spec objects
func (APISpecification) IsSame ¶
func (a APISpecification) IsSame(compare APISpecification, checkVersion bool) bool
type AgreementCountEntry ¶
type AgreementCountEntry struct { Count int // The number of agreements using this policy AgreementIds map[string]string // Map of agreement id to agreement status }
The ContractCountEntry is used to track which device addresses (contract addresses) are in agreement for a given policy name. The status of the agreement is also tracked.
func (*AgreementCountEntry) String ¶
func (self *AgreementCountEntry) String() string
A simple function used to return a human readable string representation of the agreement counts that the policy manager knows about.
type AgreementProtocol ¶
type AgreementProtocol struct { Name string `json:"name"` // The name of the agreement protocol to be used ProtocolVersion int `json:"protocolVersion,omitempty"` // The max protocol version supported Blockchains BlockchainList `json:"blockchains,omitempty"` // The blockchain to be used if the protocol requires one. }
func AgreementProtocol_Factory ¶
func AgreementProtocol_Factory(name string) *AgreementProtocol
This function creates AgreementProtocol objects
func (*AgreementProtocol) Initialize ¶
func (a *AgreementProtocol) Initialize()
func (AgreementProtocol) IsSame ¶
func (a AgreementProtocol) IsSame(compare AgreementProtocol) bool
func (*AgreementProtocol) IsValid ¶
func (a *AgreementProtocol) IsValid() error
func (*AgreementProtocol) MinimumProtocolVersion ¶
func (a *AgreementProtocol) MinimumProtocolVersion(other *AgreementProtocol, maxSupportedVersion int) int
Used to figure out what protocol version to use for the initial agreement message. All subsequent messages MUST use the same protocol version. Anax will store the protocol version of the initial message for the agreement and will use the stored version for all future messages.
func (AgreementProtocol) String ¶
func (a AgreementProtocol) String() string
type AgreementProtocolList ¶
type AgreementProtocolList []AgreementProtocol
func (*AgreementProtocolList) Add_Agreement_Protocol ¶
func (self *AgreementProtocolList) Add_Agreement_Protocol(new_ele *AgreementProtocol) error
This function adds an Agreement protocol to the list. Return an error if there are duplicates.
func (AgreementProtocolList) As_String_Array ¶
func (self AgreementProtocolList) As_String_Array() []string
This function converts an AgreementProtocolList into a list of strings based on the names of the agreement protocols in the original list.
func (*AgreementProtocolList) Concatenate ¶
func (self *AgreementProtocolList) Concatenate(new_list *AgreementProtocolList)
This function merges 2 Agreement protocol lists into one list, removing duplicates.
func (*AgreementProtocolList) FindByName ¶
func (self *AgreementProtocolList) FindByName(name string) *AgreementProtocol
This function returns a specific agreement protocol object from the list
func (*AgreementProtocolList) Intersects_With ¶
func (self *AgreementProtocolList) Intersects_With(other *AgreementProtocolList) (*AgreementProtocolList, error)
This function compares 2 AgreementProtocolList arrays, returning no error if they have at least 1 agreement protocol in common.
func (AgreementProtocolList) IsSame ¶
func (a AgreementProtocolList) IsSame(compare AgreementProtocolList) bool
func (*AgreementProtocolList) Single_Element ¶
func (self *AgreementProtocolList) Single_Element() *AgreementProtocolList
This function returns an Agreement Protocol List with just a single element.
type Blockchain ¶
type Blockchain struct { Type string `json:"type"` // The type of blockchain Name string `json:"name"` // The name of the blockchain instance in the exchange,it is specific to the value of the type Org string `json:"organization"` // The organization that owns the blockchain definition }
func Blockchain_Factory ¶
func Blockchain_Factory(bc_type string, name string, org string) *Blockchain
This function creates Blockchain objects
func (*Blockchain) Same_Blockchain ¶
func (self *Blockchain) Same_Blockchain(second *Blockchain, defaultType string, defaultOrg string) bool
This function compares 2 Blockchain objects to see if they are equal. If the caller wants this function to consider absent default for the type, then they can pass in the actual default for comparison. If defaultType is the empty string then an exact match will be performed. Same is true for the default Org.
func (Blockchain) String ¶
func (self Blockchain) String() string
type BlockchainList ¶
type BlockchainList []Blockchain
This struct indicates the type and instance of blockchain to be used by the policy
func (*BlockchainList) Add_Blockchain ¶
func (self *BlockchainList) Add_Blockchain(new_ele *Blockchain) error
This function adds a blockchain object to the list. Return an error if there are duplicates.
func (*BlockchainList) Concatenate ¶
func (self *BlockchainList) Concatenate(new_list *BlockchainList)
This function merges 2 Blockchain lists into one list, removing duplicates
func (*BlockchainList) Intersects_With ¶
func (self *BlockchainList) Intersects_With(other *BlockchainList, defaultType string, defaultOrg string) (*BlockchainList, error)
This function compares 2 BlockchainList arrays, returning all the blockchains that intersect between the 2 lists.
func (BlockchainList) IsSame ¶
func (a BlockchainList) IsSame(compare BlockchainList) bool
func (*BlockchainList) Single_Element ¶
func (self *BlockchainList) Single_Element() *BlockchainList
type Contents ¶
type Contents struct {
AllWatches map[string]map[string]*WatchEntry
}
func NewContents ¶
func NewContents() *Contents
func PolicyFileChangeWatcher ¶
func PolicyFileChangeWatcher(homePath string, contents *Contents, arch_synonymns config.ArchSynonyms, fileChanged func(org string, fileName string, policy *Policy), fileDeleted func(org string, fileName string, policy *Policy), fileError func(org string, fileName string, err error), workloadOrServiceResolver func(wURL string, wOrg string, wVersion string, wArch string) (*APISpecList, error), checkInterval int) (*Contents, error)
func (*Contents) AddWatchEntry ¶
func (*Contents) ConflictsWithAlreadyTracked ¶
check if there is already a tracked policy file with a policy name that is the same as the new policy that we're trying to add. It returns the name of the conflict file.
func (*Contents) GetPolicyName ¶
func (*Contents) RemoveWatchEntry ¶
type DataVerification ¶
type DataVerification struct { Enabled bool `json:"enabled,omitempty"` // Whether or not data verification is enabled URL string `json:"URL,omitempty"` // The URL to be used for data receipt verification URLUser string `json:"URLUser,omitempty"` // The user id to use when calling the verification URL URLPassword string `json:"URLPassword,omitempty"` // The password to use when calling the verification URL Interval int `json:"interval,omitempty"` // The number of seconds to check for data before deciding there isnt any data CheckRate int `json:"check_rate,omitempty"` // The number of seconds between checks for valid data being received Metering Meter `json:"metering,omitempty"` // The metering configuration }
func (DataVerification) IsCompatibleWith ¶
func (d DataVerification) IsCompatibleWith(compare DataVerification) bool
Two policies are compatible if they dont conflict with each other such that the compare policy satisfies the requirements of the d or "self" policy.
func (DataVerification) IsProducerCompatible ¶
func (d DataVerification) IsProducerCompatible(compare DataVerification) bool
Two producer policies are compatible with each other if the difference are reconcileable as producers.
func (DataVerification) IsSame ¶
func (d DataVerification) IsSame(compare DataVerification) bool
func (DataVerification) IsValid ¶
func (d DataVerification) IsValid() (bool, error)
func (DataVerification) MergeWith ¶
func (d DataVerification) MergeWith(other DataVerification, configInterval uint64) DataVerification
Produce a merged data verification section. Both policies are assumed to be valid and compatible.
func (*DataVerification) Obscure ¶
func (d *DataVerification) Obscure()
func (DataVerification) ProducerMergeWith ¶
func (d DataVerification) ProducerMergeWith(other DataVerification, configInterval uint64) DataVerification
Merge 2 producer DV sections. This is different from merging sections from a producer and consumer because 2 producer sections just have to be reconciled, one does not have to satisfy the other as in the consumer/producer relationship. Further this function assumes that IsProducerCompatible() has already been called for these 2 sections so they are already compatible.
func (DataVerification) String ¶
func (d DataVerification) String() string
type HighAvailabilityGroup ¶
type HighAvailabilityGroup struct {
Partners []string `json:"partners,omitempty"`
}
func HAGroup_Factory ¶
func HAGroup_Factory(partners []string) *HighAvailabilityGroup
This function creates HAGroup objects
func (*HighAvailabilityGroup) Compatible_With ¶
func (g *HighAvailabilityGroup) Compatible_With(other *HighAvailabilityGroup) bool
Check the compatibility of 2 HAGroups. HAGroups are only specified on the producer side so this check is really just comparing 2 producer side policies. A single prdducer is supposed to have the same partner list for all services, so the IsSame check should suffice as a compatibility check.
func (*HighAvailabilityGroup) IsSame ¶
func (g *HighAvailabilityGroup) IsSame(other *HighAvailabilityGroup) bool
Return true if 2 HAGroups are the same, meaning their partner lists contain the same partners. The partners dont have to be in the same order in both lists.
func (*HighAvailabilityGroup) Merge ¶
func (g *HighAvailabilityGroup) Merge(other *HighAvailabilityGroup) *HighAvailabilityGroup
Merge 2 HA groups. This should be easy because compatibility is assumes and is defined to be indentical.
func (*HighAvailabilityGroup) String ¶
func (g *HighAvailabilityGroup) String() string
type Input ¶
type Meter ¶
type Meter struct { Tokens uint64 `json:"tokens,omitempty"` // The number of tokens per time_unit PerTimeUnit string `json:"per_time_unit,omitempty"` // The per time units: min, hour and day are supported NotificationIntervalS int `json:"notification_interval,omitempty"` // The number of seconds between metering notifications }
func (Meter) IsCompatibleWith ¶
This function determines if 2 producer policies can be reconciled.
func (Meter) IsSatisfiedBy ¶
Producer requirement satisfied by consumer offer. Both policies are assumed to be valid.
func (Meter) MergeWith ¶
This function returns the normalized meter policy to be used in the proposal. Both policies are assumed to be compatible.
func (*Meter) ProducerMergeWith ¶
Merge 2 producer meter policies. This function does not do the same thing as the MergeWith function.
type NodeHealth ¶
type NodeHealth struct { MissingHBInterval int `json:"missing_heartbeat_interval,omitempty"` // How long a heartbeat can be missing until it is considered missing (in seconds) CheckAgreementStatus int `json:"check_agreement_status,omitempty"` // How often to check that the node agreement entry still exists in the exchange (in seconds) }
func NodeHealth_Factory ¶
func NodeHealth_Factory(hbInterval int, checkRate int) *NodeHealth
func (NodeHealth) IsSame ¶
func (h NodeHealth) IsSame(compare NodeHealth) bool
type Policy ¶
type Policy struct { Header PolicyHeader `json:"header"` PatternId string `json:"patternId,omitempty"` // Manually created policy files should NOT use this field. APISpecs APISpecList `json:"apiSpec,omitempty"` AgreementProtocols AgreementProtocolList `json:"agreementProtocols,omitempty"` Workloads WorkloadList `json:"workloads,omitempty"` DeviceType string `json:"deviceType,omitempty"` ValueEx ValueExchange `json:"valueExchange,omitempty"` DataVerify DataVerification `json:"dataVerification,omitempty"` ProposalReject ProposalRejection `json:"proposalRejection,omitempty"` MaxAgreements int `json:"maxAgreements,omitempty"` Properties externalpolicy.PropertyList `json:"properties,omitempty"` // Version 2.0 Constraints externalpolicy.ConstraintExpression `json:"constraints,omitempty"` // Version 2.0 RequiredWorkload string `json:"requiredWorkload,omitempty"` // Version 2.0 HAGroup HighAvailabilityGroup `json:"ha_group,omitempty"` // Version 2.0 NodeH NodeHealth `json:"nodeHealth,omitempty"` // Version 2.0 UserInput []UserInput `json:"userInput,omitempty"` }
This is the main struct that defines the Policy object.
func Are_Compatible_Producers ¶
func Are_Compatible_Producers(producer_policy1 *Policy, producer_policy2 *Policy, defaultNoData uint64) (*Policy, error)
This function is used to check if 2 producer policies are compatible with each other. This is the means by which an agbot can make an agreement with a device that utilizes more than one API spec in the contract. Producers advertise API spec availability individually in their policy files. An agbot that wants to consume 2 API specs (microservices) in the same agreement should verify that the producer policies are compatible with each other before attempting a compatibility check with it's own policy file. If the policies are found to be compatible a merged policy will be returned. If the policies are not compatible then an error will be returned.
func Create_Terms_And_Conditions ¶
func Create_Terms_And_Conditions(producer_policy *Policy, consumer_policy *Policy, workload *Workload, agreementId string, defaultPW string, defaultNoData uint64, agreementProtocolVersion int) (*Policy, error)
This function creates a merged policy file from a producer policy and a consumer policy, which will eventually become the full terms and conditions of an agreement. If no error is returned, a merged policy object is returned. The order of parameters is important, just like in the Are_Compatible API.
func DemarshalPolicy ¶
func GenPolicyFromExternalPolicy ¶
func GenPolicyFromExternalPolicy(extPol *externalpolicy.ExternalPolicy, polName string) (*Policy, error)
Generate a policy from the external policy.
func MergePolicyWithExternalPolicy ¶
func MergePolicyWithExternalPolicy(pol *Policy, extPol *externalpolicy.ExternalPolicy) (*Policy, error)
Merge a external policy into a policy
func Policy_Factory ¶
These functions are used to create Policy objects. You can create the base object and add features to it using the other functions
func ReadPolicyFile ¶
func ReadPolicyFile(name string, arch_synonymns config.ArchSynonyms) (*Policy, error)
These are functions that operate on policy files in the file system.
This function reads a file and demarshals it into a Policy struct, which is returned to the caller.
func (*Policy) Add_API_Spec ¶
func (self *Policy) Add_API_Spec(spec *APISpecification) error
func (*Policy) Add_Agreement_Protocol ¶
func (self *Policy) Add_Agreement_Protocol(ap *AgreementProtocol) error
func (*Policy) Add_Constraints ¶
func (self *Policy) Add_Constraints(c *externalpolicy.ConstraintExpression) error
func (*Policy) Add_DataVerification ¶
func (self *Policy) Add_DataVerification(d *DataVerification) error
func (*Policy) Add_HAGroup ¶
func (self *Policy) Add_HAGroup(g *HighAvailabilityGroup) error
func (*Policy) Add_NodeHealth ¶
func (self *Policy) Add_NodeHealth(nh *NodeHealth) error
func (*Policy) Add_Property ¶
func (self *Policy) Add_Property(p *externalpolicy.Property, replaceExisting bool) error
func (*Policy) Add_Workload ¶
func (*Policy) ConvertSpecRefArchToGOARCH ¶
func (p *Policy) ConvertSpecRefArchToGOARCH(arch_synonymns config.ArchSynonyms)
convert the arch in the specref into GOARCH if it is a synonym of a GOARCH. the synonyms are defined in the configuration file
func (*Policy) Get_DataVerification_enabled ¶
These are getter functions used to query attributes of a policy object
func (*Policy) IsSameWorkload ¶
func (*Policy) Is_Self_Consistent ¶
func (*Policy) Is_Version ¶
func (*Policy) MinimumProtocolVersion ¶
func (*Policy) NextHighestPriorityWorkload ¶
func (self *Policy) NextHighestPriorityWorkload(currentPriority int, retryCount int, retryStartTime uint64) *Workload
Returns the next highest priority workload given a starting priority value, the number of retries so far and the starting time of the first try at this priority. If the caller passes in zero for the priority, then this routine will return the absolute highest priority workload. If there is no next highest priority, this function will return the lowest priority workload.
Assumptions: (a) 1 is a higher priority workload than any priority value greater than 1, etc. (b) workload priorities dont have to be in order in the workload array. (c) workload priorities dont have to be sequential, i.e. you can have priority 5, 10 and 45. (d) there are no duplicate priority values in the array. This condition is checked by the Is_Self_Consistent() function
which is called by the agbot when it initializes and reads in policy files.
func (*Policy) ObscureWorkloadPWs ¶
func (*Policy) RequiresKnownBC ¶
func (*Policy) ShortString ¶
type PolicyHeader ¶
type PolicyHeader struct { Name string `json:"name"` // Name assigned to this policy by its author Version string `json:"version"` // The schema version of this file }
func (PolicyHeader) IsSame ¶
func (h PolicyHeader) IsSame(compare PolicyHeader) bool
type PolicyManager ¶
type PolicyManager struct { AgreementTracking bool // Whether or not to count agreements inside the AgreementCounts map. See PolicyManager_Factory(). APISpecCounts bool // How to count agreements inside the AgreementCounts map. See PolicyManager_Factory(). Policies map[string][]*Policy // The policies in effect at this time, by organization PolicyLock sync.Mutex // The lock that protects modification of the Policies ALock sync.Mutex // The lock that protects the contract counts map AgreementCounts map[string]map[string]*AgreementCountEntry // A map of all policies (by org and name) that have an agreement with a given device WatcherContent *Contents // The contents of the policy file watcher }
func Initialize ¶
func Initialize(policyPath string, arch_synonymns config.ArchSynonyms, workloadOrServiceResolver func(wURL string, wOrg string, wVersion string, wArch string) (*APISpecList, error), agreementTracking bool, apiSpecCounts bool) (*PolicyManager, error)
This function is used to get the policy manager up and running. When this function returns, all the current policies have been read into memory. It can be used instead of the factory method for convenience. The agreementTracking boolean is used to tell the policy manager to track agreement counts for each policy name. The apiSpecCounts boolean is used to tell the policy manager to track agreement counts by policy apiSpec ref name.
func PolicyManager_Factory ¶
func PolicyManager_Factory(agreementTracking bool, apiSpecCounts bool) *PolicyManager
This function creates the Policy Manager object. The apiSpecCounts input is used to tell the policy manager how to count agreements; true - count based on the first API spec in the policy object, or false - count by the policy name. True is used by the device side of anax, false is used by the agbot side of anax.
func (*PolicyManager) AddPolicy ¶
func (self *PolicyManager) AddPolicy(org string, newPolicy *Policy) error
Add a new policy to the policy manager. If the policy is already there (by name), an error is returned. The caller might be ok ignoring the error.
func (*PolicyManager) AgreementCountString ¶
func (self *PolicyManager) AgreementCountString() string
A simple function used to return a human readable string representation of the policies that the policy manager knows about.
func (*PolicyManager) AttemptingAgreement ¶
func (self *PolicyManager) AttemptingAgreement(policies []Policy, agreement string, org string) error
This function is used to indicate a new agreement is in progress for these policies.
func (*PolicyManager) CancelAgreement ¶
func (self *PolicyManager) CancelAgreement(policies []Policy, agreement string, org string) error
This function is used to indicate an agreement is cancelled.
func (*PolicyManager) DeletePolicy ¶
func (self *PolicyManager) DeletePolicy(org string, delPolicy *Policy)
Delete a policy in the policy manager (by name).
func (*PolicyManager) DeletePolicyByName ¶
func (self *PolicyManager) DeletePolicyByName(org string, polName string)
Delete a policy in the policy manager (by name).
func (*PolicyManager) FinalAgreement ¶
func (self *PolicyManager) FinalAgreement(policies []Policy, agreement string, org string) error
This function is used to indicate an agreement is finalized for these policies.
func (*PolicyManager) GetAllAgreementProtocols ¶
func (self *PolicyManager) GetAllAgreementProtocols() map[string]BlockchainList
func (*PolicyManager) GetAllAvailablePolicies ¶
func (self *PolicyManager) GetAllAvailablePolicies(org string) []Policy
func (*PolicyManager) GetAllPolicies ¶
func (self *PolicyManager) GetAllPolicies(org string) []Policy
func (*PolicyManager) GetAllPolicyNames ¶
func (self *PolicyManager) GetAllPolicyNames() map[string][]string
returns all the policy names keyed by organization
func (*PolicyManager) GetAllPolicyOrgs ¶
func (self *PolicyManager) GetAllPolicyOrgs() []string
func (*PolicyManager) GetPolicy ¶
func (self *PolicyManager) GetPolicy(org string, name string) *Policy
This function returns the policy object of a given name.
func (*PolicyManager) GetPolicyByURL ¶
func (self *PolicyManager) GetPolicyByURL(homeOrg string, url string, org string, version string) []Policy
This function returns the first policy objects that contains the input API spec URL. It returns copies so that the caller doesnt have to worry about them changing underneath him.
func (*PolicyManager) GetPolicyList ¶
func (self *PolicyManager) GetPolicyList(homeOrg string, inPolicy *Policy) ([]Policy, error)
This function is used by a producer to find the original policies that make up a merged policy that it received from a consumer. This function is only usable from a producer node.
func (*PolicyManager) GetPolicyNamesForOrg ¶
func (self *PolicyManager) GetPolicyNamesForOrg(org string) map[string][]string
returns the policy names for the given organization
func (*PolicyManager) GetSerializedPolicies ¶
func (self *PolicyManager) GetSerializedPolicies(org string) (map[string]string, error)
This function returns a map of json serialized policies in the PM, as strings.
func (*PolicyManager) MatchesMine ¶
func (self *PolicyManager) MatchesMine(org string, matchPolicy *Policy) error
func (*PolicyManager) MergeAllProducers ¶
func (self *PolicyManager) MergeAllProducers(policies *[]Policy, previouslyMerged *Policy) (*Policy, error)
Simple function to merge a list of producer policies and return a single merged producer policy.
func (*PolicyManager) NumberPolicies ¶
func (self *PolicyManager) NumberPolicies() int
func (*PolicyManager) ReachedMaxAgreements ¶
func (self *PolicyManager) ReachedMaxAgreements(policies []Policy, org string) (bool, error)
This function returns true if any of the policies has reached its maximum number of agreements.
func (*PolicyManager) SetNoAgreementTracking ¶
func (self *PolicyManager) SetNoAgreementTracking()
A simple function to turn off agreement tracking
func (*PolicyManager) String ¶
func (self *PolicyManager) String() string
func (*PolicyManager) UpdatePolicy ¶
func (self *PolicyManager) UpdatePolicy(org string, newPolicy *Policy)
Update a policy in the policy manager. If the policy is already there (by name), update it, otherwise it is just added.
type ProposalRejection ¶
type UserInput ¶
type UserInput struct { ServiceOrgid string `json:"serviceOrgid"` ServiceUrl string `json:"serviceUrl"` ServiceArch string `json:"serviceArch,omitempty"` // empty string means it applies to all arches ServiceVersionRange string `json:"serviceVersionRange,omitempty"` // version range such as [0.0.0,INFINITY). empty string means it applies to all versions Inputs []Input `json:"inputs"` }
func FindUserInput ¶
func FindUserInput(svcName, svcOrg, svcVersion, svcArch string, userInput []UserInput) (*UserInput, error)
Get the user input that fits this given service spec if arch is an empty string, it means any arch. if service version is an empty string, it means any version is be ok.
func MergeUserInput ¶
ui1 is the default, ui2 is the input form the user. ui2 overwrites ui1.
func MergeUserInputArrays ¶
If there are 2 UserInput for the same service, take the one from ui2 if deepMerge is false. If deepMerge is true, then merge the content from ui2 into ui1, ui2 take precedence.
type ValueExchange ¶
type ValueExchange struct { Type string `json:"type,omitempty"` // The type of value exchange Value string `json:"value,omitempty"` // The value being exchanged PaymentRate int `json:"paymentRate,omitempty"` // The number of seconds between payments Token string `json:"token,omitempty"` // A token used to identify the user of the value - added in version 2 }
type WatchEntry ¶
func (*WatchEntry) String ¶
func (w *WatchEntry) String() string
type Workload ¶
type Workload struct { Deployment string `json:"deployment,omitempty"` DeploymentSignature string `json:"deployment_signature,omitempty"` DeploymentUserInfo string `json:"deployment_user_info,omitempty"` WorkloadPassword string `json:"workload_password,omitempty"` // The password used to create the bcrypt hash that is passed to the workload so that the workload can verify the caller Priority WorkloadPriority `json:"priority,omitempty"` // The highest priority workload is tried first for an agrement, if it fails, the next priority is tried. Priority 1 is the highest, priority 2 is next, etc. WorkloadURL string `json:"workloadUrl,omitempty"` // Added with MS split, refers to a workload definition in the exchange Org string `json:"organization,omitempty"` // Added woth org support, refers to the organization where the workload is defined Version string `json:"version,omitempty"` // Added with MS split, refers to the version of the workload Arch string `json:"arch,omitempty"` // Added with MS split, refers to the hardware architecture of the workload definition DeploymentOverrides string `json:"deployment_overrides,omitempty"` // Added with MS split, env var overrides for the workload DeploymentOverridesSignature string `json:"deployment_overrides_signature,omitempty"` // Added with MS split, signature of env var overrides }
func Workload_Factory ¶
This function creates workload objects
func (Workload) HasEmptyPriority ¶
func (Workload) HasValidSignature ¶
func (Workload) IsSame ¶
This function compares 2 workload objects for sameness. This is slightly complicated because 2 workloads can be semantically the same without having identical state. For example, a workload entry that has the WorkloadURL set might also have the other workloads details that can be found at the other end of he URL. In this case, we can ignore comparing the details fields and just stick with a comparison of the URL.
func (Workload) ShortString ¶
type WorkloadList ¶
type WorkloadList []Workload
func (*WorkloadList) Add_Workload ¶
func (self *WorkloadList) Add_Workload(new_ele *Workload) error
This function adds a workload to the list. Return an error if there are duplicates.
type WorkloadPriority ¶
type WorkloadPriority struct { PriorityValue int `json:"priority_value,omitempty"` // The priority of the workload Retries int `json:"retries,omitempty"` // The number of retries before giving up and moving to the next priority RetryDurationS int `json:"retry_durations,omitempty"` // The number of seconds in which the specified number of retries must occur in order for the next priority workload to be attempted. VerifiedDurationS int `json:"verified_durations,omitempty"` // The number of second in which verified data must exist before the rollback retry feature is turned off }
func Workload_Priority_Factory ¶
func Workload_Priority_Factory(priority int, retries int, retryDur int, verifiedDur int) *WorkloadPriority
This function creates workload priority objects
func (WorkloadPriority) IsSame ¶
func (wp WorkloadPriority) IsSame(compare WorkloadPriority) bool
func (WorkloadPriority) String ¶
func (wp WorkloadPriority) String() string