governance

package
v3.2.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//db
	EL_GOV_ERR_RETRIEVE_AG_FROM_DB            = "Error retrieving agreement %v from database, error %v"
	EL_GOV_ERR_RETRIEVE_AG_FROM_DB_FOR_MNM    = "Unable to retrieve agreement %v from database for MeteringNotification message, error %v"
	EL_GOV_ERR_RETRIEVE_AG_FROM_DB_FOR_CANM   = "Unable to retrieve agreement %v from database for Cancel message, error %v"
	EL_GOV_ERR_RETRIEVE_AG_FROM_DB_FOR_RAM    = "Unable to retrieve agreement %v from database for ReplyAck message, error %v"
	EL_GOV_ERR_RETRIEVE_AG_FROM_DB_FOR_DRM    = "Unable to retrieve agreement %v from database for DataReceived message, error %v"
	EL_GOV_ERR_RETRIEVE_UNARCHIVED_AG_FROM_DB = "Unable to retrieve unarchived agreements from database. %v"
	EL_GOV_ERR_MARK_AG_TERMINATED_IN_DB       = "Error marking agreement %v terminated in database: %v."
	EL_GOV_ERR_RETRIEVE_SDEFS_FROM_DB         = "Error getting service definitions %v from db. %v"
	EL_GOV_ERR_RETRIEVE_SINSTS_VER_FROM_DB    = "Error retrieving all service instances from database for %v/%v version %v key %v. %v"
	EL_GOV_ERR_RETRIEVE_SINSTS_FOR_FROM_DB    = "Error retrieving all service instances from database for %v. %v"
	EL_GOV_ERR_RETRIEVE_SINSTS_FROM_DB        = "Error retrieving all service instances from database, error: %v"
	EL_GOV_ERR_RETRIEVE_SINST_FROM_DB         = "Error getting service instance %v from db. %v"
	EL_GOV_ERR_RETRIEVE_MATCH_AGS_FROM_DB     = "Error retrieving matching agreements from database for workloads %v. Error: %v"

	// exchange
	EL_GOV_ERR_RETRIEVE_SVC_CONFIGSTATE_FROM_EXCH = "Unable to retrieve the service configuration state for node resource %v from the exchange, error %v"
	EL_GOV_ERR_RETRIEVE_NODE_FROM_EXCH            = "Error retrieving node %v from the exchange: %v"
	EL_GOV_ERR_UPDATE_REGSVCS_IN_EXCH             = "Error updating registeredServices for node %v in the exchange: %v"

	// image
	EL_GOV_IMAGE_LOADED            = "Image loaded for %v/%v."
	EL_GOV_IMAGE_LOADED_FOR_SVC    = "Image loaded for service %v/%v."
	EL_GOV_ERR_LOADING_IMG         = "Error loading image for %v/%v."
	EL_GOV_ERR_LOADING_IMG_FOR_SVC = "Error loading image for service %v/%v."

	// agreement
	EL_GOV_START_TERM_AG_WITH_REASON    = "Start terminating agreement for %v. Termination reason: %v"
	EL_GOV_AG_REACHED                   = "Agreement reached for service %v. The agreement id is %v."
	EL_GOV_AG_NOT_VALID                 = "Agreement for %v no longer valid on the agbot. Node will cancel it."
	EL_GOV_WL_CONTAINER_UP              = "Workload service containers for %v/%v are up and running."
	EL_GOV_COMPLETE_TERM_AG_WITH_REASON = "Complete terminating agreement for %v. Termination reason: %v"
	EL_GOV_ERR_DEL_AG_IN_EXCH           = "Error deleting agreement for %v in exchange: %v. Will retry."
	EL_GOV_ERR_AG_VERIFICATION          = "Encountered error for AgreementVerification for %v with agbot, error %v"

	// message
	EL_GOV_REPLYACK_WILL_CANCEL_AG            = "ReplyAck indicated that the agbot did not want to pursue the agreement for %v. Node will cancel the agreement"
	EL_GOV_NODE_RECEIVED_CANCEL_MSG           = "Node received Cancel message for %v/%v from agbot %v."
	EL_GOV_ERR_HANDLE_REPLYACK_MSG_FOR_AG     = "Error handling ReplyAck message for %v. %v"
	EL_GOV_ERR_HANDLE_REPLYACK_MSG            = "Error handling ReplyAck message. %v"
	EL_GOV_ERR_HANDLE_DATARECEIVED_MSG_FOR_AG = "Error handling DataReceived message for %v. %v"
	EL_GOV_ERR_HANDLE_DATARECEIVED_MSG        = "Error handling DataReceived message. %v"
	EL_GOV_ERR_HANDLE_METERING_MSG_FOR_AG     = "Error handling MeterNotification message for %v. %v"
	EL_GOV_ERR_HANDLE_METERING_MSG            = "Error handling MeterNotification message. %v"
	EL_GOV_ERR_HANDLE_CANCEL_MSG_FOR_AG       = "Error handling Cancel message for %v. %v"
	EL_GOV_ERR_HANDLE_CANCEL_MSG              = "Error handling Cancel message. %v"

	// service
	EL_GOV_START_WORKLOAD_SVC             = "Start workload service for %v/%v."
	EL_GOV_WORKLOAD_DESTROYED             = "Workload destroyed for %v"
	EL_GOV_SVC_CONTAINER_STARTED          = "Service containers for %v started."
	EL_GOV_COMPLETE_CLEANUP_SVC           = "Complete cleaning up the service instance %v."
	EL_GOV_START_DEPENDENT_SVC            = "Start dependent services for %v/%v."
	EL_GOV_ERR_START_DEPENDENT_SVC        = "Encountered error starting dependen services for %v/%v. %v"
	EL_GOV_ERR_START_DEPENDENT_SVC_FOR_AG = "Error starting dependen service %v/%v version %v for agreement %v. %v"
	EL_GOV_START_CLEANUP_SVC              = "Start cleaning up service %v because agreement %v ended."
	EL_GOV_ERR_START_SVC                  = "Error starting service %v/%v version %v, error: %v"
	EL_GOV_ERR_GET_ALL_SVCS_FROM_AGS      = "Error getting all the services from agreements: %v"

	// agreement-less service
	EL_GOV_START_AGLESS_SVC                           = "Start agreement-less service %v/%v."
	EL_GOV_COMPLETE_START_AGLESS_SVC                  = "Complete starting agreement-less service %v/%v and its dependents."
	EL_GOV_ERR_START_AGLESS_SVC                       = "Unable to start agreement-less service %v/%v, error %v"
	EL_GOV_ERR_START_AGLESS_SVC_ERR_SEARCH_PATTERN    = "Unable to start agreement-less services, error searching for pattern %v in exchange, error: %v"
	EL_GOV_ERR_START_AGLESS_SVC_ERR_PATTERN_NOT_FOUND = "Unable to start agreement-less services, pattern %v not found in exchange"
	EL_GOV_ERR_START_AGLESS_SVC_ERR_SDEF_NOT_FOUND    = "Unable to start agreement-less service %v/%v, local service definition not found"

	// service upgrade
	EL_GOV_START_UPGRADE    = "Start upgrading service %v/%v from version %v to version %v."
	EL_GOV_COMPLETE_UPGRADE = "Complete upgrading service %v/%v from version %v to version %v."
	EL_GOV_FAILED_UPGRADE   = "Failed to upgrade service %v/%v from version %v to version %v, error: %v"

	// service downgrade
	EL_GOV_START_DOWNGRADE_FOR_AG                 = "Start downgrading service %v/%v version %v because service for agreement failed to start."
	EL_GOV_START_DOWNGRADE                        = "Start downgrading service %v/%v version %v because service failed to start."
	EL_GOV_START_DOWNGRADE_BECAUSW_UPGRADE_FAILED = "Start downgrading service %v/%v version %v because upgrade failed."
	EL_GOV_FAILED_DOWNGRADE                       = "Failed to downgrade service %v/%v version %v, error: %v"
	EL_GOV_COMPLETE_DOWNGRADE                     = "Complete downgrading service %v/%v from version %v to version %v."
	EL_GOV_ERR_FIND_SDEF_FOR_DOWNGRADE            = "Error finding the new service definition to downgrade to for %v/%v version %v key %v. error: %v"
	EL_GOV_ERR_NO_VERSION_TO_DOWNGRADE            = "Could not find lower version to downgrade for %v/%v version %v."
	EL_GOV_ERR_DOWNGRADE_FROM                     = "Error downgrading service %v/%v from version %v to version %v. Eror: %v"
	EL_GOV_ERR_DOWNGRADE                          = "Error downgrading service %v/%v version %v. %v"

	// service retry
	EL_GOV_START_SVC_RETRY            = "Start retrying number %v for dependent service %v version %v because service failed."
	EL_GOV_FAILED_SVC_RETRY           = "Failed retrying number %v for dependent service %v version %v."
	EL_GOV_ERR_GET_SVC_RETRY_CNT      = "Failed to get the service retry count for %v version %v. %v"
	EL_GOV_ERR_UPDATE_SVC_RETRY_STATE = "Error updating retry start state for service instance %v in dadabase. %v"
)

messages for event logs

View Source
const BC_GOVERNOR = "BlockchainGovernor"
View Source
const CONTAINER_GOVERNOR = "ContainerGovernor"

for identifying the subworkers used by this worker

View Source
const MAX_AGREEMENT_ACCEPTANCE_WAIT_TIME_M = 20

enforced only after the workloads are running

View Source
const MAX_CONTRACT_PRELAUNCH_TIME_M = 10
View Source
const MAX_CONTRACT_UNCONFIGURED_TIME_M = 20

TODO: make this module more aware of long-running setup operations like image downloading and dockerfile loading the max time we'll let a contract remain unconfigured by the provider

View Source
const MAX_MICROPAYMENT_UNPAID_RUN_DURATION_M = 60
View Source
const MICROSERVICE_GOVERNOR = "MicroserviceGovernor"
View Source
const SERVICE_CONFIGSTATE_GOVERNOR = "ServiceConfigStateGovernor"
View Source
const STATUS_AG_PROTOCOL_TERMINATED = 501
View Source
const STATUS_WORKLOAD_DESTROYED = 500

related to agreement cleanup status

Variables

View Source
var HORIZON_SERVERS = [...]string{"firmware.bluehorizon.network", "images.bluehorizon.network"}

Functions

func MarkI18nMessages

func MarkI18nMessages()

This is does nothing useful at run time. This code is only used in compileing time to make the eventlog messages gets into the catalog so that they can be translated. The event log messages will be saved in English. But the CLI can request them in different languages.

Types

type AsyncTerminationCommand

type AsyncTerminationCommand struct {
	AgreementId       string
	AgreementProtocol string
	Reason            uint
}

==============================================================================================================

func NewAsyncTerminationCommand

func NewAsyncTerminationCommand(agreementId string, agreementProtocol string, reason uint) *AsyncTerminationCommand

func (AsyncTerminationCommand) ShortString

func (c AsyncTerminationCommand) ShortString() string

type CancelAgreementCommand

type CancelAgreementCommand struct {
	AgreementId       string
	AgreementProtocol string
	Reason            uint
	ReasonDescription string
}

==============================================================================================================

func NewCancelAgreementCommand

func NewCancelAgreementCommand(agreementId string, agreementProtocol string, reason uint, desc string) *CancelAgreementCommand

func (CancelAgreementCommand) ShortString

func (c CancelAgreementCommand) ShortString() string

type CleanupExecutionCommand

type CleanupExecutionCommand struct {
	AgreementProtocol string
	AgreementId       string
	Reason            uint
	Deployment        persistence.DeploymentConfig
}

==============================================================================================================

func (CleanupExecutionCommand) ShortString

func (c CleanupExecutionCommand) ShortString() string

type CleanupStatusCommand

type CleanupStatusCommand struct {
	AgreementProtocol string
	AgreementId       string
	Status            uint
}

==============================================================================================================

func (CleanupStatusCommand) ShortString

func (c CleanupStatusCommand) ShortString() string

type ContainerStatus

type ContainerStatus struct {
	Name    string `json:"name"`
	Image   string `json:"image"`
	Created int64  `json:"created"`
	State   string `json:"state"`
}

func GetContainerStatus

func GetContainerStatus(deployment string, key string, infrastructure bool, containers []docker.APIContainers) ([]ContainerStatus, error)

find container status

func (ContainerStatus) String

func (w ContainerStatus) String() string

type DeviceStatus

type DeviceStatus struct {
	Connectivity map[string]bool  `json:"connectivity"` //  hosts and whether this device can reach them or not
	Services     []WorkloadStatus `json:"services"`
	LastUpdated  string           `json:"lastUpdated"`
}

func NewDeviceStatus

func NewDeviceStatus() *DeviceStatus

func (DeviceStatus) String

func (w DeviceStatus) String() string

type GovernanceWorker

type GovernanceWorker struct {
	worker.BaseWorker // embedded field

	ShuttingDownCmd *NodeShutdownCommand
	// contains filtered or unexported fields
}

func NewGovernanceWorker

func NewGovernanceWorker(name string, cfg *config.HorizonConfig, db *bolt.DB, pm *policy.PolicyManager) *GovernanceWorker

func (*GovernanceWorker) CleanupMicroservice

func (w *GovernanceWorker) CleanupMicroservice(spec_ref string, version string, inst_key string, ms_reason_code uint) error

It cleans the microservice instance and its associated agreements

func (*GovernanceWorker) CommandHandler

func (w *GovernanceWorker) CommandHandler(command worker.Command) bool

func (*GovernanceWorker) FindEstablishedAgreementsWithIds

func (w *GovernanceWorker) FindEstablishedAgreementsWithIds(agreementIds []string) ([]persistence.EstablishedAgreement, error)

go through all the protocols and find the agreements with given agreement ids from the db

func (*GovernanceWorker) GetEnvVarsForServiceDepolyment

func (w *GovernanceWorker) GetEnvVarsForServiceDepolyment(msdef *persistence.MicroserviceDefinition, msInst *persistence.MicroserviceInstance, agreementId string) (map[string]string, error)

Collect the user inputs from node, policy and service. Convert them to a map of strings that can be used as environmental variables for a dependent service container.

func (*GovernanceWorker) GetServicePreference

func (w *GovernanceWorker) GetServicePreference(url string, org string, tcPolicy *policy.Policy) (map[string]string, error)

Get the environmental variables for a service (this is about launching).

func (*GovernanceWorker) Initialize

func (w *GovernanceWorker) Initialize() bool

func (*GovernanceWorker) Messages

func (w *GovernanceWorker) Messages() chan events.Message

func (*GovernanceWorker) NewCleanupExecutionCommand

func (w *GovernanceWorker) NewCleanupExecutionCommand(protocol string, agreementId string, reason uint, deployment persistence.DeploymentConfig) *CleanupExecutionCommand

func (*GovernanceWorker) NewCleanupStatusCommand

func (w *GovernanceWorker) NewCleanupStatusCommand(protocol string, agreementId string, status uint) *CleanupStatusCommand

func (*GovernanceWorker) NewEvent

func (w *GovernanceWorker) NewEvent(incoming events.Message)

func (*GovernanceWorker) NewNodeHeartbeatRestoredCommand

func (w *GovernanceWorker) NewNodeHeartbeatRestoredCommand() *NodeHeartbeatRestoredCommand

func (*GovernanceWorker) NewNodeShutdownCommand

func (w *GovernanceWorker) NewNodeShutdownCommand(msg *events.NodeShutdownMessage) *NodeShutdownCommand

func (*GovernanceWorker) NewReportDeviceStatusCommand

func (w *GovernanceWorker) NewReportDeviceStatusCommand() *ReportDeviceStatusCommand

func (*GovernanceWorker) NewServiceSuspendedCommand

func (w *GovernanceWorker) NewServiceSuspendedCommand(scs []events.ServiceConfigState) *ServiceSuspendedCommand

func (*GovernanceWorker) NewStartAgreementLessServicesCommand

func (w *GovernanceWorker) NewStartAgreementLessServicesCommand() *StartAgreementLessServicesCommand

func (*GovernanceWorker) NewStartGovernExecutionCommand

func (w *GovernanceWorker) NewStartGovernExecutionCommand(deployment persistence.DeploymentConfig, protocol string, agreementId string) *StartGovernExecutionCommand

func (*GovernanceWorker) NewUpdateMicroserviceCommand

func (w *GovernanceWorker) NewUpdateMicroserviceCommand(key string, started bool, failure_code uint, failure_desc string) *UpdateMicroserviceCommand

func (*GovernanceWorker) NewUpdatePolicyCommand

func (w *GovernanceWorker) NewUpdatePolicyCommand(msg *events.UpdatePolicyMessage) *UpdatePolicyCommand

func (*GovernanceWorker) NewUpgradeMicroserviceCommand

func (w *GovernanceWorker) NewUpgradeMicroserviceCommand(msdef_id string) *UpgradeMicroserviceCommand

func (*GovernanceWorker) NoWorkHandler

func (w *GovernanceWorker) NoWorkHandler()

func (*GovernanceWorker) RecordReply

func (w *GovernanceWorker) RecordReply(proposal abstractprotocol.Proposal, protocol string) error

func (*GovernanceWorker) ReportDeviceStatus

func (w *GovernanceWorker) ReportDeviceStatus()

Report the containers status and connectivity status to the exchange.

func (*GovernanceWorker) RetryMicroservice

func (w *GovernanceWorker) RetryMicroservice(msi *persistence.MicroserviceInstance) error

This function will call StartMicroservice to restart all the containers for the given service instance. The process will eventually trigger image loading (just in case the imgges are gone on the node), old container cleaning and new container brought up.

func (*GovernanceWorker) RollbackMicroservice

func (w *GovernanceWorker) RollbackMicroservice(msdef *persistence.MicroserviceDefinition) error

Get the next highest microservice version and rollback to it. Tryer even lower version if it fails

func (*GovernanceWorker) StartMicroservice

func (w *GovernanceWorker) StartMicroservice(ms_key string, agreementId string, dependencyPath []persistence.ServiceInstancePathElement, msinst_key string) (*persistence.MicroserviceInstance, error)

It creates microservice instance and loads the containers for the given microservice def If the msinst_key is not empty, the function is called to restart a failed dependent service.

func (*GovernanceWorker) UpdateRegisteredServicesWithAgreement

func (w *GovernanceWorker) UpdateRegisteredServicesWithAgreement()

For the policy case, the registeredServices is not used except for service suspension and resumption We need to update the registeredServices when an agreement created and canceled.

func (*GovernanceWorker) UpgradeMicroservice

func (w *GovernanceWorker) UpgradeMicroservice(msdef *persistence.MicroserviceDefinition, new_msdef *persistence.MicroserviceDefinition, upgrade bool) error

It changes the current running microservice from the old to new, assuming the given microservice is ready for a change. One can check it by calling microservice.MicroserviceReadyForUpgrade to find out.

type NodeHeartbeatRestoredCommand

type NodeHeartbeatRestoredCommand struct {
}

============================================================================================================== Node heartbeat restored

func (NodeHeartbeatRestoredCommand) ShortString

func (c NodeHeartbeatRestoredCommand) ShortString() string

type NodePolicyChangedCommand

type NodePolicyChangedCommand struct {
	Msg *events.NodePolicyMessage
}

============================================================================================================== Update (re-generate) node side policies

func NewNodePolicyChangedCommand

func NewNodePolicyChangedCommand(msg *events.NodePolicyMessage) *NodePolicyChangedCommand

func (NodePolicyChangedCommand) ShortString

func (d NodePolicyChangedCommand) ShortString() string

type NodeShutdownCommand

type NodeShutdownCommand struct {
	Msg *events.NodeShutdownMessage
}

==============================================================================================================

func (NodeShutdownCommand) ShortString

func (n NodeShutdownCommand) ShortString() string

type NodeUserInputChangedCommand

type NodeUserInputChangedCommand struct {
	Msg *events.NodeUserInputMessage
}

============================================================================================================== Update node side user input

func (NodeUserInputChangedCommand) ShortString

func (d NodeUserInputChangedCommand) ShortString() string

type ReportDeviceStatusCommand

type ReportDeviceStatusCommand struct {
}

==============================================================================================================

func (ReportDeviceStatusCommand) ShortString

func (c ReportDeviceStatusCommand) ShortString() string

type ServiceSuspendedCommand

type ServiceSuspendedCommand struct {
	ServiceConfigState []events.ServiceConfigState
}

============================================================================================================== Node heartbeat restored

func (ServiceSuspendedCommand) ShortString

func (c ServiceSuspendedCommand) ShortString() string

type StartAgreementLessServicesCommand

type StartAgreementLessServicesCommand struct {
}

============================================================================================================== Start agreement-less services

func (StartAgreementLessServicesCommand) ShortString

func (c StartAgreementLessServicesCommand) ShortString() string

type StartGovernExecutionCommand

type StartGovernExecutionCommand struct {
	AgreementId       string
	AgreementProtocol string
	Deployment        persistence.DeploymentConfig
}

func (StartGovernExecutionCommand) ShortString

func (g StartGovernExecutionCommand) ShortString() string

type UpdateMicroserviceCommand

type UpdateMicroserviceCommand struct {
	MsInstKey            string // the name that was passed into the ContainerLaunchContext, it is the key to the MicroserviceInstance table.
	ExecutionStarted     bool
	ExecutionFailureCode uint
	ExecutionFailureDesc string
}

==============================================================================================================

func (UpdateMicroserviceCommand) ShortString

func (c UpdateMicroserviceCommand) ShortString() string

type UpdatePolicyCommand

type UpdatePolicyCommand struct {
	Msg *events.UpdatePolicyMessage
}

============================================================================================================== Update (re-generate) node side policies

func (UpdatePolicyCommand) ShortString

func (c UpdatePolicyCommand) ShortString() string

type UpgradeMicroserviceCommand

type UpgradeMicroserviceCommand struct {
	MsDefId string
}

============================================================================================================== Upgrade the given microservice if needed

func (UpgradeMicroserviceCommand) ShortString

func (c UpgradeMicroserviceCommand) ShortString() string

type WorkloadStatus

type WorkloadStatus struct {
	AgreementId string            `json:"agreementId"`
	ServiceURL  string            `json:"serviceUrl,omitempty"`
	Org         string            `json:"orgid,omitempty"`
	Version     string            `json:"version,omitempty"`
	Arch        string            `json:"arch,omitempty"`
	Containers  []ContainerStatus `json:"containerStatus"`
}

func (WorkloadStatus) String

func (w WorkloadStatus) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL