mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Update scripts
This commit is contained in:
parent
e27a3fda79
commit
90ae832c2e
71
jobTag.pl
71
jobTag.pl
@ -41,13 +41,20 @@ my $dbh = DBI->connect(
|
||||
"DBI:SQLite:dbname=$database", "", "", \%attr)
|
||||
or die "Could not connect to database: $DBI::errstr";
|
||||
|
||||
my $sth_query_job = $dbh->prepare(qq{
|
||||
my $sth_select_tagged_jobs = $dbh->prepare(qq{
|
||||
SELECT j.*
|
||||
FROM jobtag jt, job j, tag t
|
||||
WHERE jt.tag_id=t.tag_id
|
||||
AND t.name=?
|
||||
AND j.id=jt.job_id
|
||||
GROUP BY j.id
|
||||
FROM job j
|
||||
JOIN jobtag jt ON j.id = jt.job_id
|
||||
JOIN tag t ON jt.tag_id = t.id
|
||||
WHERE t.name = ?
|
||||
});
|
||||
|
||||
my $sth_select_job_tags = $dbh->prepare(qq{
|
||||
SELECT t.*
|
||||
FROM tag t
|
||||
JOIN jobtag jt ON t.id = jt.tag_id
|
||||
JOIN job j ON jt.job_id = j.id
|
||||
WHERE j.job_id = ?
|
||||
});
|
||||
|
||||
my $sth_select_job = $dbh->prepare(qq{
|
||||
@ -72,17 +79,63 @@ my $sth_job_add_tag = $dbh->prepare(qq{
|
||||
VALUES(?,?)
|
||||
});
|
||||
|
||||
my $sth_job_has_tag = $dbh->prepare(qq{
|
||||
SELECT id FROM job
|
||||
WHERE job_id=? AND tag_id=?
|
||||
});
|
||||
|
||||
my $CMD = $ARGV[0];
|
||||
my $JOB_ID = $ARGV[1];
|
||||
my $TAG_NAME = $ARGV[2];
|
||||
|
||||
my ($jid, $tid);
|
||||
|
||||
# check if job exists
|
||||
my @row = $dbh->selectrow_array($sth_select_job, undef, $JOB_ID);
|
||||
|
||||
if ( @row ) {
|
||||
$jid = $row[0];
|
||||
} else {
|
||||
die "Job does not exist: $JOB_ID!\n";
|
||||
}
|
||||
|
||||
# check if tag already exists
|
||||
@row = $dbh->selectrow_array($sth_select_tag, undef, $TAG_NAME);
|
||||
|
||||
if ( @row ) {
|
||||
$tid = $row[0];
|
||||
} else {
|
||||
print "Insert new tag: $TAG_NAME!\n";
|
||||
|
||||
$sth_insert_tag->execute('pathologic', $TAG_NAME);
|
||||
}
|
||||
|
||||
if ( $CMD eq 'ADD' ) {
|
||||
# body...
|
||||
@row = $dbh->selectrow_array($sth_job_has_tag, undef, $jid, $tid);
|
||||
if ( @row ) {
|
||||
die "Job already tagged!\n";
|
||||
} else {
|
||||
print "Adding tag $TAG_NAME to job $JOB_ID!\n";
|
||||
$sth_job_add_tag($jid, $tid);
|
||||
}
|
||||
}
|
||||
elsif ( $CMD eq 'RM' ) {
|
||||
# elsif...
|
||||
}
|
||||
elsif ( $CMD eq 'LS' ) {
|
||||
elsif ( $CMD eq 'LST' ) {
|
||||
$sth_select_job_tags->execute;
|
||||
my ($id, $type, $name);
|
||||
|
||||
while(($id,$type,$name) = $sth->fetchrow()){
|
||||
print("$id, $type, $name\n");
|
||||
}
|
||||
$sth_select_job_tags->finish();
|
||||
}
|
||||
elsif ( $CMD eq 'LSJ' ) {
|
||||
# elsif...
|
||||
}
|
||||
else {
|
||||
# else...
|
||||
die "Unknown command: $CMD!\n";
|
||||
}
|
||||
|
||||
$dbh->disconnect();
|
||||
|
@ -31,42 +31,9 @@ use utf8;
|
||||
use File::Slurp;
|
||||
use Data::Dumper;
|
||||
use JSON::MaybeXS qw(encode_json decode_json);
|
||||
use DBI;
|
||||
|
||||
my $database = $ARGV[0];
|
||||
my $basedir = $ARGV[1];
|
||||
|
||||
my %attr = (
|
||||
PrintError => 1,
|
||||
RaiseError => 1
|
||||
);
|
||||
|
||||
my $dbh = DBI->connect(
|
||||
"DBI:SQLite:dbname=$database", "", "", \%attr)
|
||||
or die "Could not connect to database: $DBI::errstr";
|
||||
|
||||
my $sth_select_job = $dbh->prepare(qq{
|
||||
SELECT id, user_id, job_id, cluster_id,
|
||||
start_time, stop_time, duration, num_nodes,
|
||||
has_profile
|
||||
FROM job
|
||||
WHERE job_id=?
|
||||
});
|
||||
|
||||
my $sth_update_job = $dbh->prepare(qq{
|
||||
UPDATE job
|
||||
SET has_profile = ?,
|
||||
mem_used_max = ?,
|
||||
flops_any_avg = ?,
|
||||
mem_bw_avg = ?
|
||||
WHERE id=?;
|
||||
});
|
||||
|
||||
my $sth_select_tag = $dbh->prepare(qq{
|
||||
SELECT id
|
||||
FROM tag
|
||||
WHERE tag_name=?
|
||||
});
|
||||
my $basedir = $ARGV[0];
|
||||
my $basedir = './data';
|
||||
|
||||
|
||||
my ($TS, $TE);
|
||||
@ -81,16 +48,19 @@ $TS = time();
|
||||
while ( <$fh> ) {
|
||||
|
||||
my $line = $_;
|
||||
my ($jobID, $path1, $path2) = split ' ', $line;
|
||||
my ($jobID, $system) = split '.', $line;
|
||||
$counter++;
|
||||
|
||||
my $json = read_file($jobDirectory.'/data.json');
|
||||
my $data = decode_json $json;
|
||||
$json = read_file($jobDirectory.'/meta.json');
|
||||
# my $json = read_file($jobDirectory.'/data.json');
|
||||
# my $data = decode_json $json;
|
||||
my $json = read_file($jobDirectory.'/meta.json');
|
||||
my $meta = decode_json $json;
|
||||
|
||||
my @flopsAny = $data->{flops_any}->{series};
|
||||
my @memBw = $data->{mem_bw}->{series};
|
||||
my $footprint = $meta->{statistics};
|
||||
|
||||
if ( $footprint->{flops_any}->{max} < 2.0 and $footprint->{mem_bw}->{max} < 2.0 ){
|
||||
print $fhn $jobID;
|
||||
}
|
||||
|
||||
if ( $counter == 20 ) {
|
||||
$TE = time();
|
||||
@ -100,6 +70,5 @@ while ( <$fh> ) {
|
||||
$TS = $TE;
|
||||
}
|
||||
}
|
||||
$dbh->disconnect;
|
||||
close $fh;
|
||||
close $fhn;
|
||||
|
Loading…
Reference in New Issue
Block a user