GridWay: gw_im_mad_mds2_glue-bdii

File gw_im_mad_mds2_glue-bdii, 7.9 KB (added by carlos, 10 years ago)

gw_im_mad_mds2_glue-bdii

Line 
1#!/bin/bash
2
3# --------------------------------------------------------------------------
4# Copyright 2002-2006 GridWay Team, Distributed Systems Architecture         
5# Group, Universidad Complutense de Madrid                                   
6#                                                                           
7# Licensed under the Apache License, Version 2.0 (the "License"); you may   
8# not use this file except in compliance with the License. You may obtain   
9# a copy of the License at                                                   
10#                                                                           
11# http://www.apache.org/licenses/LICENSE-2.0                                 
12#                                                                           
13# Unless required by applicable law or agreed to in writing, software       
14# distributed under the License is distributed on an "AS IS" BASIS,         
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
16# See the License for the specific language governing permissions and       
17# limitations under the License.                                             
18# --------------------------------------------------------------------------
19
20dynamic_discover (){
21       
22    if [ -n "$SERVER" -a -z "$HOSTLIST" ]
23    then
24        TMPFILE=".search.$$.$RANDOM"
25        ERRFILE=".error.$$.$RANDOM"
26
27            nice -n $PRIORITY ldapsearch -x -LLL -h $SERVER -p 2170 -b $BASE \
28                "(&(objectclass=GlueCluster)$HOSTFILTER)" GlueClusterUniqueID \
29                > $TMPFILE 2>$ERRFILE
30
31        if [ $? -eq 0 ]
32        then
33            HOSTNAMES=`grep GlueClusterUniqueID: $TMPFILE | awk '{print $2}'`
34
35            for HOSTNAME in $HOSTNAMES
36            do
37                INFO="$INFO $HOSTNAME"
38            done
39
40            echo "DISCOVER - SUCCESS $INFO"
41        else
42            INFO=`cat $ERRFILE`
43            echo "DISCOVER - FAILURE $INFO"
44        fi
45       
46        rm -f $TMPFILE $ERRFILE
47    else
48        echo "DISCOVER - SUCCESS $INFO"
49    fi
50}
51
52dynamic_monitor (){
53
54    TMPFILE=".search.$$.$1.$RANDOM"
55    ERRFILE=".error.$$.$1.$RANDOM"
56   
57    nice -n $PRIORITY ldapsearch -l 30 -x -LLL -p 2170 -h $2 -b "Mds-Vo-name=resource,o=grid" > $TMPFILE 2> $ERRFILE
58
59    if [ $? -ne 0 ]
60    then
61        nice -n $PRIORITY ldapsearch -x -LLL -h $SERVER -p 2170 -b $BASE \
62            "(&(objectclass=GlueCE)$QUEUEFILTER(GlueForeignKey=GlueClusterUniqueID=$2))" > $TMPFILE 2>$ERRFILE
63    fi   
64             
65    if [ $? -eq 0 ]
66    then
67        CPU_MHZ=0; CPU_FREE=0; CPU_SMP=0; NODECOUNT=0; FREE_MEM_MB=0
68        SIZE_MEM_MB=0; FREE_DISK_MB=0; SIZE_DISK_MB=0; SE=0; ARCH=0
69       
70        HOSTNAME=$1
71        ARCH=`grep GlueHostArchitecturePlatformType: $TMPFILE | awk -F": " '{print $2}' | head -1`
72        OS_NAME=`grep GlueHostOperatingSystemName: $TMPFILE | awk -F": " '{print $2}' | head -1`
73        OS_VERSION=`grep GlueHostOperatingSystemVersion: $TMPFILE | awk -F": " '{print $2}' | head -1`
74        CPU_MODEL=`grep GlueHostProcessorModel: $TMPFILE | awk -F": " '{print $2}' | head -1`
75        CPU_MHZ=`grep GlueHostProcessorClockSpeed: $TMPFILE | awk -F": " '{print $2}' | head -1`
76        CPU_SMP=`grep GlueHostArchitectureSMPSize: $TMPFILE | awk -F": " '{print $2}' | tail -1`
77        NODECOUNT=`grep GlueCEInfoTotalCPUs: $TMPFILE | awk -F": " '{print $2}' | sort -n | tail -1` 
78        FREE_MEM_MB=`grep GlueHostMainMemoryRAMSize: $TMPFILE | awk -F": " '{print $2}' | head -1`
79        SIZE_MEM_MB=`grep GlueHostMainMemoryRAMSize: $TMPFILE | awk -F": " '{print $2}' | head -1`
80        LRMS_NAME=`grep GlueCEUniqueID: $TMPFILE | awk -F"/" '{print $2}' | awk -F- '{ORS=""; print $1; for (i=2;i<NF;i++) print "-" $i; print "\n"}' | tail -1`
81        LRMS_TYPE=`grep GlueCEInfoLRMSType: $TMPFILE | awk -F": " '{print $2}' | tail -1`
82        SE=`grep GlueCEInfoDefaultSE: $TMPFILE | awk -F": " '{print $2}' | head -1`
83
84        if [ "$LRMS_TYPE" = "torque" ] 
85        then
86            LRMS_TYPE="pbs"
87        fi
88 
89        nice -n $PRIORITY ldapsearch -l 30 -p 2170 -x -LLL -h $2 "(&(objectclass=GlueCE)$QUEUEFILTER)" -b "Mds-Vo-name=resource,o=grid"> $TMPFILE 2> $ERRFILE
90        if [ $? -ne 0 ]
91        then
92            nice -n $PRIORITY ldapsearch -x -LLL -h $SERVER -p 2170 -b $BASE \
93                 "(&(objectclass=GlueCE)$QUEUEFILTER(GlueForeignKey=GlueClusterUniqueID=$2))" > $TMPFILE 2>$ERRFILE
94        fi
95
96        saveIFS=$IFS
97        IFS="
98"
99
100        if [ $? -eq 0 ]
101        then
102            QUEUE_NODECOUNT=0; QUEUE_FREENODECOUNT=0; QUEUE_MAXTIME=0; QUEUE_MAXCPUTIME=0
103            QUEUE_MAXCOUNT=0; QUEUE_MAXRUNNINGJOBS=0; QUEUE_MAXJOBSINQUEUE=0
104
105            QUEUE_NAME=(`grep GlueCEName: $TMPFILE | awk -F": " '{print $2}'`)
106            QUEUE_NODECOUNT=(`grep GlueCEInfoTotalCPUs: $TMPFILE | awk -F": " '{print $2}'`)
107            QUEUE_FREENODECOUNT=(`grep GlueCEStateFreeCPUs: $TMPFILE | awk -F": " '{print $2}'`)
108            QUEUE_MAXTIME=(`grep GlueCEPolicyMaxWallClockTime: $TMPFILE | awk -F": " '{print $2}'`)
109            QUEUE_MAXCPUTIME=(`grep GlueCEPolicyMaxCPUTime: $TMPFILE | awk -F": " '{print $2}'`)
110            QUEUE_MAXJOBSINQUEUE=(`grep GlueCEPolicyMaxTotalJobs: $TMPFILE | awk -F": " '{print $2}'`)
111            QUEUE_MAXRUNNINGJOBS=(`grep GlueCEPolicyMaxRunningJobs: $TMPFILE | awk -F": " '{print $2}'`)
112            QUEUE_STATUS=(`grep GlueCEStateStatus: $TMPFILE | awk -F": " '{print $2}'`)
113            QUEUE_PRIORITY=(`grep GlueCEPolicyPriority: $TMPFILE | awk -F": " '{print $2}'`)
114            QUEUE_JOBWAIT=(`grep GlueCEStateWaitingJobs: $TMPFILE | awk -F": " '{print $2}'`)
115            #QUEUE_ACCESS=(`egrep -e ^GlueCEAccessControlBaseRule: -e ^GlueCEUniqueID: $TMPFILE | uniq -w 28 | awk '{if (NR % 2 == 0) print}' | awk -F": " '{print $2}'`)
116            QUEUE_ACCESS=(`egrep -e "^GlueCEAccessControlBaseRule: VO" -e "^GlueCEUniqueID" -e "GlueVOViewLocalID" $TMPFILE | awk -F: 'BEGIN {first=0} /^GlueCEUniqueID:/ {if (first!=0) printf " \n"; first=1} /^GlueCEAccessControlBaseRule/ {printf ":%s:",$3} /^GlueVOViewLocalID/ {exit} END {print ""}'`)
117
118            INFO=`echo "HOSTNAME=\"$HOSTNAME\" ARCH=\"$ARCH\" SE=\"$SE\"" \
119                "OS_NAME=\"$OS_NAME\" OS_VERSION=\"$OS_VERSION\"" \
120                "CPU_MODEL=\"$CPU_MODEL\" CPU_MHZ=$CPU_MHZ CPU_FREE=0 CPU_SMP=$CPU_SMP" \
121                "NODECOUNT=$NODECOUNT" \
122                "SIZE_MEM_MB=$SIZE_MEM_MB FREE_MEM_MB=$FREE_MEM_MB" \
123                "SIZE_DISK_MB=0 FREE_DISK_MB=0" \
124                "FORK_NAME=\"fork\"" \
125                "LRMS_NAME=\"$LRMS_NAME\" LRMS_TYPE=\"$LRMS_TYPE\" $3"`
126
127            for ((j=0, i=0; i<${#QUEUE_NAME[@]}; i++,j++))
128            do
129                INFO=`echo "$INFO QUEUE_NAME[$j]=\"${QUEUE_NAME[$i]}\" QUEUE_NODECOUNT[$j]=${QUEUE_NODECOUNT[$i]}" \
130                    "QUEUE_FREENODECOUNT[$j]=${QUEUE_FREENODECOUNT[$i]} QUEUE_MAXTIME[$j]=${QUEUE_MAXTIME[$i]}" \
131                    "QUEUE_MAXCPUTIME[$j]=${QUEUE_MAXCPUTIME[$i]} QUEUE_MAXCOUNT[$j]=0" \
132                    "QUEUE_MAXRUNNINGJOBS[$j]=${QUEUE_MAXRUNNINGJOBS[$i]} QUEUE_MAXJOBSINQUEUE[$j]=${QUEUE_MAXJOBSINQUEUE[$i]}" \
133                    "QUEUE_DISPATCHTYPE[$j]=\"batch\" QUEUE_PRIORITY[$j]=\"${QUEUE_PRIORITY[$i]}\"" \
134                    "QUEUE_STATUS[$j]=\"${QUEUE_STATUS[$i]}\" QUEUE_ACCESS[$j]=\"${QUEUE_ACCESS[$i]}\""`
135            done
136
137            echo "MONITOR $1 SUCCESS $INFO"
138        else
139            INFO=`cat $ERRFILE`
140            echo "MONITOR $1 FAILURE $INFO"                   
141        fi           
142    else
143        INFO=`cat $ERRFILE`   
144        echo "MONITOR $1 FAILURE $INFO"
145    fi
146   
147    IFS=$saveIFS
148
149    rm -f $TMPFILE $ERRFILE
150}
151
152BASE="mds-vo-name=local,o=grid"
153HOSTFILTER=""
154QUEUEFILTER=""
155
156# Common initialization
157if [ -z "${GW_LOCATION}" ]; then
158    echo "Please, set GW_LOCATION variable."
159    exit -1
160fi
161
162. $GW_LOCATION/bin/gw_mad_common.sh
163
164setup_globus
165
166# Common initialization
167if [ -z "${GW_LOCATION}" ]; then
168    echo "Please, set GW_LOCATION variable."
169    exit -1
170fi
171
172. $GW_LOCATION/bin/gw_mad_common.sh
173
174setup_globus
175
176. $GW_LOCATION/bin/gw_im_mad_common.sh