_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q16900
parseCloudConfig
train
func parseCloudConfig(cfg []byte, report *Report) (node, error) { yaml.UnmarshalMappingKeyTransform = func(nameIn string) (nameOut string) { return nameIn } // unmarshal the config into an implicitly-typed form. The yaml library // will implicitly convert types into their normalized form // (e.g. 0744 -> 484, off -> false). var weak map[interface{}]interface{} if err := yaml.Unmarshal(cfg, &weak); err != nil { matches := yamlLineError.FindStringSubmatch(err.Error()) if len(matches) == 3 { line, err := strconv.Atoi(matches[1]) if err != nil { return node{}, err } msg := matches[2] report.Error(line, msg) return node{}, nil } matches = yamlError.FindStringSubmatch(err.Error()) if len(matches) == 2 { report.Error(1, matches[1]) return node{}, nil } return node{}, errors.New("couldn't parse yaml error") } w := NewNode(weak, NewContext(cfg)) w = normalizeNodeNames(w, report) // unmarshal the config into the explicitly-typed form. yaml.UnmarshalMappingKeyTransform = func(nameIn string) (nameOut string) { return strings.Replace(nameIn, "-", "_", -1) } var strong config.CloudConfig if err := yaml.Unmarshal([]byte(cfg), &strong); err != nil { return node{}, err } s := NewNode(strong, NewContext(cfg)) // coerceNodes weak nodes and strong nodes. strong nodes replace weak nodes // if they are compatible types (this happens when the yaml library // converts the input). // (e.g. weak 484 is replaced by strong 0744, weak 4 is not replaced by // strong false) return coerceNodes(w, s), nil }
go
{ "resource": "" }
q16901
normalizeNodeNames
train
func normalizeNodeNames(node node, report *Report) node { if strings.Contains(node.name, "-") { // TODO(crawford): Enable this message once the new validator hits stable. //report.Info(node.line, fmt.Sprintf("%q uses '-' instead of '_'", node.name)) node.name = strings.Replace(node.name, "-", "_", -1) } for i := range node.children { node.children[i] = normalizeNodeNames(node.children[i], report) } return node }
go
{ "resource": "" }
q16902
Walk
train
func Walk(data, walker interface{}) (err error) { v := reflect.ValueOf(data) ew, ok := walker.(EnterExitWalker) if ok { err = ew.Enter(WalkLoc) } if err == nil { err = walk(v, walker) } if ok && err == nil { err = ew.Exit(WalkLoc) } return }
go
{ "resource": "" }
q16903
EqualTo
train
func (header *Header) EqualTo(q *Header) bool { if header == nil || q == nil { return false } if header.Command.IsLocal() { return true } return header.TransportProtocol == q.TransportProtocol && header.SourceAddress.String() == q.SourceAddress.String() && header.DestinationAddress.String() == q.DestinationAddress.String() && header.SourcePort == q.SourcePort && header.DestinationPort == q.DestinationPort }
go
{ "resource": "" }
q16904
WriteTo
train
func (header *Header) WriteTo(w io.Writer) (int64, error) { switch header.Version { case 1: return header.writeVersion1(w) case 2: return header.writeVersion2(w) default: return 0, ErrUnknownProxyProtocolVersion } }
go
{ "resource": "" }
q16905
Read
train
func Read(reader *bufio.Reader) (*Header, error) { // In order to improve speed for small non-PROXYed packets, take a peek at the first byte alone. if b1, err := reader.Peek(1); err == nil && (bytes.Equal(b1[:1], SIGV1[:1]) || bytes.Equal(b1[:1], SIGV2[:1])) { if signature, err := reader.Peek(5); err == nil && bytes.Equal(signature[:5], SIGV1) { return parseVersion1(reader) } else if signature, err := reader.Peek(12); err == nil && bytes.Equal(signature[:12], SIGV2) { return parseVersion2(reader) } } return nil, ErrNoProxyProtocol }
go
{ "resource": "" }
q16906
ReadTimeout
train
func ReadTimeout(reader *bufio.Reader, timeout time.Duration) (*Header, error) { type header struct { h *Header e error } read := make(chan *header, 1) go func() { h := &header{} h.h, h.e = Read(reader) read <- h }() timer := time.NewTimer(timeout) select { case result := <-read: timer.Stop() return result.h, result.e case <-timer.C: return nil, ErrNoProxyProtocol } }
go
{ "resource": "" }
q16907
NewImage
train
func NewImage(r image.Rectangle) *Image { w, h := r.Dx(), r.Dy() return &Image{Pix: make([]uint8, 3*w*h), Stride: 3 * w, Rect: r} }
go
{ "resource": "" }
q16908
At
train
func (p *Image) At(x, y int) color.Color { return p.RGBAAt(x, y) }
go
{ "resource": "" }
q16909
RGBA
train
func (c RGB) RGBA() (r, g, b, a uint32) { r = uint32(c.R) r |= r << 8 g = uint32(c.G) g |= g << 8 b = uint32(c.B) b |= b << 8 a = uint32(0xFFFF) return }
go
{ "resource": "" }
q16910
Decode
train
func Decode(r io.Reader, options *DecoderOptions) (dest image.Image, err error) { dinfo := newDecompress(r) if dinfo == nil { return nil, errors.New("allocation failed") } defer destroyDecompress(dinfo) // Recover panic defer func() { if r := recover(); r != nil { if _, ok := r.(error); !ok { err = fmt.Errorf("JPEG error: %v", r) } } }() C.jpeg_read_header(dinfo, C.TRUE) setupDecoderOptions(dinfo, options) switch dinfo.num_components { case 1: if dinfo.jpeg_color_space != C.JCS_GRAYSCALE { return nil, errors.New("Image has unsupported colorspace") } dest, err = decodeGray(dinfo) case 3: switch dinfo.jpeg_color_space { case C.JCS_YCbCr: dest, err = decodeYCbCr(dinfo) case C.JCS_RGB: dest, err = decodeRGB(dinfo) default: return nil, errors.New("Image has unsupported colorspace") } } return }
go
{ "resource": "" }
q16911
DecodeIntoRGB
train
func DecodeIntoRGB(r io.Reader, options *DecoderOptions) (dest *rgb.Image, err error) { dinfo := newDecompress(r) if dinfo == nil { return nil, errors.New("allocation failed") } defer destroyDecompress(dinfo) // Recover panic defer func() { if r := recover(); r != nil { if _, ok := r.(error); !ok { err = fmt.Errorf("JPEG error: %v", r) } } }() C.jpeg_read_header(dinfo, C.TRUE) setupDecoderOptions(dinfo, options) C.jpeg_calc_output_dimensions(dinfo) dest = rgb.NewImage(image.Rect(0, 0, int(dinfo.output_width), int(dinfo.output_height))) dinfo.out_color_space = C.JCS_RGB readScanLines(dinfo, dest.Pix, dest.Stride) return }
go
{ "resource": "" }
q16912
DecodeIntoRGBA
train
func DecodeIntoRGBA(r io.Reader, options *DecoderOptions) (dest *image.RGBA, err error) { dinfo := newDecompress(r) if dinfo == nil { return nil, errors.New("allocation failed") } defer destroyDecompress(dinfo) // Recover panic defer func() { if r := recover(); r != nil { if _, ok := r.(error); !ok { err = fmt.Errorf("JPEG error: %v", r) } } }() C.jpeg_read_header(dinfo, C.TRUE) setupDecoderOptions(dinfo, options) C.jpeg_calc_output_dimensions(dinfo) dest = image.NewRGBA(image.Rect(0, 0, int(dinfo.output_width), int(dinfo.output_height))) colorSpace := getJCS_EXT_RGBA() if colorSpace == C.JCS_UNKNOWN { return nil, errors.New("JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)") } dinfo.out_color_space = colorSpace readScanLines(dinfo, dest.Pix, dest.Stride) return }
go
{ "resource": "" }
q16913
DecodeConfig
train
func DecodeConfig(r io.Reader) (config image.Config, err error) { dinfo := newDecompress(r) if dinfo == nil { err = errors.New("allocation failed") return } defer destroyDecompress(dinfo) // Recover panic defer func() { if r := recover(); r != nil { if _, ok := r.(error); !ok { err = fmt.Errorf("JPEG error: %v", r) } } }() C.jpeg_read_header(dinfo, C.TRUE) config = image.Config{ ColorModel: color.YCbCrModel, Width: int(dinfo.image_width), Height: int(dinfo.image_height), } return }
go
{ "resource": "" }
q16914
NewGrayAligned
train
func NewGrayAligned(r image.Rectangle) *image.Gray { w, h := r.Dx(), r.Dy() // TODO: check the padding size to minimize memory allocation. stride := pad(w, alignSize) + alignSize ph := pad(h, alignSize) + alignSize pix := make([]uint8, stride*ph) return &image.Gray{ Pix: pix, Stride: stride, Rect: r, } }
go
{ "resource": "" }
q16915
Encode
train
func Encode(w io.Writer, src image.Image, opt *EncoderOptions) (err error) { // Recover panic defer func() { if r := recover(); r != nil { var ok bool err, ok = r.(error) if !ok { err = fmt.Errorf("JPEG error: %v", r) } } }() cinfo := C.new_compress() defer C.destroy_compress(cinfo) dstManager := makeDestinationManager(w, cinfo) defer releaseDestinationManager(dstManager) switch s := src.(type) { case *image.YCbCr: err = encodeYCbCr(cinfo, s, opt) case *image.Gray: err = encodeGray(cinfo, s, opt) case *image.RGBA: err = encodeRGBA(cinfo, s, opt) default: return errors.New("unsupported image type") } return }
go
{ "resource": "" }
q16916
encodeYCbCr
train
func encodeYCbCr(cinfo *C.struct_jpeg_compress_struct, src *image.YCbCr, p *EncoderOptions) (err error) { // Set up compression parameters cinfo.image_width = C.JDIMENSION(src.Bounds().Dx()) cinfo.image_height = C.JDIMENSION(src.Bounds().Dy()) cinfo.input_components = 3 cinfo.in_color_space = C.JCS_YCbCr C.jpeg_set_defaults(cinfo) setupEncoderOptions(cinfo, p) compInfo := (*[3]C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info)) colorVDiv := 1 switch src.SubsampleRatio { case image.YCbCrSubsampleRatio444: // 1x1,1x1,1x1 compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 1 compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1 compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1 case image.YCbCrSubsampleRatio440: // 1x2,1x1,1x1 compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 2 compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1 compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1 colorVDiv = 2 case image.YCbCrSubsampleRatio422: // 2x1,1x1,1x1 compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 2, 1 compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1 compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1 case image.YCbCrSubsampleRatio420: // 2x2,1x1,1x1 compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 2, 2 compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1 compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1 colorVDiv = 2 } // libjpeg raw data in is in planar format, which avoids unnecessary // planar->packed->planar conversions. cinfo.raw_data_in = C.TRUE // Start compression C.jpeg_start_compress(cinfo, C.TRUE) C.encode_ycbcr( cinfo, C.JSAMPROW(unsafe.Pointer(&src.Y[0])), C.JSAMPROW(unsafe.Pointer(&src.Cb[0])), C.JSAMPROW(unsafe.Pointer(&src.Cr[0])), C.int(src.YStride), C.int(src.CStride), C.int(colorVDiv), ) C.jpeg_finish_compress(cinfo) return }
go
{ "resource": "" }
q16917
encodeRGBA
train
func encodeRGBA(cinfo *C.struct_jpeg_compress_struct, src *image.RGBA, p *EncoderOptions) (err error) { // Set up compression parameters cinfo.image_width = C.JDIMENSION(src.Bounds().Dx()) cinfo.image_height = C.JDIMENSION(src.Bounds().Dy()) cinfo.input_components = 4 cinfo.in_color_space = getJCS_EXT_RGBA() if cinfo.in_color_space == C.JCS_UNKNOWN { return errors.New("JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)") } C.jpeg_set_defaults(cinfo) setupEncoderOptions(cinfo, p) // Start compression C.jpeg_start_compress(cinfo, C.TRUE) C.encode_rgba(cinfo, C.JSAMPROW(unsafe.Pointer(&src.Pix[0])), C.int(src.Stride)) C.jpeg_finish_compress(cinfo) return }
go
{ "resource": "" }
q16918
encodeGray
train
func encodeGray(cinfo *C.struct_jpeg_compress_struct, src *image.Gray, p *EncoderOptions) (err error) { // Set up compression parameters cinfo.image_width = C.JDIMENSION(src.Bounds().Dx()) cinfo.image_height = C.JDIMENSION(src.Bounds().Dy()) cinfo.input_components = 1 cinfo.in_color_space = C.JCS_GRAYSCALE C.jpeg_set_defaults(cinfo) setupEncoderOptions(cinfo, p) compInfo := (*C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info)) compInfo.h_samp_factor, compInfo.v_samp_factor = 1, 1 // libjpeg raw data in is in planar format, which avoids unnecessary // planar->packed->planar conversions. cinfo.raw_data_in = C.TRUE // Start compression C.jpeg_start_compress(cinfo, C.TRUE) C.encode_gray(cinfo, C.JSAMPROW(unsafe.Pointer(&src.Pix[0])), C.int(src.Stride)) C.jpeg_finish_compress(cinfo) return }
go
{ "resource": "" }
q16919
SetTaskLostBehavior
train
func (r *Residency) SetTaskLostBehavior(behavior TaskLostBehaviorType) *Residency { r.TaskLostBehavior = behavior return r }
go
{ "resource": "" }
q16920
SetRelaunchEscalationTimeout
train
func (r *Residency) SetRelaunchEscalationTimeout(timeout time.Duration) *Residency { r.RelaunchEscalationTimeoutSeconds = int(timeout.Seconds()) return r }
go
{ "resource": "" }
q16921
SetBackoff
train
func (p *PodBackoff) SetBackoff(backoffSeconds int) *PodBackoff { p.Backoff = &backoffSeconds return p }
go
{ "resource": "" }
q16922
SetBackoffFactor
train
func (p *PodBackoff) SetBackoffFactor(backoffFactor float64) *PodBackoff { p.BackoffFactor = &backoffFactor return p }
go
{ "resource": "" }
q16923
SetMaxLaunchDelay
train
func (p *PodBackoff) SetMaxLaunchDelay(maxLaunchDelaySeconds int) *PodBackoff { p.MaxLaunchDelay = &maxLaunchDelaySeconds return p }
go
{ "resource": "" }
q16924
SetMinimumHealthCapacity
train
func (p *PodUpgrade) SetMinimumHealthCapacity(capacity float64) *PodUpgrade { p.MinimumHealthCapacity = &capacity return p }
go
{ "resource": "" }
q16925
SetMaximumOverCapacity
train
func (p *PodUpgrade) SetMaximumOverCapacity(capacity float64) *PodUpgrade { p.MaximumOverCapacity = &capacity return p }
go
{ "resource": "" }
q16926
SetBackoff
train
func (p *PodSchedulingPolicy) SetBackoff(backoff *PodBackoff) *PodSchedulingPolicy { p.Backoff = backoff return p }
go
{ "resource": "" }
q16927
SetUpgrade
train
func (p *PodSchedulingPolicy) SetUpgrade(upgrade *PodUpgrade) *PodSchedulingPolicy { p.Upgrade = upgrade return p }
go
{ "resource": "" }
q16928
SetPlacement
train
func (p *PodSchedulingPolicy) SetPlacement(placement *PodPlacement) *PodSchedulingPolicy { p.Placement = placement return p }
go
{ "resource": "" }
q16929
SetKillSelection
train
func (p *PodSchedulingPolicy) SetKillSelection(killSelection string) *PodSchedulingPolicy { p.KillSelection = killSelection return p }
go
{ "resource": "" }
q16930
SetUnreachableStrategy
train
func (p *PodSchedulingPolicy) SetUnreachableStrategy(strategy EnabledUnreachableStrategy) *PodSchedulingPolicy { p.UnreachableStrategy = &UnreachableStrategy{ EnabledUnreachableStrategy: strategy, } return p }
go
{ "resource": "" }
q16931
SetUnreachableStrategyDisabled
train
func (p *PodSchedulingPolicy) SetUnreachableStrategyDisabled() *PodSchedulingPolicy { p.UnreachableStrategy = &UnreachableStrategy{ AbsenceReason: UnreachableStrategyAbsenceReasonDisabled, } return p }
go
{ "resource": "" }
q16932
UnmarshalJSON
train
func (us *UnreachableStrategy) UnmarshalJSON(b []byte) error { var u unreachableStrategy var errEnabledUS, errNonEnabledUS error if errEnabledUS = json.Unmarshal(b, &u); errEnabledUS == nil { *us = UnreachableStrategy(u) return nil } if errNonEnabledUS = json.Unmarshal(b, &us.AbsenceReason); errNonEnabledUS == nil { return nil } return fmt.Errorf("failed to unmarshal unreachable strategy: unmarshaling into enabled returned error '%s'; unmarshaling into non-enabled returned error '%s'", errEnabledUS, errNonEnabledUS) }
go
{ "resource": "" }
q16933
MarshalJSON
train
func (us *UnreachableStrategy) MarshalJSON() ([]byte, error) { if us.AbsenceReason == "" { return json.Marshal(us.EnabledUnreachableStrategy) } return json.Marshal(us.AbsenceReason) }
go
{ "resource": "" }
q16934
SetInactiveAfterSeconds
train
func (us *UnreachableStrategy) SetInactiveAfterSeconds(cap float64) *UnreachableStrategy { us.InactiveAfterSeconds = &cap return us }
go
{ "resource": "" }
q16935
SetExpungeAfterSeconds
train
func (us *UnreachableStrategy) SetExpungeAfterSeconds(cap float64) *UnreachableStrategy { us.ExpungeAfterSeconds = &cap return us }
go
{ "resource": "" }
q16936
SetCommand
train
func (h *HealthCheck) SetCommand(c Command) *HealthCheck { h.Command = &c return h }
go
{ "resource": "" }
q16937
SetPortIndex
train
func (h *HealthCheck) SetPortIndex(i int) *HealthCheck { h.PortIndex = &i return h }
go
{ "resource": "" }
q16938
SetPort
train
func (h *HealthCheck) SetPort(i int) *HealthCheck { h.Port = &i return h }
go
{ "resource": "" }
q16939
SetPath
train
func (h *HealthCheck) SetPath(p string) *HealthCheck { h.Path = &p return h }
go
{ "resource": "" }
q16940
SetMaxConsecutiveFailures
train
func (h *HealthCheck) SetMaxConsecutiveFailures(i int) *HealthCheck { h.MaxConsecutiveFailures = &i return h }
go
{ "resource": "" }
q16941
SetIgnoreHTTP1xx
train
func (h *HealthCheck) SetIgnoreHTTP1xx(ignore bool) *HealthCheck { h.IgnoreHTTP1xx = &ignore return h }
go
{ "resource": "" }
q16942
NewDefaultHealthCheck
train
func NewDefaultHealthCheck() *HealthCheck { portIndex := 0 path := "" maxConsecutiveFailures := 3 return &HealthCheck{ Protocol: "HTTP", Path: &path, PortIndex: &portIndex, MaxConsecutiveFailures: &maxConsecutiveFailures, GracePeriodSeconds: 30, IntervalSeconds: 10, TimeoutSeconds: 5, } }
go
{ "resource": "" }
q16943
SetGracePeriod
train
func (p *PodHealthCheck) SetGracePeriod(gracePeriodSeconds int) *PodHealthCheck { p.GracePeriodSeconds = &gracePeriodSeconds return p }
go
{ "resource": "" }
q16944
SetInterval
train
func (p *PodHealthCheck) SetInterval(intervalSeconds int) *PodHealthCheck { p.IntervalSeconds = &intervalSeconds return p }
go
{ "resource": "" }
q16945
SetMaxConsecutiveFailures
train
func (p *PodHealthCheck) SetMaxConsecutiveFailures(maxFailures int) *PodHealthCheck { p.MaxConsecutiveFailures = &maxFailures return p }
go
{ "resource": "" }
q16946
SetTimeout
train
func (p *PodHealthCheck) SetTimeout(timeoutSeconds int) *PodHealthCheck { p.TimeoutSeconds = &timeoutSeconds return p }
go
{ "resource": "" }
q16947
SetDelay
train
func (p *PodHealthCheck) SetDelay(delaySeconds int) *PodHealthCheck { p.DelaySeconds = &delaySeconds return p }
go
{ "resource": "" }
q16948
SetPath
train
func (h *HTTPHealthCheck) SetPath(path string) *HTTPHealthCheck { h.Path = path return h }
go
{ "resource": "" }
q16949
SetScheme
train
func (h *HTTPHealthCheck) SetScheme(scheme string) *HTTPHealthCheck { h.Scheme = scheme return h }
go
{ "resource": "" }
q16950
SetCommand
train
func (c *CommandHealthCheck) SetCommand(p PodCommand) *CommandHealthCheck { c.Command = p return c }
go
{ "resource": "" }
q16951
NewPod
train
func NewPod() *Pod { return &Pod{ Labels: map[string]string{}, Env: map[string]string{}, Containers: []*PodContainer{}, Secrets: map[string]Secret{}, Volumes: []*PodVolume{}, Networks: []*PodNetwork{}, } }
go
{ "resource": "" }
q16952
EmptyLabels
train
func (p *Pod) EmptyLabels() *Pod { p.Labels = make(map[string]string) return p }
go
{ "resource": "" }
q16953
AddLabel
train
func (p *Pod) AddLabel(key, value string) *Pod { p.Labels[key] = value return p }
go
{ "resource": "" }
q16954
SetLabels
train
func (p *Pod) SetLabels(labels map[string]string) *Pod { p.Labels = labels return p }
go
{ "resource": "" }
q16955
EmptyEnvs
train
func (p *Pod) EmptyEnvs() *Pod { p.Env = make(map[string]string) return p }
go
{ "resource": "" }
q16956
AddContainer
train
func (p *Pod) AddContainer(container *PodContainer) *Pod { p.Containers = append(p.Containers, container) return p }
go
{ "resource": "" }
q16957
EmptySecrets
train
func (p *Pod) EmptySecrets() *Pod { p.Secrets = make(map[string]Secret) return p }
go
{ "resource": "" }
q16958
GetSecretSource
train
func (p *Pod) GetSecretSource(name string) (string, error) { if val, ok := p.Secrets[name]; ok { return val.Source, nil } return "", fmt.Errorf("secret does not exist") }
go
{ "resource": "" }
q16959
AddSecret
train
func (p *Pod) AddSecret(envVar, secretName, sourceName string) *Pod { if p.Secrets == nil { p = p.EmptySecrets() } p.Secrets[secretName] = Secret{EnvVar: envVar, Source: sourceName} return p }
go
{ "resource": "" }
q16960
AddVolume
train
func (p *Pod) AddVolume(vol *PodVolume) *Pod { p.Volumes = append(p.Volumes, vol) return p }
go
{ "resource": "" }
q16961
AddNetwork
train
func (p *Pod) AddNetwork(net *PodNetwork) *Pod { p.Networks = append(p.Networks, net) return p }
go
{ "resource": "" }
q16962
Count
train
func (p *Pod) Count(count int) *Pod { p.Scaling = &PodScalingPolicy{ Kind: "fixed", Instances: count, } return p }
go
{ "resource": "" }
q16963
SetPodSchedulingPolicy
train
func (p *Pod) SetPodSchedulingPolicy(policy *PodSchedulingPolicy) *Pod { p.Scheduling = policy return p }
go
{ "resource": "" }
q16964
SetExecutorResources
train
func (p *Pod) SetExecutorResources(resources *ExecutorResources) *Pod { p.ExecutorResources = resources return p }
go
{ "resource": "" }
q16965
SupportsPods
train
func (r *marathonClient) SupportsPods() (bool, error) { if err := r.apiHead(marathonAPIPods, nil); err != nil { // If we get a 404 we can return a strict false, otherwise it could be // a valid error if apiErr, ok := err.(*APIError); ok && apiErr.ErrCode == ErrCodeNotFound { return false, nil } return false, err } return true, nil }
go
{ "resource": "" }
q16966
Pod
train
func (r *marathonClient) Pod(name string) (*Pod, error) { uri := buildPodURI(name) result := new(Pod) if err := r.apiGet(uri, nil, result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16967
Pods
train
func (r *marathonClient) Pods() ([]Pod, error) { var result []Pod if err := r.apiGet(marathonAPIPods, nil, &result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16968
CreatePod
train
func (r *marathonClient) CreatePod(pod *Pod) (*Pod, error) { result := new(Pod) if err := r.apiPost(marathonAPIPods, &pod, result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16969
DeletePod
train
func (r *marathonClient) DeletePod(name string, force bool) (*DeploymentID, error) { uri := fmt.Sprintf("%s?force=%v", buildPodURI(name), force) deployID := new(DeploymentID) if err := r.apiDelete(uri, nil, deployID); err != nil { return nil, err } return deployID, nil }
go
{ "resource": "" }
q16970
UpdatePod
train
func (r *marathonClient) UpdatePod(pod *Pod, force bool) (*Pod, error) { uri := fmt.Sprintf("%s?force=%v", buildPodURI(pod.ID), force) result := new(Pod) if err := r.apiPut(uri, pod, result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16971
PodVersions
train
func (r *marathonClient) PodVersions(name string) ([]string, error) { uri := buildPodVersionURI(name) var result []string if err := r.apiGet(uri, nil, &result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16972
PodByVersion
train
func (r *marathonClient) PodByVersion(name, version string) (*Pod, error) { uri := fmt.Sprintf("%s/%s", buildPodVersionURI(name), version) result := new(Pod) if err := r.apiGet(uri, nil, result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16973
SetPersistentVolume
train
func (v *Volume) SetPersistentVolume() *PersistentVolume { ev := &PersistentVolume{} v.Persistent = ev return ev }
go
{ "resource": "" }
q16974
NewDockerContainer
train
func NewDockerContainer() *Container { container := &Container{} container.Type = "DOCKER" container.Docker = &Docker{} return container }
go
{ "resource": "" }
q16975
SetMinimumHealthCapacity
train
func (us *UpgradeStrategy) SetMinimumHealthCapacity(cap float64) *UpgradeStrategy { us.MinimumHealthCapacity = &cap return us }
go
{ "resource": "" }
q16976
SetMaximumOverCapacity
train
func (us *UpgradeStrategy) SetMaximumOverCapacity(cap float64) *UpgradeStrategy { us.MaximumOverCapacity = &cap return us }
go
{ "resource": "" }
q16977
Subscriptions
train
func (r *marathonClient) Subscriptions() (*Subscriptions, error) { subscriptions := new(Subscriptions) if err := r.apiGet(marathonAPISubscription, nil, subscriptions); err != nil { return nil, err } return subscriptions, nil }
go
{ "resource": "" }
q16978
SubscriptionURL
train
func (r *marathonClient) SubscriptionURL() string { if r.config.CallbackURL != "" { return fmt.Sprintf("%s%s", r.config.CallbackURL, defaultEventsURL) } return fmt.Sprintf("http://%s:%d%s", r.ipAddress, r.config.EventsPort, defaultEventsURL) }
go
{ "resource": "" }
q16979
registerSubscription
train
func (r *marathonClient) registerSubscription() error { switch r.config.EventsTransport { case EventsTransportCallback: return r.registerCallbackSubscription() case EventsTransportSSE: return r.registerSSESubscription() default: return fmt.Errorf("the events transport: %d is not supported", r.config.EventsTransport) } }
go
{ "resource": "" }
q16980
registerSSESubscription
train
func (r *marathonClient) registerSSESubscription() error { if r.subscribedToSSE { return nil } if r.config.HTTPSSEClient.Timeout != 0 { return fmt.Errorf( "global timeout must not be set for SSE connections (found %s) -- remove global timeout from HTTP client or provide separate SSE HTTP client without global timeout", r.config.HTTPSSEClient.Timeout, ) } go func() { for { stream, err := r.connectToSSE() if err != nil { r.debugLog("Error connecting SSE subscription: %s", err) <-time.After(5 * time.Second) continue } err = r.listenToSSE(stream) stream.Close() r.debugLog("Error on SSE subscription: %s", err) } }() r.subscribedToSSE = true return nil }
go
{ "resource": "" }
q16981
Queue
train
func (r *marathonClient) Queue() (*Queue, error) { var queue *Queue err := r.apiGet(marathonAPIQueue, nil, &queue) if err != nil { return nil, err } return queue, nil }
go
{ "resource": "" }
q16982
newCluster
train
func newCluster(client *httpClient, marathonURL string, isDCOS bool) (*cluster, error) { // step: extract and basic validate the endpoints var members []*member var defaultProto string for _, endpoint := range strings.Split(marathonURL, ",") { // step: check for nothing if endpoint == "" { return nil, newInvalidEndpointError("endpoint is blank") } // step: prepend scheme if missing on (non-initial) endpoint. if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") { if defaultProto == "" { return nil, newInvalidEndpointError("missing scheme on (first) endpoint") } endpoint = fmt.Sprintf("%s://%s", defaultProto, endpoint) } // step: parse the url u, err := url.Parse(endpoint) if err != nil { return nil, newInvalidEndpointError("invalid endpoint '%s': %s", endpoint, err) } if defaultProto == "" { defaultProto = u.Scheme } // step: check for empty hosts if u.Host == "" { return nil, newInvalidEndpointError("endpoint: %s must have a host", endpoint) } // step: if DCOS is set and no path is given, set the default DCOS path. // done in order to maintain compatibility with automatic addition of the // default DCOS path. if isDCOS && strings.TrimLeft(u.Path, "/") == "" { u.Path = defaultDCOSPath } // step: create a new node for this endpoint members = append(members, &member{endpoint: u.String()}) } return &cluster{ client: client, members: members, healthCheckInterval: 5 * time.Second, }, nil }
go
{ "resource": "" }
q16983
getMember
train
func (c *cluster) getMember() (string, error) { c.RLock() defer c.RUnlock() for _, n := range c.members { if n.status == memberStatusUp { return n.endpoint, nil } } return "", ErrMarathonDown }
go
{ "resource": "" }
q16984
markDown
train
func (c *cluster) markDown(endpoint string) { c.Lock() defer c.Unlock() for _, n := range c.members { // step: check if this is the node and it's marked as up - The double checking on the // nodes status ensures the multiple calls don't create multiple checks if n.status == memberStatusUp && n.endpoint == endpoint { n.status = memberStatusDown go c.healthCheckNode(n) break } } }
go
{ "resource": "" }
q16985
healthCheckNode
train
func (c *cluster) healthCheckNode(node *member) { // step: wait for the node to become active ... we are assuming a /ping is enough here ticker := time.NewTicker(c.healthCheckInterval) defer ticker.Stop() for range ticker.C { req, err := c.client.buildMarathonRequest("GET", node.endpoint, "ping", nil) if err == nil { res, err := c.client.Do(req) if err == nil && res.StatusCode == 200 { // step: mark the node as active again c.Lock() node.status = memberStatusUp c.Unlock() break } } } }
go
{ "resource": "" }
q16986
membersList
train
func (c *cluster) membersList(status memberStatus) []string { c.RLock() defer c.RUnlock() var list []string for _, m := range c.members { if m.status == status { list = append(list, m.endpoint) } } return list }
go
{ "resource": "" }
q16987
String
train
func (m member) String() string { status := "UP" if m.status == memberStatusDown { status = "DOWN" } return fmt.Sprintf("member: %s:%s", m.endpoint, status) }
go
{ "resource": "" }
q16988
NewPodNetwork
train
func NewPodNetwork(name string) *PodNetwork { return &PodNetwork{ Name: name, Labels: map[string]string{}, } }
go
{ "resource": "" }
q16989
NewContainerPodNetwork
train
func NewContainerPodNetwork(name string) *PodNetwork { pn := NewPodNetwork(name) return pn.SetMode(ContainerNetworkMode) }
go
{ "resource": "" }
q16990
SetName
train
func (n *PodNetwork) SetName(name string) *PodNetwork { n.Name = name return n }
go
{ "resource": "" }
q16991
SetMode
train
func (n *PodNetwork) SetMode(mode PodNetworkMode) *PodNetwork { n.Mode = mode return n }
go
{ "resource": "" }
q16992
Label
train
func (n *PodNetwork) Label(key, value string) *PodNetwork { n.Labels[key] = value return n }
go
{ "resource": "" }
q16993
SetName
train
func (e *PodEndpoint) SetName(name string) *PodEndpoint { e.Name = name return e }
go
{ "resource": "" }
q16994
SetContainerPort
train
func (e *PodEndpoint) SetContainerPort(port int) *PodEndpoint { e.ContainerPort = port return e }
go
{ "resource": "" }
q16995
SetHostPort
train
func (e *PodEndpoint) SetHostPort(port int) *PodEndpoint { e.HostPort = port return e }
go
{ "resource": "" }
q16996
AddProtocol
train
func (e *PodEndpoint) AddProtocol(protocol string) *PodEndpoint { e.Protocol = append(e.Protocol, protocol) return e }
go
{ "resource": "" }
q16997
Label
train
func (e *PodEndpoint) Label(key, value string) *PodEndpoint { e.Labels[key] = value return e }
go
{ "resource": "" }
q16998
DeletePodInstances
train
func (r *marathonClient) DeletePodInstances(name string, instances []string) ([]*PodInstance, error) { uri := buildPodInstancesURI(name) var result []*PodInstance if err := r.apiDelete(uri, instances, &result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }
q16999
DeletePodInstance
train
func (r *marathonClient) DeletePodInstance(name, instance string) (*PodInstance, error) { uri := fmt.Sprintf("%s/%s", buildPodInstancesURI(name), instance) result := new(PodInstance) if err := r.apiDelete(uri, nil, result); err != nil { return nil, err } return result, nil }
go
{ "resource": "" }