Example #1
0
func (w *worker) Deploy(app spi.Application) (err error) {
	w.wc.logger.Info("worker.Deploy(): appId=", app.Id(), " to w=", w)
	if err := w.setSA(WS_DEPLOYING, spi.NO_APP_ID); err != nil {
		return err
	}

	instance := w.instance()
	if err := app.Deploy(instance); err != nil {
		go func() {
			w.wc.logger.Warn("worker.Deploy(): failed. Rolling back to STARTED state.")
			if instance != nil {
				instance.Stop()
			}
			if err := w.startInstance(true); err != nil {
				w.wc.logger.Error("worker.Deploy(): Oops, cannot switch to STARTED state, got zombie now w=", w)
			}
		}()
		return err
	}

	if err := w.setSA(WS_DEPLOYED, app.Id()); err != nil {
		return err
	}
	w.wc.logger.Info("worker.Deploy(): Done. w=", w)
	return nil
}
Example #2
0
func (w *worker) Undeploy(app spi.Application) error {
	w.wc.logger.Info("worker.Undeploy(): w=", w)
	if w.desc.Aid != app.Id() {
		return errors.New("Cannot undeploy application: expected Id=" + string(app.Id()) + ", but actual one is " + string(w.desc.Aid))
	}

	if err := w.setSA(WS_UNDEPLOYING, spi.NO_APP_ID); err != nil {
		return err
	}
	instance := w.instance()
	if err := app.Undeploy(instance); err != nil {
		w.wc.logger.Warn("worker.Undeploy(): got unexpected error=", err, ", ignoring it")
	}
	go func() {
		instance.Stop()
		w.startInstance(true)
	}()

	return nil
}