Documentation
¶
Index ¶
Constants ¶
const ( // ScheduledActionType code for labeling ScheduledActions ScheduledActionType = "scheduled_action" // CronActionType code for labeling CronActions CronActionType = "cron_action" // InstantActionType code for labeling InstantActions. InstantActions are NOT stored on DB InstantActionType = "instant_action" )
Variables ¶
This section is empty.
Functions ¶
func DecodeActions ¶
func DecodeActions(actions []json.RawMessage) (*[]Action, error)
DecodeActions received a http response body as a []byte for decoding the actions on it and unmarshall them evaluating its specific action type. Every decoded action will be parsed as a specific action type based on its properties
Parameters: - action as a byte array. It's supposed to be used for unmarshalling the body from a HTTP request
Returns: - A slice of Action where every element was unmarshalled as it's specific Action Type - err if an Error occurs
func SplitActionsByType ¶
func SplitActionsByType(actions []Action) ([]ScheduledAction, []CronAction)
DecodeActions takes an array of Actions and splits it in separate slices classified by ActionType
Parameters: - A slice of Actions to split (will not be modified)
Returns: - A pointer to a slice of ScheduledActions - A pointer to a slice of CronAction
Types ¶
type Action ¶
type Action interface {
// GetActionOperation returns the type of action being performed.
//
// Returns:
// - An ActionOperation indicating the action type (e.g., PowerOnCluster, PowerOffCluster).
GetActionOperation() ActionOperation
// GetRegion returns the cloud region where the action is executed.
//
// Returns:
// - A string representing the cloud region.
GetRegion() string
// GetTarget returns the target resource of the action.
//
// Returns:
// - An ActionTarget representing the target cluster and instances affected by the action.
GetTarget() ActionTarget
// GetID returns a unique identifier for the action.
//
// Returns:
// - A string representing the unique action ID.
GetID() string
// GetType returns the action type
//
// Returns:
// - A string representing action type
GetType() ActionType
}
Action defines the interface for cloud actions that can be executed. Implementations of this interface should provide details about the action type, target region, target resource, and a unique identifier.
type ActionOperation ¶
type ActionOperation string
ActionOperation represents the operation of action that can be performed on a cloud resource. It defines specific operations such as powering on or off a cluster.
const ( // PowerOnCluster represents an action to power on a cluster. PowerOnCluster ActionOperation = "PowerOnCluster" // PowerOffCluster represents an action to power off a cluster. PowerOffCluster ActionOperation = "PowerOffCluster" )
type ActionTarget ¶
type ActionTarget struct {
// AccountName is the name of the cloud account associated with the target.
AccountName string `db:"account_name" json:"accountName"`
// Region specifies the cloud region where the target resources are located.
Region string `db:"region" json:"region"`
// ClusterID is the unique identifier of the cluster targeted by the action.
ClusterID string `db:"cluster_id" json:"clusterID"`
// Instances is a list of instance IDs associated with the target cluster.
Instances []string `db:"instances" json:"instances"`
}
ActionTarget represents the target of an action in a cloud environment. It includes information about the account, region, cluster, and instances involved in the action.
func NewActionTarget ¶
func NewActionTarget(accountName string, region string, clusterID string, instances []string) *ActionTarget
NewActionTarget creates and returns a new instance of ActionTarget.
Parameters: - accountName: The name of the cloud account. - region: The cloud region where the resources are located. - clusterID: The unique identifier of the cluster. - instances: A slice of instance IDs associated with the cluster.
Returns: - A pointer to a newly created ActionTarget instance.
func (*ActionTarget) GetAccountName ¶
func (at *ActionTarget) GetAccountName() string
GetAccountName returns the name of the cloud account associated with the ActionTarget.
Returns: - A string representing the account name.
func (*ActionTarget) GetClusterID ¶
func (at *ActionTarget) GetClusterID() string
GetClusterID returns the unique identifier of the cluster targeted by the action.
Returns: - A string representing the cluster ID.
func (*ActionTarget) GetInstances ¶
func (at *ActionTarget) GetInstances() []string
GetInstances returns the list of instance IDs associated with the ActionTarget.
Returns: - A slice of strings containing the instance IDs.
func (*ActionTarget) GetRegion ¶
func (at *ActionTarget) GetRegion() string
GetRegion returns the cloud region of the ActionTarget.
Returns: - A string representing the region.
type ActionType ¶
type ActionType string
type BaseAction ¶
type BaseAction struct {
ID string `db:"id" json:"id"`
Operation ActionOperation `db:"operation" json:"operation"`
Target ActionTarget `db:"target" json:"target"`
Status string `db:"status" json:"status"`
Enabled bool `db:"enabled" json:"enabled"`
}
BaseAction defines the common parameters that every action has
func NewBaseAction ¶
func NewBaseAction(ao ActionOperation, target ActionTarget, status string, enabled bool) *BaseAction
func (BaseAction) GetActionOperation ¶
func (b BaseAction) GetActionOperation() ActionOperation
type CronAction ¶
type CronAction struct {
// When specifies the scheduled time for the action execution.
Expression string `db:"cron_exp" json:"cronExp"`
Type string `db:"type" json:"type"`
BaseAction
}
CronAction represents an action that is scheduled to be executed at a specific time. It embeds BaseAction to inherit common action properties and includes a timestamp indicating when the action should be executed.
func NewCronAction ¶
func NewCronAction(actionOperation ActionOperation, target ActionTarget, status string, enabled bool, cronExpression string) *CronAction
NewCronAction creates and initializes a new CronAction.
Parameters: - actionOperation: The type of action to be performed (e.g., PowerOnCluster, PowerOffCluster). - target: The target resource (cluster and instances) affected by the action. - when: The scheduled time for executing the action.
Returns: - A pointer to a newly created CronAction instance.
func (CronAction) GetActionOperation ¶
func (s CronAction) GetActionOperation() ActionOperation
GetActionOperation returns the type of action being performed.
Returns: - An ActionOperation representing the action type (e.g., PowerOnCluster, PowerOffCluster).
func (CronAction) GetCronExpression ¶
func (s CronAction) GetCronExpression() string
GetCronExpression returns the cron expression for running this action
Returns: - A string representing the cron expression
func (CronAction) GetID ¶
func (s CronAction) GetID() string
GetID returns a unique identifier for the scheduled action.
Returns: - A string representing the unique action ID.
func (CronAction) GetRegion ¶
func (s CronAction) GetRegion() string
GetRegion returns the cloud region where the action is scheduled to execute.
Returns: - A string representing the cloud region.
func (CronAction) GetTarget ¶
func (s CronAction) GetTarget() ActionTarget
GetTarget returns the target resource of the scheduled action.
Returns: - An ActionTarget representing the target cluster and instances affected by the action.
func (CronAction) GetType ¶
func (s CronAction) GetType() ActionType
GetType returns CronActionType
Returns: - ActionType
type InstantAction ¶
type InstantAction struct {
BaseAction
}
InstantAction represents an immediate action that can be executed without additional delays or dependencies. It embeds BaseAction to inherit common action properties.
func NewInstantAction ¶
func NewInstantAction(ao ActionOperation, target ActionTarget, status string, enabled bool) *InstantAction
NewInstantAction creates and initializes a new InstantAction.
Parameters: - ao: The operation of action to be performed (e.g., PowerOnCluster, PowerOffCluster). - target: The target resource (cluster and instances) affected by the action.
Returns: - A pointer to a newly created InstantAction instance.
func (InstantAction) GetActionOperation ¶
func (i InstantAction) GetActionOperation() ActionOperation
GetActionOperation returns the type of action being performed.
Returns: - An ActionOperation representing the action type (e.g., PowerOnCluster, PowerOffCluster).
func (InstantAction) GetID ¶
func (i InstantAction) GetID() string
GetID returns a unique identifier for the action.
Returns: - A string representing the unique action ID.
func (InstantAction) GetRegion ¶
func (i InstantAction) GetRegion() string
GetRegion returns the cloud region where the action is executed.
Returns: - A string representing the cloud region.
func (InstantAction) GetTarget ¶
func (i InstantAction) GetTarget() ActionTarget
GetTarget returns the target resource of the action.
Returns: - An ActionTarget representing the target cluster and instances affected by the action.
func (InstantAction) GetType ¶
func (i InstantAction) GetType() ActionType
GetType returns InstantActionType
Returns: - ActionType
type ScheduledAction ¶
type ScheduledAction struct {
// When specifies the scheduled time for the action execution.
When time.Time `db:"time" json:"time"`
Type string `db:"type" json:"type"`
BaseAction
}
ScheduledAction represents an action that is scheduled to be executed at a specific time. It embeds BaseAction to inherit common action properties and includes a timestamp indicating when the action should be executed.
func NewScheduledAction ¶
func NewScheduledAction(ao ActionOperation, target ActionTarget, status string, enabled bool, when time.Time) *ScheduledAction
NewScheduledAction creates and initializes a new ScheduledAction.
Parameters: - actionOperation: The type of action to be performed (e.g., PowerOnCluster, PowerOffCluster). - target: The target resource (cluster and instances) affected by the action. - when: The scheduled time for executing the action.
Returns: - A pointer to a newly created ScheduledAction instance.
func (ScheduledAction) GetActionOperation ¶
func (s ScheduledAction) GetActionOperation() ActionOperation
GetActionOperation returns the type of action being performed.
Returns: - An ActionOperation representing the action type (e.g., PowerOnCluster, PowerOffCluster).
func (ScheduledAction) GetID ¶
func (s ScheduledAction) GetID() string
GetID returns a unique identifier for the scheduled action.
Returns: - A string representing the unique action ID.
func (ScheduledAction) GetRegion ¶
func (s ScheduledAction) GetRegion() string
GetRegion returns the cloud region where the action is scheduled to execute.
Returns: - A string representing the cloud region.
func (ScheduledAction) GetTarget ¶
func (s ScheduledAction) GetTarget() ActionTarget
GetTarget returns the target resource of the scheduled action.
Returns: - An ActionTarget representing the target cluster and instances affected by the action.
func (ScheduledAction) GetType ¶
func (s ScheduledAction) GetType() ActionType
GetType returns ScheduledActionType
Returns: - ActionType