This file is indexed.

/usr/lib/oar/oarnodesetting is in oar-common 2.5.4-2+deb8u1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/perl
# $Id$
# change node state dynamically

use strict;
use DBI();
use Data::Dumper;
use OAR::IO;
use OAR::Conf qw(init_conf dump_conf get_conf is_conf);
use Sys::Hostname;
use Getopt::Long;
use OAR::Tools;
use OAR::Version;

my $Old_umask = sprintf("%lo",umask());
umask(oct("022"));

$| = 1;

my $exit_code = 0;
my @notify_server_tag_list;

my @hostnames;
my $base;
my $state;
my $maintenance;
my $drain;
my $nowaitMode;
my @properties;
my $new_resource;
my $sos;
my @resource;
my $file;
my $Sql_property;
my $last_property_value;

# Get OAR configuration
init_conf($ENV{OARCONFFILE});
my $remote_host = get_conf("SERVER_HOSTNAME");
my $remote_port = get_conf("SERVER_PORT");

sub set_hostname_properties($$$){
    my $base = shift;
    my $hostname = shift;
    my $arrayProp = shift;

    foreach my $p (@{$arrayProp}){
        if ($p =~ m/(.+)\s*=\s*(.+)/m){
            if (OAR::Tools::check_resource_system_property($1) == 1){
                warn("/!\\ Cannot update property $1 because it is a system field.\n");
                $exit_code = 5;
                next;
            }
            print("Update property $1 with value $2 on node $hostname ...");
            my $ret = OAR::IO::set_node_property($base,$hostname,$1,$2);
            if ($ret == 0){
                print("DONE\n");
            }else{
                print("ERROR (wrong property or wrong value)\n");
                $exit_code = 6;
            }
        }else{
            warn("/!\\ Bad property syntax : -p property=value\n");
            $exit_code = 7;
        }
    }
}


sub set_resource_properties($$$){
    my $base = shift;
    my $resource = shift;
    my $arrayProp = shift;

    foreach my $p (@{$arrayProp}){
        if ($p =~ m/(.+)\s*=\s*(.+)/m){
            if (OAR::Tools::check_resource_system_property($1) == 1){
                warn("/!\\ Cannot update property $1 because it is a system field.\n");
                $exit_code = 8;
                next;
            }
            print("Update property $1 with value $2 ...");
            my $ret = OAR::IO::set_resource_property($base,$resource,$1,$2);
            if ($ret == 0){
                print("DONE\n");
            }elsif($ret == 2){
                print("SAME (the property is already equal to the value)\n");
            }else{
                print("ERROR (wrong property or wrong value)\n");
                $exit_code = 9;
            }
        }else{
            warn("/!\\ Bad property syntax : -p property=value\n");
            $exit_code = 10;
        }
    }
}

sub wait_end_of_running_jobs($$){
    my $dbh = shift;
    my $job_list = shift;

    my $max_timeout = 30;
    my $jobInfo;
    foreach my $j (sort(@{$job_list})){
        $jobInfo = {'state' => 'Running'};
        # active waiting : it is not very nice but it works!!
        print("\t$j ");
        my $timeCount = 0;
        while ((($jobInfo->{'state'} ne "Terminated") and ($jobInfo->{'state'} ne "Error")) and ($timeCount < $max_timeout)){
            $jobInfo = OAR::IO::get_job($dbh,$j);
            sleep(1);
            print(".");
            $timeCount++;
        }
        if ($timeCount >= $max_timeout){
            print(" Timouted\n");
            $exit_code = 11;
        }else{
            print(" Deleted\n");
        }
    }
    print("Check done\n");
}

sub set_maintenance_on($$$$$){
    my $base = shift;
    my $resources_list = shift;
    my $remote_host = shift;
    my $remote_port = shift;
    my $nowaitMode = shift;

    foreach my $res (@{$resources_list}){
	my $res_info = OAR::IO::get_resource_info($base,$res);
	if (!defined($res_info)){
	    warn("/!\\ The resource $res does not exist in OAR database.\n");
	    $exit_code = 1;
	}else{
	    print "maintenance mode set to \"ON\" on resource $res\n";
	    OAR::IO::add_event_maintenance_on($base, $res, OAR::IO::get_date($base));
	    my @prop_to_set;
	    my $last_available_upto = $res_info->{'available_upto'};
	    push @prop_to_set, "available_upto=0";
	    push @prop_to_set, "last_available_upto=$last_available_upto" if $last_available_upto != 0;
	    set_resource_properties($base, $res, \@prop_to_set);
	    OAR::IO::set_resource_nextState($base,$res,"Absent");
	    OAR::Tools::notify_tcp_socket($remote_host,$remote_port,"ChState");
	    if (!$nowaitMode){
		print("Check jobs to delete on resource $res :\n");
		my @jobs = OAR::IO::get_resource_job_to_frag($base,$res);
		wait_end_of_running_jobs($base,\@jobs);
	    }
	}
    }   
}

sub set_maintenance_off($$$$$){
    my $base = shift;    my $resources_list = shift;
    my $remote_host = shift;
    my $remote_port = shift;
    my $nowaitMode = shift;

    foreach my $res (@{$resources_list}){

	my $res_info = OAR::IO::get_resource_info($base,$res);
	if (!defined($res_info)){
	    warn("/!\\ The resource $res does not exist in OAR database.\n");
	    $exit_code = 1;
	}else{
	    print "maintenance mode set to \"OFF\" on resource $res\n";
	    OAR::IO::add_event_maintenance_off($base, $res, OAR::IO::get_date($base));
	    my @prop_to_set;
	    my $available_upto = $res_info->{'last_available_upto'};
	    push @prop_to_set, "available_upto=$available_upto" if $available_upto != 0;;
	    set_resource_properties($base, $res, \@prop_to_set);
	    OAR::IO::set_resource_nextState($base,$res,"Alive");
	    OAR::Tools::notify_tcp_socket($remote_host,$remote_port,"ChState");
	}
    }   
}

# print explanations for the user and exit
sub usage {
    print <<EOS;
Usage: $0 [[-a] [-h hostname] [-p "property=value"]] || [[-r resource_id] ||
[--sql "sql syntax"] || [-h hostname]] [[-s state] || [-p "property=value"] ||
[-m on|off]] || [-d on|off]
Change the state and properties of a node in OAR.
You can also create a new resource.
Options:
 -r, --resource [resource_id]         Resource id of the resource to modify
 -h, --hostname [hostname]            Hostname for the resources to modify
 -f, --file [file]                    Get a hostname list from a file (1
                                      hostname by line) for resources to modify
     --sql [SQL]                      Select resources to modify from database
                                      using a SQL where clause on the resource
                                      table (e.g.: "type = 'default'")
 -a, --add                            Add a new resource
 -s, --state=state                    Set the new state of the node
 -m, --maintenance [on|off]           Set/unset maintenance mode for resources,
                                      this is equivalent to setting its state
                                      to Absent and its available_upto to 0
 -d, --drain [on|off]                 Prevent new job to be scheduled on 
                                      resources, this is equivalent to setting
                                      the drain property to YES
 -p, --property ["property=value"]    Set the property of the resource to the
                                      given value
 -n, --no-wait                        Do not wait for job end when the node
                                      switches to Absent or Dead
     --last-property-value [property] Get the last value used for a property (as
                                      sorted by SQL's ORDER BY DESC)
     --help                           Display this help
 -V, --version                        Print OAR version number
N.B.:
 - The states allowed are: Alive, Absent or Dead.
 - If not specified, the hostname will be retrieved via the 'hostname'
   command.
 - "-a" and "-r" cannot be use together.
EOS
    exit(1);
}


my $Version;
# Options on arg command line
Getopt::Long::Configure ("gnu_getopt");
GetOptions ("state|s=s" => \$state,
            "maintenance|m=s" => \$maintenance,
            "drain|d=s" => \$drain,
            "care=s" => \$maintenance, # care is an alias for maintenance
            "hostname|h=s"   => \@hostnames,
            "no-wait|n" => \$nowaitMode,
            "property|p=s" => \@properties,
            "add|a" => \$new_resource,
            "help" => \$sos,
            "sql=s"   => \$Sql_property,
            "resource|r=i" => \@resource,
            "file|f=s" => \$file,
            "last-property-value=s" => \$last_property_value,
            "version|V" => \$Version
           ) or exit(1);

usage() if (defined($sos));

if (defined($Version)){
    print("OAR version : ".OAR::Version::get_version()."\n");
    exit($exit_code);
}

($#properties >= 0) || defined($state) || defined($new_resource) || defined($maintenance) || defined($drain) || defined($last_property_value) or usage();
if (defined($state) && !(($state eq 'Alive') || ($state eq 'Absent') || ($state eq 'Dead'))){
    warn("/!\\ Bad state value. Possibilities are : Alive | Absent | Dead \n");
    usage();
}
if (defined($maintenance) && !(($maintenance eq 'on') || ($maintenance eq 'off'))){
    warn("/!\\ Bad maintenance mode value. Possibilities are : on | off\n");
    usage();
}
if (defined($drain) && !(($drain eq 'on') || ($drain eq 'off'))){
    warn("/!\\ Bad drain mode value. Possibilities are : on | off\n");
    usage();
}


if (defined($Sql_property)){
    my $db = OAR::IO::connect_ro();
    foreach my $r (OAR::IO::get_resources_with_given_sql($db,$Sql_property)){
        push(@resource, $r);
    }
    OAR::IO::disconnect($db);
    if ($#resource < 0){
        warn("/!\\ Your SQL clause returns nothing and there is no resource specified.\n");
        $exit_code = 12;
    }
}

# Get hostnames from a file
if (defined($file)){
    if (open(FILE, "< $file")){
        while (<FILE>) {
            my $line = $_;
            if ($line !~ m/^\s*$/m){
                chop($line);
                push(@hostnames, $line);
            }
        }
        close(FILE);
    }else{
        warn("/!\\ Cannot open the file $file.\n");
        $exit_code = 13;
    }
}

if (defined($new_resource)){
    if (($#resource >= 0) or (defined($Sql_property))){
        warn("/!\\ You cannot use -r|--resource and (-a|--add or --sql) options together\n");
        usage();
    }
}

defined($hostnames[0]) or $hostnames[0] = hostname();
#print("$hostname\n");
my $base = OAR::IO::connect() or die("Cannot connect to the database\n");
if (defined($last_property_value)) {
    my $db = OAR::IO::connect_ro();
    my $value = OAR::IO::get_resource_last_value_of_property($db,$last_property_value);
    OAR::IO::disconnect($db);
    if (defined($value)){
        print $value."\n";
        $exit_code = 0;
    } else {
        warn("/!\\ Cannot retrive the last value for $last_property_value.\n");
        $exit_code = 14;
    }
    exit($exit_code);
}elsif (defined($new_resource)){
    # Create a new resources
    $state = "Alive" if (!defined($state));
    foreach my $h (@hostnames){
        print("new resource\n");
        print("$h added in the database\n");
        push(@resource,OAR::IO::add_resource($base, $h, $state));
    }
    push(@notify_server_tag_list, "ChState");
    push(@notify_server_tag_list, "Term");
}else{
    if (($#resource >= 0) or (defined($Sql_property))){
        if (defined($state)){
            my @resources_to_check;
            foreach my $r (@resource){
                #$base->do("LOCK TABLE resources WRITE");
                if (OAR::IO::set_resource_nextState($base,$r,$state) > 0){
                #$base->do("UNLOCK TABLES");
                    print("$r --> $state\n");
                    push(@resources_to_check, $r);
                }else{
                    warn("/!\\ The resource $r does not exist in OAR database.\n");
                    $exit_code = 3;
                }
            }
            OAR::Tools::notify_tcp_socket($remote_host,$remote_port,"ChState");
            if (($state eq 'Dead') || ($state eq 'Absent')){
                if (!$nowaitMode){
                    foreach my $r (@resources_to_check){
                        print("Check jobs to delete on resource $r :\n");
                        my @jobs = OAR::IO::get_resource_job_to_frag($base,$r);
                        wait_end_of_running_jobs($base,\@jobs);
                    }
                }
            }elsif ($state eq 'Alive'){
                print("Done\n");
            }
        }
        if (defined($maintenance)){
            if ($maintenance eq 'on'){
                set_maintenance_on($base, \@resource, $remote_host, $remote_port, $nowaitMode);
            }
            if ($maintenance eq 'off'){
                set_maintenance_off($base, \@resource, $remote_host, $remote_port, $nowaitMode);
            }
        }
    }else{
        # update all resources with netwokAdress = $hostname
        if (defined($maintenance)){
            my @res_to_maintain;
            foreach my $h (@hostnames){
            push @res_to_maintain, OAR::IO::get_all_resources_on_node($base, $h);
            }
            if ($maintenance eq 'on'){
            set_maintenance_on($base, \@res_to_maintain, $remote_host, $remote_port, $nowaitMode);
            }
            if ($maintenance eq 'off'){
            set_maintenance_off($base, \@res_to_maintain, $remote_host, $remote_port, $nowaitMode);
            }
        }
        if (defined($state)){
            my @nodes_to_check;
            foreach my $h (@hostnames){
                #$base->do("LOCK TABLE resources WRITE");
                if (OAR::IO::set_node_nextState($base,$h,$state) > 0){
                #$base->do("UNLOCK TABLES");
                    print("$h --> $state\n");
                    push(@nodes_to_check, $h);
                }else{
                    warn("/!\\ The node $h does not exist in OAR database.\n");
                    $exit_code = 4;
                }
            }
            OAR::Tools::notify_tcp_socket($remote_host,$remote_port,"ChState");
            if (($state eq 'Dead') || ($state eq 'Absent')){
                if (!$nowaitMode){
                    foreach my $h (@nodes_to_check){
                        print("Check jobs to delete on node $h :\n");
                        my @jobs = OAR::IO::get_node_job_to_frag($base,$h);
                        wait_end_of_running_jobs($base,\@jobs);
                    }
                }
            }
        }
    }
}

if (defined ($drain)){
    if ($drain = "on") {
        push @properties, "drain=YES"; 
    }elsif ($drain = "off") {
        push @properties, "drain=NO"; 
    }
}

# Update properties
if ($#properties >= 0){
    if (($#resource >= 0) or (defined($Sql_property))){
        foreach my $r (@resource){
            if (!defined(OAR::IO::get_resource_info($base,$r))){
                warn("/!\\ The resource $r does not exist in OAR database.\n");
                $exit_code = 1;
            }else{
                set_resource_properties($base,$r,\@properties);
            }
        }
    }else{
        foreach my $h (@hostnames){
            if (OAR::IO::is_node_exists($base,$h) == 0){
                warn("/!\\ The node $h does not exist in OAR database. First you must add it with -a|--add option.\n");
                $exit_code = 2;
            }else{
                set_hostname_properties($base,$h,\@properties);
            }
        }
    }
    push(@notify_server_tag_list, "Term");
}

OAR::IO::disconnect($base);

foreach my $t (@notify_server_tag_list){
    OAR::Tools::notify_tcp_socket($remote_host,$remote_port,$t);
}

exit($exit_code);