Exemple #1
0
func init() {
	kv, err := kvdb.New(mem.Name, "driver_test", []string{}, nil)
	if err != nil {
		log.Panicf("Failed to intialize KVDB")
	}
	err = kvdb.SetInstance(kv)
	if err != nil {
		log.Panicf("Failed to set KVDB instance")
	}
}
func init() {
	kv, err := kvdb.New(mem.Name, "driver_test", []string{}, nil)
	if err != nil {
		dlog.Panicf("Failed to initialize KVDB")
	}
	if err := kvdb.SetInstance(kv); err != nil {
		dlog.Panicf("Failed to set KVDB instance")
	}
	testEnumerator = NewDefaultEnumerator("enumerator_test", kv)
}
Exemple #3
0
func TestAll(t *testing.T) {
	kv, err := kvdb.New(Name, "pwx/test", nil, nil)
	if err != nil {
		t.Fatalf("Failed to initialize KVDB: %v", err)
	}

	err = kvdb.SetInstance(kv)
	if err != nil {
		t.Fatalf("Failed to set instance: %v", err)
	}

	test.Run(t)
}
func TestSetup(t *testing.T) {
	kv := kvdb.Instance()
	if kv == nil {
		kv, err := kvdb.New(mem.Name, "openstorage/1", []string{}, nil)
		if err != nil {
			t.Fatalf("Failed to set default KV store : (%v): %v", mem.Name, err)
		}
		err = kvdb.SetInstance(kv)
		if err != nil {
			t.Fatalf("Failed to set default KV store: (%v): %v", mem.Name, err)
		}
	}

	var err error
	kva, err = New("alerts_kvdb")
	if err != nil {
		t.Fatalf("Failed to create new Kvapi.Alerts object")
	}
}
Exemple #5
0
func start(c *cli.Context) {
	var cm *cluster.ClusterManager

	if !osdcli.DaemonMode(c) {
		cli.ShowAppHelp(c)
		return
	}

	datastores := []string{mem.Name, etcd.Name}

	// We are in daemon mode.
	file := c.String("file")
	if file == "" {
		fmt.Println("OSD configuration file not specified.  Visit openstorage.org for an example.")
		return
	}
	cfg, err := config.Parse(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	kvdbURL := c.String("kvdb")
	u, err := url.Parse(kvdbURL)
	scheme := u.Scheme
	u.Scheme = "http"

	kv, err := kvdb.New(scheme, "openstorage", []string{u.String()}, nil)
	if err != nil {
		fmt.Println("Failed to initialize KVDB: ", u.Scheme, err)
		fmt.Println("Supported datastores: ", datastores)
		return
	}
	err = kvdb.SetInstance(kv)
	if err != nil {
		fmt.Println("Failed to initialize KVDB: ", err)
		return
	}

	// Start the cluster state machine, if enabled.
	if cfg.Osd.ClusterConfig.NodeId != "" && cfg.Osd.ClusterConfig.ClusterId != "" {
		dockerClient, err := docker.NewClientFromEnv()
		if err != nil {
			fmt.Println("Failed to initialize docker client: ", err)
			return
		}
		cm = cluster.New(cfg.Osd.ClusterConfig, kv, dockerClient)
	}

	// Start the volume drivers.
	for d, v := range cfg.Osd.Drivers {
		fmt.Println("Starting volume driver: ", d)
		_, err := volume.New(d, v)
		if err != nil {
			fmt.Println("Unable to start volume driver: ", d, err)
			return
		}

		err = apiserver.StartServerAPI(d, 0, config.DriverAPIBase)
		if err != nil {
			fmt.Println("Unable to start volume driver: ", err)
			return
		}

		err = apiserver.StartPluginAPI(d, config.PluginAPIBase)
		if err != nil {
			fmt.Println("Unable to start volume plugin: ", err)
			return
		}
	}

	if cm != nil {
		err = cm.Start()
		if err != nil {
			fmt.Println("Unable to start cluster manager: ", err)
			return
		}
	}

	// Daemon does not exit.
	select {}
}
Exemple #6
0
func start(c *cli.Context) {
	var cm cluster.Cluster

	if !osdcli.DaemonMode(c) {
		cli.ShowAppHelp(c)
		return
	}

	datastores := []string{mem.Name, etcd.Name, consul.Name}

	// We are in daemon mode.
	file := c.String("file")
	if file == "" {
		logrus.Warn("OSD configuration file not specified.  Visit openstorage.org for an example.")
		return
	}
	cfg, err := config.Parse(file)
	if err != nil {
		logrus.Error(err)
		return
	}
	kvdbURL := c.String("kvdb")
	u, err := url.Parse(kvdbURL)
	scheme := u.Scheme
	u.Scheme = "http"

	kv, err := kvdb.New(scheme, "openstorage", []string{u.String()}, nil)
	if err != nil {
		logrus.Warnf("Failed to initialize KVDB: %v (%v)", scheme, err)
		logrus.Warnf("Supported datastores: %v", datastores)
		return
	}
	err = kvdb.SetInstance(kv)
	if err != nil {
		logrus.Warnf("Failed to initialize KVDB: %v", err)
		return
	}

	// Start the cluster state machine, if enabled.
	if cfg.Osd.ClusterConfig.NodeId != "" && cfg.Osd.ClusterConfig.ClusterId != "" {
		logrus.Infof("OSD enabling cluster mode.")

		dockerClient, err := docker.NewClientFromEnv()
		if err != nil {
			logrus.Warnf("Failed to initialize docker client: %v", err)
			return
		}

		cm = cluster.New(cfg.Osd.ClusterConfig, kv, dockerClient)

		if err := server.StartClusterAPI(config.ClusterAPIBase); err != nil {
			logrus.Warnf("Unable to start cluster API server: %v", err)
			return
		}
	}

	// Start the volume drivers.
	for d, v := range cfg.Osd.Drivers {
		logrus.Infof("Starting volume driver: %v", d)
		if _, err := volume.New(d, v); err != nil {
			logrus.Warnf("Unable to start volume driver: %v, %v", d, err)
			return
		}

		if err := server.StartPluginAPI(d, config.DriverAPIBase, config.PluginAPIBase); err != nil {
			logrus.Warnf("Unable to start volume plugin: %v", err)
			return
		}
	}

	// Start the graph drivers.
	for d, _ := range cfg.Osd.GraphDrivers {
		logrus.Infof("Starting graph driver: %v", d)
		if err := server.StartGraphAPI(d, config.PluginAPIBase); err != nil {
			logrus.Warnf("Unable to start graph plugin: %v", err)
			return
		}
	}

	if cm != nil {
		if err := cm.Start(); err != nil {
			logrus.Warnf("Unable to start cluster manager: %v", err)
			return
		}
	}

	// Daemon does not exit.
	select {}
}