Example #1
0
    def __init__(self, nodeid, clustername):
        """
        constructor
        """
        SpecialNode.__init__(self, nodeid, clustername, None)
        self.nodestates = None
        self.PBSStateCommand = PBSStateCommand(self.hostname)
        self.nodestates = None
        self.statusCommand = MasterStatusCommand(self.hostname)

        self.customCommandClass = SshCommand  # this is a class, the others should be real commands
        self.setOnlineCommand = SetOnlineMasterCommand(self.hostname)
        self.setOfflineCommand = SetOfflineMasterCommand(self.hostname)

        # no such commands
        self.pbsmomstatusCommand = TestCommand("No pbsmom on the masters!")
        self.pbsmomstopCommand = TestCommand("No pbsmom on the masters!")
        self.pbsmomrestartCommand = TestCommand("No pbsmom on the masters!")
        self.pbsmomcleanupCommand = TestCommand("No pbsmom on the masters!")
        self.fixdownonerrorCommand = TestCommand("fixdownonerror is not run on a master")
        # scheduling commands
        self.pauseSchedulerCommand = MoabPauseCommand(self.hostname)
        self.resumeSchedulerCommand = MoabResumeCommand(self.hostname)
        self.restartSchedulerCommand = MoabRestartCommand(self.hostname)
Example #2
0
class MasterNode(SpecialNode):
    """
    this class implements a masternode
    extended from node
    """
    def __init__(self, nodeid, clustername):
        """
        constructor
        """
        SpecialNode.__init__(self, nodeid, clustername, None)
        self.nodestates = None
        self.PBSStateCommand = PBSStateCommand(self.hostname)
        self.nodestates = None
        self.statusCommand = MasterStatusCommand(self.hostname)

        self.customCommandClass = SshCommand  # this is a class, the others should be real commands
        self.setOnlineCommand = SetOnlineMasterCommand(self.hostname)
        self.setOfflineCommand = SetOfflineMasterCommand(self.hostname)

        # no such commands
        self.pbsmomstatusCommand = TestCommand("No pbsmom on the masters!")
        self.pbsmomstopCommand = TestCommand("No pbsmom on the masters!")
        self.pbsmomrestartCommand = TestCommand("No pbsmom on the masters!")
        self.pbsmomcleanupCommand = TestCommand("No pbsmom on the masters!")
        self.fixdownonerrorCommand = TestCommand("fixdownonerror is not run on a master")
        # scheduling commands
        self.pauseSchedulerCommand = MoabPauseCommand(self.hostname)
        self.resumeSchedulerCommand = MoabResumeCommand(self.hostname)
        self.restartSchedulerCommand = MoabRestartCommand(self.hostname)

        # No set on or offline commands in masternodes
        # set this depending on what type of node this is

        # self.poweronCommand =
        # self.poweroffCommand =
        # self.rebootCommand =

    def setonline(self, nodelist):
        """
        Run setonline on the master
        """
        self.setOnlineCommand.setNodeList(nodelist)
        self._adcommand(self.setOnlineCommand)

    def setoffline(self, nodelist):
        """
        Run setoffline on the master
        """
        self.setOfflineCommand.setNodeList(nodelist)
        self._adcommand(self.setOfflineCommand)

    def getNodeStates(self):
        """
        returns the states of all nodes owned by this masternode
        """
        if not self.nodestates:
            self.nodestates, err = self.PBSStateCommand.run()
            self.log.debug("got pbsStatuses:%s" % self.nodestates)
        return self.nodestates

    def getPbsStatusForNode(self, nodeid):
        """
        get the status of this node
        as reported by pbsmon
        use the node.DOWN etc constants (DOWN,OFFLINE and IDLE are defined by default)
        """
        out = None
        err = None
        try:
            out = self.getNodeStates()[nodeid]
        except KeyError:  # node not found in pbsStats
            self.log.warning("unable to get PBSStatus for %s from %s" % (nodeid, self.nodeid))
            self.log.debug(traceback.format_exc())
            err = "PbsStatus for %s not found on %s" % (nodeid, self.nodeid)
        return out, err

    def getWorkerNodeIds(self):
        """
        return the workernode id's for this masternode
        """
        return self.getNodeStates().keys()

    def getMaster(self):
        """
        returns a master of this node
        """
        return self

    def pauseScheduler(self):
        """
        pauses the cheduler on a cluster
        """
        self.log.debug("scheduling the scheduler to pause")
        self._adcommand(self.pauseSchedulerCommand)

    def resumeScheduler(self):
        """
        resume the cheduler on a cluster
        """
        self.log.debug("scheduling the scheduler to resume")
        self._adcommand(self.resumeSchedulerCommand)

    def restartScheduler(self):
        """
        restarts the cheduler on a cluster
        """
        self.log.debug("scheduling the scheduler to restart")
        self._adcommand(self.restartSchedulerCommand)

    def __repr__(self):
        return """%s("%s","%s")""" % (self.__class__.__name__, self.nodeid,
                                      self.clustername)