From 85de64f30e1e9bff15740b3d3af36504f6443376 Mon Sep 17 00:00:00 2001 From: Junghyun Kim Date: Fri, 21 Oct 2016 16:45:02 +0900 Subject: [PATCH] notify_buildmonitor.pm is added. You need to set BSConfig.pm like below: our $notification_plugin = "notify_jenkins notify_termini"; our $build_monitor_db_conf = "/usr/lib/obs/server/build_monitor_db.conf"; if $build_monitor_db_conf is not defined, notify_buildmonitor.pm is disabled. Change-Id: Ifc88b6ce49a2fd99854a866ad9cd91e74acd283c Signed-off-by: Junghyun Kim --- notify_buildmonitor.pm | 240 +++++++++++++++++++++++++++++++++++++ packaging/obs-event-plugin.changes | 5 + packaging/obs-event-plugin.spec | 5 +- 3 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 notify_buildmonitor.pm diff --git a/notify_buildmonitor.pm b/notify_buildmonitor.pm new file mode 100644 index 0000000..7f48773 --- /dev/null +++ b/notify_buildmonitor.pm @@ -0,0 +1,240 @@ +################################################################ +# +# Module for TERMINI DB logging. +# +package notify_termini; + +use BSConfig; +use TerminiDB; +use Data::Dumper; + +use strict; + +sub new { + my $self = {}; + bless $self, shift; + return $self; +} + +sub srcsrv_start { + my ($paramRef) = @_; + + # update all projects and packages info. + print "[", __LINE__, "] SRCSRV_START!\n"; + + my $start_time = TerminiDB::get_cur_time(); + TerminiDB::initialize_projpack_info($paramRef->{'projpack'}); + my $elapsed_time = TerminiDB::get_cur_time() - $start_time; + print "[",__LINE__,"] took $elapsed_time seconds.\n"; +} + +sub srcsrv_create_project { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $description = $paramRef->{'description'}; + + print "[", __LINE__, "] create a project ($proj_name, $description)\n"; + TerminiDB::insert_or_update_project_info($proj_name, $description); +} + +sub srcsv_update_project { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $description = $paramRef->{'description'}; + + print "[", __LINE__, "] update a project ($proj_name, $description)\n"; + TerminiDB::insert_or_update_project_info($proj_name, $description); +} + +sub srcsrv_delete_project { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + + print "[", __LINE__, "] delete a project ($proj_name )\n"; + TerminiDB::delete_project_info($proj_name); +} + +sub srcsrv_create_package { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $pkg_name = $paramRef->{'package'}; + my $description = $paramRef->{'description'}; + + print "[", __LINE__, "] create a package ($proj_name, $pkg_name, $description)\n"; + TerminiDB::insert_or_update_package_info($proj_name, $pkg_name, $description); +} + +sub srcsrv_update_package { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $pkg_name = $paramRef->{'package'}; + my $description = $paramRef->{'description'}; + + print "[", __LINE__, "] update a package ($proj_name, $pkg_name, $description)\n"; + TerminiDB::insert_or_update_package_info($proj_name, $pkg_name, $description); +} + +sub srcsrv_delete_package { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $pkg_name = $paramRef->{'package'}; + + print "[", __LINE__, "] delete a package ($proj_name, $pkg_name)\n"; + TerminiDB::delete_package_info($proj_name, $pkg_name); +} + +sub build_start { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repository'}; + my $arch = $paramRef->{'arch'}; + my $pkg_name = $paramRef->{'package'}; + my $reason = $paramRef->{'reason'}; + + my $config = "test"; + + TerminiDB::package_build_start($config, $proj_name, $repo, $arch, $pkg_name, $reason); +} + +sub build_unchanged { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repository'}; + my $arch = $paramRef->{'arch'}; + my $pkg_name = $paramRef->{'package'}; + my $build_result_dir = $paramRef->{'build_result_dir'}; + + my $status = "unchanged"; + my $config = "test"; + + TerminiDB::package_build_finished($config, $proj_name, $repo, $arch, $pkg_name, $status, $build_result_dir); +} + +sub build_success { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repository'}; + my $arch = $paramRef->{'arch'}; + my $pkg_name = $paramRef->{'package'}; + my $build_result_dir = $paramRef->{'build_result_dir'}; + + my $status = "succeeded"; + my $config = "test"; + + TerminiDB::package_build_finished($config, $proj_name, $repo, $arch, $pkg_name, $status, $build_result_dir); +} + +sub build_fail { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repository'}; + my $arch = $paramRef->{'arch'}; + my $pkg_name = $paramRef->{'package'}; + my $build_result_dir = $paramRef->{'build_result_dir'}; + + my $status = "failed"; + my $config = "test"; + + TerminiDB::package_build_finished($config, $proj_name, $repo, $arch, $pkg_name, $status, $build_result_dir); +} + +sub build_broken { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repository'}; + my $arch = $paramRef->{'arch'}; + my $pkg_name = $paramRef->{'package'}; + my $detail = $paramRef->{'detail'}; + + my $status = "broken"; + my $config = "test"; + + TerminiDB::package_build_status($config, $proj_name, $repo, $arch, $pkg_name, $status, $detail); +} + +sub build_unresolvable { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repository'}; + my $arch = $paramRef->{'arch'}; + my $pkg_name = $paramRef->{'package'}; + my $detail = $paramRef->{'detail'}; + + my $status = "unresolvable"; + my $config = "test"; + + TerminiDB::package_build_status($config, $proj_name, $repo, $arch, $pkg_name, $status, $detail); +} + +sub repo_publish_state { + my ($paramRef) = @_; + + my $proj_name = $paramRef->{'project'}; + my $repo = $paramRef->{'repo'}; + my $state = $paramRef->{'state'}; + my $arch = $paramRef->{'arch'}; + + my $config = "test"; + + if( $state eq "published") { + #if published, the project build is finished. + TerminiDB::project_build_finished($config, $proj_name, $repo, $arch); + } +} + +my %event_handlers = ( + 'SRCSRV_START' => \&srcsrv_start, + + 'SRCSRV_CREATE_PROJECT' => \&srcsrv_create_project, + 'SRCSRV_UPDATE_PROJECT' => \&srcsrv_update_project, + 'SRCSRV_DELETE_PROJECT' => \&srcsrv_delete_project, + + 'SRCSRV_CREATE_PACKAGE' => \&srcsrv_create_package, + 'SRCSRV_UPDATE_PACKAGE' => \&srcsrv_update_package, + 'SRCSRV_DELETE_PACKAGE' => \&srcsrv_delete_package, + + 'BUILD_START' => \&build_start, + 'BUILD_UNCHAGED' => \&build_unchanged, + 'BUILD_SUCCESS' => \&build_success, + 'BUILD_FAIL' => \&build_fail, + 'BUILD_BROKEN' => \&build_broken, + 'BUILD_UNRESOLVABLE' => \&build_unresolvable, + + 'REPO_PUBLISH_STATE' => \&repo_publish_state, +); + +my $g_dbh = undef; + +sub notify() { + my ($self, $type, $paramRef ) = @_; + + #termini_db_conf = "db.conf" + return unless $BSConfig::termini_db_conf; + + $g_dbh = TerminiDB::connect_db($BSConfig::termini_db_conf); + if( ! $g_dbh ) { + print "[", __FILE__, ":",__LINE__, "] TerminiDB::connect_db() failed.\n"; + return ; + } + + my $evhandler = $event_handlers{$type}; + if( $evhandler ) { + $evhandler->($paramRef); + } else { + print "[TERMINI] undefined event type: $type\n"; + } +} + +1; diff --git a/packaging/obs-event-plugin.changes b/packaging/obs-event-plugin.changes index eb591df..84043a7 100644 --- a/packaging/obs-event-plugin.changes +++ b/packaging/obs-event-plugin.changes @@ -1,4 +1,9 @@ -------------------------------------------------------------------------- +Sat Oct 22 02:24:18 KST 2016 Junghyun Kim - 0.1.2 + +- add another OBS plugin for buildmonitor. + +-------------------------------------------------------------------------- Wed Oct 16 13:24:28 UTC 2013 Ed Bartosh - 0.1.1 - Used POST method to create jobs. diff --git a/packaging/obs-event-plugin.spec b/packaging/obs-event-plugin.spec index a8e57a5..ca8c81f 100644 --- a/packaging/obs-event-plugin.spec +++ b/packaging/obs-event-plugin.spec @@ -1,5 +1,5 @@ Name: obs-event-plugin -Version: 0.1.1 +Version: 0.1.2 Release: 1 License: Intel Proprietary Summary: Plugin for OBS to trigger jenkins build @@ -23,7 +23,7 @@ true %install install -d %{buildroot}/usr/lib/obs/server/plugins/ -install notify_jenkins.pm %{buildroot}/usr/lib/obs/server/plugins/ +install notify_jenkins.pm notify_buildmonitor.pm %{buildroot}/usr/lib/obs/server/plugins/ %clean rm -rf %{buildroot} @@ -34,5 +34,6 @@ rm -rf %{buildroot} %dir %{_prefix}/lib/obs/server/ %dir %{_prefix}/lib/obs/server/plugins/ %{_prefix}/lib/obs/server/plugins/notify_jenkins.pm +%{_prefix}/lib/obs/server/plugins/notify_buildmonitor.pm %changelog -- 2.7.4