util

package
Version: v0.0.0-...-a69e935 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResourceEpsilon is the minimum epsilon mesos resource;
	// This is because Mesos internally uses a fixed point precision. See MESOS-4687 for details.
	ResourceEpsilon = 0.0009
)

Variables

View Source
var UUIDLength = len(uuid.New())

UUIDLength represents the length of a 16 byte v4 UUID as a string

Functions

func ConfigHasSecretVolumes

func ConfigHasSecretVolumes(config *task.TaskConfig) bool

ConfigHasSecretVolumes returns true if config contains secret volumes

func Contains

func Contains(list []string, item string) bool

Contains checks whether an item contains in a list

func ContainsTaskState

func ContainsTaskState(list []task.TaskState, item task.TaskState) bool

ContainsTaskState checks whether a TaskState contains in a list of TaskStates

func ConvertInstanceIDListToInstanceRange

func ConvertInstanceIDListToInstanceRange(instIDs []uint32) []*pod.InstanceIDRange

ConvertInstanceIDListToInstanceRange converts list of instance ids to list of instance ranges

func ConvertLabels

func ConvertLabels(pelotonLabels []*peloton.Label) *mesos.Labels

ConvertLabels will convert Peloton labels to Mesos labels.

func ConvertTimestampToUnixSeconds

func ConvertTimestampToUnixSeconds(timestamp string) (int64, error)

ConvertTimestampToUnixSeconds converts timestamp string in RFC3339 format to the unix time in seconds.

func CreateHostInfo

func CreateHostInfo(hostname string,
	agentInfo *mesos.AgentInfo) *hostsvc.HostInfo

CreateHostInfo takes the agent Info and create the hostsvc.HostInfo

func CreateLeaseIDFromHostOfferID

func CreateLeaseIDFromHostOfferID(id *peloton.HostOfferID) *pbhostmgr.LeaseID

CreateLeaseIDFromHostOfferID creates a LeaseId from host offer ID.

func CreateMesosScalarResources

func CreateMesosScalarResources(values map[string]float64, role string) []*mesos.Resource

CreateMesosScalarResources is a helper function to convert resource values into Mesos resources.

func CreateMesosTaskID

func CreateMesosTaskID(jobID *peloton.JobID,
	instanceID uint32,
	runID uint64) *mesos.TaskID

CreateMesosTaskID creates mesos task id given jobID, instanceID and runID

func CreatePelotonTaskID

func CreatePelotonTaskID(
	jobID string,
	instanceID uint32,
) string

CreatePelotonTaskID creates a PelotonTaskID given jobID and instanceID

func CreatePodIDFromMesosTaskID

func CreatePodIDFromMesosTaskID(t *mesos.TaskID) *v1alphapeloton.PodID

CreatePodIDFromMesosTaskID creates a peloton pod ID from mesos taskID.

func CreatePortRanges

func CreatePortRanges(portSet map[uint32]bool) *mesos.Value_Ranges

CreatePortRanges create Mesos Ranges type from given port set.

func CreatePortResources

func CreatePortResources(portSet map[uint32]string) []*mesos.Resource

CreatePortResources create a list of Mesos resources suitable for launching from a map from port number to role name.

func CreateSecretVolume

func CreateSecretVolume(secretPath string, secretStr string) *mesos.Volume

CreateSecretVolume builds a mesos volume of type secret from the given secret path and secret value string This volume will be added to the job's default config

func ExtractIPAndPortFromMesosAgentPID

func ExtractIPAndPortFromMesosAgentPID(pid string) (string, string, error)

ExtractIPAndPortFromMesosAgentPID parses Mesos PID to extract IP-address and port number (if present).

func ExtractPortSet

func ExtractPortSet(resource *mesos.Resource) map[uint32]bool

ExtractPortSet is helper function to extract available port set from a Mesos resource.

func FormatTime

func FormatTime(timestamp float64, layout string) string

FormatTime converts a Unix timestamp to a string format of the given layout in UTC. See https://golang.org/pkg/time/ for possible time layout in golang. For example, it will return RFC3339 format string like 2017-01-02T11:00:00.123456789Z if the layout is time.RFC3339Nano

func GetDereferencedJobIDsList

func GetDereferencedJobIDsList(jobIDs []*peloton.JobID) []peloton.JobID

GetDereferencedJobIDsList dereferences the jobIDs list

func GetOfferScalarResourceSummary

func GetOfferScalarResourceSummary(offer *mesos.Offer) map[string]map[string]float64

GetOfferScalarResourceSummary generates a summary for all the scalar values: role -> offerName-> Value first level : role -> map(resource type-> resouce value)

func GetPortsNumFromOfferMap

func GetPortsNumFromOfferMap(offerMap map[string]*mesos.Offer) uint32

GetPortsNumFromOfferMap is helper function to get number of available ports from given id to offer map.

func GetPortsSetFromResources

func GetPortsSetFromResources(resources []*mesos.Resource) map[uint32]bool

GetPortsSetFromResources is helper function to extract ports resources.

func IntersectSlice

func IntersectSlice(slice1 []uint32, slice2 []uint32) []uint32

IntersectSlice get return the result of slice1 ∩ slice2 element must be present in both slices

func IsPelotonJobStateTerminal

func IsPelotonJobStateTerminal(state job.JobState) bool

IsPelotonJobStateTerminal returns true if job state is terminal otherwise false

func IsPelotonPodStateTerminal

func IsPelotonPodStateTerminal(state pod.PodState) bool

IsPelotonPodStateTerminal returns true if pod state is terminal otherwise false

func IsPelotonStateTerminal

func IsPelotonStateTerminal(state task.TaskState) bool

IsPelotonStateTerminal returns true if state is terminal otherwise false

func IsSecretVolume

func IsSecretVolume(volume *mesos.Volume) bool

IsSecretVolume returns true if the given volume is of type secret

func IsTaskHasValidVolume

func IsTaskHasValidVolume(taskInfo *task.TaskInfo) bool

IsTaskHasValidVolume returns true if a task is stateful and has a valid volume

func IsTaskThrottled

func IsTaskThrottled(state task.TaskState, message string) bool

IsTaskThrottled returns true if a task is currently throttled due to repeated failures

func Max

func Max(x, y uint32) uint32

Max returns the maximum value of x, y

func MesosStateToPelotonState

func MesosStateToPelotonState(mstate mesos.TaskState) task.TaskState

MesosStateToPelotonState translates mesos task state to peloton task state TODO: adjust in case there are additional peloton states

func Min

func Min(x, y uint32) uint32

Min returns the minimum value of x, y

func ParseJobAndInstanceID

func ParseJobAndInstanceID(mesosTaskID string) (string, uint32, error)

ParseJobAndInstanceID return jobID and instanceID from given mesos task id.

func ParseRunID

func ParseRunID(mesosTaskID string) (uint64, error)

ParseRunID parse the runID from mesosTaskID

func ParseTaskID

func ParseTaskID(taskID string) (string, uint32, error)

ParseTaskID parses the jobID and instanceID from peloton taskID

func ParseTaskIDFromMesosTaskID

func ParseTaskIDFromMesosTaskID(mesosTaskID string) (string, error)

ParseTaskIDFromMesosTaskID parses the taskID from mesosTaskID

func PtrPrintf

func PtrPrintf(format string, a ...interface{}) *string

PtrPrintf returns a pointer to a string format

func RemoveSecretVolumesFromConfig

func RemoveSecretVolumesFromConfig(config *task.TaskConfig) []*mesos.Volume

RemoveSecretVolumesFromConfig removes secret volumes from the task config in place and returns the secret volumes Secret volumes are added internally at the time of creating a job with secrets by handleSecrets method. They are not supplied in the config in job create/update requests. Consequently, they should not be displayed as part of Job Get API response. This is necessary to achieve the broader goal of using the secrets proto message in Job Create/Update/Get API to describe secrets and not allow users to checkin secrets as part of config

func RemoveSecretVolumesFromJobConfig

func RemoveSecretVolumesFromJobConfig(cfg *job.JobConfig) []*mesos.Volume

RemoveSecretVolumesFromJobConfig removes secret volumes from the default config as well as instance config in place and returns the secret volumes

func RunInParallel

func RunInParallel(identifier string, idList []uint32, task singleTask) error

RunInParallel runs go routines which will perform action on given list of instances

func SubtractSlice

func SubtractSlice(slice1 []uint32, slice2 []uint32) []uint32

SubtractSlice returns the result of slice1 - slice2 if an element is in slice2 but not in slice1, it would be ignored

func UnmarshalToType

func UnmarshalToType(jsonString string, resultType reflect.Type) (interface{},
	error)

UnmarshalToType unmarshal a string to a typed interface{}

Types

type MesosResourceBuilder

type MesosResourceBuilder struct {
	Resource mesos.Resource
}

MesosResourceBuilder is the helper to build a mesos resource

func NewMesosResourceBuilder

func NewMesosResourceBuilder() *MesosResourceBuilder

NewMesosResourceBuilder creates a MesosResourceBuilder

func (*MesosResourceBuilder) Build

func (o *MesosResourceBuilder) Build() *mesos.Resource

Build returns the mesos resource

func (*MesosResourceBuilder) WithDisk

WithDisk sets disk info.

func (*MesosResourceBuilder) WithName

WithName sets name

func (*MesosResourceBuilder) WithRanges

WithRanges sets ranges

func (*MesosResourceBuilder) WithReservation

func (o *MesosResourceBuilder) WithReservation(
	reservation *mesos.Resource_ReservationInfo) *MesosResourceBuilder

WithReservation sets reservation info.

func (*MesosResourceBuilder) WithRevocable

WithRevocable sets resource as revocable resource type

func (*MesosResourceBuilder) WithRole

WithRole sets role

func (*MesosResourceBuilder) WithType

WithType sets type

func (*MesosResourceBuilder) WithValue

func (o *MesosResourceBuilder) WithValue(value float64) *MesosResourceBuilder

WithValue sets value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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