77 "fmt"
88 "github.com/coreos/go-omaha/omaha"
99 update "github.com/coreos/updatectl/client/update/v1"
10- "github.com/deis/deisctl/lock"
11- "github.com/deis/deisctl/systemd"
1210 "github.com/deis/deisctl/utils"
1311 "io"
1412 "log"
@@ -67,11 +65,11 @@ var (
6765 Run : instanceListAppVersions ,
6866 }
6967
70- cmdInstanceFake = & Command {
71- Name : "instance fake " ,
68+ cmdInstanceDeis = & Command {
69+ Name : "instance deis " ,
7270 Usage : "[OPTION]..." ,
73- Description : "Simulate multiple fake instances." ,
74- Run : instanceFake ,
71+ Description : "Simulate single deis to update instances." ,
72+ Run : instanceDeis ,
7573 }
7674)
7775
@@ -87,18 +85,18 @@ func init() {
8785 cmdInstanceListAppVersions .Flags .Int64Var (& instanceFlags .end , "end" , 0 , "End date filter" )
8886
8987 cmdInstanceFake .Flags .BoolVar (& instanceFlags .verbose , "verbose" , false , "Print out the request bodies" )
90- cmdInstanceFake .Flags .IntVar (& instanceFlags .clientsPerApp , "clients-per-app" , 20 , "Number of fake fents per appid." )
91- cmdInstanceFake .Flags .IntVar (& instanceFlags .minSleep , "min-sleep" , 1 , "Minimum time between update checks." )
88+ cmdInstanceFake .Flags .IntVar (& instanceFlags .clientsPerApp , "clients-per-app" , 1 , "Number of fake fents per appid." )
89+ cmdInstanceFake .Flags .IntVar (& instanceFlags .minSleep , "min-sleep" , 5 , "Minimum time between update checks." )
9290 cmdInstanceFake .Flags .IntVar (& instanceFlags .maxSleep , "max-sleep" , 10 , "Maximum time between update checks." )
9391 cmdInstanceFake .Flags .IntVar (& instanceFlags .errorRate , "errorrate" , 1 , "Chance of error (0-100)%." )
9492 cmdInstanceFake .Flags .StringVar (& instanceFlags .OEM , "oem" , "fakeclient" , "oem to report" )
9593 // simulate reboot lock.
9694 cmdInstanceFake .Flags .IntVar (& instanceFlags .pingOnly , "ping-only" , 0 , "halt update and just send ping requests this many times." )
97- cmdInstanceFake .Flags .Var (& instanceFlags .appId , "app-id" , "Application ID to update." )
95+ cmdInstanceFake .Flags .Var (& instanceFlags .appId , os . Getenv ( "DEISCTL_APP_ID" ) , "Application ID to update." )
9896 instanceFlags .appId .required = true
99- cmdInstanceFake .Flags .Var (& instanceFlags .groupId , "group-id" , "Group ID to update." )
97+ cmdInstanceFake .Flags .Var (& instanceFlags .groupId , os . Getenv ( "DEISCTL_GROUP_ID" ) , "Group ID to update." )
10098 instanceFlags .groupId .required = true
101- cmdInstanceFake .Flags .StringVar (& instanceFlags .version , "version" , "0.0.0" , "Version to report." )
99+ cmdInstanceFake .Flags .StringVar (& instanceFlags .version , "version" , os . Getenv ( "DEISCTL_APP_VERSION" ) , "Version to report." )
102100}
103101
104102func instanceListUpdates (args []string , service * update.Service , out * tabwriter.Writer ) int {
@@ -181,8 +179,6 @@ type Client struct {
181179 config * serverConfig
182180 errorRate int
183181 pingsRemaining int
184- conn * systemd.SystemdUnitManager
185- lock * lock.Lock
186182}
187183
188184func (c * Client ) Log (format string , v ... interface {}) {
@@ -198,14 +194,7 @@ func (c *Client) updateservice() {
198194 fmt .Println ("starting systemd units" )
199195 files , _ := utils .ListFiles (downloadDir + "*.service" )
200196 fmt .Println (files )
201- c .conn .Enable (files )
202- for _ , file := range files {
203- fmt .Println (file )
204- _ , file = filepath .Split (file )
205- fmt .Println (file )
206- c .conn .Start (file )
207- }
208- //c.conn.Start("deis-cache.service")
197+
209198}
210199
211200func (c * Client ) downloadFromUrl (url , fileName string ) (err error ) {
@@ -298,20 +287,6 @@ func (c *Client) MakeRequest(otype, result string, updateCheck, isPing bool) (*o
298287 return oresp , nil
299288}
300289
301- func (c * Client ) RequestLock () {
302- elc , err := lock .NewEtcdLockClient (nil )
303- if err != nil {
304- fmt .Fprintln (os .Stderr , "Error initializing etcd client:" , err )
305- }
306-
307- var mID string
308- mID = lock .GetMachineID ("/" )
309- if mID == "" {
310- fmt .Fprintln (os .Stderr , "Cannot read machine-id" )
311- }
312- c .lock = lock .New (mID , elc )
313- }
314-
315290func (c * Client ) SetVersion (resp * omaha.Response ) {
316291 // A field can potentially be nil.
317292 defer func () {
@@ -363,23 +338,7 @@ func (c *Client) Loop(n, m int) {
363338 if uc .Status != "ok" {
364339 c .Log ("update check status: %s\n " , uc .Status )
365340 } else {
366- c .RequestLock ()
367- err = c .lock .Lock ()
368- if err != nil && err != lock .ErrExist {
369- interval = expBackoff (interval )
370- fmt .Printf ("Retrying in %v. Error locking: %v\n " , interval , err )
371- time .Sleep (interval )
372- continue
373- }
374341 c .SetVersion (resp )
375- err = c .lock .Unlock ()
376- if err == lock .ErrNotExist {
377- fmt .Println ("no lock found" )
378- } else if err == nil {
379- fmt .Println ("Unlocked existing lock for this machine" )
380- } else {
381- fmt .Fprintln (os .Stderr , "Error unlocking:" , err )
382- }
383342 }
384343 }
385344}
@@ -393,7 +352,7 @@ func randSleep(n, m int) {
393352 time .Sleep (time .Duration (r ) * time .Second )
394353}
395354
396- func instanceFake (args []string , service * update.Service , out * tabwriter.Writer ) int {
355+ func instanceDeis (args []string , service * update.Service , out * tabwriter.Writer ) int {
397356 if instanceFlags .appId .Get () == nil || instanceFlags .groupId .Get () == nil {
398357 return ERROR_USAGE
399358 }
@@ -402,21 +361,17 @@ func instanceFake(args []string, service *update.Service, out *tabwriter.Writer)
402361 server : globalFlags .Server ,
403362 }
404363
405- for i := 0 ; i < instanceFlags .clientsPerApp ; i ++ {
406- c := & Client {
407- Id : fmt .Sprintf ("{fake-client-%03d}" , i ),
408- SessionId : uuid .New (),
409- Version : instanceFlags .version ,
410- AppId : instanceFlags .appId .String (),
411- Track : instanceFlags .groupId .String (),
412- config : conf ,
413- errorRate : instanceFlags .errorRate ,
414- pingsRemaining : instanceFlags .pingOnly ,
415- }
416- c .conn , _ = systemd .NewSystemdUnitManager ()
417- c .lock = nil
418- go c .Loop (instanceFlags .minSleep , instanceFlags .maxSleep )
364+ c := & Client {
365+ Id : fmt .Sprintf ("{update-client-" + utils .NewID (), i ),
366+ SessionId : uuid .New (),
367+ Version : instanceFlags .version ,
368+ AppId : instanceFlags .appId .String (),
369+ Track : instanceFlags .groupId .String (),
370+ config : conf ,
371+ errorRate : instanceFlags .errorRate ,
372+ pingsRemaining : instanceFlags .pingOnly ,
419373 }
374+ go c .Loop (instanceFlags .minSleep , instanceFlags .maxSleep )
420375
421376 // run forever
422377 wait := make (chan bool )
0 commit comments