This file is indexed.

/usr/lib/oar/oarnodesetting is in oar-common 2.5.7-3.

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
#!/usr/bin/perl
# Create of change resources

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 @resources;
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_resources_properties($$$){
    my $base = shift;
    my $resources = shift; # ref to hash, {nodes => [...]}} or {resources => [...]}

    my $arrayProp = shift;

    # The following line  locks the tables in mysql, but just begins a transaction in postgresql
    OAR::IO::lock_table($base, ["resources","resource_logs"]);
    # To avoid deadlocks with postgresql, does lock the tables. This MUST also be done in other places (node_change_state, sarko, bipbip, ...)
    if (OAR::IO::get_database_type() eq "Pg") {
        $base->do("LOCK TABLE resources, resource_logs IN EXCLUSIVE MODE");
    }
    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("Set property $1 to $2...");
            my $ret = OAR::IO::set_resources_property($base,$resources,$1,$2);
            print(" $ret resource(s) updated.\n");
            if (not defined($ret) or ($ret < 0)){
                $exit_code = 9;
            }
        }else{
            warn("/!\\ Bad property syntax: -p property=value\n");
            $exit_code = 10;
        }
    }
    OAR::IO::unlock_table($base);
}

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_resources_properties($base, {resources => [$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_resources_properties($base, {resources => [$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]

Create a new resource or change the state and properties of existing resources.

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
     --verbose                        Verbose output
 -V, --version                        Print OAR version number
N.B.:
 - The states allowed are: Alive, Absent or Dead.
 - If not specified, the hostname will be retrieved with the 'hostname' command.
 - "-a, --add" and "-r, --resource" or "--sql"  cannot be used at a same time.
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" => \@resources,
            "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. Possible values are: Alive | Absent | Dead \n");
    usage();
}
if (defined($maintenance) && !(($maintenance eq 'on') || ($maintenance eq 'off'))){
    warn("/!\\ Bad maintenance mode value. Possible values are: on | off\n");
    usage();
}
if (defined($drain) && !(($drain eq 'on') || ($drain eq 'off'))){
    warn("/!\\ Bad drain mode value. Possible values 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(@resources, $r);
    }
    OAR::IO::disconnect($db);
    if ($#resources < 0){
        warn("/!\\ Your SQL clause returns nothing and there is no resource specified.\n");
        $exit_code = 12;
        exit($exit_code);
    }
}

# 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 (($#resources >= 0) or (defined($Sql_property))){
        warn("/!\\ You cannot use -r|--resource or --sql and -a|--add options at a same time\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";
    } else {
        warn("# Warning: Cannot retrieve the last value for $last_property_value. Either no resource or no such property exists (yet).\n");
    }
    $exit_code = 0;
    exit($exit_code);
}elsif (defined($new_resource)){
    # Create a new resources
    $state = "Alive" if (!defined($state));
    foreach my $h (@hostnames){
        print("New resource added:  $h\n");
        push(@resources,OAR::IO::add_resource($base, $h, $state));
    }
    push(@notify_server_tag_list, "ChState");
    push(@notify_server_tag_list, "Term");
}else{
    if ($#resources >= 0){
        if (defined($state)){
            my $tmpnbupdates = OAR::IO::set_resources_nextState($base,\@resources,$state);
            if ($tmpnbupdates <= $#resources){
                warn("/!\\  ".$#resources + 1 - $tmpnbupdates." resource(s) cannot be updated.\n");
                $exit_code = 3;
            }else{
                print("(".join(",",@resources).") --> $state\n");
            }
            OAR::Tools::notify_tcp_socket($remote_host,$remote_port,"ChState");
            if (($state eq 'Dead') || ($state eq 'Absent')){
                if (!$nowaitMode){
                    foreach my $r (@resources){
                        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, \@resources, $remote_host, $remote_port, $nowaitMode);
            }
            if ($maintenance eq 'off'){
                set_maintenance_off($base, \@resources, $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){
                if (OAR::IO::set_node_nextState($base,$h,$state) > 0){
                    print("$h --> $state\n");
                    push(@nodes_to_check, $h);
                }else{
                    warn("/!\\ 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 eq "on") {
        push @properties, "drain=YES"; 
    }elsif ($drain eq "off") {
        push @properties, "drain=NO"; 
    }
}

# Update properties
if ($#properties >= 0){
    if ($#resources >= 0){
        set_resources_properties($base, {resources => \@resources}, \@properties);
    }elsif($#hostnames >= 0){
        set_resources_properties($base, {nodes => \@hostnames}, \@properties);
    } else {
        warn("/!\\ Cannot find resources to set in OAR database.\n");
        $exit_code = 2;
    }
    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);