Esempio n. 1
0
    def __init__(self):
        # read the tile config to get a list of all the nodes in this cluster available for running apps
        self._nodeHash = {}  #key=IP, value=[0...n]   --> how many apps are running on that node

        if TILE_CONFIG_FILE:
            self.__readNodeIPs()
        else:
            self._nodeHash = {"127.0.0.1":0}

        # read the sage app configuration file and create the container for all the requests
        WriteLog( "\nUsing config file: " + APP_CONFIG_FILE )
        self.configs = Configurations(APP_CONFIG_FILE)
        self.requests = CurrentRequests(self._nodeHash)

        # report ourselves to the sage server
        self.sageServer = xmlrpclib.ServerProxy("http://"+SAGE_SERVER+":8009")
        self.launcherId = ""
        self.reportLauncher()
Esempio n. 2
0
class AppLauncher:
    def __init__(self):
        # read the tile config to get a list of all the nodes in this cluster available for running apps
        self._nodeHash = {}  #key=IP, value=[0...n]   --> how many apps are running on that node

        if TILE_CONFIG_FILE:
            self.__readNodeIPs()
        else:
            self._nodeHash = {"127.0.0.1":0}

        # read the sage app configuration file and create the container for all the requests
        WriteLog( "\nUsing config file: " + APP_CONFIG_FILE )
        self.configs = Configurations(APP_CONFIG_FILE)
        self.requests = CurrentRequests(self._nodeHash)

        # report ourselves to the sage server
        self.sageServer = xmlrpclib.ServerProxy("http://"+SAGE_SERVER+":8009")
        self.launcherId = ""
        self.reportLauncher()

                            

    def __readNodeIPs(self):
        f = open(TILE_CONFIG_FILE, "r")
        for line in f:
            previous = False  # True if previous line was an IP, False otherwise
            if previous:
                previous = False
                continue
            elif line.strip().startswith("IP"):
                self._nodeHash[line.strip().split()[1].split(':')[0]] = 0   #add the machine ip to the hash
        f.close()
        WriteLog( "\n\nNodeHash = \n" + str(self._nodeHash) + "\n\n" )
    

    def startDefaultApp(self, appName, fsIP, fsPort, useBridge, configName, pos=False, size=False, optionalArgs=""):
        """ starts the application based on the entry in applications.conf """
        return self.startApp(appName, fsIP, fsPort, useBridge, configName, optionalArgs=optionalArgs, pos=pos, size=size)
        

    def startApp(self, appName, fsIP, fsPort, useBridge, configName="", command="", optionalArgs="", pos=False, size=False, nodeNum=False, protocol=False):
        """ receive the request for starting an app
            either start the default app from a predefined config
            or start a completely custom app with dynamic config
        """

        # first split the optionalArgs and add quotes around each piece
        oaTokens = optionalArgs.split()
        optionalArgs = ""
        for arg in oaTokens:
            optionalArgs += "\""+arg.strip("\"")+"\" "

        if configName != "":   # this assumes a default config and app startup
            if configName == "default":
                config = self.configs.getDefaultConfig(appName)
            else:
                config = self.configs.getConfig(appName, configName)
        elif command != "":    # this assumes a completely custom app startup
            config = OneConfig(appName+"_temp", appName, True)
            config.setCommand(command + " " + optionalArgs)

        # common set of parameters that can be changed in either case
        if pos:      config.setPosition(pos)
        if size:     config.setSize(size)
        if nodeNum:  config.setNodeNum(nodeNum)
        if protocol: config.setProtocol(protocol)

        if not fsIP: fsIP = DEFAULT_SYSTEM_IP
        config.setFSIP(fsIP)

        if not fsPort:
            fsPort = DEFAULT_SYSTEM_PORT
        config.setFSPort(fsPort)
        
        config.setUseBridge(useBridge)
        config.setLauncherId(socket.gethostbyname(socket.gethostname())+":"+str(XMLRPC_PORT))
        config.setConfigFilename()
        if useBridge:
            if config.getBridgeIP() == "":   #means that there was no app-specific bridge info set so use the default
                config.setBridgeIP(self.configs.getBridgeIP())
                config.setBridgePort(self.configs.getBridgePort())

        config.setCommand(config.getCommand()+" "+optionalArgs)

        # create the request, set the appropriate appId, write the config file and submit it
        return self.requests.addRequest(config)

        
    def stopApp(self, appId):
        """ forcefully kills the application """
        return self.requests.stopRequest(appId)


    def appStatus(self):
        """ returns a list of currently running applications as a hash key=appId, value=appName-command """
        return self.requests.getStatus()
        

    def getAppList(self):
        """ return configurations for all apps in a hash of strings """
        self.configs.reloadConfigFile()
        return self.configs.getConfigHash()


    def getAppConfigInfo(self, appId):
        """ return the configuration information for the running app """
        if self.requests.getRequest(appId):
            s = self.requests.getRequest(appId).config.getConfigString()
            return s
        else:
            return -1
  

    def killLauncher(self):
        """ used for killing the appLauncher remotely """
        global STOP_LAUNCHER
        STOP_LAUNCHER = True

        # unregister from the sage server
        if self.launcherId:
            try: self.sageServer.UnregisterLauncher(self.launcherId)
            except: pass

        return 1


    def reportLauncher(self):
        """ only used to report ourselves to the sage server that we are still alive
            every time pretend like it's our first time connecting so that even if the
            sage server was started after the appLauncher, it will still be reported
        """
        if not DO_REPORT:
            return
        
        try:
            self.launcherId = self.sageServer.ReportLauncher( REPORT_NAME, socket.gethostbyname(socket.gethostname()),
                                                              XMLRPC_PORT, self.getAppList() )
        except socket.error:
            pass
        except:
            WriteLog( "".join(tb.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) )


    def test(self):
        return 1