func InstallIntoCli(dir string, port int) error { var err error kernelDirs, err := filepath.Glob(fmt.Sprint(dir, "/kernel*")) if err != nil { log.Fatal("Could not find kernel directory") } log.Infof("Found kernel dirs: %v", kernelDirs) err = RestoreAssets(fmt.Sprint(kernelDirs[0], "/ebin"), "") if err != nil { log.Panic(err) } if err := common.KillEPMD("root/riak"); err != nil { log.Fatal("Could not kill EPMd: ", err) } os.MkdirAll(fmt.Sprint(kernelDirs[0], "/priv"), 0777) ioutil.WriteFile(fmt.Sprint(kernelDirs[0], "/priv/cepmd_port"), []byte(fmt.Sprintf("%d.", port)), 0777) log.Infof("Port written to %v", fmt.Sprint(kernelDirs[0], "/priv/cepmd_port")) return nil }
func NewRiakExplorer(port int64, nodename string, c *cepm.CEPM, root string, useSuperChroot bool) (*RiakExplorer, error) { exepath := "/riak_explorer/bin/riak_explorer" var err error args := []string{"console", "-noinput"} healthCheckFun := func() error { log.Info("Running healthcheck: ", port) _, err := rexclient.NewRiakExplorerClient(fmt.Sprintf("localhost:%d", port)).Ping() log.Info("Healthcheck result ", err) return err } tearDownFun := func() { log.Info("Tearing down riak explorer") //err := os.RemoveAll("riak_explorer") //if err != nil { /// log.Error(err) //} } re := &RiakExplorer{ port: port, } if c != nil { // This is gross -- we're passing "hidden" state by passing it through the unix environment variables. // Fix it -- we should convert the NewRiakExplorer into using a fluent pattern? libpath := filepath.Join(root, "riak_explorer", "lib", "basho-patches") os.Mkdir(libpath, 0777) err := cepm.InstallInto(libpath) if err != nil { log.Panic(err) } if err := common.KillEPMD(filepath.Join(root, "riak_explorer")); err != nil { log.Fatal("Could not kill EPMd: ", err) } args = append(args, "-no_epmd") re.configureAdvanced(c.GetPort(), root) } re.configure(port, nodename, root) log.Debugf("Starting up Riak Explorer %v", exepath) re.pm, err = process_manager.NewProcessManager(tearDownFun, exepath, args, healthCheckFun, &root, useSuperChroot) if err != nil { log.Error("Could not start Riak Explorer: ", err) } return re, err }
func (riakNode *RiakNode) Run() { var err error var fetchURI string var resp *http.Response os.Mkdir("root", 0777) riakNode.decompress() fetchURI = fmt.Sprintf("%s/static2/riak-2.1.1-bin.tar.gz", riakNode.taskData.URI) log.Info("Preparing to fetch riak from: ", fetchURI) resp, err = http.Get(fetchURI) if err != nil { log.Panic("Unable to fetch riak root: ", err) } err = common.ExtractGZ("root", resp.Body) if err != nil { log.Panic("Unable to extract riak root: ", err) } config := riakNode.configureRiak(riakNode.taskData) c := cepm.NewCPMd(0, riakNode.metadataManager) c.Background() riakNode.configureAdvanced(c.GetPort()) args := []string{"console", "-noinput"} kernelDirs, err := filepath.Glob("root/riak/lib/kernel*") if err != nil { log.Fatal("Could not find kernel directory") } log.Infof("Found kernel dirs: %v", kernelDirs) err = cepm.InstallInto(fmt.Sprint(kernelDirs[0], "/ebin")) if err != nil { log.Panic(err) } if err := common.KillEPMD("root/riak"); err != nil { log.Fatal("Could not kill EPMd: ", err) } args = append(args, "-no_epmd") os.MkdirAll(fmt.Sprint(kernelDirs[0], "/priv"), 0777) ioutil.WriteFile(fmt.Sprint(kernelDirs[0], "/priv/cepmd_port"), []byte(fmt.Sprintf("%d.", c.GetPort())), 0777) HealthCheckFun := func() error { log.Info("Checking is Riak is started") data, err := ioutil.ReadFile("root/riak/log/console.log") if err != nil { if bytes.Contains(data, []byte("Wait complete for service riak_kv")) { log.Info("Riak started, waiting 10 seconds to avoid race conditions (HACK)") time.Sleep(10 * time.Second) return nil } return errors.New("Riak KV not yet started") } return err } wd, err := os.Getwd() if err != nil { log.Panic("Could not get wd: ", err) } chroot := filepath.Join(wd, "root") riakNode.pm, err = process_manager.NewProcessManager(func() { return }, "/riak/bin/riak", args, HealthCheckFun, &chroot, riakNode.taskData.UseSuperChroot) if err != nil { log.Error("Could not start Riak: ", err) runStatus := &mesos.TaskStatus{ TaskId: riakNode.taskInfo.GetTaskId(), State: mesos.TaskState_TASK_FAILED.Enum(), } _, err = riakNode.executor.Driver.SendStatusUpdate(runStatus) if err != nil { log.Panic("Got error", err) } // Shutdown: time.Sleep(15 * time.Minute) log.Info("Shutting down due to GC, after failing to bring up Riak node") riakNode.executor.Driver.Stop() } else { rexPort := riakNode.taskData.RexPort riakNode.startRex(rexPort, c) rootNode := riakNode.metadataManager.GetRootNode() rootNode.CreateChildIfNotExists("coordinator") coordinator, err := rootNode.GetChild("coordinator") if err != nil { log.Panic(err) } coordinator.CreateChildIfNotExists("coordinatedNodes") coordinatedNodes, err := coordinator.GetChild("coordinatedNodes") if err != nil { log.Panic(err) } child, err := coordinatedNodes.MakeChild(riakNode.taskInfo.GetTaskId().GetValue(), true) if err != nil { log.Panic(err) } coordinatedData := common.CoordinatedData{ NodeName: riakNode.taskData.FullyQualifiedNodeName, DisterlPort: int(config.DisterlPort), PBPort: int(config.PBPort), HTTPPort: int(config.HTTPPort), Hostname: riakNode.executor.slaveInfo.GetHostname(), ClusterName: riakNode.taskData.ClusterName, FrameworkName: riakNode.taskData.FrameworkName, } cdBytes, err := coordinatedData.Serialize() if err != nil { log.Panic("Could not serialize coordinated data ", err) } child.SetData(cdBytes) // lock.Unlock() tsd := common.TaskStatusData{ RexPort: rexPort, } tsdBytes, err := tsd.Serialize() if err != nil { log.Panic("Could not serialize Riak Explorer data", err) } runStatus := &mesos.TaskStatus{ TaskId: riakNode.taskInfo.GetTaskId(), State: mesos.TaskState_TASK_RUNNING.Enum(), Data: tsdBytes, } _, err = riakNode.executor.Driver.SendStatusUpdate(runStatus) if err != nil { log.Panic("Got error", err) } riakNode.running = true go riakNode.runLoop(child) } }
func (riakNode *RiakNode) Run() { var err error config := riakNode.configureRiak(riakNode.taskData) c := cepm.NewCPMd(0, riakNode.metadataManager) c.Background() riakNode.configureAdvanced(c.GetPort()) args := []string{"console", "-noinput"} kernelDirs, err := filepath.Glob("root/riak/lib/kernel*") if err != nil { log.Fatal("Could not find kernel directory") } log.Infof("Found kernel dirs: %v", kernelDirs) err = cepm.InstallInto(fmt.Sprint(kernelDirs[0], "/ebin")) if err != nil { log.Panic(err) } if err := common.KillEPMD("root/riak"); err != nil { log.Fatal("Could not kill EPMd: ", err) } args = append(args, "-no_epmd") os.MkdirAll(fmt.Sprint(kernelDirs[0], "/priv"), 0777) ioutil.WriteFile(fmt.Sprint(kernelDirs[0], "/priv/cepmd_port"), []byte(fmt.Sprintf("%d.", c.GetPort())), 0777) HealthCheckFun := func() error { log.Info("Checking is Riak is started") data, err := ioutil.ReadFile("root/riak/log/console.log") if err != nil { if bytes.Contains(data, []byte("Wait complete for service riak_kv")) { log.Info("Riak started, waiting 10 seconds to avoid race conditions (HACK)") time.Sleep(10 * time.Second) return nil } return errors.New("Riak KV not yet started") } return err } wd, err := os.Getwd() if err != nil { log.Panic("Could not get wd: ", err) } chroot := filepath.Join(wd, "root") riakNode.pm, err = process_manager.NewProcessManager(func() { return }, "/riak/bin/riak", args, HealthCheckFun, &chroot, riakNode.taskData.UseSuperChroot) if err != nil { log.Error("Could not start Riak: ", err) runStatus := &mesos.TaskStatus{ TaskId: riakNode.taskInfo.GetTaskId(), State: mesos.TaskState_TASK_FAILED.Enum(), } _, err = riakNode.executor.Driver.SendStatusUpdate(runStatus) if err != nil { log.Panic("Got error", err) } // Shutdown: time.Sleep(15 * time.Minute) log.Info("Shutting down due to GC, after failing to bring up Riak node") riakNode.executor.Driver.Stop() } else { child := riakNode.getCoordinatedChild() riakNode.setCoordinatedData(child, config) rexPort := riakNode.taskData.HTTPPort tsd := common.TaskStatusData{ RexPort: rexPort, } tsdBytes, err := tsd.Serialize() if err != nil { log.Panic("Could not serialize Riak Explorer data", err) } runStatus := &mesos.TaskStatus{ TaskId: riakNode.taskInfo.GetTaskId(), State: mesos.TaskState_TASK_RUNNING.Enum(), Data: tsdBytes, } _, err = riakNode.executor.Driver.SendStatusUpdate(runStatus) if err != nil { log.Panic("Got error", err) } riakNode.running = true go riakNode.runLoop(child) } }