SimpleDeployLang is a helper method that takes a struct representing a cluster and runs a sequence of methods on it. This particular helper starts up a series of instances linearly, deploys some code, and then shuts down. Both after initially starting up, after peering each instance, and after deplo
(code string)
| 96 | // Both after initially starting up, after peering each instance, and after |
| 97 | // deploy, it waits for the instance to converge before running the next step. |
| 98 | func (obj *Cluster) SimpleDeployLang(code string) error { |
| 99 | if err := obj.Init(); err != nil { |
| 100 | return errwrap.Wrapf(err, "could not init instance") |
| 101 | } |
| 102 | defer obj.Close() // clean up working directories |
| 103 | |
| 104 | // start the cluster |
| 105 | if err := obj.RunLinear(); err != nil { |
| 106 | return errwrap.Wrapf(err, "mgmt could not start") |
| 107 | } |
| 108 | defer obj.Kill() // do a kill -9 |
| 109 | |
| 110 | // wait for an internal converge signal as a baseline |
| 111 | // FIXME: add this wait if we remove it from RunLinear |
| 112 | //{ |
| 113 | // ctx, cancel := context.WithTimeout(context.Background(), time.Duration(longTimeout*len(obj.Hostnames))*time.Second) |
| 114 | // defer cancel() |
| 115 | // if err := obj.Wait(ctx); err != nil { // wait to get a converged signal |
| 116 | // return errwrap.Wrapf(err, "mgmt initial wait failed") // timeout expired |
| 117 | // } |
| 118 | //} |
| 119 | |
| 120 | // push a deploy |
| 121 | if err := obj.DeployLang(code); err != nil { |
| 122 | return errwrap.Wrapf(err, "mgmt could not deploy") |
| 123 | } |
| 124 | |
| 125 | // wait for an internal converge signal |
| 126 | { |
| 127 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(longTimeout*len(obj.Hostnames))*time.Second) |
| 128 | defer cancel() |
| 129 | if err := obj.WaitForConvergedAfterActivity(ctx); err != nil { // wait to get a converged signal |
| 130 | return errwrap.Wrapf(err, "mgmt post-deploy wait failed") // timeout expired |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // press ^C |
| 135 | { |
| 136 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(longTimeout*len(obj.Hostnames))*time.Second) |
| 137 | defer cancel() |
| 138 | if err := obj.Quit(ctx); err != nil { |
| 139 | if err == context.DeadlineExceeded { |
| 140 | return errwrap.Wrapf(err, "mgmt blocked on exit") |
| 141 | } |
| 142 | return errwrap.Wrapf(err, "mgmt exited with error") |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return nil |
| 147 | } |