示例#1
0
// PlannerSteps helps command-line tools implement the planner steps:
// * "unregister" - unregisters nodesToRemove from the cfg.
// * "planner" - runs the planner to save a new plan into the cfg.
//
// The default steps are "unregister" and "planner".
//
// An additional composite step, "FAILOVER" (fully capitalized), is
// used to process the nodesToRemove as nodes to be failover'ed.
// "FAILOVER" is comprised of the lower-level steps of "unregister"
// and "failover" (all lowercase).
func PlannerSteps(steps map[string]bool,
	cfg cbgt.Cfg, version, server string, nodesToRemove []string,
	dryRun bool) error {
	if steps == nil || steps["unregister"] || steps["FAILOVER"] {
		log.Printf("planner: step unregister")

		if !dryRun {
			err := cbgt.UnregisterNodes(cfg, cbgt.VERSION, nodesToRemove)
			if err != nil {
				return err
			}
		}
	}

	if steps == nil || steps["planner"] {
		log.Printf("planner: step planner")

		if !dryRun {
			_, err := cbgt.Plan(cfg, cbgt.VERSION, "", server)
			if err != nil {
				return err
			}
		}
	}

	if steps["failover"] || steps["FAILOVER"] {
		log.Printf("planner: step failover")

		if !dryRun {
			_, err := Failover(cfg, cbgt.VERSION, server, nodesToRemove)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
示例#2
0
文件: planner.go 项目: couchbase/cbgt
// PlannerSteps helps command-line tools implement the planner steps:
// * "unregister" - unregisters nodesRemove from the cfg.
// * "planner" - runs the planner to save a new plan into the cfg.
// * "failover" - a composite step, comprised of "unregister" and "failover_".
// * "failover_" - processes the nodesRemove as nodes to be failover'ed.
//
// The "NODES-REMOVE-ALL" step overrides the nodesRemove with every
// known and wanted node.  This can have a lot of impact, and was
// meant to be used for cluster cleanup/purging situations.
func PlannerSteps(steps map[string]bool,
	cfg cbgt.Cfg, version, server string, options map[string]string,
	nodesRemove []string, dryRun bool, plannerFilter cbgt.PlannerFilter) error {
	if steps != nil && steps["failover"] {
		steps["unregister"] = true
		steps["failover_"] = true
	}

	if steps != nil && steps["NODES-REMOVE-ALL"] {
		nodesRemove = nil

		nodesSeen := map[string]bool{}
		for _, kind := range []string{
			cbgt.NODE_DEFS_WANTED,
			cbgt.NODE_DEFS_KNOWN,
		} {
			nodeDefs, _, err := cbgt.CfgGetNodeDefs(cfg, kind)
			if err != nil {
				return err
			}

			for _, nodeDef := range nodeDefs.NodeDefs {
				if !nodesSeen[nodeDef.UUID] {
					nodesSeen[nodeDef.UUID] = true
					nodesRemove = append(nodesRemove, nodeDef.UUID)
				}
			}
		}
	}

	log.Printf("planner: nodesRemove: %#v", nodesRemove)

	if steps != nil && steps["unregister"] {
		log.Printf("planner: step unregister")

		if !dryRun {
			err := cbgt.UnregisterNodes(cfg, cbgt.VERSION, nodesRemove)
			if err != nil {
				return err
			}
		}
	}

	if steps != nil && steps["planner"] {
		log.Printf("planner: step planner")

		if !dryRun {
			_, err :=
				cbgt.Plan(cfg, cbgt.VERSION, "", server, options, plannerFilter)
			if err != nil {
				return err
			}
		}
	}

	if steps != nil && steps["failover_"] {
		log.Printf("planner: step failover_")

		if !dryRun {
			_, err := Failover(cfg, cbgt.VERSION, server, options, nodesRemove)
			if err != nil {
				return err
			}
		}
	}

	return nil
}