Swarmkit notes (7)--exec. Executor interface

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

exec.Executor interfaceDefinition (located agent/exec/executor.go ):

// Executor provides controllers for tasks.type Executor interface {    // Describe returns the underlying node description.    Describe(ctx context.Context) (*api.NodeDescription, error)    // Configure uses the node object state to propagate node    // state to the underlying executor.    Configure(ctx context.Context, node *api.Node) error    // Controller provides a controller for the given task.    Controller(t *api.Task) (Controller, error)    // SetNetworkBootstrapKeys passes the symmetric keys from the    // manager to the executor.    SetNetworkBootstrapKeys([]*api.EncryptionKey) error}

container PackageImplements the executor structure (located agent/exec/container/executor.go ):

import engineapi "github.com/docker/engine-api/client"type executor struct {    client engineapi.APIClient}

There is only one member: one Docker APIClient . executorthe structure actually implements only the following two methods:

Describe returns the underlying node description from the Docker Client.func (e *executor) Describe (CTX context. Context) (*api. Nodedescription, error) {info, err: = E.client.info (CTX) if err! = Nil {return nil, err} plugins: = Map[api.            plugindescription]struct{}{} addplugins: = Func (Typ string, names []string) {for _, Name: = range Names { Plugins[api. plugindescription{Type:typ, Name:name,}] = struct{}{}}} Addplu Gins ("Volume", info. Plugins.volume)//ADD Builtin Driver "overlay" (the only builtin multi-host driver) to//The plugin list by defaul    T. addplugins ("Network", append ([]string{"Overlay"}, info.Plugins.Network ...)) Addplugins ("Authorization", info. plugins.authorization) Pluginfields: = Make ([]api. Plugindescription, 0, Len (plugins)) for k: = Range Plugins {pluginfields = append (Pluginfields, k)} sort . Sort (Sortedplugins (Pluginfields))//PARSE []string labels to a map[string]string labels: = map[string]string{} for _, L: = range info. Labels {stringslice: = strings. SPLITN (l, "=", 2)//This is the last value of the list for a given key//Ideally, one shouldn ' t         IGN multiple values to the same key if Len (Stringslice) > 1 {labels[stringslice[0]] = stringslice[1] }} Description: = &api. nodedescription{Hostname:info. Name, Platform: &api. platform{Architecture:info. Architecture, Os:info. OSType,}, Engine: &api. enginedescription{Engineversion:info. ServerVersion, Labels:labels, Plugins:pluginfields,}, Resources: & Api. resources{Nanocpus:int64 (info. NCPU) * 1e9, Memorybytes:info. Memtotal,},} return description, nil}//Controller returns a Docker container Controller.func (e *executor) Controller (t *api. Task) (exec. Controller, error) {CTLR, err: = Newcontroller (e.client, T) if err! = Nil {return nil, err} return C TLR, nil}

Describe()method returns the current Docker engine resource configuration information, and Controller() then returns a container.controller struct.

Where client the initialization of the is located:

        client, err := engineapi.NewClient(engineAddr, "", nil, nil)        if err != nil {            return err        }        executor := container.NewExecutor(client)

If no engineAddr special settings are made, their default values are used: unix:///var/run/docker.sock . The client value defaults to the following:

(dlv) p client*github.com/docker/swarmkit/vendor/github.com/docker/engine-api/client.Client {        proto: "unix",        addr: "/var/run/docker.sock",        basePath: "",        transport: (unreadable interface type "*transport.apiTransport" not found for 0xc8202ecbd8: no type entry found, use 'types' for a list of valid types),        version: "",        customHTTPHeaders: map[string]string [],}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.