Example #1
0
func runInit(cmd *cobra.Command, args []string) {
	driver, err := NewDriver(Context)
	if err != nil {
		log.Errorf("could not create driver: %v", err)
		return
	}

	nodes, err := docker.ListCockroachNodes()
	if err != nil {
		log.Errorf("failed to get list of existing cockroach nodes: %v", err)
		return
	}
	if len(nodes) != 0 {
		log.Errorf("init called but docker-machine has %d existing cockroach nodes: %v", len(nodes), nodes)
		return
	}

	nodeName := docker.MakeNodeName(0)

	// Create first node.
	err = docker.CreateMachine(driver, nodeName)
	if err != nil {
		log.Errorf("could not create machine %s: %v", nodeName, err)
		return
	}

	// Run driver steps after first-node creation.
	err = driver.AfterFirstNode()
	if err != nil {
		log.Errorf("could not run AfterFirstNode steps for: %v", err)
		return
	}

	// Lookup node info.
	nodeConfig, err := driver.GetNodeConfig(nodeName)
	if err != nil {
		log.Errorf("could not get node config for %s: %v", nodeName, err)
		return
	}

	// Initialize cockroach node.
	err = docker.RunDockerInit(driver, nodeName, nodeConfig)
	if err != nil {
		log.Errorf("could not initialize first cockroach node %s: %v", nodeName, err)
		return
	}

	// Do "start node" logic.
	err = driver.StartNode(nodeName, nodeConfig)
	if err != nil {
		log.Errorf("could not run StartNode steps for %s: %v", nodeName, err)
		return
	}

	// Start the cockroach node.
	err = docker.RunDockerStart(driver, nodeName, nodeConfig)
	if err != nil {
		log.Errorf("could not initialize first cockroach node %s: %v", nodeName, err)
	}
}
Example #2
0
func runStart(cmd *cobra.Command, args []string) {
	driver, err := NewDriver(Context)
	if err != nil {
		log.Errorf("could not create driver: %v", err)
		return
	}

	var nodes []string
	if len(args) == 0 {
		// TODO(marc): only get nodes in state "Stopped".
		nodes, err = docker.ListCockroachNodes()
		if err != nil {
			log.Errorf("failed to get list of existing cockroach nodes: %v", err)
			return
		}
		if len(nodes) == 0 {
			log.Errorf("no existing cockroach nodes detected, does the cluster exist?")
			return
		}
	} else {
		// We let docker-machine dump errors if nodes do not exist.
		nodes = args
	}

	for _, nodeName := range nodes {
		// Start machine.
		err = docker.StartMachine(nodeName)
		if err != nil {
			log.Errorf("could not start machine %s: %v", nodeName, err)
		}

		// Lookup node info.
		nodeConfig, err := driver.GetNodeConfig(nodeName)
		if err != nil {
			log.Errorf("could not get node config for %s: %v", nodeName, err)
			return
		}

		// Do "start node" logic.
		err = driver.StartNode(nodeName, nodeConfig)
		if err != nil {
			log.Errorf("could not run StartNode steps for %s: %v", nodeName, err)
			return
		}

		// Start the cockroach node.
		err = docker.RunDockerStart(driver, nodeName, nodeConfig)
		if err != nil {
			log.Errorf("could not start cockroach node %s: %v", nodeName, err)
		}
	}
}
Example #3
0
// AddOneNode is a helper to add a single node. Called repeatedly.
func AddOneNode(driver drivers.Driver) error {
	nodes, err := docker.ListCockroachNodes()
	if err != nil {
		return util.Errorf("failed to get list of existing cockroach nodes: %v", err)
	}
	if len(nodes) == 0 {
		return util.Errorf("no existing cockroach nodes detected, does the cluster exist?")
	}

	largestIndex, err := docker.GetLargestNodeIndex(nodes)
	if err != nil {
		return util.Errorf("problem parsing existing node list: %v", err)
	}

	nodeName := docker.MakeNodeName(largestIndex + 1)

	// Create node.
	err = docker.CreateMachine(driver, nodeName)
	if err != nil {
		return util.Errorf("could not create machine %s: %v", nodeName, err)
	}

	// Lookup node info.
	nodeConfig, err := driver.GetNodeConfig(nodeName)
	if err != nil {
		return util.Errorf("could not get node config for %s: %v", nodeName, err)
	}

	// Do "start node" logic.
	err = driver.StartNode(nodeName, nodeConfig)
	if err != nil {
		return util.Errorf("could not run StartNode steps for %s: %v", nodeName, err)
	}

	// Start the cockroach node.
	err = docker.RunDockerStart(driver, nodeName, nodeConfig)
	if err != nil {
		return util.Errorf("could not initialize first cockroach node %s: %v", nodeName, err)
	}
	return nil
}