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_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_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 __workflowxml(self, transid): tsClient = TransformationClient() retVal = tsClient.getTransformations({'TransformationID': transid}) if not retVal['OK']: raise WErr.fromSERROR(retVal) print retVal['Value'] return {"success": "true", "result": retVal['Value'][0]['Body']}
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_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_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_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_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_listAppState( self ): self.__tc.setSetup( False ) try: app = self.request.arguments[ 'app' ][-1] except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) up = UserProfileClient( "Web/App/%s" % app ) result = yield self.threadTask( up.listAvailableVars, { 'UserName' : [ self.getUserName() ] } ) if not result[ 'OK' ]: raise WErr.fromSERROR( result) data = result[ 'Value' ] self.finish( { 'app': [ e[-1] for e in data ] } )
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_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_listAppState(self): self.__tc.setSetup(False) try: app = self.request.arguments['app'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) up = UserProfileClient("Web/App/%s" % app) result = yield self.threadTask(up.listAvailableVars, {'UserName': [self.getUserName()]}) if not result['OK']: raise WErr.fromSERROR(result) data = result['Value'] self.finish({'app': [e[-1] for e in data]})
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 ) ) result = yield self.threadTask( up.storeVar, name, data ) if not result[ 'OK' ]: raise WErr.fromSERROR( result ) self.set_status( 200 ) self.finish()
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)) result = yield self.threadTask(up.storeVar, name, data) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_getInstallationData(self): """ Retrieves a list of dictionaries containing components to be displayed by the Component History page """ # Get the selectors values req = self.__request() client = RPCClient('Framework/ComponentMonitoring') result = yield self.threadTask(client.getInstallations, req['installation'], req['component'], req['host'], True) if result['OK']: values = [] installations = result['Value'] for i in range(self.pageNumber, self.pageNumber + self.numberOfInstallations): if len(installations) > i: installation = installations[i] else: break uninstalled = '-' installedBy = '-' uninstalledBy = '-' if installation['UnInstallationTime']: uninstalled = installation['UnInstallationTime'].strftime( '%Y-%m-%d %H:%M') if installation['InstalledBy']: installedBy = installation['InstalledBy'] if installation['UnInstalledBy']: uninstalledBy = installation['UnInstalledBy'] values.append( { 'Name': installation[ 'Instance' ], \ 'Module': installation[ 'Component' ][ 'Module' ], \ 'Host': installation[ 'Host' ][ 'HostName' ], \ 'System': installation[ 'Component' ][ 'System' ], \ 'Type': installation[ 'Component' ][ 'Type' ], \ 'Installed': installation[ 'InstallationTime' ].strftime( '%Y-%m-%d %H:%M' ), \ 'Uninstalled': uninstalled, \ 'InstalledBy': installedBy, \ 'UninstalledBy': uninstalledBy } ) timestamp = Time.dateTime().strftime('%Y-%m-%d %H:%M [UTC]') total = len(installations) callback = { 'success': 'true', 'result': values, 'total': total, 'date': timestamp } else: raise WErr.fromSERROR(result) self.finish(callback)
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_loadAppState( self ): self.__tc.setSetup( False ) try: app = self.request.arguments[ 'app' ][-1] name = self.request.arguments[ 'name' ][-1] except KeyError as excp: raise WErr( 400, "Missing %s" % excp ) up = UserProfileClient( "Web/App/%s" % app ) 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.set_header( "Content-Type", "application/json" ) self.finish( data )
def web_saveAppState(self): self.__tc.setSetup(False) try: app = self.request.arguments['app'][-1] 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)) up = UserProfileClient("Web/App/%s" % app) result = yield self.threadTask(up.storeVar, name, data) if not result['OK']: raise WErr.fromSERROR(result) self.set_status(200) self.finish()
def web_saveAppState( self ): self.__tc.setSetup( False ) try: app = self.request.arguments[ 'app' ][-1] 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 ) ) up = UserProfileClient( "Web/App/%s" % app ) result = yield self.threadTask( up.storeVar, name, data ) if not result[ 'OK' ]: raise WErr.fromSERROR( result ) self.set_status( 200 ) self.finish()
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_loadAppState(self): self.__tc.setSetup(False) try: app = self.request.arguments['app'][-1] name = self.request.arguments['name'][-1] except KeyError as excp: raise WErr(400, "Missing %s" % excp) up = UserProfileClient("Web/App/%s" % app) 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.set_header("Content-Type", "application/json") self.finish(data)
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' ): 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_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_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_getSelectionData(self): """ Returns a list of possible values for each different selector to choose from """ req = self.__request() data = {} userData = self.getSessionData() setup = userData['setup'].split('-')[-1] systemList = [] system = None fields = ['name', 'host', 'module', 'system', 'type'] client = RPCClient('Framework/ComponentMonitoring') result = yield self.threadTask(client.getInstallations, {}, {}, {}, True) if result['OK']: for field in fields: data[field] = set() for installation in result['Value']: data['name'].add(installation['Instance']) data['host'].add(installation['Host']['HostName']) data['module'].add(installation['Component']['Module']) data['system'].add(installation['Component']['System']) data['type'].add(installation['Component']['Type']) # Order and format the results for field in fields: data[field] = list(data[field]) data[field].sort() data[field] = map(lambda x: [x], data[field]) else: raise WErr.fromSERROR(result) self.finish(data)
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_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)
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 )