From 758179a26f1545d801108d8f8f3331e8b6ef0b7b Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 13 Mar 2009 15:36:44 +0000
Subject: [PATCH] svn merge -r16871:16882
 https://eris.llnl.gov/svn/slurm/branches/slurm-1.3

---
 contribs/perlapi/libslurm-perl/Slurm.xs   |   6 +
 contribs/slurmdb-direct/config.slurmdb.pl |  15 +++
 contribs/slurmdb-direct/moab_2_slurmdb.pl | 156 ++++++++++++++++++++++
 src/sreport/job_reports.c                 |   3 +-
 4 files changed, 179 insertions(+), 1 deletion(-)
 create mode 100644 contribs/slurmdb-direct/config.slurmdb.pl
 create mode 100755 contribs/slurmdb-direct/moab_2_slurmdb.pl

diff --git a/contribs/perlapi/libslurm-perl/Slurm.xs b/contribs/perlapi/libslurm-perl/Slurm.xs
index 7c64054a2b7..57c51227306 100644
--- a/contribs/perlapi/libslurm-perl/Slurm.xs
+++ b/contribs/perlapi/libslurm-perl/Slurm.xs
@@ -25,6 +25,7 @@ extern int slurm_hostlist_push(hostlist_t hl, const char *hosts);
 extern int slurm_hostlist_push_host(hostlist_t hl, const char *host);
 extern int slurm_hostlist_find(hostlist_t hl, const char *hostname);
 extern size_t slurm_hostlist_ranged_string(hostlist_t hl, size_t n, char *buf);
+extern void slurm_hostlist_uniq(hostlist_t hl);
 
 struct slurm {
 	node_info_msg_t *node_info_msg;
@@ -804,6 +805,11 @@ slurm_hostlist_ranged_string(hostlist_t hl = NULL)
 	OUTPUT:
 		RETVAL
 
+void
+slurm_hostlist_uniq(hostlist_t hl = NULL)
+        CODE:
+		slurm_hostlist_uniq(hl);
+
 void
 DESTROY(hl)
 		hostlist_t hl=NULL;
diff --git a/contribs/slurmdb-direct/config.slurmdb.pl b/contribs/slurmdb-direct/config.slurmdb.pl
new file mode 100644
index 00000000000..f1e81d5dbed
--- /dev/null
+++ b/contribs/slurmdb-direct/config.slurmdb.pl
@@ -0,0 +1,15 @@
+# Set database information
+$db_name      = "slurm_acct_db";
+$db_job_table = "job_table";
+
+# These are the options you should change for your own site.
+#$db_host      = "fargo";
+#$db_port      = "3306";
+#$db_user      = "some_user";
+#$db_passwd    = "some_password";
+
+# Database connection line for the DBI
+$db_conn_line = "DBI:mysql:database=${db_name};host=${db_host}";
+
+# "1;" Required for file inclusion
+1;
diff --git a/contribs/slurmdb-direct/moab_2_slurmdb.pl b/contribs/slurmdb-direct/moab_2_slurmdb.pl
new file mode 100755
index 00000000000..6dfe6d7e2ed
--- /dev/null
+++ b/contribs/slurmdb-direct/moab_2_slurmdb.pl
@@ -0,0 +1,156 @@
+#! /usr/bin/perl -w
+###############################################################################
+#
+# slurmdbd_direct - write directly into the slurmdbd.
+#
+# based off the index in
+# http://www.clusterresources.com/products/mwm/docs/16.3.3workloadtrace.shtml
+#
+#
+###############################################################################
+#  Copyright (C) 2009 Lawrence Livermore National Security.
+#  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
+#  Written by Danny Auble <da@llnl.gov>
+#  CODE-OCEC-09-009. All rights reserved.
+#  
+#  This file is part of SLURM, a resource management program.
+#  For details, see <http://www.llnl.gov/linux/slurm/>.
+#  
+#  SLURM is free software; you can redistribute it and/or modify it under
+#  the terms of the GNU General Public License as published by the Free
+#  Software Foundation; either version 2 of the License, or (at your option)
+#  any later version.
+#
+#  In addition, as a special exception, the copyright holders give permission 
+#  to link the code of portions of this program with the OpenSSL library under
+#  certain conditions as described in each individual source file, and 
+#  distribute linked combinations including the two. You must obey the GNU 
+#  General Public License in all respects for all of the code used other than 
+#  OpenSSL. If you modify file(s) with this exception, you may extend this 
+#  exception to your version of the file(s), but you are not obligated to do 
+#  so. If you do not wish to do so, delete this exception statement from your
+#  version.  If you delete this exception statement from all source files in 
+#  the program, then also delete it here.
+#  
+#  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
+#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+#  details.
+#  
+#  You should have received a copy of the GNU General Public License along
+#  with SLURM; if not, write to the Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+#  
+###############################################################################
+
+use strict;
+use FindBin;
+use Getopt::Long 2.24 qw(:config no_ignore_case require_order);
+use lib "${FindBin::Bin}/../lib/perl";
+use lib qw(/home/da/slurm/1.3/snowflake/lib/perl/5.8.8);
+use autouse 'Pod::Usage' => qw(pod2usage);
+use Slurm ':all';
+use Switch;
+use DBI;
+BEGIN { require "config.slurmdb.pl"; }
+our ($logLevel, $db_conn_line, $db_job_table, $db_user, $db_passwd);
+
+my $set = 0;
+
+my $sql = "INSERT INTO $db_job_table " .
+	"(jobid, associd, wckeyid, uid, gid, nodelist, " .
+	"cluster, account, partition, wckey, eligible, " .
+	"submit, start, name, track_steps, state, priority, " .
+	"req_cpus, alloc_cpus) VALUES ";
+
+foreach my $line (<STDIN>) {
+	chomp $line;
+	# the below list is based off the index in
+#  http://www.clusterresources.com/products/mwm/docs/16.3.3workloadtrace.shtml
+	my ($hr_time,
+	    $timestamp,
+	    $type,
+	    $id,
+	    $event,
+	    $req_nodes,
+	    $req_tasks,
+	    $user,
+	    $group,
+	    $wall_limit,
+	    $state,
+	    $class,
+	    $sub_time,
+	    $dispatch_time,
+	    $start_time,
+	    $end_time,
+	    $network,
+	    $arch,
+	    $op,
+	    $node_mem_comp,
+	    $node_mem,
+	    $node_disk_comp,
+	    $node_disk,
+	    $node_features,
+	    $queue_time,
+	    $alloc_tasks,
+	    $tasks_per_node,
+	    $qos,
+	    $flags,
+	    $account,
+	    $executable,
+	    $rm_ext,
+	    $bypass_cnt,
+	    $cpu_secs,
+	    $partition,
+	    $procs_per_task,
+	    $mem_per_task,
+	    $disk_per_task,
+	    $swap_per_task,
+	    $eligible_time,
+	    $timeout,
+	    $alloc_hostlist,
+	    $rm_name,
+	    $req_hostlist,
+	    $resv,
+	    $app_sim_data,
+	    $desc,
+	    $message,
+	    $cost,
+	    $history,
+	    $util,
+	    $estimate,
+	    $comp_code,
+	    $ext_mem,
+	    $ext_cpu,
+	    @extra) = split /\s+/, $line;
+	next if !$type;
+	next if $type ne "job";
+	next if $event eq "JOBMIGRATE";
+
+	my $uid = getpwnam($user);
+	my $gid = getgrnam($group);
+	$uid = -2 if !$uid;
+	$gid = -2 if !$gid;
+
+	my $alloc_hl = Slurm::Hostlist::create($alloc_hostlist);
+	if($alloc_hl) {
+		Slurm::Hostlist::uniq($alloc_hl);
+		$alloc_hl = Slurm::Hostlist::ranged_string($alloc_hl);
+	}
+
+	$sql .= ", " if $set;
+	$sql .= "($id, 0, 0, $uid, $gid, '$alloc_hl', )";
+	$set = 1;
+}
+
+exit 0 if !$set;
+$sql .= " on duplicate key update nodelist=VALUES(nodelist), account=VALUES(account), partition=VALUES(partition), wckey=VALUES(wckey), start=VALUES(start), alloc_cpus=VALUES(alloc_cpus)";
+print "$sql\n";
+
+exit 0;
+$db_user = (getpwuid($<))[0] if !$db_user;
+my $dbhandle = DBI->connect($db_conn_line, $db_user, $db_passwd,
+			    {AutoCommit => 1, RaiseError => 1});
+$dbhandle->do($sql);
+
+exit 0;
diff --git a/src/sreport/job_reports.c b/src/sreport/job_reports.c
index 08ae5fea956..b7298cb4cad 100644
--- a/src/sreport/job_reports.c
+++ b/src/sreport/job_reports.c
@@ -608,7 +608,8 @@ extern int job_sizes_grouped_by_top_acct(int argc, char *argv[])
 	memset(&assoc_cond, 0, sizeof(acct_association_cond_t));
 	assoc_cond.id_list = job_cond->associd_list;
 	assoc_cond.cluster_list = job_cond->cluster_list;
-	assoc_cond.partition_list = job_cond->partition_list;
+	/* don't limit associations to having the partition_list */
+	//assoc_cond.partition_list = job_cond->partition_list;
 	if(!job_cond->acct_list || !list_count(job_cond->acct_list)) {
 		job_cond->acct_list = list_create(NULL);
 		list_append(job_cond->acct_list, "root");
-- 
GitLab