This file is indexed.

/usr/share/arc/glue-generator.pl is in nordugrid-arc-aris 5.3.0~rc1-1.

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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#!/usr/bin/perl -w
# Queries NDGF site information and translates it from ARC to GLUE schema
# Prototype by L.Field (2006)
# Corrections and Performance enhancements by M.Flechl (2006-08-17)
# Merged with adjusted bdii-update (David Groep, L.Field, M.Litmaath) by L.Field and M.Flechl (2006-08-21)
# ARC GIIS traversal and some sanity checks for failing GRISes by Mattias Wadenstein (2007-07-03)
# Updated to work at a resource bdii-level by Daniel (2009-2010)
# Now we can generate the CEUniqueID correctly with the queue name by Pekka Kaitaniemi (2012-04-19)
#
# $Id: glite-info-provider-ndgf,v 1.1 2006/08/30 12:13:15 lfield Exp $ 

use strict;
use LWP::Simple;
use POSIX;
use IO::Handle;

sub translator;

sub build_glueCEUniqueID
{
    my $cluster_name = shift;
    my $cluster_lrms_type = shift;
    my $queue_name = shift;
    return $cluster_name . ":" . "2811" . "/nordugrid-". $cluster_lrms_type . "-" . $queue_name;
}

sub build_glueServiceUniqueID
{
    my $cluster_name = shift;
    return $cluster_name . "_" . "org.nordugrid.arex";
}

# Global variables for translator
use vars qw($DEFAULT); $DEFAULT = 0;
use vars qw($outbIP $inbIP $glueSubClusterUniqueID $norduBenchmark $norduOpsys $norduNodecput $norduNodecpu);
use vars qw($glueHostMainMemoryRAMSize $glueHostArchitecturePlatformType $glueSubClusterUniqueID $GlueHostBenchmarkSI00 $GlueHostBenchmarkSF00);
use vars qw($glueSubClusterName $glueSubClusterPhysicalCPUs $glueSubClusterLogicalCPUs $glueClusterUniqueID $processorOtherDesc $smpSize);
use vars qw($AssignedSlots $mappedStatus $waitingJobs $totalJobs $waitingJobs $freeSlots $estRespTime $worstRespTime $vo $ce_unique_id);
use vars qw(@envs @vos);

#Create nordugrid ldif
#TODO read this from optarg
my $ldif_input=`$LDIF_GENERATOR_FILE_NG`;

# These values will be read from NorduGrid MDS
my %cluster_attributes=(
    'nordugrid-cluster-location' => '',
    'nordugrid-cluster-support' => '',
    'nordugrid-cluster-name' => '',
    'nordugrid-cluster-runtimeenvironment' => '',
    'nordugrid-cluster-contactstring' => '',
    'nordugrid-cluster-aliasname' => '',
    'nordugrid-cluster-lrms-type' => '',
    'nordugrid-cluster-lrms-version' => '',
    'nordugrid-cluster-totalcpus' => '',
    'nordugrid-cluster-opsys' => '',
    'nordugrid-cluster-benchmark' => '',
    'nordugrid-cluster-nodecpu' => '',
    'nordugrid-cluster-nodememory' => '',
    'nordugrid-cluster-nodeaccess' => '',
    'nordugrid-cluster-architecture' => '',
    'nordugrid-cluster-acl' => '',
    'nordugrid-cluster-homogeneity' => '',
    'nordugrid-cluster-comment' => '',
    'nordugrid-cluster-owner' => '',
    'nordugrid-cluster-localse' => '',
    );

#all these values will be checked if they are numeric only:
my @cluster_attributes_num = ('totalcpus','nodememory');
for (my $i=0; $i<=$#cluster_attributes_num; $i++){ $cluster_attributes_num[$i] = 'nordugrid-cluster-'.$cluster_attributes_num[$i]; }

# Queue attributes read from NorduGrid MDS
my %queue_attributes=(
    'nordugrid-queue-name' => '',
    'nordugrid-queue-running' => '',
    'nordugrid-queue-maxrunning' => '',
    'nordugrid-queue-maxcputime' => '',
    'nordugrid-queue-maxqueuable' => '',
    'nordugrid-queue-totalcpus' => '',
    'nordugrid-queue-opsys' => '',
    'nordugrid-queue-benchmark' => '',
    'nordugrid-queue-nodecpu' => '',           
    'nordugrid-queue-nodememory' => '',
    'nordugrid-queue-architecture' => '',
    'nordugrid-queue-status' => '',
    'nordugrid-queue-gridqueued' => '',
    'nordugrid-queue-localqueued' => '',
    'nordugrid-queue-prelrmsqueued' => '',
    );

#all these values will be checked if they are numeric only:
my @queue_attributes_num = ('running','maxrunning','maxcputime','maxqueuable','totalcpus','nodememory','gridqueued','localqueued','prelrmsqueued');
for (my $i=0; $i<=$#queue_attributes_num; $i++){ $queue_attributes_num[$i] = 'nordugrid-queue-'.$queue_attributes_num[$i]; }

#Translate and print glue ldif
#TODO this should perhaps be able to write do different rootdn:s, not just mds-vo-name=resource,o=grid.
translator($ldif_input);

exit;

#translator takes an ldif-output in a scalar variable as input and prints the output to stdout
sub translator(){

    my $temp=$_[0];

    #$DEFAULT = -1;
    # Store ldif here
    my @ldif;

    #Remove blank space at the start of the line
    $temp=~s/\n //gm;
    @ldif=split "\n", $temp;
    push @ldif, "EOF";
    
    #my $hostname=hostname();
    
    #set the attributes from the ldif
    for my $key ( keys %cluster_attributes ) {
	$cluster_attributes{$key} = join (" ", grep { /^$key/ } @ldif);
	chomp $cluster_attributes{$key};
	if ($key eq "nordugrid-cluster-opsys" or $key eq "nordugrid-cluster-owner"
	    or $key eq "nordugrid-cluster-benchmark") {
	    $cluster_attributes{$key}=~s/ ?$key//g;
	} else {
	    $cluster_attributes{$key}=~s/$key: //g;
	}
	if ($cluster_attributes{$key}=~/^$/) { $cluster_attributes{$key}="$DEFAULT" }
    }

    my $glue_site_unique_id="$GLUESITEUNIQUEID";
    #my $glue_site_unique_id=$cluster_attributes{'nordugrid-cluster-aliasname'};

    @envs = split / /, $cluster_attributes{'nordugrid-cluster-runtimeenvironment'};
    my @storages = split / /, $cluster_attributes{'nordugrid-cluster-localse'};
    
    $outbIP = "FALSE";
    $inbIP = "FALSE";
    if ($cluster_attributes{'nordugrid-cluster-nodeaccess'} eq "outbound"){
	$outbIP = "TRUE";
    } elsif ($cluster_attributes{'nordugrid-cluster-nodeaccess'} eq "inbound"){
	$inbIP = "TRUE";
    }
    if ($cluster_attributes{'nordugrid-cluster-acl'} eq "$DEFAULT") {
	$cluster_attributes{'nordugrid-cluster-acl'}="VO:ops";
    }
    
    my @owner  = split /: /, $cluster_attributes{'nordugrid-cluster-owner'};
    
    my $nclocation=$cluster_attributes{'nordugrid-cluster-location'};
    
    my $loc = $LOC; 
    my $lat = $LAT; 
    my $long = $LONG;
    my $provide_glue_site_info = "$PROVIDE_GLUE_SITE_INFO";
    $processorOtherDesc = "$PROCESSOROTHERDESCRIPTION";
    #set numeric values to $DEFAULT if they are on the list and not numeric
    for (my $i=0; $i<=$#cluster_attributes_num; $i++){
	if (! ($cluster_attributes{$cluster_attributes_num[$i]} =~ /^\d+$/) ){ $cluster_attributes{$cluster_attributes_num[$i]} = $DEFAULT; }
    }

    # Write Site Entries
    if($provide_glue_site_info =~ /true/i) {
	write_site_entries($glue_site_unique_id,
			   $cluster_attributes{'nordugrid-cluster-comment'},
			   $cluster_attributes{'nordugrid-cluster-support'},
			   $loc,$lat,$long,"$GLUESITEWEB",\@owner);
    }

    if ($cluster_attributes{'nordugrid-cluster-homogeneity'} =~ /true/i){
	$glueSubClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'};
	$norduOpsys=$cluster_attributes{'nordugrid-cluster-opsys'};
	$norduBenchmark=$cluster_attributes{'nordugrid-cluster-benchmark'};
	$norduNodecpu=$cluster_attributes{'nordugrid-cluster-nodecpu'};
	$glueHostMainMemoryRAMSize=$cluster_attributes{'nordugrid-cluster-nodememory'};
	$glueHostArchitecturePlatformType=$cluster_attributes{'nordugrid-cluster-architecture'};
	$glueSubClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'};
	$glueSubClusterName=$glue_site_unique_id;
	if ( $processorOtherDesc =~ m/Cores=(\d+)/ ){
	    $smpSize=$1;
	    $glueSubClusterPhysicalCPUs=int($cluster_attributes{'nordugrid-cluster-totalcpus'}/$smpSize);
	}
	else {
	    $smpSize=1;
	    $glueSubClusterPhysicalCPUs=$cluster_attributes{'nordugrid-cluster-totalcpus'};
	}
	$glueSubClusterLogicalCPUs=$cluster_attributes{'nordugrid-cluster-totalcpus'};
	$glueClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'};
    
	WriteSubCluster();
    }

    #Do GlueCE entry for each nordugrid queue
    write_gluece_entries(\@ldif);

    # Write Cluster Entries
    write_cluster_entries($cluster_attributes{'nordugrid-cluster-name'},$glue_site_unique_id);

    #write CE-SE Binding Entries
    if ( $cluster_attributes{'nordugrid-cluster-localse'} ) {
        write_ce_se_binding_entries($cluster_attributes{'nordugrid-cluster-localse'},\@storages);
    }
    
    # Service information. This is an hack to mimic Site-BDII service information.
    my $glueServiceUniqueID = build_glueServiceUniqueID($cluster_attributes{'nordugrid-cluster-name'});
    my $glueservicename = $glue_site_unique_id."-arc";
    my $glueservicestatusinfo=`/etc/init.d/a-rex status`;
    chomp $glueservicestatusinfo;
    my $glueservicestatus;
    if ($? == 0) {
        $glueservicestatus="OK";
    } else {
        $glueservicestatus="Warning";
    }
    my $serviceendpoint = "gsiftp://". $cluster_attributes{'nordugrid-cluster-name'} . ":" . "2811" . "/jobs";
    my $serviceversion = "3.0.0";
    my $servicetype = "ARC-CE";
    write_service_information ($glueServiceUniqueID,$glueservicename,$glueservicestatus,$glueservicestatusinfo,$serviceendpoint,$serviceversion,$servicetype,'_UNDEF_');
}

# Write SubCluster Entries

sub WriteSubCluster {
    
#dn: GlueSubClusterUniqueID=$glueSubClusterUniqueID,GlueClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'},mds-vo-name=resource,o=grid

    print "
dn: GlueSubClusterUniqueID=$glueSubClusterUniqueID,GlueClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'},mds-vo-name=resource,o=grid
objectClass: GlueClusterTop
objectClass: GlueSubCluster
objectClass: GlueSchemaVersion
objectClass: GlueHostApplicationSoftware
objectClass: GlueHostArchitecture
objectClass: GlueHostBenchmark
objectClass: GlueHostMainMemory
objectClass: GlueHostNetworkAdapter
objectClass: GlueHostOperatingSystem
objectClass: GlueHostProcessor
objectClass: GlueInformationService
objectClass: GlueKey
";
 
    foreach (@envs){
	chomp;
	print "GlueHostApplicationSoftwareRunTimeEnvironment:  $_\n"
    }
 
    print "GlueHostArchitectureSMPSize: $smpSize
GlueHostNetworkAdapterInboundIP: $inbIP
GlueHostNetworkAdapterOutboundIP: $outbIP";
 
    my @opsys = split /: /, $norduOpsys;
    for (my $i=0; $i<=3; $i++){
	if ($i > $#opsys) { $opsys[$i]=$DEFAULT; }
	chomp($opsys[$i]);
	$opsys[$i]=~s/\s+$//;
    }
    $GlueHostBenchmarkSI00 = $DEFAULT;
    $GlueHostBenchmarkSF00 = $DEFAULT;
    my $benchmark;
    if($norduBenchmark) {
	foreach $benchmark (split /: /, $norduBenchmark) {
	    if($benchmark =~ /SPECINT2000 @ (\d+)/) {
		$GlueHostBenchmarkSI00 = $1;
	    }
	    if($benchmark =~ /SPECFP2000 @ (\d+)/) {
		$GlueHostBenchmarkSF00 = $1;
	    }
	}
    }
 
    my @nodecpu  = split / /, $norduNodecpu;
    my $clockSpeed=$DEFAULT;
    my $cpuVer=$DEFAULT;
    for (my $i=0; $i<=$#nodecpu; $i++){
	if ($i >= 2){
	    if ($nodecpu[$i -2] =~ /@/) { $clockSpeed = $nodecpu[$i -1]." ".$nodecpu[$i]; }
	}
	if ($nodecpu[$i] =~ /I$/) { $cpuVer = $nodecpu[$i]; }
    }
    for (my $i=0; $i<=1; $i++){ if ($i > $#nodecpu) { $nodecpu[$i]=$DEFAULT; } }
    
    $clockSpeed=~s/\.[0-9]*//;
    $clockSpeed=~s/MHz//i;
    $clockSpeed=~s/GHz/000/i;
    $clockSpeed=~s/[^0-9]//g;
    if (! $clockSpeed=~m/[0-9]/) { $clockSpeed=$DEFAULT; } 
    print "
GlueHostOperatingSystemName: $opsys[1]
GlueHostOperatingSystemRelease: $opsys[2]
GlueHostOperatingSystemVersion: $opsys[3]
GlueHostProcessorVendor: $nodecpu[0]
GlueHostProcessorModel: $nodecpu[1]
GlueHostProcessorVersion: $cpuVer
GlueHostProcessorClockSpeed: $clockSpeed
GlueHostProcessorOtherDescription: $processorOtherDesc
GlueHostMainMemoryRAMSize: $glueHostMainMemoryRAMSize
GlueHostArchitecturePlatformType: $glueHostArchitecturePlatformType
GlueHostBenchmarkSI00: $GlueHostBenchmarkSI00
GlueHostBenchmarkSF00: $GlueHostBenchmarkSF00
GlueSubClusterUniqueID: $glueSubClusterUniqueID
GlueSubClusterName: $glueSubClusterName
GlueSubClusterPhysicalCPUs: $glueSubClusterPhysicalCPUs
GlueSubClusterLogicalCPUs: $glueSubClusterLogicalCPUs
GlueChunkKey: GlueClusterUniqueID=$glueClusterUniqueID
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2
";
}

sub write_site_entries($$){
    my $site_id=shift;
    my $cluster_comment=shift;
    my $cluster_support=shift;
    my $loc=shift;
    my $lat=shift;
    my $long=shift;
    my $siteweb=shift;
    my $s_owner=shift;
    my @owner=@{$s_owner};
    print "
dn: GlueSiteUniqueID=$site_id,mds-vo-name=resource,o=grid
objectClass: GlueTop
objectClass: GlueSite
objectClass: GlueKey
objectClass: GlueSchemaVersion
GlueSiteUniqueID: $site_id
GlueSiteName: $site_id
GlueSiteDescription: ARC-$cluster_comment
GlueSiteUserSupportContact: mailto: $cluster_support
GlueSiteSysAdminContact: mailto: $cluster_support
GlueSiteSecurityContact: mailto: $cluster_support
GlueSiteLocation: $loc
GlueSiteLatitude: $lat
GlueSiteLongitude: $long
GlueSiteWeb: $siteweb";

    for (my $i=1; $i<=$#owner; $i++){
	print "\nGlueSiteSponsor: $owner[$i]";
    }

    print "
GlueSiteOtherInfo: Middleware=ARC
GlueForeignKey: None
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2

";
}    

sub write_gluece_entries(){
    my $s_ldif=shift;
    my @ldif = @{$s_ldif};
    my $is_queue="false";
    my @tmp_queue;

    foreach(@ldif){
	push @tmp_queue, $_;
	if(m/^dn:\s+nordugrid-queue-name/){
	    $is_queue="true";
	    undef @tmp_queue;
	}
	
	if( ( (m/^\s*$/) || (m/^EOF/) ) && ( $is_queue eq "true" )  ){
	    $is_queue = "false";
	    
	    #Set the queue attributes from the ldif
	    for my $key ( keys %queue_attributes ) {
		$queue_attributes{$key} = join (" ", grep { /^$key/ } @tmp_queue);
		chomp $queue_attributes{$key};
		
		if ($key eq "nordugrid-queue-opsys"){
		    $queue_attributes{$key}=~s/$key//g;
		} else {
		    $queue_attributes{$key}=~s/$key: //g;
		}
		if ($queue_attributes{$key}=~/^$/) { $queue_attributes{$key}="$DEFAULT" }
		
	    }
	    
	    #set non-numeric values to $DEFAULT if they are on the list
	    for (my $i=0; $i<=$#queue_attributes_num; $i++){
		if (! ($queue_attributes{$queue_attributes_num[$i]} =~ /^\d+$/) ){
		    #print "XXX Change $queue{$queue_num[$i]} to $DEFAULT\n";
		    $queue_attributes{$queue_attributes_num[$i]} = $DEFAULT;
		}
	    }


	    if ($cluster_attributes{'nordugrid-cluster-homogeneity'} =~ /false/i){

		$glueSubClusterUniqueID=$queue_attributes{'nordugrid-queue-name'}; ##XX
		$norduOpsys=$queue_attributes{'nordugrid-queue-opsys'}; ##XX
		$norduBenchmark=$queue_attributes{'nordugrid-queue-benchmark'}; ##XX
		$norduNodecpu=$queue_attributes{'nordugrid-queue-nodecpu'}; ##XX
		$glueHostMainMemoryRAMSize=$queue_attributes{'nordugrid-queue-nodememory'}; ##XX
		$glueHostArchitecturePlatformType=$queue_attributes{'nordugrid-queue-architecture'}; ##XX
		$glueSubClusterUniqueID=$queue_attributes{'nordugrid-queue-name'};  ##XX
		$glueSubClusterName=$queue_attributes{'nordugrid-queue-name'};  ##XX
		if ( $processorOtherDesc =~ m/Cores=(\d+)/ ){
		    $smpSize=$1;
		    $glueSubClusterPhysicalCPUs=int($queue_attributes{'nordugrid-queue-totalcpus'}/$smpSize);
		}
		else {
		    $smpSize=1;
		    $glueSubClusterPhysicalCPUs=$queue_attributes{'nordugrid-queue-totalcpus'};
		}
		$glueSubClusterLogicalCPUs=$queue_attributes{'nordugrid-queue-totalcpus'};  ##XX
		$glueClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'};  ##XX

		WriteSubCluster();
	    }
	    

	    $AssignedSlots = 0;
	    if ($queue_attributes{'nordugrid-queue-totalcpus'} ne $DEFAULT){
		$AssignedSlots = $queue_attributes{'nordugrid-queue-totalcpus'};
	    } elsif ($queue_attributes{'nordugrid-queue-maxrunning'} ne $DEFAULT)  {
		$AssignedSlots = $queue_attributes{'nordugrid-queue-maxrunning'};
	    } elsif ($cluster_attributes{'nordugrid-cluster-totalcpus'} ne $DEFAULT)  {
		$AssignedSlots = $cluster_attributes{'nordugrid-cluster-totalcpus'};
	    }
	    
	    if ($queue_attributes{'nordugrid-queue-totalcpus'} eq $DEFAULT){
		$queue_attributes{'nordugrid-queue-totalcpus'} = $cluster_attributes{'nordugrid-cluster-totalcpus'};
	    }
	    
	    $mappedStatus="";
	    if ($queue_attributes{'nordugrid-queue-status'} eq "active"){
		$mappedStatus = "Production";
	    } else{
		$mappedStatus = "Closed";
	    }
	    
	    $waitingJobs = 0;
	    if ($queue_attributes{'nordugrid-queue-gridqueued'} ne $DEFAULT) {$waitingJobs += $queue_attributes{'nordugrid-queue-gridqueued'};}
	    if ($queue_attributes{'nordugrid-queue-localqueued'} ne $DEFAULT) {$waitingJobs += $queue_attributes{'nordugrid-queue-localqueued'};}
	    if ($queue_attributes{'nordugrid-queue-prelrmsqueued'} ne $DEFAULT) {$waitingJobs += $queue_attributes{'nordugrid-queue-prelrmsqueued'};}
	    
	    $totalJobs = $waitingJobs;
	    if ($queue_attributes{'nordugrid-queue-running'} ne $DEFAULT) { $totalJobs += $queue_attributes{'nordugrid-queue-running'}; }

	    $freeSlots=$DEFAULT;
	    if ( ($queue_attributes{'nordugrid-queue-totalcpus'} ne $DEFAULT) && ($queue_attributes{'nordugrid-queue-running'} ne $DEFAULT) ){
		$freeSlots = $queue_attributes{'nordugrid-queue-totalcpus'} - $queue_attributes{'nordugrid-queue-running'};
	    }
	    
	    # Get an arbitrary approximate of how long a job may
	    # expect to wait at this site, it depends on jobs that are
	    # currently running and jobs that are waiting. Formula
	    # aquired from Kalle Happonen and the "NDGF BDII" for LHC
	    # T1 services
	    if ( $queue_attributes{'nordugrid-queue-maxrunning'} ne $DEFAULT ) {
           $estRespTime = int(600 + ($queue_attributes{'nordugrid-queue-running'} /$queue_attributes{'nordugrid-queue-maxrunning'}) *3600 + ($waitingJobs /$queue_attributes{'nordugrid-queue-maxrunning'}) * 600 );
        } else {
           $estRespTime = $DEFAULT;
        }
	    $worstRespTime = $estRespTime + 2000;
	    my @vos= split / /, $cluster_attributes{'nordugrid-cluster-acl'};
        
        my $ce_unique_id=build_glueCEUniqueID($cluster_attributes{'nordugrid-cluster-name'},
						  $cluster_attributes{'nordugrid-cluster-lrms-type'},
						  $queue_attributes{'nordugrid-queue-name'});

	    # Write CE Entries
	    
	    print "
dn: GlueCEUniqueID=$ce_unique_id,mds-vo-name=resource,o=grid
objectClass: GlueCETop
objectClass: GlueCE
objectClass: GlueSchemaVersion
objectClass: GlueCEAccessControlBase
objectClass: GlueCEInfo
objectClass: GlueCEPolicy
objectClass: GlueCEState
objectClass: GlueInformationService
objectClass: GlueKey
GlueCEUniqueID: $ce_unique_id
GlueCEHostingCluster: $cluster_attributes{'nordugrid-cluster-name'}
GlueCEName: $queue_attributes{'nordugrid-queue-name'}
GlueCEInfoGatekeeperPort: 2811
GlueCEInfoHostName: $cluster_attributes{'nordugrid-cluster-name'}
GlueCEInfoLRMSType: $cluster_attributes{'nordugrid-cluster-lrms-type'}
GlueCEInfoLRMSVersion: $cluster_attributes{'nordugrid-cluster-lrms-version'}
GlueCEInfoGRAMVersion: $DEFAULT
GlueCEInfoTotalCPUs: $queue_attributes{'nordugrid-queue-totalcpus'}
GlueCECapability: CPUScalingReferenceSI00=$CPUSCALINGREFERENCESI00
GlueCEInfoJobManager: arc
GlueCEInfoContactString: $cluster_attributes{'nordugrid-cluster-contactstring'}?queue=$queue_attributes{'nordugrid-queue-name'}
GlueInformationServiceURL: ldap://$cluster_attributes{'nordugrid-cluster-name'}:$BDIIPORT/mds-vo-name=resource,o=grid
GlueCEStateEstimatedResponseTime: $estRespTime
GlueCEStateRunningJobs: $queue_attributes{'nordugrid-queue-running'}
GlueCEStateStatus: $mappedStatus
GlueCEStateTotalJobs: $totalJobs
GlueCEStateWaitingJobs: $waitingJobs
GlueCEStateWorstResponseTime: $worstRespTime
GlueCEStateFreeJobSlots: $freeSlots
GlueCEPolicyMaxCPUTime: $queue_attributes{'nordugrid-queue-maxcputime'}
GlueCEPolicyMaxRunningJobs: $queue_attributes{'nordugrid-queue-maxrunning'}
GlueCEPolicyMaxTotalJobs: $queue_attributes{'nordugrid-queue-maxqueuable'}
GlueCEPolicyMaxWallClockTime: $queue_attributes{'nordugrid-queue-maxcputime'}
GlueCEPolicyPriority: 1
GlueCEPolicyAssignedJobSlots: $AssignedSlots\n";
            foreach (@vos){
                chomp;
                print "GlueCEAccessControlBaseRule: $_\n";
            }
            print "GlueForeignKey: GlueClusterUniqueID=$cluster_attributes{'nordugrid-cluster-name'}
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2
GlueCEImplementationName: ARC-CE
";

            foreach (@vos){
                chomp;
        	$vo = $_;
        	$vo =~ s/VO:// ;

                print "
dn: GlueVOViewLocalID=$vo,GlueCEUniqueID=$ce_unique_id,Mds-Vo-name=resource,o=grid
objectClass: GlueCETop
objectClass: GlueVOView
objectClass: GlueCEInfo
objectClass: GlueCEState
objectClass: GlueCEAccessControlBase
objectClass: GlueCEPolicy
objectClass: GlueKey
objectClass: GlueSchemaVersion
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2
GlueCEInfoDefaultSE: $cluster_attributes{'nordugrid-cluster-localse'}
GlueCEStateTotalJobs: $totalJobs
GlueCEInfoDataDir: unset
GlueCEAccessControlBaseRule: VO:$vo
GlueCEStateRunningJobs: $queue_attributes{'nordugrid-queue-running'}
GlueChunkKey: GlueCEUniqueID=$ce_unique_id
GlueVOViewLocalID: $vo
GlueCEInfoApplicationDir: unset
GlueCEStateWaitingJobs: $waitingJobs
GlueCEStateEstimatedResponseTime: $estRespTime
GlueCEStateWorstResponseTime: $worstRespTime
GlueCEStateFreeJobSlots: $freeSlots
";
            }
        }
    }
}

sub write_cluster_entries(){
    my $cluster_name=shift;
    my $site_unique_id=shift;
    my $ce_unique_id=build_glueCEUniqueID($cluster_attributes{'nordugrid-cluster-name'},
					  $cluster_attributes{'nordugrid-cluster-lrms-type'},
					  $queue_attributes{'nordugrid-queue-name'});
    print "
dn: GlueClusterUniqueID=$cluster_name,mds-vo-name=resource,o=grid
objectClass: GlueClusterTop
objectClass: GlueCluster
objectClass: GlueSchemaVersion
objectClass: GlueInformationService
objectClass: GlueKey
GlueClusterName: $site_unique_id
GlueClusterService: $cluster_name
GlueClusterUniqueID: $cluster_name
GlueForeignKey: GlueCEUniqueID=$ce_unique_id
GlueForeignKey: GlueSiteUniqueID=$site_unique_id
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2

";
}

sub write_ce_se_binding_entries(){
    my $localse=shift;
    my $ce_unique_id=build_glueCEUniqueID($cluster_attributes{'nordugrid-cluster-name'},
					  $cluster_attributes{'nordugrid-cluster-lrms-type'},
					  $queue_attributes{'nordugrid-queue-name'});
    my $s_storages=shift;
    my @storages=@{$s_storages};
    
    if($localse ne '') {
	print "
dn: GlueCESEBindGroupCEUniqueID=$ce_unique_id,mds-vo-name=resource,o=grid
objectClass: GlueGeneralTop
objectClass: GlueCESEBindGroup
objectClass: GlueSchemaVersion
GlueCESEBindGroupCEUniqueID: $ce_unique_id
";

	foreach (@storages){
	    chomp;
	    print "GlueCESEBindGroupSEUniqueID: $_\n"
	}

	print "GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2
";
	
	foreach (@storages){
	    chomp;
	    print "
dn: GlueCESEBindSEUniqueID=$_,GlueCESEBindGroupCEUniqueID=$ce_unique_id,mds-vo-name=resource,o=grid
objectClass: GlueGeneralTop
objectClass: GlueCESEBind
objectClass: GlueSchemaVersion
GlueCESEBindSEUniqueID: $_
GlueCESEBindCEUniqueID: $ce_unique_id
GlueCESEBindMountInfo: none
GlueCESEBindWeight: 0
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 2
";
	}
    }
}

sub write_service_information () {
    my $serviceuniqueid = shift;
    my $servicename = shift;
    my $glueservicestatus = shift;
    my $glueservicestatusinfo = shift;
    my $serviceendpoint = shift;
    my $serviceversion = shift;
    my $servicetype = shift;
    my $servicewsdl = shift;
    my $s_acb=shift;
    my $s_acr=shift;
    my @accesscontrolbase = @{$s_acb} if defined $s_acb;
    my @accesscontrolrule = @{$s_acr} if defined $s_acr;
    
    print "
dn: GlueServiceUniqueID=$serviceuniqueid,mds-vo-name=resource,o=grid
";
    foreach (@accesscontrolbase) {
	chomp;
	print "
GlueServiceAccessControlBaseRule: $_
";
    }
    print "
GlueServiceStatus: $glueservicestatus
GlueServiceStatusInfo: $glueservicestatusinfo
objectClass: GlueTop
objectClass: GlueService
objectClass: GlueKey
objectClass: GlueSchemaVersion
GlueServiceUniqueID: $serviceuniqueid
";
    foreach (@accesscontrolrule) {
	chomp;
	print "
GlueServiceAccessControlRule: $_
";
    }
    print "
GlueServiceEndpoint: $serviceendpoint
GlueServiceVersion: $serviceversion
GlueSchemaVersionMajor: 1
GlueSchemaVersionMinor: 3
GlueServiceName: $servicename
GlueServiceType: $servicetype
GlueServiceWSDL: $servicewsdl
";
}

#EOF