github.com/bndr/gojenkins@v1.1.0/label.go (about) 1 // Copyright 2015 Vadim Kravcenko 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package gojenkins 16 17 import "context" 18 19 type Label struct { 20 Raw *LabelResponse 21 Jenkins *Jenkins 22 Base string 23 } 24 25 type MODE string 26 27 const ( 28 NORMAL MODE = "NORMAL" 29 EXCLUSIVE = "EXCLUSIVE" 30 ) 31 32 type LabelNode struct { 33 NodeName string `json:"nodeName"` 34 NodeDescription string `json:"nodeDescription"` 35 NumExecutors int64 `json:"numExecutors"` 36 Mode string `json:"mode"` 37 Class string `json:"_class"` 38 } 39 40 type LabelResponse struct { 41 Name string `json:"name"` 42 Description string `json:"description"` 43 Nodes []LabelNode `json:"nodes"` 44 Offline bool `json:"offline"` 45 IdleExecutors int64 `json:"idleExecutors"` 46 BusyExecutors int64 `json:"busyExecutors"` 47 TotalExecutors int64 `json:"totalExecutors"` 48 } 49 50 func (l *Label) GetName() string { 51 return l.Raw.Name 52 } 53 54 func (l *Label) GetNodes() []LabelNode { 55 return l.Raw.Nodes 56 } 57 58 func (l *Label) Poll(ctx context.Context) (int, error) { 59 response, err := l.Jenkins.Requester.GetJSON(ctx, l.Base, l.Raw, nil) 60 if err != nil { 61 return 0, err 62 } 63 return response.StatusCode, nil 64 }