Exemple #1
0
 def getComponentStatus(self, config):
     components = config.listComponents_() + config.listWebapps_()
     agentInfo = {}
     agentInfo['down_components'] = set()
     agentInfo['down_component_detail'] = []
     agentInfo['status'] = 'ok'
     # check the component status
     for component in components:
         compDir = config.section_(component).componentDir
         compDir = config.section_(component).componentDir
         compDir = os.path.expandvars(compDir)
         daemonXml = os.path.join(compDir, "Daemon.xml")
         downFlag = False;
         if not os.path.exists(daemonXml):
             downFlag = True
         else:
             daemon = Details(daemonXml)
             if not daemon.isAlive():
                 downFlag = True
         if downFlag:
             agentInfo['down_components'].add(component)
             agentInfo['status'] = 'down'
     
     # check the thread status
     results = self.componentStatusAction.execute()
     for componentInfo in results:
         if (componentInfo["state"] == "Error"):
             agentInfo['down_components'].add(componentInfo['name'])
             agentInfo['status'] = 'down'
             agentInfo['down_component_detail'].append(componentInfo)
     
     agentInfo['down_components'] = list(agentInfo['down_components'])
     return agentInfo
Exemple #2
0
    def getComponentStatus(self, config):
        components = config.listComponents_() + config.listWebapps_()
        agentInfo = {}
        agentInfo['down_components'] = set()
        agentInfo['down_component_detail'] = []
        agentInfo['status'] = 'ok'
        # check the component status
        for component in components:
            compDir = config.section_(component).componentDir
            compDir = os.path.expandvars(compDir)
            daemonXml = os.path.join(compDir, "Daemon.xml")
            downFlag = False
            if not os.path.exists(daemonXml):
                downFlag = True
            else:
                daemon = Details(daemonXml)
                if not daemon.isAlive():
                    downFlag = True
            if downFlag:
                agentInfo['down_components'].add(component)
                agentInfo['status'] = 'down'

        # check the thread status
        results = self.componentStatusAction.execute()
        for componentInfo in results:
            if componentInfo["state"] == "Error":
                agentInfo['down_components'].add(componentInfo['name'])
                agentInfo['status'] = 'down'
                agentInfo['down_component_detail'].append(componentInfo)

        agentInfo['down_components'] = list(agentInfo['down_components'])
        return agentInfo
Exemple #3
0
    def getComponentStatus(self, config):
        """
        _getComponentStatus_

        Aggregates the output of getHeartbeatWarning method with the Daemon
        checks performed.
        :param config: agent configuration object
        :return: returns a dictionary with a summary of the component
        status and a short error message, if any.
        """
        agentInfo = self.getHeartbeatWarning()

        components = config.listComponents_() + config.listWebapps_()
        # check the component status
        for component in components:
            compDir = config.section_(component).componentDir
            compDir = os.path.expandvars(compDir)
            daemonXml = os.path.join(compDir, "Daemon.xml")
            downFlag = False
            if not os.path.exists(daemonXml):
                downFlag = True
            else:
                daemon = Details(daemonXml)
                if not daemon.isAlive():
                    downFlag = True
            if downFlag and component not in agentInfo['down_components']:
                agentInfo['status'] = 'down'
                agentInfo['down_components'].append(component)
                agentInfo['down_component_detail'].append(component)

        return agentInfo
Exemple #4
0
    def getComponentStatus(self, config):
        """
        _getComponentStatus_

        Aggregates the output of getHeartbeatWarning method with the Daemon
        checks performed.
        :param config: agent configuration object
        :return: returns a dictionary with a summary of the component
        status and a short error message, if any.
        """
        agentInfo = self.getHeartbeatWarning()

        components = config.listComponents_() + config.listWebapps_()
        # check the component status
        for component in components:
            compDir = config.section_(component).componentDir
            compDir = os.path.expandvars(compDir)
            daemonXml = os.path.join(compDir, "Daemon.xml")
            downFlag = False
            if not os.path.exists(daemonXml):
                downFlag = True
            else:
                daemon = Details(daemonXml)
                if not daemon.isAlive():
                    downFlag = True
            if downFlag and component not in agentInfo['down_components']:
                agentInfo['status'] = 'down'
                agentInfo['down_components'].append(component)
                agentInfo['down_component_detail'].append(component)

        agentInfo['workers'] = self.listWorkers.execute()
        return agentInfo
Exemple #5
0
 def testA(self):
     """
     __testSubscribe__
     
     Test daemon creation
     """
     # keep the parent alive
     self.pid = createDaemon(self.tempDir, True)
     try:
         try:
             if self.pid != 0 :
                 time.sleep(2)
                 details = Details(os.path.join(self.tempDir,"Daemon.xml"))
                 time.sleep(10)
                 details.killWithPrejudice()
             else:
                 while True:
                     time.sleep(1)
         except:
             pass
     finally:
         if self.pid == 0:
             os._exit(-1)
         else:
             os.system('kill -9 %s' % self.pid)
Exemple #6
0
    def testA(self):
        """
        __testSubscribe__

        Test daemon creation
        """
        # keep the parent alive
        self.pid = createDaemon(self.tempDir, True)
        try:
            try:
                if self.pid != 0:
                    time.sleep(2)
                    details = Details(os.path.join(self.tempDir, "Daemon.xml"))
                    time.sleep(10)
                    details.killWithPrejudice()
                else:
                    while True:
                        time.sleep(1)
            except:
                pass
        finally:
            if self.pid == 0:
                os._exit(-1)
            else:
                os.system('kill -9 %s' % self.pid)
Exemple #7
0
    def testD(self):
        raise nose.SkipTest
        config = self.testInit.getConfiguration()
        config.component_("TestComponent")
        config.TestComponent.logLevel = 'INFO'
        config.section_("General")
        self.tempDir = self.testInit.generateWorkDir(config)
        # try starting a component as a daemon:
        config.TestComponent.componentDir = os.path.join( \
            self.tempDir, "Components/TestComponent2")
        os.makedirs(config.TestComponent.componentDir)
        testComponent = TestComponent(config)
        # we set the parent to true as we are testing
        testComponent.startDaemon(keepParent=True)
        time.sleep(2)
        daemonFile = os.path.join(config.TestComponent.componentDir,
                                  "Daemon.xml")
        details = Details(daemonFile)
        print('Is component alive: ' + str(details.isAlive()))

        # create msgService to send stop message.
        myThread = threading.currentThread()
        factory = WMFactory("msgService", "WMCore.MsgService." + \
                            myThread.dialect)
        myThread.transaction = Transaction(myThread.dbi)
        msgService = factory.loadObject("MsgService")
        msgService.registerAs("HarnessTest")
        myThread.transaction.commit()

        print(
            'Publish a stop message to test if the component shutsdown gracefully'
        )
        myThread.transaction.begin()
        msg = {'name': 'Stop', 'payload': ''}
        msgService.publish(msg)
        myThread.transaction.commit()

        msgService.finish()

        while details.isAlive():
            print('Component has not received stop message')
            time.sleep(2)
        print('Daemon shutdown gracefully')
Exemple #8
0
    def testD(self):
        raise nose.SkipTest
        config = self.testInit.getConfiguration()
        config.component_("TestComponent")
        config.TestComponent.logLevel = 'INFO'
        config.section_("General")
        self.tempDir = self.testInit.generateWorkDir(config)
        # try starting a component as a daemon:
        config.TestComponent.componentDir = os.path.join( \
                    self.tempDir, "Components/TestComponent2")
        os.makedirs( config.TestComponent.componentDir )
        testComponent = TestComponent(config)
        # we set the parent to true as we are testing
        testComponent.startDaemon(keepParent = True)
        time.sleep(2)
        daemonFile = os.path.join(config.TestComponent.componentDir, "Daemon.xml")
        details = Details(daemonFile)
        print('Is component alive: '+str(details.isAlive()))

        #create msgService to send stop message.
        myThread = threading.currentThread()
        factory = WMFactory("msgService", "WMCore.MsgService."+ \
            myThread.dialect)
        myThread.transaction = Transaction(myThread.dbi)
        msgService = factory.loadObject("MsgService")
        msgService.registerAs("HarnessTest")
        myThread.transaction.commit()

        print('Publish a stop message to test if the component shutsdown gracefully')
        myThread.transaction.begin()
        msg = {'name' : 'Stop', 'payload' : ''}
        msgService.publish(msg)
        myThread.transaction.commit()


        msgService.finish()

        while details.isAlive():
            print('Component has not received stop message')
            time.sleep(2)
        print('Daemon shutdown gracefully')
Exemple #9
0
 def testC(self):
     raise nose.SkipTest
     config = self.testInit.getConfiguration()
     self.tempDir = self.testInit.generateWorkDir(config)
     config.component_("TestComponent")
     config.TestComponent.logLevel = 'INFO'
     config.section_("General")
     # try starting a component as a daemon:
     config.TestComponent.componentDir = os.path.join( \
         self.tempDir, "Components/TestComponent1")
     os.makedirs(config.TestComponent.componentDir)
     testComponent = TestComponent(config)
     # we set the parent to true as we are testing
     testComponent.startDaemon(keepParent=True)
     print('trying to kill the component')
     time.sleep(2)
     daemonFile = os.path.join(config.TestComponent.componentDir, "Daemon.xml")
     details = Details(daemonFile)
     print('Is component alive: ' + str(details.isAlive()))
     time.sleep(2)
     details.killWithPrejudice()
     print('Daemon killed')
Exemple #10
0
 def testC(self):
     raise nose.SkipTest
     config = self.testInit.getConfiguration()
     self.tempDir = self.testInit.generateWorkDir(config)
     config.component_("TestComponent")
     config.TestComponent.logLevel = 'INFO'
     config.section_("General")
     # try starting a component as a daemon:
     config.TestComponent.componentDir = os.path.join( \
                 self.tempDir, "Components/TestComponent1")
     os.makedirs( config.TestComponent.componentDir )
     testComponent = TestComponent(config)
     # we set the parent to true as we are testing
     testComponent.startDaemon(keepParent = True)
     print('trying to kill the component')
     time.sleep(2)
     daemonFile = os.path.join(config.TestComponent.componentDir, "Daemon.xml")
     details = Details(daemonFile)
     print('Is component alive: '+str(details.isAlive()))
     time.sleep(2)
     details.killWithPrejudice()
     print('Daemon killed')
Exemple #11
0
                        dest="terminate",
                        default=False,
                        help="Terminate the daemon (kill, wait, kill -9)")
    opts = parser.parse_args()

    if not opts.inifile:
        sys.exit('No configuration specified')
    cfg = loadConfigurationFile(opts.inifile)

    component = cfg.Webtools.application
    workdir = getattr(cfg.Webtools, 'componentDir', '/tmp/webtools')
    if workdir is None:
        workdir = '/tmp/webtools'
    root = Root(cfg)
    if opts.status:
        daemon = Details('%s/Daemon.xml' % workdir)

        if not daemon.isAlive():
            print("Component:%s Not Running" % component)
        else:
            print("Component:%s Running:%s" % (component, daemon['ProcessID']))
    elif opts.kill:
        daemon = Details('%s/Daemon.xml' % workdir)
        daemon.kill()
        daemon.removeAndBackupDaemonFile()
    elif opts.terminate:
        daemon = Details('%s/Daemon.xml' % workdir)
        daemon.killWithPrejudice()
        daemon.removeAndBackupDaemonFile()
    elif opts.daemon:
        createDaemon(workdir)
Exemple #12
0
    parser.add_argument("-t", "--terminate",
                        action="store_true", dest="terminate", default=False,
                        help="Terminate the daemon (kill, wait, kill -9)")
    opts = parser.parse_args()

    if not opts.inifile:
        sys.exit('No configuration specified')
    cfg = loadConfigurationFile(opts.inifile)

    component = cfg.Webtools.application
    workdir = getattr(cfg.Webtools, 'componentDir', '/tmp/webtools')
    if workdir is None:
        workdir = '/tmp/webtools'
    root = Root(cfg)
    if opts.status:
        daemon = Details('%s/Daemon.xml' % workdir)

        if not daemon.isAlive():
            print("Component:%s Not Running" % component)
        else:
            print("Component:%s Running:%s" % (component, daemon['ProcessID']))
    elif opts.kill:
        daemon = Details('%s/Daemon.xml' % workdir)
        daemon.kill()
        daemon.removeAndBackupDaemonFile()
    elif opts.terminate:
        daemon = Details('%s/Daemon.xml' % workdir)
        daemon.killWithPrejudice()
        daemon.removeAndBackupDaemonFile()
    elif opts.daemon:
        createDaemon(workdir)