14714: Adds keep-balance to cluster config loading
[arvados.git] / lib / config / deprecated.go
index 0a030fb040db9d36de290e29d67f84db76b8522c..ba2c79acf197a07f0cd520864d690e8c21bb511a 100644 (file)
@@ -474,3 +474,71 @@ func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
        cfg.Clusters[cluster.ClusterID] = *cluster
        return nil
 }
+
+const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
+
+type oldKeepBalanceConfig struct {
+       Client              *arvados.Client
+       Listen              *string
+       KeepServiceTypes    *[]string
+       KeepServiceList     *arvados.KeepServiceList
+       RunPeriod           *arvados.Duration
+       CollectionBatchSize *int
+       CollectionBuffers   *int
+       RequestTimeout      *arvados.Duration
+       LostBlocksFile      *string
+       ManagementToken     *string
+}
+
+func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
+       if ldr.KeepBalancePath == "" {
+               return nil
+       }
+       var oc oldKeepBalanceConfig
+       err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
+       if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
+               return nil
+       } else if err != nil {
+               return err
+       }
+
+       cluster, err := cfg.GetCluster("")
+       if err != nil {
+               return err
+       }
+
+       loadOldClientConfig(cluster, oc.Client)
+
+       if oc.Listen != nil {
+               cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
+       }
+       if oc.ManagementToken != nil {
+               cluster.ManagementToken = *oc.ManagementToken
+       }
+       if oc.RunPeriod != nil {
+               cluster.Collections.BalancePeriod = *oc.RunPeriod
+       }
+       if oc.LostBlocksFile != nil {
+               cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
+       }
+       if oc.CollectionBatchSize != nil {
+               cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
+       }
+       if oc.CollectionBuffers != nil {
+               cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
+       }
+       if oc.RequestTimeout != nil {
+               cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
+       }
+
+       msg := "To balance specfic keep services, please update to the cluster config."
+       if oc.KeepServiceTypes != nil && len(*oc.KeepServiceTypes) > 0 {
+               ldr.Logger.Warnf("The KeepServiceType configuration option is not longer supported and is being ignored. %s", msg)
+       }
+       if oc.KeepServiceList != nil {
+               return fmt.Errorf("The KeepServiceList configuration option is no longer supported. Please remove it from your configuration file. %s", msg)
+       }
+
+       cfg.Clusters[cluster.ClusterID] = *cluster
+       return nil
+}