<commit_before>#!/usr/bin/perl

# --------------------------------------------------------------------------
# Copyright 2002-2010, GridWay Project Leads (GridWay.org)          
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --------------------------------------------------------------------------

use Net::LDAP;

###########
# Discovery
###########

sub dynamic_discover
{
	# Arg1 = BDII
	# Arg2 = QUEUEFILTER
	# Arg3 = TMPFILE
	my($bdii, $QUEUEFILTER, $TMPFILE) = @_;

	open(TMPFILE,">$TMPFILE");

	$ldap = Net::LDAP->new( "$bdii:2170" ) or print TMPFILE "DISCOVER - FAILURE $@\n";
	$mesg = $ldap->bind ;    # an anonymous bind
	$mesg = $ldap->search( # perform a search
				base   => "mds-vo-name=local,o=grid",
				filter => "(&(objectclass=GlueCE)$QUEUEFILTER)"
			);
	my $max = $mesg->count;
	for($i = 0 ; $i < $max ; $i++) 
	{
		my $entry = $mesg->entry($i);
		foreach my $attr ($entry->attributes) 
		{
			my $value = $entry->get_value($attr);
			if ($attr eq "GlueCEUniqueID")
			{
				($host,$trash) = split (":",$value);
				push (@hosts,$host);
			}
		}
	}
	print TMPFILE "DISCOVER - SUCCESS @hosts\n";
	close(TMPFILE);
	$mesg = $ldap->unbind;
}

###########
# Monitor
###########

sub dynamic_monitor
{
	# Arg1 = BDII
	# Arg2 = MID
	# Arg3 = HOST
	# Arg4 = QUEUEFILTER
	# Arg5 = TMPFILE
	my ($bdii, $mid, $host, $QUEUEFILTER, $TMPFILE) = @_;
	
	open(TMPFILE,">$TMPFILE");

	$ldap = Net::LDAP->new( "$bdii:2170" ) or print TMPFILE "DISCOVER - FAILURE $@\n";
	$mesg = $ldap->bind ;    # an anonymous bind
	# First search
	$mesg = $ldap->search( # perform a search
				base   => "mds-vo-name=local,o=grid",
				filter => "(&(objectclass=GlueCE)(GlueCEInfoHostName=$host)$QUEUEFILTER)"
			);
	my $max = $mesg->count;
	# Default values
	$info = "";
	$queue_nodecount = 0;
	$queue_freenodecount = 0;
	$queue_maxtime = 0;
	$queue_maxcputime = 0;
	$queue_maxcount = 0;
	$queue_maxrunningjobs = 0;
	$queue_maxjobsinqueue = 0;
	for($i = 0 ; $i < $max ; $i++) 
		{
		my $entry = $mesg->entry($i);
		foreach my $attr ($entry->attributes) 
		{
			my $value = $entry->get_value($attr);
			if ($attr eq "GlueCEInfoTotalCPUs")
			{
				$nodecount = $value;
				$queue_nodecount = $value;
			}
			elsif ($attr eq "GlueCEUniqueID")
			{
				($trash,$lrms_name) = split ("/",$value);
				($lrms_name1,$lrms_name2,$trash) = split ("-",$lrms_name);
				$lrms_name = $lrms_name1 . "-" . $lrms_name2;
			}
			elsif ($attr eq "GlueCEInfoLRMSType")
			{
				$lrms_type = $value;
			}
			elsif ($attr eq "GlueCEName")
			{
				$queue_name = $value;
			}
			elsif ($attr eq "GlueCEStateFreeCPUs")
			{
				$queue_freenodecount = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxWallClockTime")
			{
				$queue_maxtime = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxCPUTime")
			{
				$queue_maxcputime = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxTotalJobs")
			{
				$queue_maxjobsinqueue = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxRunningJobs")
			{
				$queue_maxrunningjobs = $value;
			}
			elsif ($attr eq "GlueCEStateStatus")
			{
				$queue_status = $value;
			}
			elsif ($attr eq "GlueCEPolicyPriority")
			{
				$queue_priority = $value;
			}
			elsif ($attr eq "GlueCEStateWaitingJobs")
			{
				$queue_jobwait = $value;
			}
			elsif ($attr eq "GlueCEAccessControlBaseRule")
			{
				my @values = $entry->get_value($attr);
				$queue_access = "";
				foreach $value(@values)
				{
					($trash,$value) = split (":",$value); 
					$queue_access = "$queue_access:$value:";
				}
			}
		}	
		$info = $info . "QUEUE_NAME[$i]=\"$queue_name\" QUEUE_NODECOUNT[$i]=$queue_nodecount QUEUE_FREENODECOUNT[$i]=$queue_freenodecount QUEUE_MAXTIME[$i]=$queue_maxtime QUEUE_MAXCPUTIME[$i]=$queue_maxcputime QUEUE_MAXJOBSINQUEUE[$i]=$queue_maxjobsinqueue QUEUE_MAXRUNNINGJOBS[$i]=$queue_maxrunningjobs QUEUE_STATUS[$i]=\"$queue_status\" QUEUE_DISPATCHTYPE[$i]=\"batch\" QUEUE_PRIORITY[$i]=\"$queue_priority\" QUEUE_JOBWAIT[$i]=\"$queue_jobwait\" QUEUE_ACCESS[$i]=\"$queue_access\" ";
	}
	
	# Second search
	$mesg = $ldap->search( # perform a search
				base   => "mds-vo-name=local,o=grid",
				filter => "(&(objectclass=GlueHostOperatingSystem)(GlueSubClusterName=$host))"
			);	
	$max = $mesg->count;
	for($i = 0 ; $i < $max ; $i++) 
		{
		my $entry = $mesg->entry($i);
		foreach my $attr ($entry->attributes) 
		{
			my $value = $entry->get_value($attr);
			if ($attr eq "GlueHostOperatingSystemName")
			{
				$os_name = $value;
			}
			elsif ($attr eq "GlueHostOperatingSystemVersion")
			{
				$os_version = $value;
			}
			elsif ($attr eq "GlueHostProcessorModel")
			{
				$cpu_model = $value;
			}
			elsif ($attr eq "GlueHostProcessorClockSpeed")<commit_msg>Bug #89: Change in search base of BDII<commit_after>#!/usr/bin/perl

# --------------------------------------------------------------------------
# Copyright 2002-2010, GridWay Project Leads (GridWay.org)          
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --------------------------------------------------------------------------

use Net::LDAP;

###########
# Discovery
###########

sub dynamic_discover
{
	# Arg1 = BDII
	# Arg2 = QUEUEFILTER
	# Arg3 = TMPFILE
	my($bdii, $QUEUEFILTER, $TMPFILE) = @_;

	open(TMPFILE,">$TMPFILE");

	$ldap = Net::LDAP->new( "$bdii:2170" ) or print TMPFILE "DISCOVER - FAILURE $@\n";
	$mesg = $ldap->bind ;    # an anonymous bind
	$mesg = $ldap->search( # perform a search
				base   => "mds-vo-name=resource,o=grid",
				filter => "(&(objectclass=GlueCE)$QUEUEFILTER)"
			);
	my $max = $mesg->count;
	for($i = 0 ; $i < $max ; $i++) 
	{
		my $entry = $mesg->entry($i);
		foreach my $attr ($entry->attributes) 
		{
			my $value = $entry->get_value($attr);
			if ($attr eq "GlueCEUniqueID")
			{
				($host,$trash) = split (":",$value);
				push (@hosts,$host);
			}
		}
	}
	print TMPFILE "DISCOVER - SUCCESS @hosts\n";
	close(TMPFILE);
	$mesg = $ldap->unbind;
}

###########
# Monitor
###########

sub dynamic_monitor
{
	# Arg1 = BDII
	# Arg2 = MID
	# Arg3 = HOST
	# Arg4 = QUEUEFILTER
	# Arg5 = TMPFILE
	my ($bdii, $mid, $host, $QUEUEFILTER, $TMPFILE) = @_;
	
	open(TMPFILE,">$TMPFILE");

	$ldap = Net::LDAP->new( "$bdii:2170" ) or print TMPFILE "DISCOVER - FAILURE $@\n";
	$mesg = $ldap->bind ;    # an anonymous bind
	# First search
	$mesg = $ldap->search( # perform a search
				base   => "mds-vo-name=resource,o=grid",
				filter => "(&(objectclass=GlueCE)(GlueCEInfoHostName=$host)$QUEUEFILTER)"
			);
	my $max = $mesg->count;
	# Default values
	$info = "";
	$queue_nodecount = 0;
	$queue_freenodecount = 0;
	$queue_maxtime = 0;
	$queue_maxcputime = 0;
	$queue_maxcount = 0;
	$queue_maxrunningjobs = 0;
	$queue_maxjobsinqueue = 0;
	for($i = 0 ; $i < $max ; $i++) 
		{
		my $entry = $mesg->entry($i);
		foreach my $attr ($entry->attributes) 
		{
			my $value = $entry->get_value($attr);
			if ($attr eq "GlueCEInfoTotalCPUs")
			{
				$nodecount = $value;
				$queue_nodecount = $value;
			}
			elsif ($attr eq "GlueCEUniqueID")
			{
				($trash,$lrms_name) = split ("/",$value);
				($lrms_name1,$lrms_name2,$trash) = split ("-",$lrms_name);
				$lrms_name = $lrms_name1 . "-" . $lrms_name2;
			}
			elsif ($attr eq "GlueCEInfoLRMSType")
			{
				$lrms_type = $value;
			}
			elsif ($attr eq "GlueCEName")
			{
				$queue_name = $value;
			}
			elsif ($attr eq "GlueCEStateFreeCPUs")
			{
				$queue_freenodecount = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxWallClockTime")
			{
				$queue_maxtime = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxCPUTime")
			{
				$queue_maxcputime = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxTotalJobs")
			{
				$queue_maxjobsinqueue = $value;
			}
			elsif ($attr eq "GlueCEPolicyMaxRunningJobs")
			{
				$queue_maxrunningjobs = $value;
			}
			elsif ($attr eq "GlueCEStateStatus")
			{
				$queue_status = $value;
			}
			elsif ($attr eq "GlueCEPolicyPriority")
			{
				$queue_priority = $value;
			}
			elsif ($attr eq "GlueCEStateWaitingJobs")
			{
				$queue_jobwait = $value;
			}
			elsif ($attr eq "GlueCEAccessControlBaseRule")
			{
				my @values = $entry->get_value($attr);
				$queue_access = "";
				foreach $value(@values)
				{
					($trash,$value) = split (":",$value); 
					$queue_access = "$queue_access:$value:";
				}
			}
		}	
		$info = $info . "QUEUE_NAME[$i]=\"$queue_name\" QUEUE_NODECOUNT[$i]=$queue_nodecount QUEUE_FREENODECOUNT[$i]=$queue_freenodecount QUEUE_MAXTIME[$i]=$queue_maxtime QUEUE_MAXCPUTIME[$i]=$queue_maxcputime QUEUE_MAXJOBSINQUEUE[$i]=$queue_maxjobsinqueue QUEUE_MAXRUNNINGJOBS[$i]=$queue_maxrunningjobs QUEUE_STATUS[$i]=\"$queue_status\" QUEUE_DISPATCHTYPE[$i]=\"batch\" QUEUE_PRIORITY[$i]=\"$queue_priority\" QUEUE_JOBWAIT[$i]=\"$queue_jobwait\" QUEUE_ACCESS[$i]=\"$queue_access\" ";
	}
	
	# Second search
	$mesg = $ldap->search( # perform a search
				base   => "mds-vo-name=resource,o=grid",
				filter => "(&(objectclass=GlueHostOperatingSystem)(GlueSubClusterName=$host))"
			);	
	$max = $mesg->count;
	for($i = 0 ; $i < $max ; $i++) 
		{
		my $entry = $mesg->entry($i);
		foreach my $attr ($entry->attributes) 
		{
			my $value = $entry->get_value($attr);
			if ($attr eq "GlueHostOperatingSystemName")
			{
				$os_name = $value;
			}
			elsif ($attr eq "GlueHostOperatingSystemVersion")
			{
				$os_version = $value;
			}
			elsif ($attr eq "GlueHostProcessorModel")
			{
				$cpu_model = $value;
			}
			elsif ($attr eq "GlueHostProcessorClockSpeed")
{'fraction_non_alphanumeric': 0.19590812584443157, 'fraction_numerical': 0.008299556070256708, 'mean_word_length': 3.2367130008176614, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1863345', 'n_tokens_mistral': 4462, 'n_tokens_neox': 3868, 'n_words': 802}