Changeset 1751


Ignore:
Timestamp:
Feb 15, 2016 7:44:16 AM (8 years ago)
Author:
maronga
Message:

watchdog changes and bugfixes

Location:
palm/trunk/SCRIPTS
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SCRIPTS/palm_wd

    r1619 r1751  
    2020# Current revisions:
    2121# -----------------
    22 #
     22# Bugfixes: runs on multiple hosts caused crash of the watchdog. Progress bar
     23# occasionally showed wrong progress.
     24# New: Hosts can be switched on/off and update_frequency can be modified via
     25# File->Options. Security check for cancelation of jobs.
    2326#
    2427# Former revisions:
     
    6972import time
    7073
     74global update_frequency
     75
    7176# Determine PALM directories
    7277try:
     
    99104 
    100105    if ( description_tmp != 'Settings' ):
    101        description.append(description_tmp)
    102        hostname.append(config.get(description_tmp, 'hostname'))
    103        username.append(config.get(description_tmp, 'username'))
     106     
     107       if ( config.get(description_tmp, 'enabled') == 'true' ):
     108          description.append(description_tmp)
     109          hostname.append(config.get(description_tmp, 'hostname'))
     110          username.append(config.get(description_tmp, 'username'))
    104111    else:
    105112       update_frequency = int(config.get(description_tmp, 'update_frequency'))*60000
     
    123130job_data_list = []
    124131
     132# Message box for showing RUN_CONTROL output
    125133class MessageBoxScroll(QtGui.QMessageBox):
    126134    def __init__(self):
     
    149157
    150158        return result
     159
     160
     161# Message box for showing RUN_CONTROL output
     162class OptionBox(QtGui.QDialog):
     163    def __init__(self):
     164     
     165        super(OptionBox, self).__init__()
     166     
     167        uic.loadUi(palm_bin + '/palm_wd_files/wdoptions.ui', self)
     168       
     169        hostname = []
     170        self.checkbox = []
     171        j = -1
     172        ypos = 0
     173   
     174        self.vbox = QtGui.QVBoxLayout(self)
     175        self.vbox.setSpacing(0)
     176        self.vbox.setMargin(0)       
     177   
     178        config.read(palm_dir + '/.wd.config')
     179   
     180        for i in range(0,len(config.sections())):
     181
     182           description_tmp = config.sections()[i]
     183 
     184           if ( description_tmp != 'Settings' ):
     185              description.append(description_tmp)
     186              hostname.append(config.get(description_tmp, 'hostname'))
     187             
     188              j = j + 1
     189              self.checkbox.append(j)
     190              self.checkbox[j] = QtGui.QCheckBox(description_tmp, self)   
     191              ypos = ypos + 20
     192              self.checkbox[j].move(10,0)
     193              if ( config.get(description_tmp, 'enabled') == 'true' ):
     194                 self.checkbox[j].toggle()
     195                       
     196              self.vbox.addWidget(self.checkbox[j])
     197           else:
     198              self.update_spin.setValue(int(config.get(description_tmp, 'update_frequency')))
     199     
     200        self.hostBox.setLayout(self.vbox)
     201        self.hostBox.setGeometry(0, 0, 272, 50+ypos)
     202        self.settingBox.setGeometry(281, 0, 214, 50+ypos)
     203        self.ok.setGeometry(385, 50+ypos, 111, 24)
     204        self.cancel.setGeometry(270, 50+ypos, 111, 24)
     205       
     206        self.setGeometry(0, 0, 500, 80+ypos)
     207        self.show()
     208       
     209        return
     210
     211#   save updtes to file
     212    def SaveAndClose(self):
     213     
     214       for i in range(0,len(self.checkbox)):
     215         
     216          if ( self.checkbox[i].checkState() == 0 ):
     217             config.set(str(self.checkbox[i].text()),'enabled','false')
     218          else:
     219             config.set(str(self.checkbox[i].text()),'enabled','true')       
     220       
     221       config.set('Settings','update_frequency',self.update_spin.text()) 
     222
     223       with open(palm_dir + '/.wd.config', 'wb') as configfile:
     224          config.write(configfile)
     225
     226
     227       self.close()
     228     
     229       return
     230
    151231
    152232
     
    273353     
    274354        # Use global variables
    275         global jobs_save
    276355        global pbars
     356        global update_frequency
    277357
    278358        # Deactivate timer processes until update is finished
     
    317397            job_data = []
    318398            job_data_n = []   
    319             job_data_old = []
    320             job_data_old_n = []
    321399            job_progress = 0
    322400
     
    353431            result = file2.readlines()
    354432            file2.close()
    355            
     433
     434            job_data_old = []
     435            job_data_old_n = []
     436            k = -1
    356437            for j in range(0,len(result)):
    357438                if ( result[j].split()[1] == description[h] ):
    358                     job_data_old.append(j)
    359                     job_data_old[j] = result[j].split(" ")
    360                     job_data_old[j] = filter(None, job_data_old[j])
    361                     job_data_old[j] = [line.rstrip('\n') for line in job_data_old[j]]
    362                
    363                     job_data_old_n.append(j)
    364                     job_data_old_n[j] = job_data_old[j][6]
     439                    k = k + 1
     440                    job_data_old.append(k)
     441                    job_data_old[k] = result[j].split(" ")
     442                    job_data_old[k] = filter(None, job_data_old[k])
     443                    job_data_old[k] = [line.rstrip('\n') for line in job_data_old[k]]
     444                    job_data_old_n.append(k)
     445                    job_data_old_n[k] = job_data_old[k][6]
    365446
    366447            # Merge the job_data and job_data_old to find completed, new and
     
    410491                # Apply a color depending on the status of the job
    411492                if ( job_data[to_display[j]][3] == "Running" ):
    412                     self.table.setCellWidget(i,4,pbars[j])
     493                    self.table.setCellWidget(i,4,pbars[i])
    413494                    self.table.item(i,0).setBackground(QtGui.QColor(255, 251, 168))
    414495                    self.table.item(i,1).setBackground(QtGui.QColor(255, 251, 168))
     
    419500                else:
    420501                    pbars[j].setEnabled(False)
    421                     self.table.setCellWidget(i,4,pbars[j])
     502                    self.table.setCellWidget(i,4,pbars[i])
    422503                    self.table.item(i,0).setBackground(QtGui.QColor(255, 112, 118))
    423504                    self.table.item(i,1).setBackground(QtGui.QColor(255, 112, 118))
     
    549630            del(jobs_new)
    550631            del(result)
    551 
     632            del(job_data_old)
     633            del(job_data_old_n)
     634           
    552635        file.close()
    553636
     
    564647        self.label2.setText("Last update: " + timestamp)
    565648        self.label.setText("Update complete.")
    566         self.timetimer.restart()
    567         self.timer.start()
    568         self.labeltimer.start()
     649        self.timetimer.start()
     650        self.timer.start(update_frequency)
     651        self.labeltimer.start(update_frequency/10)
     652        self.UpdateLabel()
    569653        QtGui.QApplication.processEvents()
    570654       
     
    577661        # Check description of job in order to login on the correct host
    578662        descr = self.table.item(self.table.currentRow(),1).text()
    579         for h in range(0,len(description)):
    580             if ( descr == description[h] ):
    581                 host = username[h] + "@" + hostname[h]
    582 
    583         ssh = sub.Popen(["ssh", "%s" % host, "/sw/tools/python/2.7.6/generic/bin/python palm_wdd cancel " + jobname],
    584                            shell=False,
    585                            stdout=sub.PIPE,
    586                            stderr=sub.PIPE)
    587         result = ssh.stdout.readlines()
    588         result = filter(None, result)
    589        
    590         # In case of error display a warning message
    591         if ( len(result) == 0 ):
    592             error = ssh.stderr.readlines()
    593             notify = QtGui.QMessageBox.warning(self,'Cancel job',"Error. Could not cancel job " + jobname + ".\n\nError message:\n" + ''.join(error))
    594 
    595         # Otherwise inform the user and mark the job in the table
    596         else:
    597             self.table.setItem(self.table.currentRow(),3,QtGui.QTableWidgetItem("Canceled"))
    598             notify = QtGui.QMessageBox.information(self,'Cancel job',"Job" + jobname + " canceled!\n\nServer message:\n" + ''.join(result))
     663       
     664        querybox = QtGui.QMessageBox()
     665        querybox.setText("Attention!\nYou are trying to cancel a job. It will not be able to terminate properly.")
     666        querybox.setInformativeText("Do you really want to cancel " + jobname + " on host " + descr + "?")
     667        querybox.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
     668        querybox.setDefaultButton(QtGui.QMessageBox.No)
     669        returnvalue = querybox.exec_()
     670       
     671        if ( returnvalue == QtGui.QMessageBox.Yes ):
     672       
     673           for h in range(0,len(description)):
     674               if ( descr == description[h] ):
     675                  host = username[h] + "@" + hostname[h]
     676
     677           ssh = sub.Popen(["ssh", "%s" % host, "/sw/tools/python/2.7.6/generic/bin/python palm_wdd cancel " + jobname],
     678                              shell=False,
     679                              stdout=sub.PIPE,
     680                              stderr=sub.PIPE)
     681           result = ssh.stdout.readlines()
     682           result = filter(None, result)
     683       
     684           # In case of error display a warning message
     685           if ( len(result) == 0 ):
     686               error = ssh.stderr.readlines()
     687               notify = QtGui.QMessageBox.warning(self,'Cancel job',"Error. Could not cancel job " + jobname + ".\n\nError message:\n" + ''.join(error))
     688
     689           # Otherwise inform the user and mark the job in the table
     690           else:
     691               self.table.setItem(self.table.currentRow(),3,QtGui.QTableWidgetItem("Canceled"))
     692               notify = QtGui.QMessageBox.information(self,'Cancel job',"Job" + jobname + " canceled!\n\nServer message:\n" + ''.join(result))
    599693
    600694
     
    650744        else:
    651745            self.table.setItem(self.table.currentRow(),3,QtGui.QTableWidgetItem("Terminated"))
    652             notify = QtGui.QMessageBox.information(self,'Terminatie job',"Termination of job " + jobname + " was initiated!\n\nServer message:\n" + ''.join(result))
     746            notify = QtGui.QMessageBox.information(self,'Terminate job',"Termination of job " + jobname + " was initiated!\n\nServer message:\n" + ''.join(result))
    653747
    654748
     
    810904       
    811905
     906    # Enter Options menu
     907    def Options(self):
     908 
     909#       disable mainwindow 
     910        self.setEnabled(False)
     911     
     912#       show Options Dialog     
     913        opt = OptionBox()
     914        opt.exec_()
     915
     916        self.UpdateHosts()
     917        self.setEnabled(True)
     918
     919# Update settings
     920    def UpdateHosts(self):
     921
     922       global update_frequency
     923       description = []
     924       hostname = []
     925       username = []
     926
     927       for i in range(0,len(config.sections())):
     928
     929          description_tmp = config.sections()[i]
     930 
     931          if ( description_tmp != 'Settings' ):
     932     
     933             if ( config.get(description_tmp, 'enabled') == 'true' ):
     934                description.append(description_tmp)
     935                hostname.append(config.get(description_tmp, 'hostname'))
     936                username.append(config.get(description_tmp, 'username'))
     937          else:
     938             update_frequency = int(config.get(description_tmp, 'update_frequency'))*60000
     939
     940
    812941# Main loop       
    813942def main():
  • palm/trunk/SCRIPTS/palm_wd_files/.wd.config.default

    r1618 r1751  
    33
    44[<Replace_by_your_description_of_hostname_1>]
    5 hostname=<replace_by_the_remote_hostname>
    6 username=<replace_by_your_remote_username>
     5enabled=true
     6hostname=<replace_by_the_remote_hostname_1>
     7username=<replace_by_your_remote_username_1>
    78
    8 [<Replace_by_your_description_of_hostname_1>]
    9 hostname=<replace_by_the_remote_hostname>
    10 username=<replace_by_your_remote_username>
     9[<Replace_by_your_description_of_hostname_2>]
     10enabled=true
     11hostname=<replace_by_the_remote_hostname_2>
     12username=<replace_by_your_remote_username_2>
    1113
    1214[Settings]
  • palm/trunk/SCRIPTS/palm_wd_files/.wd.config.hlrnIII

    r1618 r1751  
    44
    55[Hannover]
     6enabled=true
    67hostname=hlogin.hlrn.de
    78username=<replace_by_your_remote_username>
    89
    910[Berlin]
     11enabled=true
    1012hostname=blogin.hlrn.de
    1113username=<replace_by_your_remote_username>
Note: See TracChangeset for help on using the changeset viewer.