def web_saveAppState(self): up = self.__getUP() try: name = self.request.arguments['name'][-1] state = self.request.arguments['state'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) data = base64.b64encode(zlib.compress(DEncode.encode(state), 9)) # before we save the state (modify the state) we have to remeber the actual access: ReadAccess and PublishAccess result = yield self.threadTask(up.getVarPermissions, name) if result['OK']: access = result['Value'] else: access = { 'ReadAccess': 'USER', 'PublishAccess': 'USER' } # this is when the application/desktop does not exists. result = yield self.threadTask(up.storeVar, name, data) if not result['OK']: raise WErr.fromSERROR(result) # change the access to the application/desktop result = yield self.threadTask(up.setVarPermissions, name, access) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_makePublicAppState(self): up = self.__getUP() try: name = self.request.arguments['name'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) try: access = self.request.arguments['access'][-1].upper() except KeyError as excp: access = 'ALL' if access not in ('ALL', 'VO', 'GROUP', 'USER'): raise WErr(400, "Invalid access") revokeAccess = {'ReadAccess': access} if access == 'USER': # if we make private a state, # we have to revoke from the public as well revokeAccess['PublishAccess'] = 'USER' # TODO: Check access is in either 'ALL', 'VO' or 'GROUP' result = yield self.threadTask(up.setVarPermissions, name, revokeAccess) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_delAppState(self): up = self.__getUP() try: name = self.request.arguments['name'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) result = yield self.threadTask(up.deleteVar, name) if not result['OK']: raise WErr.fromSERROR(result) self.finish()
def web_loadAppState(self): up = self.__getUP() try: name = self.request.arguments['name'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) result = yield self.threadTask(up.retrieveVar, name) if not result['OK']: raise WErr.fromSERROR(result) data = result['Value'] data, count = DEncode.decode(zlib.decompress(base64.b64decode(data))) self.finish(data)
def web_action( self ): try: id = int( self.request.arguments[ 'id' ][-1] ) except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) callback = {} if self.request.arguments["data_kind"][0] == "getLoggingInfo": callback = yield self.threadTask( self.__getLoggingInfo, id ) elif self.request.arguments["data_kind"][0] == "fileStatus": callback = yield self.threadTask( self.__transformationFileStatus, id ) elif self.request.arguments["data_kind"][0] == "fileProcessed": callback = yield self.threadTask( self.__fileRetry, id, 'proc' ) elif self.request.arguments["data_kind"][0] == "fileNotProcessed": callback = yield self.threadTask( self.__fileRetry, id, 'not' ) elif self.request.arguments["data_kind"][0] == "fileAllProcessed": callback = yield self.threadTask( self.__fileRetry, id, 'all' ) elif self.request.arguments["data_kind"][0] == "dataQuery": callback = yield self.threadTask( self.__dataQuery, id ) elif self.request.arguments["data_kind"][0] == "additionalParams": callback = yield self.threadTask( self.__additionalParams, id ) elif self.request.arguments["data_kind"][0] == "transformationDetail": callback = yield self.threadTask( self.__transformationDetail, id ) elif self.request.arguments["data_kind"][0] == "extend": callback = yield self.threadTask( self.__extendTransformation, id ) else: callback = {"success":"false", "error":"Action is unknown!!!"} self.finish( callback )
def __getUP(self): try: obj = self.request.arguments['obj'][-1] app = self.request.arguments['app'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) print "UserProfileClient" print UserProfileClient("Web/%s/%s" % (obj, app)) return UserProfileClient("Web/%s/%s" % (obj, app))
def prepare(self): if not self.isRegisteredUser(): raise WErr(401, "Not a registered user") self.set_header("Pragma", "no-cache") self.set_header("Cache-Control", "max-age=0, no-store, no-cache, must-revalidate") # Do not use the defined user setup. Use the web one to show the same profile independenly of # user setup self.__tc.setSetup(False)
def web_makePublicDesktopState(self): up = UserProfileClient("Web/application/desktop") try: name = self.request.arguments['name'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) try: access = self.request.arguments['access'][-1].upper() except KeyError as excp: access = 'ALL' if access not in ('ALL', 'VO', 'GROUP', 'USER'): raise WErr(400, "Invalid access") # TODO: Check access is in either 'ALL', 'VO' or 'GROUP' result = yield self.threadTask(up.setVarPermissions, name, {'ReadAccess': access}) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_listAppState(self): up = self.__getUP() result = yield self.threadTask(up.retrieveAllVars) if not result['OK']: raise WErr.fromSERROR(result) data = result['Value'] for k in data: # Unpack data data[k] = json.loads( DEncode.decode(zlib.decompress(base64.b64decode(data[k])))[0]) self.finish(data)
def web_changeView(self): up = self.__getUP() try: desktopName = self.request.arguments['desktop'][-1] view = self.request.arguments['view'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) result = yield self.threadTask(up.retrieveVar, desktopName) if not result['OK']: raise WErr.fromSERROR(result) data = result['Value'] oDesktop = json.loads( DEncode.decode(zlib.decompress(base64.b64decode(data)))[0]) oDesktop[unicode('view')] = unicode(view) oDesktop = json.dumps(oDesktop) data = base64.b64encode(zlib.compress(DEncode.encode(oDesktop), 9)) result = yield self.threadTask(up.storeVar, desktopName, data) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_publishAppState(self): up = self.__getUP() try: name = self.request.arguments['name'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) try: access = self.request.arguments['access'][-1].upper() except KeyError as excp: access = 'ALL' if access not in ('ALL', 'VO', 'GROUP', 'USER'): raise WErr(400, "Invalid access") result = yield self.threadTask(up.setVarPermissions, name, { 'PublishAccess': access, 'ReadAccess': access }) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_listPublicDesktopStates(self): up = self.__getUP() result = yield self.threadTask(up.listAvailableVars) if not result['OK']: raise WErr.fromSERROR(result) data = result['Value'] paramNames = ['UserName', 'Group', 'VO', 'desktop'] records = [] for i in data: records += [dict(zip(paramNames, i))] sharedDesktops = {} for i in records: result = yield self.threadTask(up.getVarPermissions, i['desktop']) if not result['OK']: raise WErr.fromSERROR(result) if result['Value']['ReadAccess'] == 'ALL': print i['UserName'], i['Group'], i result = yield self.threadTask(up.retrieveVarFromUser, i['UserName'], i['Group'], i['desktop']) if not result['OK']: raise WErr.fromSERROR(result) if i['UserName'] not in sharedDesktops: sharedDesktops[i['UserName']] = {} sharedDesktops[i['UserName']][i['desktop']] = json.loads( DEncode.decode( zlib.decompress(base64.b64decode( result['Value'])))[0]) sharedDesktops[i['UserName']]['Metadata'] = i else: sharedDesktops[i['UserName']][i['desktop']] = json.loads( DEncode.decode( zlib.decompress(base64.b64decode( result['Value'])))[0]) sharedDesktops[i['UserName']]['Metadata'] = i self.finish(sharedDesktops)
def web_executeOperation( self ): try: cmd = self.request.arguments[ 'action' ][-1] ids = self.request.arguments["ids"][0].split( "," ) ids = [int( i ) for i in ids ] except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) tsClient = TransformationClient() agentType = 'Manual' if cmd == 'clean': status = 'Cleaning' elif cmd == 'start': status = 'Active' agentType = 'Automatic' elif cmd == 'flush': status = 'Flush' agentType = 'Automatic' elif cmd == 'stop': status = 'Stopped' elif cmd == 'complete': status = 'Completed' else: self.finish( {"success":"false", "error": "Unknown action"} ) callback = [] for i in ids: try: id = int( i ) result = yield self.threadTask( tsClient.setTransformationParameter, id, 'Status', status ) if result["OK"]: resString = "ProdID: %s set to %s successfully" % ( i, cmd ) result = yield self.threadTask( tsClient.setTransformationParameter, id, 'AgentType', agentType ) if not result["OK"]: resString = "ProdID: %s failed to set to %s: %s" % ( i, cmd, result["Message"] ) else: resString = "ProdID: %s failed due the reason: %s" % ( i, result["Message"] ) except: resString = "Unable to convert given ID %s to transformation ID" % i callback.append( resString ) callback = {"success":"true", "showResult":callback} gLogger.info( cmd, ids ) self.finish( callback )
def web_showFileStatus( self ): callback = {} start = int( self.request.arguments["start"][-1] ) limit = int( self.request.arguments["limit"][-1] ) try: id = self.request.arguments[ 'transformationId' ][-1] status = self.request.arguments[ 'status' ][-1] except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) tsClient = TransformationClient() result = yield self.threadTask( tsClient.getTransformationFilesSummaryWeb, {'TransformationID':id, 'Status':status}, [["FileID", "ASC"]], start, limit ) if not result['OK']: callback = {"success":"false", "error":result["Message"]} else: result = result["Value"] if result.has_key( "TotalRecords" ) and result["TotalRecords"] > 0: if result.has_key( "ParameterNames" ) and result.has_key( "Records" ): if len( result["ParameterNames"] ) > 0: if len( result["Records"] ) > 0: callback = [] jobs = result["Records"] head = result["ParameterNames"] headLength = len( head ) for i in jobs: tmp = {} for j in range( 0, headLength ): tmp[head[j]] = i[j] callback.append( tmp ) total = result["TotalRecords"] timestamp = Time.dateTime().strftime( "%Y-%m-%d %H:%M [UTC]" ) if result.has_key( "Extras" ): extra = result["Extras"] callback = {"success":"true", "result":callback, "total":total, "extra":extra, "date":timestamp} else: callback = {"success":"true", "result":callback, "total":total, "date":timestamp} else: callback = {"success":"false", "result":"", "error":"There are no data to display"} else: callback = {"success":"false", "result":"", "error":"ParameterNames field is undefined"} else: callback = {"success":"false", "result":"", "error":"Data structure is corrupted"} else: callback = {"success":"false", "result":"", "error":"There were no data matching your selection"} self.finish( callback )
def web_setSite( self ): callback = {} try: transID = int( self.request.arguments[ 'TransformationId' ][-1] ) runID = int( self.request.arguments[ 'RunNumber' ][-1] ) site = self.request.arguments[ 'Site' ][-1] except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) gLogger.info( "\033[0;31m setTransformationRunsSite(%s, %s, %s) \033[0m" % ( transID, runID, site ) ) tsClient = TransformationClient() result = yield self.threadTask( tsClient.setTransformationRunsSite, transID, runID, site ) if result["OK"]: callback = {"success":"true", "result":"true"} else: callback = {"success":"false", "error":result["Message"]} self.finish( callback )
def __extendTransformation( self, transid ): try: tasks = int( self.request.arguments["tasks"][-1] ) except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) gLogger.info( "extend %s" % transid ) tsClient = TransformationClient() gLogger.info( "extendTransformation(%s,%s)" % ( transid, tasks ) ) res = tsClient.extendTransformation( transid, tasks ) if res["OK"]: resString = "%s extended by %s successfully" % ( transid, tasks ) else: resString = "%s failed to extend: %s" % ( transid, res["Message"] ) callback = {"success":"true", "showResult":[resString], "result":resString} gLogger.info( "#######", res ) return callback
def web_changeSetup(self): try: to = self.request.arguments['to'][-1] except KeyError: raise WErr(400, "Missing 'to' argument") self.__change(setup=to)
def web_listPublicStates(self): session = self.getSessionData() user = session["user"]["username"] up = self.__getUP() retVal = yield self.threadTask(up.getUserProfileNames, {'PublishAccess': 'ALL'}) if not retVal['OK']: raise WErr.fromSERROR(retVal) data = retVal['Value'] if data == None: raise WErr(404, "There are no public states!") paramNames = ['user', 'group', 'vo', 'name'] mydesktops = { 'name': 'My Desktops', 'group': '', 'vo': '', 'user': '', 'iconCls': 'my-desktop', 'children': [] } shareddesktops = { 'name': 'Shared Desktops', 'group': '', 'vo': '', 'user': '', 'expanded': 'true', 'iconCls': 'shared-desktop', 'children': [] } myapplications = { 'name': 'My Applications', 'group': '', 'vo': '', 'user': '', 'children': [] } sharedapplications = { 'name': 'Shared Applications', 'group': '', 'vo': '', 'user': '', 'expanded': 'true', 'iconCls': 'shared-desktop', 'children': [] } desktopsApplications = { 'text': '.', 'children': [{ 'name': 'Desktops', 'group': '', 'vo': '', 'user': '', 'children': [mydesktops, shareddesktops] }, { 'name': 'Applications', 'group': '', 'vo': '', 'user': '', 'children': [myapplications, sharedapplications] }] } type = '' for i in data: application = i.replace('Web/application/', '') up = UserProfileClient(i) retVal = up.listAvailableVars() if not retVal['OK']: raise WErr.fromSERROR(retVal) else: states = retVal['Value'] for state in states: record = dict(zip(paramNames, state)) record['app'] = application retVal = yield self.threadTask(up.getVarPermissions, record['name']) if not retVal['OK']: raise WErr.fromSERROR(retVal) else: permissions = retVal['Value'] if permissions['PublishAccess'] == 'ALL': if application == 'desktop': record['type'] = 'desktop' record['leaf'] = 'true' record['iconCls'] = 'core-desktop-icon', if record['user'] == user: mydesktops['children'].append(record) else: shareddesktops['children'].append(record) else: record['type'] = 'application' record['leaf'] = 'true' record['iconCls'] = 'core-application-icon' if record['user'] == user: myapplications['children'].append(record) else: sharedapplications['children'].append( record) self.finish(desktopsApplications)