Ejemplo n.º 1
0
 def createDMInfo(self, info):
     configmgr = ConfigurationProvider()
     jobdir = configmgr.get_config("PBS_JOBDIR")
     file = open("%s/dm.info" % jobdir, 'w+')
     file.write(info)
     file.flush()
     file.close()
Ejemplo n.º 2
0
class InterativeJob:
 
    def __init__(self, session_mgr, app_mgr):

        logging.basicConfig(filename='dmtrace.log', level=logging.INFO, format='%(asctime)s %(message)s',
                            datefmt='%m/%d/%Y %I:%M:%S %p')

        #trap sigterm and terminate the session gracefully
        signal.signal(signal.SIGTERM, self.__terminate)
        self.session_mgr = session_mgr
	self.app_mgr = app_mgr	
	self.config_provider = ConfigurationProvider()
	self.maxtimeout=5*12*30*24*60*60
	self.old_handler=signal.getsignal(signal.SIGALRM)
     
    def run(self):

 	# 1. Update submit
	self.__updateSubmit()
        status=False
	if self.config_provider.get_config('PAS_DM_APP_LAUNCH_STYLE') == "EARLY":
            # 2. Start App With Session
            status = self.app_mgr.start_app(self.config_provider.get_config('PAS_EXECUTABLE'), \
	                           self.config_provider.get_config('PAS_DM_APP_ARGS'), \
                               self.config_provider.get_config('PAS_DM_APP_ENVS'), \
                               self.config_provider.get_config('PAS_DM_APP_WDIR'))
	else:
	    # 2. Start session only
	    status = self.session_mgr.start_session()

        if not status or status is None:
            self.session_mgr.stop_session()
            logging.error('failed to either start app or start session')
            sys.exit(1)
           
	# 3. hold job until either app or session terminates
	self.__holdJob()

	# 4. Update delete
	self.__updateDelete()

    def __updateSubmit(self):
	try:
            sleep(1)
	    self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)	
	    self.sock.connect((jobsubmon.getHost(), jobsubmon.getPort()))
	    self.sock.send('command=submit' + '\n' + 'app=' + jobinfo.appinfo.name + '\n' + \
		                'jobid=' + jobinfo.jobid + '\n' + 'server=' + os.getenv('PAS_CLUSTER_NAME')  + '\n')
            logging.info('update this job submit to DM server')
	    self.sock.close()
	except socket.error, (value, msg):
            logging.error(msg)
	    if self.sock:	
	    	self.sock.close()
            sys.exit(1)
Ejemplo n.º 3
0
    def __init__(self, session_mgr, app_mgr):

        logging.basicConfig(filename='dmtrace.log', level=logging.INFO, format='%(asctime)s %(message)s',
                            datefmt='%m/%d/%Y %I:%M:%S %p')

        #trap sigterm and terminate the session gracefully
        signal.signal(signal.SIGTERM, self.__terminate)
        self.session_mgr = session_mgr
	self.app_mgr = app_mgr	
	self.config_provider = ConfigurationProvider()
	self.maxtimeout=5*12*30*24*60*60
	self.old_handler=signal.getsignal(signal.SIGALRM)
Ejemplo n.º 4
0
 def removeDMInfo(self):
     status = False
     configmgr = ConfigurationProvider()
     jobdir = configmgr.get_config("PBS_JOBDIR")
     filepath = "%s/dm.info" % jobdir
     if os.path.isfile(filepath):
         os.remove(filepath)
         logging.info("removed DM info file %s" % filepath)
         status = True
     else:
         logging.error('file %s does not exist' % filepath)
         sys.stderr.write('file %s does not exist' % filepath)
     return status
Ejemplo n.º 5
0
    def start_app(self, cmd, args=None, envs=None, cwd=None, display=None):

        sessionmgr = TurboVNCSessionManager()
        configmgr = ConfigurationProvider()

        # Get the allocated GPU resource
        resource = self.__getRes()
        logging.info("GPU resource id =%(res)s" % {'res': resource})

        # Validate X access as the first thing for OpenGL apps
        if self.__check_X_access(resource) != 0:
            return False

        # Start a new TurboVNC server if required
        if display is None:
            display = sessionmgr.start_session()
            if display is None:
                return False

# Update the process envs
        self.__updateEnvs(envs)

        # Set the DISPLAY environment
        os.environ['DISPLAY'] = display
        envs = os.environ.copy()

        if cwd is None:
            cwd = configmgr.get_config("PBS_JOBDIR")

        if resource is not None:
            cmd = "%(vglpath)svglrun -d %(d)s -sp %(cmd)s" % {
                'vglpath': Constants.VGL_EXEC_PATH,
                'd': resource,
                'cmd': cmd
            }

        if args is not None:
            cmd = '%(c)s %(a)s' % {'c': cmd, 'a': args}

# Start the application on a given display {use VGL for OpenGL}
        logging.info("starting application exec=%(cmd)s envs=%(envs)s cwd=%(cwd)s display=%(d)s" \
                                 % {'cmd':cmd, 'envs':envs, 'cwd':cwd, 'd':display})

        appname = configmgr.get_config('PAS_APPLICATION')
        app = subprocess.Popen(re.split(' ', cmd), env=envs, cwd=cwd, shell=False, \
       stdout=open('%s.STDOUT'%appname, 'w'), \
                     stderr=open('%s.STDERR'%appname, 'w'), close_fds=True)

        util = Util()
        util.update("appPid", app.pid)
        return True
Ejemplo n.º 6
0
    def __getRes(self):

        resource = None
        configmgr = ConfigurationProvider()
        jobdir = configmgr.get_config("PBS_JOBDIR")
        filepath = "%s/resource" % jobdir
        if os.path.isfile(filepath):
            file = open(filepath, 'r')
            filec = file.readline()
            logging.info("reading resource file %(o)s" % {'o': filec})
            splitwords = filec.split(":")
            # Format :<display>.<screen>
            resource = ":0.%s" % splitwords[1]
            resource = resource.rstrip('\n')
            file.close()
        return resource
Ejemplo n.º 7
0
 def getValue(self, var):
     configmgr = ConfigurationProvider()
     jobdir = configmgr.get_config("PBS_JOBDIR")
     filepath = "%s/dm.info" % jobdir
     value = None
     if os.path.isfile(filepath):
         file = open(filepath, 'r')
         for entry in file.readlines():
             splitwords = entry.split("=")
             if var == splitwords[0]:
                 value = splitwords[1].replace("\n", "")
                 logging.info('Found key= %(key)s value=%(val)s' % {
                     'key': var,
                     'val': value
                 })
                 break
             file.close()
     return value
Ejemplo n.º 8
0
 def update(self, key, value):
     status = False
     configmgr = ConfigurationProvider()
     jobdir = configmgr.get_config("PBS_JOBDIR")
     filepath = "%s/dm.info" % jobdir
     if os.path.isfile(filepath):
         file = open(filepath, 'a')
         output="%(key)s=%(val)s\n" \
                     % {'key': key, 'val': value}
         logging.info("Updated %s" % output)
         file.write(output)
         file.flush()
         file.close()
         status = True
     else:
         logging.error('file %s does not exist' % filepath)
         sys.stderr.write('file %s does not exist' % filepath)
     return status
Ejemplo n.º 9
0
    def set_expiry(self, timeout):

        status = False
        logging.info('setting the session expiry timer')
        logging.debug('ENVS: %s' % os.environ)
        configmgr = ConfigurationProvider()
        jobdir = configmgr.get_config("PBS_JOBDIR")
        if timeout is not None:
            filepath = "%s/expiry" % jobdir
            file = open(filepath, 'w+')
            os.chmod(filepath, 0644)
            file.write("%s" % timeout)
            file.flush()
            file.close()
            logging.info('session expiry timer updated to: %s' % timeout)
            status = True
        else:
            logging.error('session expiry timer update failed')
        return status
Ejemplo n.º 10
0
    def start_session(self):

        logging.info('starting display server')
        configmgr = ConfigurationProvider()
        geometry = configmgr.get_config('PAS_DM_APP_GEOMETRY')
        cmd = "%(vncpath)svncserver -geometry %(geo)s -novncauth -nopam" % {
            'vncpath': Constants.TurboVNC_EXEC_PATH,
            'geo': geometry
        }
        logging.info('executing cmd %(cmd)s' % {'cmd': cmd})
        vncstart = subprocess.Popen(re.split(' ', cmd),
                                    shell=False,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    close_fds=True)
        out, err = vncstart.communicate()
        if vncstart.returncode != 0:
            logging.error('display server failed to start with error %s' % err)
            sys.stderr.write(err)
        else:
            self.__update(err, geometry)
            util = Util()
        return util.getValue("display")
Ejemplo n.º 11
0
 def getDMInfo(self):
     status = False
     configmgr = ConfigurationProvider()
     logging.info('getting the session information')
     logging.debug('ENVS: %s' % os.environ)
     jobdir = configmgr.get_config("PBS_JOBDIR")
     filepath = "%s/dm.info" % jobdir
     counter = 5
     while ((not os.path.exists(filepath)) and (counter > 0)):
         sleep(0.5)
         counter -= 1
     if os.path.isfile(filepath):
         file = open(filepath, 'r')
         sessionout = file.read()
         logging.info('session output %s' % sessionout)
         sys.stdout.write(sessionout)
         sys.stdout.flush()
         file.close()
         status = True
     else:
         logging.error('file %s does not exist' % filepath)
         sys.stderr.write('file %s does not exist' % filepath)
     return status
Ejemplo n.º 12
0
import logging
import cloudinary
import cloudinary.api
import cloudinary.uploader
from telegram import (InlineQueryResultPhoto, InputTextMessageContent)
from telegram.ext import (Updater, MessageHandler, Filters, InlineQueryHandler)
from telegram.error import (TelegramError, Unauthorized, BadRequest, TimedOut,
                            ChatMigrated, NetworkError)
from random import shuffle, randint
from TextProvider import TextProvider
from ConfigurationProvider import ConfigurationProvider
import threading

config = ConfigurationProvider()

updater = Updater(token=config.token)
dispatcher = updater.dispatcher
handlers = []
dict = dict()

cloudinary.config(cloud_name=config.cloud_name,
                  api_key=config.api_key,
                  api_secret=config.api_secret)

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.ERROR)


def start(bot, update):
    bot.sendMessage(chat_id=update.message.chat_id, text=TextProvider.start)
Ejemplo n.º 13
0
            if timeout == 0:
        	logging.info('disable session expiry timer')
                signal.signal(signal.SIGALRM, self.old_handler)
                signal.alarm(0)
            else:
        	logging.info('reset session expiry timer from %(f)d to %(t)d' % {'f':ltimeout, 't':timeout})
                signal.signal(signal.SIGALRM, self.__expiry_handler)
                signal.alarm(timeout)
            ltimeout = timeout

        signal.signal(signal.SIGALRM, self.old_handler)
        signal.alarm(0)
        sleep(2)

    def __terminate(self, signum, frame):
	self.__updateDelete()
	sys.exit(1)

#main 	
config_provider = ConfigurationProvider()

sessionmgr_provider = SessionManagerProvider()
sessionmgr = sessionmgr_provider.get_session_mgr(config_provider.get_config('DM_SESSION_MGR'))

appmgr_provider = ApplicationManagerProvider()
appmgr = appmgr_provider.get_app_mgr(config_provider.get_config('DM_APP_MGR'))

job = InterativeJob(sessionmgr, appmgr)
job.run()
sys.exit(0)
Ejemplo n.º 14
0
# WARNING: Display Manager(DM) solution is built based on this custom action script; further customization might not be supported and might break DM

import os
import sys

sys.path.append(os.getcwd() + "/runtime")

from SessionManagerProvider import SessionManagerProvider
from ConfigurationProvider import ConfigurationProvider
from ApplicationManagerProvider import ApplicationManagerProvider
from Util import Util

config_provider = ConfigurationProvider()
appmgr_provider = ApplicationManagerProvider()
appmgr = appmgr_provider.get_app_mgr(config_provider.get_config('DM_APP_MGR'))

sessionmgr_provider = SessionManagerProvider()
sessionmgr = sessionmgr_provider.get_session_mgr(
    config_provider.get_config('DM_SESSION_MGR'))

util = Util()

status = False
action = os.environ['PAS_ACTION_DM_CUSTOM_ACTION_TYPE']
if action == "START_APP":
    status=appmgr.start_app(config_provider.get_config('PAS_EXECUTABLE'), config_provider.get_config('PAS_ACTION_DM_APP_ARGS'), \
   config_provider.get_config('PAS_ACTION_DM_APP_ENVS'),config_provider.get_config('PAS_ACTION_DM_APP_WDIR'), util.getValue("display"))
elif action == "GET_OTP":
    status = sessionmgr.gen_password()
elif action == "WAIT_ON_SESSION":
    sessionmgr.set_waitflag()