github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/boskos/common/common.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package common
    18  
    19  import (
    20  	"errors"
    21  	"fmt"
    22  	"strings"
    23  	"time"
    24  )
    25  
    26  type Resource struct {
    27  	Type       string    `json:"type"`
    28  	Name       string    `json:"name"`
    29  	State      string    `json:"state"`
    30  	Owner      string    `json:"owner"`
    31  	LastUpdate time.Time `json:"lastupdate"`
    32  }
    33  
    34  type Metric struct {
    35  	Type    string         `json:"type"`
    36  	Current map[string]int `json:"current"`
    37  	Owners  map[string]int `json:"owner"`
    38  	// TODO: Implement state transition metrics
    39  }
    40  
    41  type ResTypes []string
    42  
    43  func (r *ResTypes) String() string {
    44  	return fmt.Sprint(*r)
    45  }
    46  
    47  func (rtypes *ResTypes) Set(value string) error {
    48  	if len(*rtypes) > 0 {
    49  		return errors.New("resTypes flag already set")
    50  	}
    51  	for _, rtype := range strings.Split(value, ",") {
    52  		*rtypes = append(*rtypes, rtype)
    53  	}
    54  	return nil
    55  }