Project

General

Profile

blacklist_orig.sh

Marco Mambelli, 11/27/2018 04:07 PM

 
1
#!/bin/bash
2
# Script to send in with glide-ins to blacklist slots per VO when needed
3

    
4
glidein_config="$1"
5

    
6
function advertise {
7
    # atype is the type of the value as defined by GlideinWMS:
8
    #   I - integer
9
    #   S - quoted string
10
    #   C - unquoted string (i.e. Condor keyword or expression)
11
    key="$1"
12
    value="$2"
13
    atype="$3"
14

    
15
    if [ "$glidein_config" != "NONE" ]; then
16
        add_config_line $key "$value"
17
        add_condor_vars_line $key "$atype" "-" "+" "Y" "Y" "+" 
18
    fi  
19

    
20
    if [ "$atype" = "S" ]; then
21
        echo "$key = \"$value\""
22
    else
23
        echo "$key = $value"
24
    fi  
25
}
26

    
27
# import add_config_line and add_condor_vars_line functions 
28

    
29
add_config_line_source=`grep '^ADD_CONFIG_LINE_SOURCE ' ${glidein_config} | awk '{print $2}'`
30
condor_vars_file=`grep -i '^CONDOR_VARS_FILE ' ${glidein_config} | awk '{print $2}'` 
31
error_gen=`grep '^ERROR_GEN_PATH ' ${glidein_config} | awk '{print $2}'`
32

    
33
source ${add_config_line_source} 
34

    
35
#----------MAIN SCRIPT----------#
36

    
37
export MYKERNEL=`uname -r`
38
export MYSITE=`grep -w "GLIDEIN_Site" ${glidein_config} |awk '{print $2}'`
39

    
40
export TMPFILE=./blacklist.local
41
export ITBFEGROUP="fife_test"
42

    
43
# Get the Glideclient so we know if we're in dev, itb, or prod
44
glideclientgroup=`grep '^GLIDECLIENT_Group' ${glidein_config} | awk '{print $2}'`
45

    
46
# Find which one matches, set which url we want to use
47

    
48
if [[ -n ${glideclientgroup+x} ]] && [[ $glideclientgroup == $ITBFEGROUP ]] ; 
49
then
50
	echo "This is the itb frontend group.  Using the itb blacklist"
51
	urlpat="-itb"
52
else
53
	echo "Using the production blacklist"
54
	urlpat=""
55
fi  
56

    
57
blacklist_url="https://fife-service.fnal.gov/blacklist${urlpat}.txt"
58
echo $blacklist_url
59

    
60
# Max 5 retries
61
n=0
62
until [ $n -ge 5 ]
63
do
64
	#Replace the next line with the real webserver/blacklist file
65
	curl -s --insecure $blacklist_url > $TMPFILE && break
66
	n=$[$n+1]
67
	sleep 60
68
done
69

    
70
# Parse the blacklist file, store it in the BAD_JOBSUB_GROUPS variable
71
echo "Parsing blacklist file"
72

    
73
awkcmd='
74
function checklines(valuestring, checkvar) {
75
        n = split(valuestring, vals, ",");
76
        for (i=1; i<=n; i++) {
77
                if (checkvar ~ vals[i]) {
78
                        return "true";
79
                }   
80
        }   
81
        return "false";
82
}
83

    
84
{
85
        firstfield = $1; 
86
        target = $2; 
87
        if (substr(firstfield, 1, 1) != "#")  {   
88
                split(target, labelvalues, ":"); 
89
                label = labelvalues[1];
90
                values = labelvalues[2];
91
    
92
                if (label == "host") {
93
                        result = checklines(values, myhost);
94
                        if (result == "true") {
95
                                print firstfield;
96
                        }   
97
                } else if (label == "site") {
98
                        result = checklines(values, mysite);
99
                        if (result == "true") {
100
                                print firstfield;
101
                        }   
102
                } else if (label == "kernel") {
103
                        result = checklines(values, mykernel);
104
                        if (result == "true") {
105
                                print firstfield;
106
                        }   
107
                } else {
108
                        print ""; 
109
                }   
110
        }   
111
}
112
'
113

    
114
export BAD_JOBSUB_GROUPS=`awk -v myhost=$HOSTNAME -v mysite=$MYSITE -v mykernel=$MYKERNEL "$awkcmd" $TMPFILE | tr '\n' ',' | sed  's/,*$//g;s/^,*//g' ` 
115

    
116
echo "blacklisted VOs are: $BAD_JOBSUB_GROUPS"
117

    
118

    
119
if [ ${#BAD_JOBSUB_GROUPS} == 0 ]
120
then
121
	export BAD_JOBSUB_GROUPS="EMPTY"	
122
fi
123

    
124
export BADATTR="SLOT_BAD_JOBSUB_GROUPS"
125

    
126
# Advertise back the VOs for which this slot won't work
127
advertise $BADATTR "${BAD_JOBSUB_GROUPS}" "S" 
128

    
129
if [ -f $TMPFILE ]
130
then
131
	rm $TMPFILE
132
fi
133

    
134
#"$error_gen" -ok  "blacklist.sh"
135
exit 0