Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaprokop authored and dimaprokop committed Mar 15, 2018
2 parents 33311b5 + b6b8eea commit eafd0cc
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 207 deletions.
2 changes: 1 addition & 1 deletion config/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"default": "latest",
"versions": {
"latest": {
"image": "selenoid/chrome",
"image": "selenoid/vnc:chrome_64.0",
"port": "4444",
"tmpfs": {"/tmp":"size=512m"}
}
Expand Down
296 changes: 213 additions & 83 deletions mesos/scheduler/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,133 +5,263 @@ type ID struct {
Value string `json:"value"`
}

type Docker struct {
Image string `json:"image"`
Network string `json:"network"`
Privileged bool `json:"privileged"`
PortMappings *[]PortMappings `json:"port_mappings"`
}

//Структура для хранения данных о контейнере
type Container struct {
Type string `json:"type"`
Docker struct {
Image string `json:"image"`
Network string `json:"network"`
PortMappings []struct {
ContainerPort int `json:"containerPort"`
HostPort int `json:"hostPort"`
Protocol string `json:"protocol"`
Name string `json:"name"`
} `json:"portMappings"`
} `json:"docker"`
Type string `json:"type"`
Docker Docker `json:"docker"`
}

type PortMappings struct {
ContainerPort int `json:"container_port"`
HostPort int `json:"host_port"`
Protocol string `json:"protocol"`
Name string `json:"name"`
}

//Резервируемые ресурсы
type Resources []struct {
Name string `json:"name"`
Type string `json:"type"`
Scalar struct {
Value float64 `json:"value"`
} `json:"scalar"`
type Resource struct {
Name string `json:"name"`
Ranges *Ranges `json:"ranges,omitempty"`
Role string `json:"role,omitempty"`
Type string `json:"type"`
Scalar *Scalar `json:"scalar,omitempty"`
}

type Scalar struct {
Value float64 `json:"value,numbers"`
}

type Ranges struct {
Range [] Range `json:"range"`
}

type Range struct {
Begin int `json:"begin"`
End int `json:"end"`
}

//Структура для хранения таски запуска
type Launch struct {
TaskInfos []TaskInfo `json:"task_infos"`
}

type Command struct {
Shell bool `json:"shell"`
}

type TaskInfo struct {
Name string `json:"name"`
TaskID ID `json:"task_id"`
AgentID ID `json:"agent_id"`
Command struct {
Shell bool `json:"shell"`
} `json:"command"`
Container Container `json:"container"`
Resources Resources `json:"resources"`
Name string `json:"name"`
TaskID ID `json:"task_id"`
AgentID ID `json:"agent_id"`
Command Command `json:"command"`
Container *Container `json:"container"`
Resources []Resource `json:"resources"`
}

type FrameworkInfo struct {
User string `json:"user"`
Name string `json:"name"`
Roles []string `json:"roles"`
}

type Subscribe struct {
FrameworkInfo FrameworkInfo `json:"framework_info"`
}

type SubscribeMessage struct {
Type string `json:"type"`
Subscribe struct {
FrameworkInfo struct {
User string `json:"user"`
Name string `json:"name"`
Roles []string `json:"roles"`
} `json:"framework_info"`
} `json:"subscribe"`
Type string `json:"type"`
Subscribe Subscribe `json:"subscribe"`
}

type Decline struct {
OfferIds []ID `json:"offer_ids"`
Filters Filters `json:"filters"`
}

type DeclineMessage struct {
FrameworkID ID `json:"framework_id"`
Type string `json:"type"`
Decline struct {
OfferIds []ID `json:"offer_ids"`
Filters struct {
RefuseSeconds float64 `json:"refuse_seconds"`
} `json:"filters"`
} `json:"decline"`
FrameworkID ID `json:"framework_id"`
Type string `json:"type"`
Decline Decline `json:"decline"`
}

type Filters struct {
RefuseSeconds float64 `json:"refuse_seconds"`
}

type Accept struct {
OfferIds []ID `json:"offer_ids"`
Operations *[]Operation `json:"operations"`
Filters Filters `json:"filters"`
}

type AcceptMessage struct {
FrameworkID ID `json:"framework_id"`
Type string `json:"type"`
Accept struct {
OfferIds []ID `json:"offer_ids"`
//тут может быть одна или много тасок, надо подумать как их сюда передать
Operations []Operation `json:"operations"`
Filters struct {
RefuseSeconds float64 `json:"refuse_seconds"`
} `json:"filters"`
} `json:"accept"`
Accept Accept `json:"accept"`
}

type Operation struct {
Type string `json:"type"`
Launch Launch `json:"launch"`
Type string `json:"type"`
Launch *Launch `json:"launch"`
}

type AcknowledgeMessage struct {
FrameworkID ID `json:"framework_id"`
Type string `json:"type"`
Acknowledge struct {
AgentID ID `json:"agent_id"`
TaskID ID `json:"task_id"`
UUID string `json:"uuid"`
} `json:"acknowledge"`
FrameworkID ID `json:"framework_id"`
Type string `json:"type"`
Acknowledge Acknowledge `json:"acknowledge"`
}

type Acknowledge struct {
AgentID ID `json:"agent_id"`
TaskID ID `json:"task_id"`
UUID string `json:"uuid"`
}

type Kill struct {
TaskID ID `json:"task_id"`
}

type KillMessage struct {
FrameworkID ID `json:"framework_id"`
Type string `json:"type"`
Kill struct {
TaskID ID `json:"task_id"`
} `json:"kill"`
Kill Kill `json:"kill"`
}

func GetPortMappings(portRange Range) *[]PortMappings {
var portMappings = PortMappings{ContainerPort: 4444}
portMappings.Name = "http"
portMappings.ContainerPort = 4444
portMappings.HostPort = portRange.Begin
portMappings.Protocol = "tcp"
return &[]PortMappings{portMappings}
}

func NewContainer(portRange Range) *Container {
return &Container{
Type: "DOCKER",
Docker: Docker{
Image: "selenoid/chrome",
Network: "BRIDGE",
Privileged: true,
PortMappings: GetPortMappings(portRange),
},
}
}

func NewResourcePorts(portRange Range) Resource {
var rangePort = Range{
Begin: portRange.Begin,
End: portRange.Begin,
}

return Resource{
Type: "RANGES",
Name: "ports",
Ranges: &Ranges{
[]Range{rangePort},
},
Role: "*",
}
}

func NewResourcesContainer(name string, value float64) Resource {
return Resource{
Type: "SCALAR",
Name: name,
Scalar: &Scalar{value},
}
}

func NewLaunchTaskInfo(offer Offer, taskId string) *Launch {
portRange := offer.Resources[0].Ranges.Range[0]
var taskInfo = TaskInfo{
Name: "My Task",
TaskID: ID{taskId},
AgentID: offer.AgentId,
Command: Command{false},
Container: NewContainer(portRange),
Resources: []Resource{
NewResourcePorts(portRange),
NewResourcesContainer("cpus", 1.0),
NewResourcesContainer("mem", 128.0),
},
}

return &Launch{TaskInfos: []TaskInfo{taskInfo}}
}

func NewOperations(offer Offer, taskId string) *[]Operation {
return &[]Operation{{
Type: "LAUNCH",
Launch: NewLaunchTaskInfo(offer, taskId),
},
}
}

func GetAcceptMessage(frameworkId ID, offer Offer, taskId string) (AcceptMessage) {
offerIds := []ID{offer.Id}
return AcceptMessage{
FrameworkID: frameworkId,
Type: "ACCEPT",
Accept: Accept{
offerIds,
NewOperations(offer, taskId),
Filters{RefuseSeconds: 5.0},
},
}
}

func GetSubscribedMessage(user string, name string, roles []string) (SubscribeMessage) {
var message = SubscribeMessage{Type: "SUBSCRIBE"}
message.Subscribe.FrameworkInfo.User = user
message.Subscribe.FrameworkInfo.Name = name
message.Subscribe.FrameworkInfo.Roles = roles
return message
return SubscribeMessage{
Type: "SUBSCRIBE",
Subscribe: Subscribe{
FrameworkInfo{
User: user,
Name: name,
Roles: roles,
},
},
}
}

func GetAcknowledgeMessage(frameworkId ID, agentId ID, UUID string) (AcknowledgeMessage) {
var message = AcknowledgeMessage{FrameworkID: frameworkId,
Type: "ACKNOWLEDGE"}
message.Acknowledge.AgentID = agentId
message.Acknowledge.TaskID = ID{"12220-3440-12532-my-task"}
message.Acknowledge.UUID = UUID
return message
func GetAcknowledgeMessage(frameworkId ID, agentId ID, UUID string, taskId ID) (AcknowledgeMessage) {
return AcknowledgeMessage{
FrameworkID: frameworkId,
Type: "ACKNOWLEDGE",
Acknowledge: Acknowledge{
AgentID: agentId,
TaskID: taskId,
UUID: UUID,
},
}
}

func GetDeclineMessage(frameworkId ID, offerId []ID) (DeclineMessage) {
var message = DeclineMessage{FrameworkID: frameworkId,
Type: "DECLINE"}
message.Decline.OfferIds = offerId
message.Decline.Filters.RefuseSeconds = 5.0
return message
return DeclineMessage{
FrameworkID: frameworkId,
Type: "DECLINE",
Decline: Decline{
OfferIds: offerId,
Filters: Filters{
RefuseSeconds: 5.0,
},
},
}
}

func GetKillMessage(frameworkId ID) (KillMessage) {
var message = KillMessage{
func GetKillMessage(frameworkId ID, taskId string) (KillMessage) {
return KillMessage{
FrameworkID: frameworkId,
Type: "KILL"}
message.Kill.TaskID = ID{"12220-3440-12532-my-task"}
return message
Type: "KILL",
Kill: Kill{
TaskID: ID{taskId},
},
}
}
Loading

0 comments on commit eafd0cc

Please sign in to comment.