Esempio n. 1
0
	def getGroupData(self):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
			interface = UserDataInterface()
			username = cherrypy.request.login
			simulationID = interface.getSimulationid(username) #pass in this format			
			siminfo = interface.getSimulationUserData(simulationID)
			simFolderId = interface.getSimulationFolder(simulationID, username)
			problem_id = self.problemsDAO.getProblemID(simulationID)
			problem = self.problemsDAO.readProblem(problem_id)
			interface.ensureSimulationExists(simFolderId)
			sim_folder = str(simFolderId)
			userDetails = interface.getUserDetails(username)
			firstname = userDetails.get('firstname')
			lastname = userDetails.get('lastname')
			groupname = userDetails.get('groupname')
			
			# In COLAB mode, rest of the junctions are returned in addition to the
			# one that a group is associated with			
			assoc_junctions = interface.getJunctionsofOtherGroups(simulationID, username)
			logging.info('Returning login data for user: '******'response' : {'status': "success", 'siminfo' : siminfo, 'sim_id' : str(simulationID),
				'sim_folder' : sim_folder, 'username': cherrypy.request.login, 'firstname':firstname,
				'lastname':lastname, 'groupname':groupname, 'assoc_junctions':assoc_junctions,
				'problem_id' : problem_id, 'problem_type' : problem['type']}}
			logging.info(response_data)
			return response_data
		else:
			return {'response' :  {'status':"failure"}}
Esempio n. 2
0
class trafficsim(threading.Thread):

	cloudInterface = CloudInterface()
        	
	def __init__(self, vmIP, key_name, simulationID, userID):
		threading.Thread.__init__(self)
		logging.info('Initializing trafficsim from SimID' + str(simulationID));
		self.userInterface = UserDataInterface()
		self.simulationID = simulationID
		self.strSimulationID = str(simulationID)
		self.userID = userID
		self.vmIP = vmIP 
		self.keyName = key_name
		self.sumoport = SUMO_PORT
		datafolder = GENERATED_DATA_FOLDER + self.strSimulationID
		self.trafficdataxml = datafolder + TRAFFIC_DATA_XML
		self.trafficsignaldataxml = datafolder + TRAFFIC_SIGNAL_DATA_XML
		self.running = False
		self.traciinst = None
		print("..initialized")
			
	def disconnectSumo(self):
		print("Disconnecting...")
		self.running = False
		if self.traciinst is not None:
			self.traciinst.close()
		
		#self.sumoprocess.wait()
		
	def run(self):
		try:			
			print("running...")
			logging.info('Performing simulation setup for id: ' + self.strSimulationID);
			self.userInterface.updateSimulationRunningState(self.simulationID, "INITIALIZING", self.vmIP)
			self.remoteSim = RemoteSimulation(self.vmIP, self.keyName, self.simulationID)
			if (self.remoteSim.runRemoteSimulation() is False):
				logging.exception('Unable to start remote simulation: ' + self.strSimulationID)
				return		
			logging.info('Simulation server started for id: ' + self.strSimulationID);
			self.userInterface.ensureSimulationExists(self.simulationID)
			self.userInterface.updateSimulationRunningState(self.simulationID, "CONFIGURED")
    			# wait for simulation to start server
			time.sleep(1)
			logging.info('Instantiating Traci for host: ' + self.vmIP + ' for simulation: ' + self.strSimulationID);
			self.traciinst = Traci(port=self.sumoport, numRetries=10, host=self.vmIP)
			logging.info('Backing up old simulation...' + ' for simulation: ' + self.strSimulationID);
			backup = SimulationBackupInterface(self.simulationID)
			backup.backupSimulation(self.userID, "INACTIVE")
			
			logging.info('Starting simulation with ID: ' + self.strSimulationID);			
			self.mainloop()			
			
		except Exception, err:
			logging.exception(err)
		
		finally:
Esempio n. 3
0
	def setMode(self, user_mode=None):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
			username = cherrypy.request.login
			interface = UserDataInterface()
			simulationID = interface.getSimulationid(username)
			logging.info('simulationID: ' + str(simulationID) + ' , username: '******', usermode: ' + user_mode)
			interface.setUserMode(username, user_mode);
			cloudInterface = CloudInterface();			
			simFolderId = interface.getSimulationFolder(simulationID, username)
			interface.ensureSimulationExists(simFolderId)
			return {'response' : {'status': "success", 'sim_folder' : str(simFolderId),
				 'sim_id' : str(simulationID)}}
		else:
			return {'response' :  "failure"}
Esempio n. 4
0
    def getGroupData(self):
        if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
            interface = UserDataInterface()
            username = cherrypy.request.login
            simulationID = interface.getSimulationid(
                username)  #pass in this format
            siminfo = interface.getSimulationUserData(simulationID)
            simFolderId = interface.getSimulationFolder(simulationID, username)
            problem_id = self.problemsDAO.getProblemID(simulationID)
            problem = self.problemsDAO.readProblem(problem_id)
            interface.ensureSimulationExists(simFolderId)
            sim_folder = str(simFolderId)
            userDetails = interface.getUserDetails(username)
            firstname = userDetails.get('firstname')
            lastname = userDetails.get('lastname')
            groupname = userDetails.get('groupname')

            # In COLAB mode, rest of the junctions are returned in addition to the
            # one that a group is associated with
            assoc_junctions = interface.getJunctionsofOtherGroups(
                simulationID, username)
            logging.info('Returning login data for user: '******'response': {
                    'status': "success",
                    'siminfo': siminfo,
                    'sim_id': str(simulationID),
                    'sim_folder': sim_folder,
                    'username': cherrypy.request.login,
                    'firstname': firstname,
                    'lastname': lastname,
                    'groupname': groupname,
                    'assoc_junctions': assoc_junctions,
                    'problem_id': problem_id,
                    'problem_type': problem['type']
                }
            }
            logging.info(response_data)
            return response_data
        else:
            return {'response': {'status': "failure"}}
Esempio n. 5
0
 def setMode(self, user_mode=None):
     if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
         username = cherrypy.request.login
         interface = UserDataInterface()
         simulationID = interface.getSimulationid(username)
         logging.info('simulationID: ' + str(simulationID) +
                      ' , username: '******', usermode: ' +
                      user_mode)
         interface.setUserMode(username, user_mode)
         cloudInterface = CloudInterface()
         simFolderId = interface.getSimulationFolder(simulationID, username)
         interface.ensureSimulationExists(simFolderId)
         return {
             'response': {
                 'status': "success",
                 'sim_folder': str(simFolderId),
                 'sim_id': str(simulationID)
             }
         }
     else:
         return {'response': "failure"}