Exemplo n.º 1
0
// UpdateActivation updates one build with the given id
// to the given activation setting.
func UpdateActivation(buildId string, active bool, caller string) error {
	var err error
	if !active && (evergreen.IsSystemActivator(caller)) {
		_, err = UpdateAllBuilds(
			bson.M{IdKey: buildId,
				ActivatedByKey: caller,
			},
			bson.M{
				"$set": bson.M{
					ActivatedKey:     active,
					ActivatedTimeKey: time.Now(),
					ActivatedByKey:   caller,
				},
			},
		)
	} else {
		_, err = UpdateAllBuilds(
			bson.M{IdKey: buildId},
			bson.M{
				"$set": bson.M{
					ActivatedKey:     active,
					ActivatedTimeKey: time.Now(),
					ActivatedByKey:   caller,
				},
			},
		)
	}
	return err

}
Exemplo n.º 2
0
func SetActiveState(taskId string, caller string, active bool) error {
	t, err := task.FindOne(task.ById(taskId))
	if err != nil {
		return err
	}
	if active {
		// if the task is being activated, make sure to activate all of the task's
		// dependencies as well
		for _, dep := range t.DependsOn {
			if err = SetActiveState(dep.TaskId, caller, true); err != nil {
				return fmt.Errorf("error activating dependency for %v with id %v: %v",
					taskId, dep.TaskId, err)
			}
		}

		if t.DispatchTime != util.ZeroTime && t.Status == evergreen.TaskUndispatched {
			err = resetTask(t.Id)
			if err != nil {
				return fmt.Errorf("error resetting task: %v:", err.Error())
			}
		} else {
			err = t.ActivateTask(caller)
			if err != nil {
				return fmt.Errorf("error while activating task: %v", err.Error())
			}
		}
		// if the caller is not evergreen or the the task is activated by evergreen, deactivate it
	} else if !evergreen.IsSystemActivator(caller) || evergreen.IsSystemActivator(t.ActivatedBy) {

		err = t.DeactivateTask(caller)
		if err != nil {
			return fmt.Errorf("error deactivating task : %v:", err.Error())
		}
	} else {
		return nil
	}

	if active {
		event.LogTaskActivated(taskId, caller)
	} else {
		event.LogTaskDeactivated(taskId, caller)
	}
	return build.SetCachedTaskActivated(t.BuildId, taskId, active)
}
Exemplo n.º 3
0
// SetBuildActivation updates the "active" state of this build and all associated tasks.
// It also updates the task cache for the build document.
func SetBuildActivation(buildId string, active bool, caller string) error {
	var err error

	// If activating a task, set the ActivatedBy field to be the caller
	if active {
		_, err = task.UpdateAll(
			bson.M{
				task.BuildIdKey: buildId,
				task.StatusKey:  evergreen.TaskUndispatched,
			},
			bson.M{"$set": bson.M{task.ActivatedKey: active, task.ActivatedByKey: caller}},
		)
	} else {

		// if trying to deactivate a task then only deactivate tasks that have not been activated by a user.
		// if the caller is the default task activator,
		// only deactivate tasks that are activated by the default task activator
		if evergreen.IsSystemActivator(caller) {
			_, err = task.UpdateAll(
				bson.M{
					task.BuildIdKey:     buildId,
					task.StatusKey:      evergreen.TaskUndispatched,
					task.ActivatedByKey: caller,
				},
				bson.M{"$set": bson.M{task.ActivatedKey: active, task.ActivatedByKey: caller}},
			)

		} else {
			// update all tasks if the caller is not evergreen.
			_, err = task.UpdateAll(
				bson.M{
					task.BuildIdKey: buildId,
					task.StatusKey:  evergreen.TaskUndispatched,
				},
				bson.M{"$set": bson.M{task.ActivatedKey: active, task.ActivatedByKey: caller}},
			)
		}
	}

	if err != nil {
		return err
	}
	if err = build.UpdateActivation(buildId, active, caller); err != nil {
		return err
	}
	return RefreshTasksCache(buildId)
}