From 44f3c20e502eddf5f2606cffc702582cd0ee6e9c Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Thu, 22 Jan 2015 11:14:28 -0800 Subject: [PATCH] command/maint: clean up --- command/agent/agent.go | 22 +++++++++++----------- command/maint.go | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 95ef455725..5aeb783a80 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -32,8 +32,8 @@ const ( "and try again." // The ID of the faux health checks for maintenance mode - ServiceMaintCheckPrefix = "_service_maintenance" - NodeMaintCheckID = "_node_maintenance" + serviceMaintCheckPrefix = "_service_maintenance" + nodeMaintCheckID = "_node_maintenance" // Default reasons for node/service maintenance mode defaultNodeMaintReason = "Maintenance mode is enabled for this node, " + @@ -1028,7 +1028,7 @@ func (a *Agent) unloadChecks() error { // serviceMaintCheckID returns the ID of a given service's maintenance check func serviceMaintCheckID(serviceID string) string { - return fmt.Sprintf("%s:%s", ServiceMaintCheckPrefix, serviceID) + return fmt.Sprintf("%s:%s", serviceMaintCheckPrefix, serviceID) } // EnableServiceMaintenance will register a false health check against the given @@ -1061,7 +1061,7 @@ func (a *Agent) EnableServiceMaintenance(serviceID, reason string) error { Status: structs.HealthCritical, } a.AddCheck(check, nil, true) - a.logger.Printf("[INFO] agent: service %q entered maintenance mode", serviceID) + a.logger.Printf("[INFO] agent: Service %q entered maintenance mode", serviceID) return nil } @@ -1081,7 +1081,7 @@ func (a *Agent) DisableServiceMaintenance(serviceID string) error { // Deregister the maintenance check a.RemoveCheck(checkID, true) - a.logger.Printf("[INFO] agent: service %q left maintenance mode", serviceID) + a.logger.Printf("[INFO] agent: Service %q left maintenance mode", serviceID) return nil } @@ -1089,7 +1089,7 @@ func (a *Agent) DisableServiceMaintenance(serviceID string) error { // EnableNodeMaintenance places a node into maintenance mode. func (a *Agent) EnableNodeMaintenance(reason string) { // Ensure node maintenance is not already enabled - if _, ok := a.state.Checks()[NodeMaintCheckID]; ok { + if _, ok := a.state.Checks()[nodeMaintCheckID]; ok { return } @@ -1101,20 +1101,20 @@ func (a *Agent) EnableNodeMaintenance(reason string) { // Create and register the node maintenance check check := &structs.HealthCheck{ Node: a.config.NodeName, - CheckID: NodeMaintCheckID, + CheckID: nodeMaintCheckID, Name: "Node Maintenance Mode", Notes: reason, Status: structs.HealthCritical, } a.AddCheck(check, nil, true) - a.logger.Printf("[INFO] agent: node entered maintenance mode") + a.logger.Printf("[INFO] agent: Node entered maintenance mode") } // DisableNodeMaintenance removes a node from maintenance mode func (a *Agent) DisableNodeMaintenance() { - if _, ok := a.state.Checks()[NodeMaintCheckID]; !ok { + if _, ok := a.state.Checks()[nodeMaintCheckID]; !ok { return } - a.RemoveCheck(NodeMaintCheckID, true) - a.logger.Printf("[INFO] agent: node left maintenance mode") + a.RemoveCheck(nodeMaintCheckID, true) + a.logger.Printf("[INFO] agent: Node left maintenance mode") } diff --git a/command/maint.go b/command/maint.go index eb8d6ef518..4c89c34825 100644 --- a/command/maint.go +++ b/command/maint.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/command/agent" "github.com/mitchellh/cli" ) @@ -109,12 +108,12 @@ func (c *MaintCommand) Run(args []string) int { } for _, check := range checks { - if check.CheckID == agent.NodeMaintCheckID { + if check.CheckID == "_node_maintenance" { c.Ui.Output("Node:") c.Ui.Output(" Name: " + nodeName) c.Ui.Output(" Reason: " + check.Notes) c.Ui.Output("") - } else if strings.HasPrefix(check.CheckID, agent.ServiceMaintCheckPrefix) { + } else if strings.HasPrefix(check.CheckID, "_service_maintenance:") { c.Ui.Output("Service:") c.Ui.Output(" ID: " + check.ServiceID) c.Ui.Output(" Reason: " + check.Notes)