Exemplo n.º 1
0
    def handle(self):
        target_type = self.request.input.target_type
        validate_input_dict(('target_type', target_type, INVOCATION_TARGET))

        with closing(self.odb.session()) as session:
            self.response.payload[:] = self.get_data(
                session, self.request.input.cluster_id, target_type)
Exemplo n.º 2
0
    def handle(self):
        with closing(self.odb.session()) as session:

            target_type = self.request.input.target_type
            validate_input_dict(
                ('target_type', target_type, INVOCATION_TARGET))
            self._validate_times()

            input = self.request.input

            if not self._is_edit:
                self._check_def_name(session, input)

            target_query = _target_query_by_name[target_type]
            target = target_query(session, input.cluster_id, input.target)
            if not target:
                raise Exception(
                    'Target [{}] ({}) does not exist on this cluster'.format(
                        input.target, input.target_type))

            try:
                item = self._get_item(session, target_def_class[target_type],
                                      input)

                item.target_id = target.id
                item.short_def = '{}-{}-{}'.format(input.check_after,
                                                   input.retry_repeats,
                                                   input.retry_seconds)

                if not self._is_edit:
                    item.name = input.name

                item.target_type = input.target_type
                item.expire_after = input.expire_after
                item.expire_arch_succ_after = input.expire_arch_succ_after
                item.expire_arch_fail_after = input.expire_arch_fail_after
                item.check_after = input.check_after
                item.retry_repeats = input.retry_repeats
                item.retry_seconds = input.retry_seconds
                item.cluster_id = input.cluster_id
                item.callback_list = input.callback_list.encode('utf-8')

                session.add(item)
                session.commit()

                self.delivery_store.set_deleted(item.name, False)

                if self._is_edit:
                    self.delivery_store.set_deleted(item.name, True)

                self.response.payload.id = item.id
                self.response.payload.name = item.name

            except Exception, e:
                msg = self._error_msg.format(format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Exemplo n.º 3
0
 def _validate_get_state(self, input):
     if input.state != DELIVERY_STATE.IN_PROGRESS_ANY:
         validate_input_dict(('state', input.state, DELIVERY_STATE))
         return [input.state]
     else:
         return [
             DELIVERY_STATE.IN_PROGRESS_STARTED,
             DELIVERY_STATE.IN_PROGRESS_TARGET_OK,
             DELIVERY_STATE.IN_PROGRESS_TARGET_FAILURE
         ]
Exemplo n.º 4
0
    def handle(self):
        with closing(self.odb.session()) as session:
            
            target_type = self.request.input.target_type
            validate_input_dict(('target_type', target_type, INVOCATION_TARGET))
            self._validate_times()
        
            input = self.request.input
            
            if not self._is_edit:
                self._check_def_name(session, input)
            
            target_query = _target_query_by_name[target_type]
            target = target_query(session, input.cluster_id, input.target)
            if not target:
                raise Exception('Target [{}] ({}) does not exist on this cluster'.format(
                    input.target, input.target_type))
                
            try:
                item = self._get_item(session, target_def_class[target_type], input)
                        
                item.target_id = target.id
                item.short_def = '{}-{}-{}'.format(input.check_after, input.retry_repeats, input.retry_seconds)
            
                if not self._is_edit:
                    item.name = input.name
                    
                item.target_type = input.target_type
                item.expire_after = input.expire_after
                item.expire_arch_succ_after = input.expire_arch_succ_after
                item.expire_arch_fail_after = input.expire_arch_fail_after
                item.check_after = input.check_after
                item.retry_repeats = input.retry_repeats
                item.retry_seconds = input.retry_seconds
                item.cluster_id = input.cluster_id
                item.callback_list = input.callback_list.encode('utf-8')
                
                session.add(item)
                session.commit()
                
                self.delivery_store.set_deleted(item.name, False)

                if self._is_edit:
                    self.delivery_store.set_deleted(item.name, True)
                
                self.response.payload.id = item.id
                self.response.payload.name = item.name
                
            except Exception, e:
                msg = self._error_msg.format(format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise 
Exemplo n.º 5
0
 def handle(self):
     target_type = self.request.input.target_type
     validate_input_dict(('target_type', target_type, INVOCATION_TARGET))
     
     with closing(self.odb.session()) as session:
         self.response.payload[:] = self.get_data(session, self.request.input.cluster_id, target_type)
Exemplo n.º 6
0
 def _validate_get_state(self, input):
     if input.state != DELIVERY_STATE.IN_PROGRESS_ANY:
         validate_input_dict(('state', input.state, DELIVERY_STATE))
         return [input.state]
     else:
         return [DELIVERY_STATE.IN_PROGRESS_STARTED, DELIVERY_STATE.IN_PROGRESS_TARGET_OK, DELIVERY_STATE.IN_PROGRESS_TARGET_FAILURE]