Use topo.ParseTabletType everywhere now.

This commit is contained in:
Alain Jobart 2015-08-10 11:16:54 -07:00
Родитель e3fcf35b2a
Коммит 57838636dc
6 изменённых файлов: 22 добавлений и 26 удалений

Просмотреть файл

@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"path"
"strings"
"time"
"github.com/coreos/go-etcd/etcd"
@ -43,8 +42,8 @@ func (s *Server) GetSrvTabletTypesPerShard(ctx context.Context, cellName, keyspa
tabletTypes := make([]pb.TabletType, 0, len(resp.Node.Nodes))
for _, n := range resp.Node.Nodes {
strType := path.Base(n.Key)
if tt, ok := pb.TabletType_value[strings.ToUpper(strType)]; ok {
tabletTypes = append(tabletTypes, pb.TabletType(tt))
if tt, err := topo.ParseTabletType(strType); err == nil {
tabletTypes = append(tabletTypes, tt)
}
}
return tabletTypes, nil

Просмотреть файл

@ -13,7 +13,6 @@ import (
"fmt"
"html/template"
"reflect"
"strings"
"time"
log "github.com/golang/glog"
@ -104,9 +103,9 @@ func (agent *ActionAgent) initHealthCheck() {
return
}
tt, ok := pbt.TabletType_value[strings.ToUpper(*targetTabletType)]
if !ok {
log.Fatalf("Invalid target tablet type: %v", *targetTabletType)
tt, err := topo.ParseTabletType(*targetTabletType)
if err != nil {
log.Fatalf("Invalid target tablet type %v: %v", *targetTabletType, err)
}
log.Infof("Starting periodic health check every %v with target_tablet_type=%v", *healthCheckInterval, *targetTabletType)
@ -119,10 +118,10 @@ func (agent *ActionAgent) initHealthCheck() {
t.Stop()
// Now we can finish up and force ourselves to not healthy.
agent.terminateHealthChecks(pbt.TabletType(tt))
agent.terminateHealthChecks(tt)
})
t.Start(func() {
agent.runHealthCheck(pbt.TabletType(tt))
agent.runHealthCheck(tt)
})
t.Trigger()
}

Просмотреть файл

@ -53,16 +53,13 @@ func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error {
log.Fatalf("cannot specify both target_tablet_type and init_tablet_type parameters (as they might conflict)")
}
itt, ok := pb.TabletType_value[strings.ToUpper(*initTabletType)]
if !ok {
log.Fatalf("Invalid init tablet type: %v", *initTabletType)
// use the type specified on the command line
var err error
tabletType, err = topo.ParseTabletType(*initTabletType)
if err != nil {
log.Fatalf("Invalid init tablet type %v: %v", *initTabletType, err)
}
// use the type specified on the command line
tabletType = pb.TabletType(itt)
if !topo.IsTypeInList(tabletType, topo.AllTabletTypes) {
log.Fatalf("InitTablet encountered unknown init_tablet_type '%v'", *initTabletType)
}
if tabletType == pb.TabletType_MASTER || tabletType == pb.TabletType_SCRAP {
// We disallow TYPE_MASTER, so we don't have to change
// shard.MasterAlias, and deal with the corner cases.

Просмотреть файл

@ -18,10 +18,11 @@ import (
// TabletTypeToProto turns a TabletType into a proto
func TabletTypeToProto(t TabletType) pb.TabletType {
if result, ok := pb.TabletType_value[strings.ToUpper(string(t))]; ok {
return pb.TabletType(result)
if result, err := ParseTabletType(string(t)); err != nil {
panic(fmt.Errorf("unknown tablet type: %v", t))
} else {
return result
}
panic(fmt.Errorf("unknown tablet type: %v", t))
}
// ProtoToTabletType turns a proto to a TabletType

Просмотреть файл

@ -557,14 +557,14 @@ func tabletParamsToTabletAliases(params []string) ([]*pb.TabletAlias, error) {
// parseTabletType parses the string tablet type and verifies
// it is an accepted one
func parseTabletType(param string, types []pb.TabletType) (pb.TabletType, error) {
tabletType, ok := pb.TabletType_value[strings.ToUpper(param)]
if !ok {
return pb.TabletType_UNKNOWN, fmt.Errorf("invalid tablet type %v", param)
tabletType, err := topo.ParseTabletType(param)
if err != nil {
return pb.TabletType_UNKNOWN, fmt.Errorf("invalid tablet type %v: %v", param, err)
}
if !topo.IsTypeInList(pb.TabletType(tabletType), types) {
return pb.TabletType_UNKNOWN, fmt.Errorf("Type %v is not one of: %v", tabletType, strings.Join(topo.MakeStringTypeList(types), " "))
}
return pb.TabletType(tabletType), nil
return tabletType, nil
}
// parseKeyspaceIdType parses the keyspace id type into the enum

Просмотреть файл

@ -63,8 +63,8 @@ func (zkts *Server) GetSrvTabletTypesPerShard(ctx context.Context, cell, keyspac
if tt == "action" || tt == "actionlog" {
continue
}
if ptt, ok := pb.TabletType_value[strings.ToUpper(tt)]; ok {
result = append(result, pb.TabletType(ptt))
if ptt, err := topo.ParseTabletType(tt); err == nil {
result = append(result, ptt)
}
}
return result, nil