Пример #1
0
    def web_file(self):
        """ Get the file information, use:
        GET /filecatalogue/file/<file>/attributes -- get the file information
        GET /filecatalogue/file/<file>/metadata -- get the file metadata

    """
        optns = self.overpath.strip('/').split('/')
        if len(optns) > 2:
            raise WErr(404, "Wrone way")
        path = self.__decodePath()
        __obj = re.match("([a-z]+)?",
                         optns[1]).group() if len(optns) > 1 else None
        if __obj == "attributes":
            result = yield self.threadTask(self.rpc.getFileMetadata, path)
            if not result['OK'] or path not in result['Value']['Successful']:
                raise WErr.fromError(result)
            self.finish(
                self.__sanitizeForJSON(result['Value']['Successful'][path]))
        elif __obj == "metadata":
            result = yield self.threadTask(self.rpc.getFileUserMetadata, path)
            if not result['OK']:
                raise WErr.fromError(result)
            self.finish(self.__sanitizeForJSON(result['Value']))
        else:
            raise WErr(404, "WTF?")
Пример #2
0
 def web_metadata(self):
     """ Retrieve all metadata keys with their type and possible values that are
       compatible with the metadata restriction. Accepts metadata condition:
       GET /filecatalogue/metadata -- retrieve all metadata keys with their type and possible values
           that are compatible with the metadata restriction. Accepts metadata condition
     
     :return: json with requested data
 """
     if self.overpath:
         raise WErr(404, "Wrone way")
     cond = self.__decodeMetadataQuery()
     result = yield self.threadTask(self.__rpc.getMetadataFields)
     if not result['OK']:
         raise WErr.fromError(result)
     data = result['Value']
     fields = {}
     for k in data['DirectoryMetaFields']:
         fields[k] = data['DirectoryMetaFields'][k].lower()
     result = yield self.threadTask(self.__rpc.getCompatibleMetadata, cond,
                                    "/")
     if not result['OK']:
         raise WErr.fromError(result)
     values = result['Value']
     data = {}
     for k in fields:
         if k not in values:
             continue
         data[k] = {'type': fields[k], 'values': values[k]}
     self.finish(data)
Пример #3
0
  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 )
Пример #4
0
    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()
Пример #5
0
    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()
Пример #6
0
    def web_requestNew(self):
        # validate
        # * dataset
        # * srcse
        # * dstse
        # * protocol
        self.log.debug(self.request.arguments)
        valid_list = ["dataset", "srcse", "dstse", "protocol"]
        build_input_param = {}
        for k in valid_list:
            if not self.request.arguments.has_key(k):
                raise WErr(400, "Missing %s" % k)
            build_input_param[k] = self.request.arguments[k][0]
        self.log.debug(build_input_param)
        # check the data
        ## SE
        if build_input_param["dstse"] == build_input_param["srcse"]:
            raise WErr(400, "dstse and srcse are same")
        ## protocol
        if build_input_param["protocol"] not in ["DIRACDMS", "DIRACFTS"]:
            raise WErr(400,
                       "protocol %s is wrong" % build_input_param["protocol"])
        # create
        RPC = RPCClient("Transfer/TransferRequest")
        res = RPC.create(build_input_param["dataset"],
                         build_input_param["srcse"],
                         build_input_param["dstse"],
                         build_input_param["protocol"])
        # TODO how to return error to the user?
        if not res["OK"]:
            self.log.error(res)

        self.set_status(200)
        self.finish()
        self.log.debug("finish")
Пример #7
0
    def web_conf(self):
        """ Configuration endpoint, used to:
          GET /conf/get?<options> -- get configuration information, with arguments
            * options:
              * fullCFG - to get dump of configuration
              * option - option path to get option value
              * options - section path to get list of options
              * section - section path to get dict of all options/values there
              * sections - section path to get list of sections there
              * version - version of configuration that request information(optional)
          
          GET /conf/<helper method>?<arguments> -- get some information by using helpers methods
            * helper method - helper method of configuration service
            * arguments - arguments specifecly for every helper method
        
        :return: json with requested data
    """
        self.log.notice('Request configuration information')
        optns = self.overpath.strip('/').split('/')
        if not optns or len(optns) > 1:
            raise WErr(404, "Wrone way")

        if optns[0] == 'get':
            if 'version' in self.args and (
                    self.args.get('version')
                    or '0') >= gConfigurationData.getVersion():
                self.finish()

            result = {}
            if 'fullCFG' in self.args:
                remoteCFG = yield self.threadTask(
                    gConfigurationData.getRemoteCFG)
                result['Value'] = str(remoteCFG)
            elif 'option' in self.args:
                result = yield self.threadTask(gConfig.getOption,
                                               self.args['option'])
            elif 'section' in self.args:
                result = yield self.threadTask(gConfig.getOptionsDict,
                                               self.args['section'])
            elif 'options' in self.args:
                result = yield self.threadTask(gConfig.getOptions,
                                               self.args['options'])
            elif 'sections' in self.args:
                result = yield self.threadTask(gConfig.getSections,
                                               self.args['sections'])
            else:
                raise WErr(500, 'Invalid argument')

        elif any([
                optns[0] == m and re.match('^[a-z][A-z]+', m)
                for m in dir(Registry)
        ]) and self.isRegisteredUser():
            result = yield self.threadTask(getattr(Registry, optns[0]),
                                           **self.args)

        if not result['OK']:
            raise WErr(404, result['Message'])
        self.finishJEncode(result['Value'])
Пример #8
0
 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()
Пример #9
0
 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)
Пример #10
0
 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()
Пример #11
0
 def _getJobSB( self, jid, objName ):
   with TmpDir() as tmpDir:
     if objName == "outputsandbox":
       objName = "Output"
     else:
       objName = "Input"
     result = SandboxStoreClient().downloadSandboxForJob( int( jid ), objName, tmpDir, inMemory = True )
     if not result[ 'OK' ]:
       msg = result[ 'Message' ]
       if msg.find( "No %s sandbox" % objName ) == 0:
         return WErr( 404, "No %s sandbox defined for job %s" % ( jid, objName.lower() ) )
       return WErr( 500, result[ 'Message' ] )
     return WOK( result[ 'Value' ] )
Пример #12
0
 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]})
Пример #13
0
 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)
Пример #14
0
 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()
Пример #15
0
    def web_action(self):
        try:
            transid = 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, transid)
        elif self.request.arguments["data_kind"][0] == "fileStatus":
            callback = yield self.threadTask(self.__transformationFileStatus,
                                             transid)
        elif self.request.arguments["data_kind"][0] == "fileProcessed":
            callback = yield self.threadTask(self.__fileRetry, transid, 'proc')
        elif self.request.arguments["data_kind"][0] == "fileNotProcessed":
            callback = yield self.threadTask(self.__fileRetry, transid, 'not')
        elif self.request.arguments["data_kind"][0] == "fileAllProcessed":
            callback = yield self.threadTask(self.__fileRetry, transid, 'all')
        elif self.request.arguments["data_kind"][0] == "dataQuery":
            callback = yield self.threadTask(self.__dataQuery, transid)
        elif self.request.arguments["data_kind"][0] == "additionalParams":
            callback = yield self.threadTask(self.__additionalParams, transid)
        elif self.request.arguments["data_kind"][0] == "transformationDetail":
            callback = yield self.threadTask(self.__transformationDetail,
                                             transid)
        elif self.request.arguments["data_kind"][0] == "extend":
            callback = yield self.threadTask(self.__extendTransformation,
                                             transid)
        elif self.request.arguments["data_kind"][0] == "workflowxml":
            callback = yield self.threadTask(self.__workflowxml, transid)
        else:
            callback = {"success": "false", "error": "Action is unknown!!!"}
        self.finish(callback)
Пример #16
0
 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)
     return UserProfileClient("Web/%s/%s" % (obj, app))
Пример #17
0
 def _getJobs(self, selDict, startJob=0, maxJobs=500):
   result = RPCClient("WorkloadManagement/JobMonitoring").getJobPageSummaryWeb(selDict, [('JobID', 'DESC')],
                                                                               startJob, maxJobs, True)
   if not result['OK']:
     return WErr(500, result['Message'])
   origData = result['Value']
   totalRecords = origData['TotalRecords']
   retData = {'entries': totalRecords, 'jobs': []}
   if totalRecords == 0:
     return WOK(retData)
   indexes = self.__findIndexes(origData['ParameterNames'])
   records = origData['Records']
   for record in records:
     job = {}
     for param in indexes['attrs']:
       job[param] = record[indexes['attrs'][param]]
       if param in self.NUMERICAL:
         job[param] = int(float(job[param]))
     for k in ('flags', 'times'):
       job[k] = {}
       for field in indexes[k]:
         value = record[indexes[k][field]]
         if value.lower() == "none":
           continue
         if k == 'flags':
           job[k][field] = value.lower() == 'true'
         else:
           job[k][field] = value
     retData['jobs'].append(job)
   return WOK(retData)
Пример #18
0
    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 __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']}
Пример #20
0
 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)
Пример #21
0
 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()
Пример #22
0
 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 )
Пример #23
0
 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()
Пример #24
0
 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)
Пример #25
0
 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()
Пример #26
0
    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:
                transid = int(i)

                result = yield self.threadTask(
                    tsClient.setTransformationParameter, transid, 'Status',
                    status)

                if result["OK"]:
                    resString = "ProdID: %s set to %s successfully" % (i, cmd)
                    result = yield self.threadTask(
                        tsClient.setTransformationParameter, transid,
                        '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)
Пример #27
0
 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()
Пример #28
0
 def _getJobManifest( self, jid ):
   result = RPCClient( "WorkloadManagement/JobMonitoring" ).getJobJDL( int( jid  ) )
   if not result[ 'OK' ]:
     return WErr( 500, result[ 'Message' ] )
   result = loadJDLAsCFG( result[ 'Value' ] )
   if not result[ 'OK' ]:
     return WErr( 500, result[ 'Message' ] )
   cfg = result[ 'Value' ][0]
   jobData = {}
   stack = [ ( cfg, jobData ) ]
   while stack:
     cfg, level = stack.pop( 0 )
     for op in cfg.listOptions():
       val = List.fromChar( cfg[ op ] )
       if len( val ) == 1:
         val = val[0]
       level[ op ] = val
     for sec in cfg.listSections():
       level[ sec ] = {}
       stack.append( ( cfg[ sec ], level[ sec ] ) )
   return WOK( jobData )
Пример #29
0
 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 )
Пример #30
0
    def web_upload(self):

        if 'filename' not in self.request.arguments:
            raise WErr(400, "Please provide a file name!")
        data = self.request.arguments.get("data", "")[0]
        filename = self.request.arguments.get("filename", "")[0]

        if re.match("(?!\.)^[\w\d_\.\-]*$", filename):
            filepath = "%s/webRoot/www/pilot/%s" % (rootPath, filename)
        else:
            raise WErr(400, "Please provide a valid file name!")

        try:
            tmpfile = "%s.tmp" % filepath
            with open(tmpfile, 'w') as tmp:
                tmp.write(data)
            os.rename(tmpfile, filepath)
        except OSError as e:
            raise WErr(400,
                       "Cannot create the file: %s; %s" % (filename, repr(e)))
        self.finish('File has created')
Пример #31
0
 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 ] } )
Пример #32
0
    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()
Пример #33
0
 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()
Пример #34
0
    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)
Пример #35
0
    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)
Пример #36
0
  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()
Пример #37
0
    def __decodePath(self):
        """ All directories that have to be set in a URL have to be encoded in url safe base 64
          (RFC 4648 Spec where ‘+’ is encoded as ‘-‘ and ‘/’ is encoded as ‘_’).
          There are several implementations for different languages already.

        :return: basestring
    """
        did = re.match("([A-z0-9=-_]+)?",
                       self.overpath.strip('/').split('/')[0]).group()
        if not did:
            return "/"
        try:
            return base64.urlsafe_b64decode(str(did)).rstrip("/") or "/"
        except TypeError, e:
            raise WErr(400, "Cannot decode path")
Пример #38
0
 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()
Пример #39
0
 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 )
Пример #40
0
 def uploadSandbox(self, fileData):
   with TmpDir() as tmpDir:
     fileList = []
     for fName in fileData:
       for entry in fileData[fName]:
         tmpFile = os.path.join(tmpDir, entry.filename)
         if tmpFile not in fileList:
           fileList.append(tmpFile)
         dfd = open(tmpFile, "w")
         dfd.write(entry.body)
         dfd.close()
     sbClient = SandboxStoreClient()
     result = sbClient.uploadFilesAsSandbox(fileList)
     if not result['OK']:
       return WErr(500, result['Message'])
     return WOK(result['Value'])
Пример #41
0
 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()
Пример #42
0
    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)
Пример #43
0
  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()
Пример #44
0
  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 )