Esempio n. 1
0
// runInit.
func runInit(cmd *commander.Command, args []string) {
	if len(args) != 1 {
		cmd.Usage()
		return
	}
	// Initialize the engine based on the first argument and
	// then verify it's not in-memory.
	engines, err := initEngines(args[0])
	if err != nil {
		log.Errorf("Failed to initialize engine %q: %v", args[0], err)
		return
	}
	e := engines[0]
	if _, ok := e.(*engine.InMem); ok {
		log.Errorf("Cannot initialize a cluster using an in-memory store")
		return
	}
	// Generate a new UUID for cluster ID and bootstrap the cluster.
	clusterID := uuid.New()
	localDB, err := BootstrapCluster(clusterID, e)
	if err != nil {
		log.Errorf("Failed to bootstrap cluster: %v", err)
		return
	}
	defer localDB.Close()
	fmt.Fprintf(os.Stdout, "Cockroach cluster %s has been initialized\n", clusterID)
	fmt.Fprintf(os.Stdout, "To start the cluster, run \"cockroach start\"\n")
}
Esempio n. 2
0
// runRmZone invokes the REST API with DELETE action and key prefix as
// path.
func runRmZone(cmd *commander.Command, args []string) {
	if len(args) != 1 {
		cmd.Usage()
		return
	}
	server.RunRmZone(Context, args[0])
}
Esempio n. 3
0
// runSetAcct invokes the REST API with POST action and key prefix as
// path. The specified configuration file is read from disk and sent
// as the POST body.
func runSetAcct(cmd *commander.Command, args []string) {
	if len(args) != 2 {
		cmd.Usage()
		return
	}
	server.RunSetAcct(Context, args[0], args[1])
}
Esempio n. 4
0
// runLsZones invokes the REST API with GET action and no path, which
// fetches a list of all zone configuration prefixes. The optional
// regexp is applied to the complete list and matching prefixes
// displayed.
func runLsZones(cmd *commander.Command, args []string) {
	if len(args) > 1 {
		cmd.Usage()
		return
	}
	pattern := ""
	if len(args) == 1 {
		pattern = args[0]
	}
	server.RunLsZone(Context, pattern)
}
Esempio n. 5
0
// runGetZones invokes the REST API with GET action and key prefix as path.
func runGetZones(cmd *commander.Command, args []string) {
	if len(args) != 1 {
		cmd.Usage()
		return
	}
	req, err := http.NewRequest("GET", kv.HTTPAddr()+zoneKeyPrefix+"/"+args[0], nil)
	if err != nil {
		log.Errorf("unable to create request to admin REST endpoint: %v", err)
		return
	}
	// TODO(spencer): need to move to SSL.
	b, err := sendAdminRequest(req)
	if err != nil {
		log.Errorf("admin REST request failed: %v", err)
		return
	}
	fmt.Fprintf(os.Stdout, "zone config for key prefix %q:\n%s\n", args[0], string(b))
}
Esempio n. 6
0
// runRmZone invokes the REST API with DELETE action and key prefix as
// path.
func runRmZone(cmd *commander.Command, args []string) {
	if len(args) != 1 {
		cmd.Usage()
		return
	}
	req, err := http.NewRequest("DELETE", kv.HTTPAddr()+zoneKeyPrefix+"/"+args[0], nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unable to create request to admin REST endpoint: %v\n", err)
		return
	}
	// TODO(spencer): need to move to SSL.
	_, err = sendAdminRequest(req)
	if err != nil {
		fmt.Fprintf(os.Stderr, "admin REST request failed: %v\n", err)
		return
	}
	fmt.Fprintf(os.Stdout, "removed zone config for key prefix %q\n", args[0])
}
Esempio n. 7
0
// runLsZones invokes the REST API with GET action and no path, which
// fetches a list of all zone configuration prefixes. The optional
// regexp is applied to the complete list and matching prefixes
// displayed.
func runLsZones(cmd *commander.Command, args []string) {
	if len(args) > 1 {
		cmd.Usage()
		return
	}
	req, err := http.NewRequest("GET", kv.HTTPAddr()+zoneKeyPrefix, nil)
	if err != nil {
		log.Errorf("unable to create request to admin REST endpoint: %v", err)
		return
	}
	b, err := sendAdminRequest(req)
	if err != nil {
		log.Errorf("admin REST request failed: %v", err)
		return
	}
	var prefixes []string
	if err = json.Unmarshal(b, &prefixes); err != nil {
		log.Errorf("unable to parse admin REST response: %v", err)
		return
	}
	var re *regexp.Regexp
	if len(args) == 1 {
		if re, err = regexp.Compile(args[0]); err != nil {
			log.Warningf("invalid regular expression %q; skipping regexp match and listing all zone prefixes", args[0])
			re = nil
		}
	}
	for _, prefix := range prefixes {
		if re != nil {
			unescaped, err := url.QueryUnescape(prefix)
			if err != nil || !re.MatchString(unescaped) {
				continue
			}
		}
		if prefix == "" {
			prefix = "[default]"
		}
		fmt.Fprintf(os.Stdout, "%s\n", prefix)
	}
}
Esempio n. 8
0
// runInit.
func runInit(cmd *commander.Command, args []string) {
	if len(args) != 2 {
		cmd.Usage()
		return
	}
	// Specifying the disk type as HDD may be incorrect, but doesn't
	// matter for this bootstrap step.
	engine, err := initEngine(args[0])
	if engine.Type() == storage.MEM {
		glog.Fatal("Cannot initialize a cockroach cluster using an in-memory storage device")
	}
	if err != nil {
		glog.Fatal(err)
	}
	// Generate a new cluster UUID.
	clusterID := uuid.New()
	if _, err := BootstrapCluster(clusterID, engine); err != nil {
		glog.Fatal(err)
	}
	// TODO(spencer): install the default zone config.
	glog.Infof("Cockroach cluster %s has been initialized", clusterID)
	glog.Infof(`To start the cluster, run "cockroach start"`)
}
Esempio n. 9
0
// runSetZone invokes the REST API with POST action and key prefix as
// path. The specified configuration file is read from disk and sent
// as the POST body.
func runSetZone(cmd *commander.Command, args []string) {
	if len(args) != 2 {
		cmd.Usage()
		return
	}
	// Read in the config file.
	body, err := ioutil.ReadFile(args[1])
	if err != nil {
		log.Errorf("unable to read zone config file %q: %v", args[1], err)
		return
	}
	req, err := http.NewRequest("POST", kv.HTTPAddr()+zoneKeyPrefix+"/"+args[0], bytes.NewReader(body))
	if err != nil {
		log.Errorf("unable to create request to admin REST endpoint: %v", err)
		return
	}
	// TODO(spencer): need to move to SSL.
	_, err = sendAdminRequest(req)
	if err != nil {
		log.Errorf("admin REST request failed: %v", err)
		return
	}
	fmt.Fprintf(os.Stdout, "set zone config for key prefix %q\n", args[0])
}