Exemplo n.º 1
0
// InitializeUpdate initializes update, creates update context
func (u *Updater) InitializeUpdate(log log.T, detail *UpdateDetail) (context *UpdateContext, err error) {
	var pluginResult *updateutil.UpdatePluginResult

	// load plugin update result
	pluginResult, err = updateutil.LoadUpdatePluginResult(log, detail.UpdateRoot)
	if err != nil {
		return nil, fmt.Errorf("update failed, no rollback needed %v", err.Error())
	}
	detail.StandardOut = pluginResult.StandOut
	detail.StartDateTime = pluginResult.StartDateTime

	// Load UpdateContext from local storage, set current update with the new UpdateDetail
	if context, err = LoadUpdateContext(log, updateutil.UpdateContextFilePath(detail.UpdateRoot)); err != nil {
		return context, fmt.Errorf("update failed, no rollback needed %v", err.Error())
	}

	if context.IsUpdateInProgress(log) {
		return context, fmt.Errorf("another update is in progress, please retry later")
	}

	context.Current = detail
	if err = u.mgr.inProgress(context, log, Initialized); err != nil {
		return
	}

	return context, nil
}
Exemplo n.º 2
0
// finalizeUpdateAndSendReply completes the update and send reply to message service
func (u *updateManager) finalizeUpdateAndSendReply(log log.T, context *UpdateContext, errorCode string) (err error) {
	update := context.Current
	update.EndDateTime = time.Now().UTC()

	// resolve context location base on the UpdateRoot
	contextLocation := updateutil.UpdateContextFilePath(update.UpdateRoot)
	if err = u.ctxMgr.saveUpdateContext(log, context, contextLocation); err != nil {
		return err
	}

	// send reply
	if update.HasMessageID() {
		if err = u.svc.SendReply(log, update); err != nil {
			log.Errorf(err.Error())
		}

		if err = u.svc.DeleteMessage(log, update); err != nil {
			log.Errorf(err.Error())
		}
	}

	// update health information
	if err = u.svc.UpdateHealthCheck(log, update, errorCode); err != nil {
		log.Errorf(err.Error())
	}

	// upload output to s3 bucket
	log.Debugf("output s3 bucket name is %v", update.OutputS3BucketName)
	if update.OutputS3BucketName != "" {
		u.ctxMgr.uploadOutput(log, context)
	}

	context.cleanUpdate()
	if err = u.ctxMgr.saveUpdateContext(log, context, contextLocation); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 3
0
// inProgress sets update to inProgressing with given new UpdateState
func (u *updateManager) inProgress(context *UpdateContext, log log.T, state UpdateState) (err error) {
	update := context.Current
	update.State = state
	update.Result = contracts.ResultStatusInProgress

	// resolve context location base on the UpdateRoot
	contextLocation := updateutil.UpdateContextFilePath(update.UpdateRoot)
	if err = u.ctxMgr.saveUpdateContext(log, context, contextLocation); err != nil {
		return err
	}

	if update.HasMessageID() {
		err = u.svc.SendReply(log, update)
		if err != nil {
			log.Errorf(err.Error())
		}
	}

	if err = u.svc.UpdateHealthCheck(log, update, ""); err != nil {
		log.Errorf(err.Error())
	}

	return nil
}