Ejemplo n.º 1
0
 def _check_conflicting_actions(ctx, target, action):
     conflict_actions = ao.Action.get_all_active_by_target(ctx, target)
     if conflict_actions and action == consts.CLUSTER_DELETE:
         delete_ids = [a['id'] for a in conflict_actions
                       if a['action'] == consts.CLUSTER_DELETE]
         if delete_ids:
             raise exception.ActionConflict(
                 type=action, target=target, actions=",".join(
                     delete_ids))
     elif conflict_actions:
         action_ids = [a['id'] for a in conflict_actions]
         raise exception.ActionConflict(
             type=action, target=target, actions=",".join(action_ids))
Ejemplo n.º 2
0
 def _check_conflicting_actions(ctx, target, action):
     conflict_actions = ao.Action.get_all_active_by_target(ctx, target)
     # Ignore conflicting actions on deletes.
     if not conflict_actions or action in consts.CONFLICT_BYPASS_ACTIONS:
         return
     else:
         action_ids = [a['id'] for a in conflict_actions]
         raise exception.ActionConflict(
             type=action, target=target, actions=",".join(action_ids))
Ejemplo n.º 3
0
    def validate_scaling_action(ctx, cluster_id, action):
        """Validate scaling action against actions table and policy cooldown.

        :param ctx: An instance of the request context.
        :param cluster_id: ID of the cluster the scaling action is targeting.
        :param action: Scaling action being validated.
        :return: None
        :raises: An exception of ``ActionCooldown`` when the action being
        validated is still in cooldown based off the policy or
        ``ActionConflict`` when a scaling action is already in the action
        table.
        """
        # Check for conflicting actions in the actions table.
        conflicting_actions = Action._get_conflicting_scaling_actions(
            ctx, cluster_id)
        if conflicting_actions:
            action_ids = [a.get('id', None) for a in conflicting_actions]
            LOG.info(
                "Unable to process %(action)s for cluster %(cluster_id)s "
                "the action conflicts with %(conflicts)s", {
                    'action': action,
                    'cluster_id': cluster_id,
                    'conflicts': action_ids
                })
            raise exception.ActionConflict(type=action,
                                           target=cluster_id,
                                           actions=",".join(action_ids))

        # Check to see if action cooldown should be observed.
        bindings = cpo.ClusterPolicy.get_all(ctx,
                                             cluster_id,
                                             sort='priority',
                                             filters={'enabled': True})
        for pb in bindings:
            policy = policy_mod.Policy.load(ctx, pb.policy_id)
            if getattr(policy, 'cooldown', None) and policy.event == action:
                if pb.last_op and not timeutils.is_older_than(
                        pb.last_op, policy.cooldown):
                    LOG.info(
                        "Unable to process %(action)s for cluster "
                        "%(cluster_id)s the actions policy %(policy)s "
                        "cooldown still in progress", {
                            'action': action,
                            'cluster_id': cluster_id,
                            'policy': pb.policy_id
                        })
                    raise exception.ActionCooldown(type=action,
                                                   cluster=cluster_id,
                                                   policy_id=pb.policy_id)
        return