From 704afc22596e39b06bf32ee7ea6f38910f779260 Mon Sep 17 00:00:00 2001 From: JC Martin Date: Thu, 10 May 2018 12:36:12 -0700 Subject: [PATCH] Add startMaintenance --- realis.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/realis.go b/realis.go index 84c8b1e..86cc6eb 100644 --- a/realis.go +++ b/realis.go @@ -72,6 +72,7 @@ type Realis interface { // Admin functions DrainHosts(hosts ...string) (*aurora.Response, *aurora.DrainHostsResult_, error) + StartMaintenance(hosts ...string) (*aurora.Response, *aurora.StartMaintenanceResult_, error) EndMaintenance(hosts ...string) (*aurora.Response, *aurora.EndMaintenanceResult_, error) MaintenanceStatus(hosts ...string) (*aurora.Response, *aurora.MaintenanceStatusResult_, error) SetQuota(role string, cpu *float64, ram *int64, disk *int64) (*aurora.Response, error) @@ -984,6 +985,37 @@ func (r *realisClient) DrainHosts(hosts ...string) (*aurora.Response, *aurora.Dr return resp, result, nil } +func (r *realisClient) StartMaintenance(hosts ...string) (*aurora.Response, *aurora.StartMaintenanceResult_, error) { + + var result *aurora.StartMaintenanceResult_ + + if len(hosts) == 0 { + return nil, nil, errors.New("no hosts provided to start maintenance on") + } + + hostList := aurora.NewHosts() + hostList.HostNames = make(map[string]bool) + for _, host := range hosts { + hostList.HostNames[host] = true + } + + r.logger.DebugPrintf("StartMaintenance Thrift Payload: %v\n", hostList) + + resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) { + return r.adminClient.StartMaintenance(hostList) + }) + + if resp.GetResult_() != nil { + result = resp.GetResult_().GetStartMaintenanceResult_() + } + + if retryErr != nil { + return resp, result, errors.Wrap(retryErr, "Unable to recover connection") + } + + return resp, result, nil +} + func (r *realisClient) EndMaintenance(hosts ...string) (*aurora.Response, *aurora.EndMaintenanceResult_, error) { var result *aurora.EndMaintenanceResult_ @@ -1015,6 +1047,7 @@ func (r *realisClient) EndMaintenance(hosts ...string) (*aurora.Response, *auror return resp, result, nil } + func (r *realisClient) MaintenanceStatus(hosts ...string) (*aurora.Response, *aurora.MaintenanceStatusResult_, error) { var result *aurora.MaintenanceStatusResult_