def parse(self, req): if req.content: raise UnknownError('unexpected output received when using HEAD to /{db} endpoint. {msg}'\ .format(db=self.database, msg=support_msg_api())) if self.is_ok(): self.msg += 'exists'
def parse_json(self, json_data): if not isList(json_data): raise UnknownError('non-list returned by Presto for nodes failed. {0}'.format(support_msg_api())) num_failed_nodes = len(json_data) self.msg = 'Presto SQL - {0} worker node{1} failed'.format(num_failed_nodes, plural(num_failed_nodes)) self.check_thresholds(num_failed_nodes)
def get_nodes(json_data): if not isList(json_data): raise UnknownError( 'non-list returned by Presto for nodes. {0}'.format( support_msg_api())) return json_data
def subscribe(self): credentials = pika.credentials.PlainCredentials( self.user, self.password) parameters = pika.ConnectionParameters( host=self.host, port=self.port, virtual_host=self.vhost, credentials=credentials, heartbeat_interval=1, ssl=self.ssl, connection_attempts=self.default_conn_attempts, retry_delay=self.retry_delay, backpressure_detection=True, # socket_timeout – Use for high latency networks ) self.conn = pika.BlockingConnection(parameters=parameters) log.debug('adding blocked connection callback') self.conn.add_on_connection_blocked_callback( self.connection_blocked_callback) log.debug( 'adding connection timeout to one 3rd of total timeout (%.2f out of %.2f secs)', self.timeout / 3, self.timeout) # no args to this callback self.conn.add_timeout(max(self.timeout - 1, 1), self.connection_timeout_handler) # self.check_connection() log.info('requesting channel') self.channel = self.conn.channel() log.info('got channel number %s', self.channel.channel_number) log.debug('adding channel cancel callback') self.channel.add_on_cancel_callback(self.connection_cancel_callback) # newer versions of RabbitMQ won't use this but will instead use TCP backpressure # not available on BlockingChannel #self.channel.add_on_flow_callback(self.on_flow_callback) log.debug('adding return callback') # not available on BlockingChannel #self.channel.add_on_return_callback(self.connection_return_callback) if self.use_transactions: log.info('setting channel to use AMQP transactions') self.channel.tx_select() else: log.info('setting RabbitMQ specific channel confirmation') # different in BlockingChannel #self.channel.confirm_delivery(callback=self.confirm_delivery_callback, nowait=False) self.channel.confirm_delivery() self.check_channel() log.info('declaring queue \'%s\'', self.queue) if self.queue: result = self.channel.queue_declare(queue=self.queue, durable=self.durable) if self.queue != result.method.queue: raise UnknownError("queue returned in subscribe ('{queue_returned}') "\ .format(queue_returned=result.method.queue) + \ "did not match requested queue name ('{queue}')"\ .format(queue=self.queue)) else: # auto-generate uniq queue, durable flag is ignored for exclusive result = self.channel.queue_declare(exclusive=True) self.queue = result.method.queue if not self.routing_key: self.routing_key = self.queue log.info('was assigned unique exclusive queue: %s', self.queue) if self.exchange: log.info("declaring exchange: '%s', type: '%s'", self.exchange, self.exchange_type) self.channel.exchange_declare(exchange=self.exchange, exchange_type=self.exchange_type) # if using nameless exchange this isn't necessary as routing key will send to queue log.info("binding queue '%s' to exchange '%s'", self.queue, self.exchange) self.channel.queue_bind(exchange=self.exchange, queue=self.queue)
def end(self): if self._read_value is None: raise UnknownError('read value is not set!') #self.msg = self.create_output() self.create_output() qquit(self.status, self.msg)
def parse_results(self, content): build = self.get_latest_build(content) number = build['number'] log.info('build number = %s', number) if not isInt(number): raise UnknownError('build number returned is not an integer!') message = build['message'] log.info('message = %s', message) branch = build['branch'] log.info('branch = %s', branch) commit = build['commit'] log.info('commit = %s', commit) started_at = build['started_at'] log.info('started_at = %s', started_at) finished_at = build['finished_at'] log.info('finished_at = %s', finished_at) duration = build['duration'] log.info('duration = %s', duration) if not isInt(duration): raise UnknownError('duration returned is not an integer!') repository_id = build['repository_id'] log.info('repository_id = %s', repository_id) if not isInt(repository_id): raise UnknownError('repository_id returned is not an integer!') result = build['result'] log.info('result = %s', result) state = build['state'] log.info('state = %s', state) if result == 0: self.ok() status = "PASSED" else: self.critical() status = "FAILED" self.msg = "Travis CI build #{number} {status} for repo '{repo}' in {duration} secs".format(\ number=number, status=status, repo=self.repo, duration=duration) self.check_thresholds(duration) self.msg += ", started_at='{0}'".format(started_at) self.msg += ", finished_at='{0}'".format(finished_at) if self.verbose: self.msg += ", message='{0}'".format(message) self.msg += ", branch='{0}'".format(branch) self.msg += ", commit='{0}'".format(commit) self.msg += ", repository_id='{0}'".format(repository_id) if self.verbose or self.builds_in_progress > 0: self.msg += ", {0} build{1} in progress".format( self.builds_in_progress, plural(self.builds_in_progress)) self.msg += " | last_build_duration={duration}s{perf_thresholds} num_builds_in_progress={builds_in_progress}"\ .format(duration=duration, perf_thresholds=self.get_perf_thresholds(), builds_in_progress=self.builds_in_progress)