[ARVADOS] created: 1.1.4-488-gd95b795d2

Git user git at public.curoverse.com
Wed Jun 20 09:28:38 EDT 2018


        at  d95b795d26cbb613c150e67cbd2c819731a4d783 (commit)


commit d95b795d26cbb613c150e67cbd2c819731a4d783
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Wed Jun 20 09:24:25 2018 -0400

    13611: Change InstanceTypes config from array to hash.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/lib/dispatchcloud/node_size.go b/lib/dispatchcloud/node_size.go
index b5fd0262a..d752cd7cb 100644
--- a/lib/dispatchcloud/node_size.go
+++ b/lib/dispatchcloud/node_size.go
@@ -48,7 +48,9 @@ func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvad
 	needRAM = (needRAM * 100) / int64(100-discountConfiguredRAMPercent)
 
 	availableTypes := make([]arvados.InstanceType, len(cc.InstanceTypes))
-	copy(availableTypes, cc.InstanceTypes)
+	for _, t := range cc.InstanceTypes {
+		availableTypes = append(availableTypes, t)
+	}
 	sort.Slice(availableTypes, func(a, b int) bool {
 		return availableTypes[a].Price < availableTypes[b].Price
 	})
diff --git a/sdk/go/arvados/config.go b/sdk/go/arvados/config.go
index 841f95281..ed067d45b 100644
--- a/sdk/go/arvados/config.go
+++ b/sdk/go/arvados/config.go
@@ -5,6 +5,8 @@
 package arvados
 
 import (
+	"encoding/json"
+	"errors"
 	"fmt"
 	"os"
 
@@ -52,7 +54,7 @@ type Cluster struct {
 	ClusterID          string `json:"-"`
 	ManagementToken    string
 	NodeProfiles       map[string]NodeProfile
-	InstanceTypes      []InstanceType
+	InstanceTypes      InstanceTypeMap
 	HTTPRequestTimeout Duration
 }
 
@@ -66,6 +68,46 @@ type InstanceType struct {
 	Preemptable  bool
 }
 
+type InstanceTypeMap map[string]InstanceType
+
+var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
+
+// UnmarshalJSON handles old config files that provide an array of
+// instance types instead of a hash.
+func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
+	if len(data) > 0 && data[0] == '[' {
+		var arr []InstanceType
+		err := json.Unmarshal(data, &arr)
+		if err != nil {
+			return err
+		}
+		if len(arr) == 0 {
+			*it = nil
+			return nil
+		}
+		*it = make(map[string]InstanceType, len(arr))
+		for _, t := range arr {
+			if _, ok := (*it)[t.Name]; ok {
+				return errDuplicateInstanceTypeName
+			}
+			(*it)[t.Name] = t
+		}
+		return nil
+	}
+	var hash map[string]InstanceType
+	err := json.Unmarshal(data, &hash)
+	if err != nil {
+		return err
+	}
+	// Fill in Name field using hash key.
+	*it = InstanceTypeMap(hash)
+	for name, t := range *it {
+		t.Name = name
+		(*it)[name] = t
+	}
+	return nil
+}
+
 // GetNodeProfile returns a NodeProfile for the given hostname. An
 // error is returned if the appropriate configuration can't be
 // determined (e.g., this does not appear to be a system node). If
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index b4033e78b..23a8a0ca0 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -367,17 +367,17 @@ func (s *StubbedSuite) TestSbatchInstanceTypeConstraint(c *C) {
 	}
 
 	for _, trial := range []struct {
-		types      []arvados.InstanceType
+		types      map[string]arvados.InstanceType
 		sbatchArgs []string
 		err        error
 	}{
 		// Choose node type => use --constraint arg
 		{
-			types: []arvados.InstanceType{
-				{Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
-				{Name: "a1.small", Price: 0.04, RAM: 256000000, VCPUs: 2},
-				{Name: "a1.medium", Price: 0.08, RAM: 512000000, VCPUs: 4},
-				{Name: "a1.large", Price: 0.16, RAM: 1024000000, VCPUs: 8},
+			types: map[string]arvados.InstanceType{
+				"a1.tiny":   {Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
+				"a1.small":  {Name: "a1.small", Price: 0.04, RAM: 256000000, VCPUs: 2},
+				"a1.medium": {Name: "a1.medium", Price: 0.08, RAM: 512000000, VCPUs: 4},
+				"a1.large":  {Name: "a1.large", Price: 0.16, RAM: 1024000000, VCPUs: 8},
 			},
 			sbatchArgs: []string{"--constraint=instancetype=a1.medium"},
 		},
@@ -388,8 +388,8 @@ func (s *StubbedSuite) TestSbatchInstanceTypeConstraint(c *C) {
 		},
 		// No node type is big enough => error
 		{
-			types: []arvados.InstanceType{
-				{Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
+			types: map[string]arvados.InstanceType{
+				"a1.tiny": {Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
 			},
 			err: dispatchcloud.ConstraintsNotSatisfiableError{},
 		},

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list