func getConsulManifest(dir string) (string, error) { consulTar := fmt.Sprintf( "file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-consul_052.tar.gz"), ) builder := manifest.NewBuilder() builder.SetID("consul") stanzas := map[launch.LaunchableID]launch.LaunchableStanza{ "consul": { LaunchableType: "hoist", Location: consulTar, }, } builder.SetLaunchables(stanzas) manifest := builder.GetManifest() consulPath := path.Join(dir, "consul.yaml") f, err := os.OpenFile(consulPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return "", err } defer f.Close() err = manifest.Write(f) if err != nil { return "", err } return consulPath, f.Close() }
// Writes a pod manifest for the hello pod at with the specified name in the // specified dir, configured to run on the specified port. Returns the path to // the signed manifest func writeHelloManifest(dir string, manifestName string, port int) (string, error) { hello := fmt.Sprintf("file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-hello_def456.tar.gz")) builder := manifest.NewBuilder() builder.SetID("hello") builder.SetStatusPort(port) builder.SetStatusHTTP(true) stanzas := map[launch.LaunchableID]launch.LaunchableStanza{ "hello": { LaunchableType: "hoist", Location: hello, }, } builder.SetLaunchables(stanzas) builder.SetConfig(map[interface{}]interface{}{ "port": port, }) manifest := builder.GetManifest() manifestPath := filepath.Join(dir, manifestName) f, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return "", err } defer f.Close() err = manifest.Write(f) if err != nil { return "", err } return signManifest(manifestPath, dir) }
func createHelloReplicationController(dir string) (fields.ID, error) { hello := fmt.Sprintf("file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-hello_def456.tar.gz")) builder := manifest.NewBuilder() builder.SetID("hello") builder.SetStatusPort(43770) stanzas := map[launch.LaunchableID]launch.LaunchableStanza{ "hello": { LaunchableId: "hello", LaunchableType: "hoist", Location: hello, }, } builder.SetLaunchables(stanzas) manifest := builder.GetManifest() manifestPath := path.Join(dir, "hello.yaml") f, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return fields.ID(""), err } defer f.Close() err = manifest.Write(f) if err != nil { return fields.ID(""), err } f.Close() manifestPath, err = signManifest(manifestPath, dir) if err != nil { return fields.ID(""), err } cmd := exec.Command("p2-rctl", "--log-json", "create", "--manifest", manifestPath, "--node-selector", "test=yes") out := bytes.Buffer{} cmd.Stdout = &out cmd.Stderr = &out err = cmd.Run() if err != nil { return fields.ID(""), fmt.Errorf("Couldn't create replication controller for hello: %s %s", out.String(), err) } var rctlOut struct { ID string `json:"id"` } err = json.Unmarshal(out.Bytes(), &rctlOut) if err != nil { return fields.ID(""), fmt.Errorf("Couldn't read RC ID out of p2-rctl invocation result: %v", err) } return fields.ID(rctlOut.ID), exec.Command("p2-rctl", "set-replicas", rctlOut.ID, "1").Run() }