diff --git a/buildman/builder.py b/buildman/builder.py index 3e14db3eb..4f0d8f2d7 100644 --- a/buildman/builder.py +++ b/buildman/builder.py @@ -44,8 +44,8 @@ def run_build_manager(): if os.environ.get('SSL_CONFIG'): logger.debug('Loading SSL cert and key') ssl_context = SSLContext() - ssl_context.load_cert_chain(os.environ.get('SSL_CONFIG') + '/ssl.cert', - os.environ.get('SSL_CONFIG') + '/ssl.key') + ssl_context.load_cert_chain(os.path.join(os.environ.get('SSL_CONFIG'), 'ssl.cert'), + os.path.join(os.environ.get('SSL_CONFIG'), 'ssl.key')) server = BuilderServer(app.config['SERVER_HOSTNAME'], dockerfile_build_queue, build_logs, user_files, manager_klass) diff --git a/buildman/manager/basemanager.py b/buildman/manager/basemanager.py index f66054c45..a688f09cb 100644 --- a/buildman/manager/basemanager.py +++ b/buildman/manager/basemanager.py @@ -47,3 +47,9 @@ class BaseManager(object): one of: incomplete, error, complete. If incomplete, the job should be requeued. """ raise NotImplementedError + + def num_workers(self): + """ Returns the number of active build workers currently registered. This includes those + that are currently busy and awaiting more work. + """ + raise NotImplementedError diff --git a/buildman/manager/enterprise.py b/buildman/manager/enterprise.py index 824e02d53..6583284a8 100644 --- a/buildman/manager/enterprise.py +++ b/buildman/manager/enterprise.py @@ -70,3 +70,5 @@ class EnterpriseManager(BaseManager): def build_component_disposed(self, build_component, timed_out): self.build_components.remove(build_component) + def num_workers(self): + return len(self.build_components) diff --git a/buildman/server.py b/buildman/server.py index 3863406f2..e6d254536 100644 --- a/buildman/server.py +++ b/buildman/server.py @@ -9,7 +9,7 @@ from aiowsgi import create_server as create_wsgi_server from flask import Flask from threading import Event from trollius.coroutines import From -from datetime import datetime, timedelta +from datetime import timedelta from buildman.jobutil.buildjob import BuildJob, BuildJobLoadException from data.queue import WorkQueue @@ -137,7 +137,7 @@ class BuilderServer(object): @trollius.coroutine def _work_checker(self): while self._current_status == 'running': - logger.debug('Checking for more work') + logger.debug('Checking for more work for %d active workers', self._lifecycle_manager.num_workers()) job_item = self._queue.get(processing_time=self._lifecycle_manager.setup_time()) if job_item is None: logger.debug('No additional work found. Going to sleep for %s seconds', WORK_CHECK_TIMEOUT) diff --git a/data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py b/data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py new file mode 100644 index 000000000..87aaf84a3 --- /dev/null +++ b/data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py @@ -0,0 +1,24 @@ +"""Convert slack webhook data + +Revision ID: 5b84373e5db +Revises: 1c5b738283a5 +Create Date: 2014-12-16 12:02:55.167744 + +""" + +# revision identifiers, used by Alembic. +revision = '5b84373e5db' +down_revision = '1c5b738283a5' + +from alembic import op +import sqlalchemy as sa + +from tools.migrateslackwebhook import run_slackwebhook_migration + + +def upgrade(tables): + run_slackwebhook_migration() + + +def downgrade(tables): + pass diff --git a/endpoints/notificationmethod.py b/endpoints/notificationmethod.py index d7085f1f0..4d2d685f8 100644 --- a/endpoints/notificationmethod.py +++ b/endpoints/notificationmethod.py @@ -1,14 +1,10 @@ import logging -import io -import os.path -import tarfile -import base64 import json import requests import re from flask.ext.mail import Message -from app import mail, app, get_app_url +from app import mail, app from data import model from workers.worker import JobException @@ -363,11 +359,8 @@ class SlackMethod(NotificationMethod): return 'slack' def validate(self, repository, config_data): - if not config_data.get('token', ''): - raise CannotValidateNotificationMethodException('Missing Slack Token') - - if not config_data.get('subdomain', '').isalnum(): - raise CannotValidateNotificationMethodException('Missing Slack Subdomain Name') + if not config_data.get('url', ''): + raise CannotValidateNotificationMethodException('Missing Slack Callback URL') def format_for_slack(self, message): message = message.replace('\n', '') @@ -378,10 +371,8 @@ class SlackMethod(NotificationMethod): def perform(self, notification, event_handler, notification_data): config_data = json.loads(notification.config_json) - token = config_data.get('token', '') - subdomain = config_data.get('subdomain', '') - - if not token or not subdomain: + url = config_data.get('url', '') + if not url: return owner = model.get_user_or_org(notification.repository.namespace_user.username) @@ -389,8 +380,6 @@ class SlackMethod(NotificationMethod): # Something went wrong. return - url = 'https://%s.slack.com/services/hooks/incoming-webhook?token=%s' % (subdomain, token) - level = event_handler.get_level(notification_data['event_data'], notification_data) color = { 'info': '#ffffff', @@ -426,5 +415,5 @@ class SlackMethod(NotificationMethod): raise NotificationMethodPerformException(error_message) except requests.exceptions.RequestException as ex: - logger.exception('Slack method was unable to be sent: %s' % ex.message) + logger.exception('Slack method was unable to be sent: %s', ex.message) raise NotificationMethodPerformException(ex.message) diff --git a/static/directives/create-external-notification-dialog.html b/static/directives/create-external-notification-dialog.html index 650862690..03479015b 100644 --- a/static/directives/create-external-notification-dialog.html +++ b/static/directives/create-external-notification-dialog.html @@ -73,7 +73,7 @@
- {{ field.title }}: + {{ field.title }}:
@@ -81,6 +81,9 @@ +