Esempio n. 1
0
def getUserData():
    userData = []
    username = credentials.getUsername()
    if not username or username == "anonymous":
        userData.append("username : '******'")
    else:
        userData.append("username : '******'" % username)
        userData.append("group : '%s'" % credentials.getSelectedGroup())
        properties = credentials.getProperties(credentials.getSelectedGroup())
        if len(properties) > 0:
            userData.append("groupProperties : %s" % properties)
        else:
            userData.append("groupProperties : []")
        availableGroups = list()
        for groupName in credentials.getAvailableGroups():
            properties = credentials.getProperties(groupName)
            if not len(properties) > 0:
                continue
            if ("Pilot" in properties) or ("GenericPilot" in properties):
                continue
            url = diracURL(controller="web/userdata", action="changeGroup", id=groupName)
            availableGroups.append("{ text : '%s', url : '%s' }" % (groupName, url))
        userData.append("groupMenu : [%s]" % ",".join(availableGroups))
    dn = credentials.getUserDN()
    if not dn:
        if "REQUEST_URI" in request.environ:
            uri = str(request.environ["REQUEST_URI"])
        else:
            uri = ""
        dn = '<a href="https://%s%s">certificate login</a>' % (str(request.environ["HTTP_HOST"]), uri)
    userData.append("DN : '%s'" % dn)
    return "{%s}" % ",".join(userData)
Esempio n. 2
0
 def __getHistory(self, state):
     """
 Just get the history based on state
 Return resulting list
 "state" can be either "Save" or "Load"
 """
     gLogger.info("Running getHistory( %s )" % state)
     msg = "getHistory() for %s@%s" % (getUsername(), getSelectedGroup())
     opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
     history_length = gConfig.getOptions(opt, 5)
     upc = UserProfileClient("Default", getRPCClient)
     group = str(getSelectedGroup())
     profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
     result = upc.retrieveVar(profile_name)
     gLogger.info(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
         history = list()
     else:
         history = result["Value"]
     if not isinstance(history, list):
         err = "List expected at: %s" % profile_name
         gLogger.error("Result %s: %s" % (msg, err))
         return S_ERROR(err)
     if (len(history) > history_length):
         history = result[history_length]
     gLogger.info("Result %s: %s" % (msg, history))
     return S_OK(history)
Esempio n. 3
0
 def __getHistory( self , state ):
   """
   Just get the history based on state
   Return resulting list
   "state" can be either "Save" or "Load"
   """
   gLogger.info( "Running getHistory( %s )" % state )
   msg = "getHistory() for %s@%s" % ( getUsername() , getSelectedGroup() )
   opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
   history_length = gConfig.getOptions( opt , 5 )
   upc = UserProfileClient( "Default" , getRPCClient )
   group = str( getSelectedGroup() )
   profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
   result = upc.retrieveVar( profile_name )
   gLogger.info( result )
   if not result[ "OK" ]:
     if result[ "Message" ].find( "No data" ) < 0 :
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       return S_ERROR( result[ "Message" ] )
     history = list()
   else:
     history = result[ "Value" ]
   if not isinstance( history , list ):
     err = "List expected at: %s" % profile_name
     gLogger.error( "Result %s: %s" % ( msg , err ) )
     return S_ERROR( err )
   if( len( history ) > history_length ):
     history = result[ history_length ]
   gLogger.info( "Result %s: %s" % ( msg , history ) )
   return S_OK( history )
Esempio n. 4
0
def getUserData():
  userData = []
  username = credentials.getUsername()
  if not username or username == "anonymous":
    userData.append( "username : '******'" )
  else:
    userData.append( "username : '******'" % username )
    userData.append( "group : '%s'" % credentials.getSelectedGroup() )
    properties = credentials.getProperties( credentials.getSelectedGroup() )
    if len( properties ) > 0:
      userData.append( "groupProperties : %s" % properties )
    else:
      userData.append( "groupProperties : []" )
    availableGroups = list()
    for groupName in credentials.getAvailableGroups():
      properties = credentials.getProperties( groupName )
      if not len( properties ) > 0:
        continue
      if ( "Pilot" in properties ) or ( "GenericPilot" in properties ):
        continue
      url = diracURL( controller = 'web/userdata',
                      action = 'changeGroup',
                      id = groupName )
      availableGroups.append( "{ text : '%s', url : '%s' }" %
                                ( groupName , url ) )
    userData.append( "groupMenu : [%s]" % ",".join( availableGroups ) )
  dn = credentials.getUserDN()
  if not dn:
    if 'REQUEST_URI' in request.environ:
      uri = str( request.environ[ 'REQUEST_URI' ] )
    else:
      uri = ""
    dn = "<a href=\"https://%s%s\">certificate login</a>" % ( str( request.environ[ 'HTTP_HOST' ] ), uri )
  userData.append( "DN : '%s'" % dn )
  return "{%s}" % ",".join( userData )
Esempio n. 5
0
def getUserData():
  userData = []
  username = credentials.getUsername()
  if not username or username == "anonymous":
    userData.append( "username : '******'" )
  else:
    userData.append( "username : '******'" % username )
    userData.append( "group : '%s'" % credentials.getSelectedGroup() )
    properties = credentials.getProperties( credentials.getSelectedGroup() )
    if len( properties ) > 0:
      userData.append( "groupProperties : %s" % properties )
    else:
      userData.append( "groupProperties : []" )
    availableGroups = [ "{ text : '%s', url : '%s' }" % ( groupName,
                                                                        diracURL( controller = 'web/userdata',
                                                                                  action = 'changeGroup',
                                                                                  id = groupName )
                                                                         ) for groupName in credentials.getAvailableGroups() ]
    userData.append( "groupMenu : [%s]" % ",".join( availableGroups ) )
  dn = credentials.getUserDN()
  if not dn:
    if 'REQUEST_URI' in request.environ:
      uri = str( request.environ[ 'REQUEST_URI' ] )
    else:
      uri = ""
    dn = "<a href=\"https://%s%s\">certificate login</a>" % ( str( request.environ[ 'HTTP_HOST' ] ), uri )
  userData.append( "DN : '%s'" % dn )
  return "{%s}" % ",".join( userData )
Esempio n. 6
0
  def authorizeRequest( self ):
    #Check the setup is allright
    if 'setup' in request.params:
      requestedSetup = request.params[ 'setup' ]
      result = gConfig.getSections( "/DIRAC/Setups" )
      if not result[ 'OK' ]:
        c.error( "Oops: %s" % result[ 'Value' ] )
        return render( "/error.mako" )
      knownSetups = result[ 'Value' ]
      if requestedSetup not in knownSetups:
        c.error = "Unknown %s setup" % requestedSetup
        return render( "/error.mako" )
      if getSelectedSetup() != requestedSetup:
        return self.__changeSetupAndRedirect( requestedSetup )

    params = {}
    for key in request.params:
      params[ key ] = request.params[ key ]
    gOAManager.parse( method = request.method,
                      url = request.url,
                      headers = request.headers,
                      parameters = params,
                      query_string = request.query_string )
    if not gOAData.token:
      c.error = "Dude! You shouldn't be here without a request token :P"
      return render( "/error.mako" )
    if not getUserDN() or getSelectedGroup() == "visitor":
      c.error = "Please log in with your certificate"
      return render( "/error.mako" )
    result = gOAManager.credentials.getRequestData( gOAData.token )
    if not result[ 'OK' ]:
      c.error = result[ 'Message' ]
      return render( "/error.mako" )
    reqData = result[ 'Value' ]
    consData = reqData[ 'consumer' ]
    result = gOAManager.credentials.generateVerifier( consData[ 'key' ],
                                                         reqData[ 'request' ],
                                                         c.userDN, c.userGroup )
    if not result[ 'OK' ]:
      c.error = result[ 'Message' ]
      return render( "/error.mako" )
    verifier = result[ 'Value' ]

    c.consName = consData[ 'name' ]
    c.consImg = consData[ 'icon' ]
    c.userDN = getUserDN()
    c.userGroup = getSelectedGroup()
    c.request = gOAData.token
    c.verifier = verifier
    c.consumerKey = consData[ 'key' ]

    c.callback = gOAData.callback or reqData[ 'callback' ]
    c.callback = urllib.quote_plus( c.callback )

    return render( "/WebAPI/authorizeRequest.mako" )
Esempio n. 7
0
  def authorizeCode( self ):
    #Check the setup is allright
    if 'setup' in request.params:
      requestedSetup = request.params[ 'setup' ]
      result = gConfig.getSections( "/DIRAC/Setups" )
      if not result[ 'OK' ]:
        c.error( "Oops: %s" % result[ 'Value' ] )
        return render( "/error.mako" )
      knownSetups = result[ 'Value' ]
      if requestedSetup not in knownSetups:
        c.error = "Unknown %s setup" % requestedSetup
        return render( "/error.mako" )
      if getSelectedSetup() != requestedSetup:
        return self.__changeSetupAndRedirect( requestedSetup )

    try:
      cid = str( request.params[ 'client_id' ] )
    except KeyError:
      c.error = "Dude! You shouldn't be here without a client_id :P"
      return render( "/error.mako" )
    if not getUserDN() or getSelectedGroup() == "visitor":
      c.error = "Please log in with your certificate"
      return render( "/error.mako" )
    result = self.__oaToken.getClientDataByID( cid )
    if not result[ 'OK' ]:
      c.error = "Unknown originating client"
      return render( "/error.mako" )
    cData = result[ 'Value' ]

    try:
      redirect = str( request.params[ 'redirect_uri' ] )
    except KeyError:
      redirect = ""

    c.cName = cData[ 'Name' ]
    c.cImg = cData[ 'Icon' ]
    c.cID = cid
    if redirect:
      c.redirect = base64.urlsafe_b64encode( redirect )
    c.userDN = getUserDN()
    c.userGroup = getSelectedGroup()

    for k in ( 'scope', 'state' ):
      if k in request.params:
        setattr( c, k, str( request.params[k] ) )
      else:
        setattr( c, k, False )

    return render( "/OAuth2/authorizeCode.mako" )
Esempio n. 8
0
 def __loadLayout(self):
     gLogger.info("Running loadLayout()")
     msg = "loadLayout() for %s@%s" % (getUsername(), getSelectedGroup())
     result = self.__params2string(LOAD_LAYOUT_ARGS)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return {"success": "false", "error": result["Message"]}
     args = result["Value"]
     name = args["name"]
     user = args["user"]
     group = args["group"]
     upc = UserProfileClient(USER_PROFILE_NAME, getRPCClient)
     result = upc.retrieveVarFromUser(user, group, name)
     gLogger.debug(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return {"success": "false", "error": result["Message"]}
         err = "No data found for '%s' by %s@%s" % (name, user, group)
         gLogger.error("Result %s: %s" % (msg, err))
         return {"success": "false", "error": err}
     layout = result["Value"]
     for i in LOAD_LAYOUT_ARGS:  # Add params to layout if they are absent
         if not layout.has_key(i):
             layout[i] = args[i]
     result = self.__setHistory(args, "Load")
     history = dict()
     if not result["OK"]:
         history["Load"] = result["Message"]
     else:
         history["Load"] = result["Value"]
     gLogger.info("Result %s: %s AND %s" % (msg, layout, history))
     return {"success": "true", "result": layout, "history": history}
    def __getUniqueKeyValues(self, typeName):
        userGroup = getSelectedGroup()
        if 'NormalUser' in CS.getPropertiesForGroup(userGroup):
            cacheKey = (getUsername(), userGroup, getSelectedSetup(), typeName)
        else:
            cacheKey = (userGroup, getSelectedSetup(), typeName)
        data = AccountingplotsController.__keysCache.get(cacheKey)
        if not data:
            rpcClient = getRPCClient("Accounting/ReportGenerator")
            retVal = rpcClient.listUniqueKeyValues(typeName)
            if 'rpcStub' in retVal:
                del (retVal['rpcStub'])
            if not retVal['OK']:
                return retVal

            #Site ordering based on TierLevel / alpha
            if 'Site' in retVal['Value']:
                siteLevel = {}
                for siteName in retVal['Value']['Site']:
                    sitePrefix = siteName.split(".")[0].strip()
                    level = gConfig.getValue(
                        "/Resources/Sites/%s/%s/MoUTierLevel" %
                        (sitePrefix, siteName), 10)
                    if level not in siteLevel:
                        siteLevel[level] = []
                    siteLevel[level].append(siteName)
                orderedSites = []
                for level in sorted(siteLevel):
                    orderedSites.extend(sorted(siteLevel[level]))
                retVal['Value']['Site'] = orderedSites
            data = retVal
            AccountingplotsController.__keysCache.add(cacheKey, 300, data)
        return data
Esempio n. 10
0
 def getSandbox( self ):
   """ Get job sandbox 
   """
   if 'jobID' not in request.params:
     c.error = "Maybe you forgot the jobID ?"
     return render( "/error.mako" )
   jobID = int(request.params['jobID']) 
   sbType = 'Output'
   if 'sandbox' in request.params:
     sbType = str(request.params['sandbox'])
       
   client = SandboxStoreClient(useCertificates=True,
                               delegatedDN=str( credentials.getUserDN() ),
                               delegatedGroup=str( credentials.getSelectedGroup() ),
                               setup = credentials.getSelectedSetup() )
   result = client.downloadSandboxForJob(jobID,sbType,inMemory=True)
   if not result['OK']:
     c.error = "Error: %s" % result['Message']
     return render( "/error.mako" ) 
   
   data = result['Value'] 
   fname = "%s_%sSandbox.tar" % (str(jobID),sbType)
   response.headers['Content-type'] = 'application/x-tar'
   response.headers['Content-Disposition'] = 'attachment; filename="%s"' % fname
   response.headers['Content-Length'] = len( data )
   return data
Esempio n. 11
0
 def __loadLayout( self ):
   gLogger.info( "Running loadLayout()" )
   msg = "loadLayout() for %s@%s" % ( getUsername() , getSelectedGroup() )
   result = self.__params2string( LOAD_LAYOUT_ARGS )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return { "success" : "false" , "error" : result[ "Message" ] }
   args = result[ "Value" ]
   name = args[ "name" ]
   user = args[ "user" ]
   group = args[ "group" ]
   upc = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   result = upc.retrieveVarFromUser( user , group, name )
   gLogger.debug( result )
   if not result[ "OK" ]:
     if result[ "Message" ].find( "No data" ) < 0 :
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       return { "success" : "false" , "error" : result[ "Message" ] }
     err = "No data found for '%s' by %s@%s" % ( name , user , group )
     gLogger.error( "Result %s: %s" % ( msg , err ) )
     return { "success" : "false" , "error" : err }
   layout = result[ "Value" ]
   for i in LOAD_LAYOUT_ARGS : # Add params to layout if they are absent
     if not layout.has_key( i ):
       layout[ i ] = args[ i ]
   result = self.__setHistory( args , "Load" )
   history = dict()
   if not result[ "OK" ]:
     history[ "Load" ] = result[ "Message" ]
   else:
     history[ "Load" ] = result[ "Value" ]
   gLogger.info( "Result %s: %s AND %s" % ( msg , layout , history ) )
   return { "success" : "true" , "result" : layout , "history" : history }
Esempio n. 12
0
 def __getProxyStatus(self,secondsOverride = None):
     
   from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient
   
   proxyManager = ProxyManagerClient()
   group = str(credentials.getSelectedGroup())
   if group == "visitor":
     return {"success":"false","error":"User is anonymous or is not registered in the system"}
   userDN = str(credentials.getUserDN())
   if secondsOverride and str(secondsOverride).isdigit():
     validSeconds = int(secondsOverride)
   else:
     defaultSeconds = 24 * 3600 + 60 # 24H + 1min
     validSeconds = gConfig.getValue("/Registry/DefaultProxyLifeTime",defaultSeconds)
   gLogger.info("\033[0;31m userHasProxy(%s, %s, %s) \033[0m" % (userDN,group,validSeconds))
   result = proxyManager.userHasProxy(userDN,group,validSeconds)
   if result["OK"]:
     if result["Value"]:
       c.result = {"success":"true","result":"true"}
     else:
       c.result = {"success":"true","result":"false"}
   else:
     c.result = {"success":"false","error":"false"}
   gLogger.info("\033[0;31m PROXY: \033[0m",result)
   return c.result
Esempio n. 13
0
 def __lastUsed( self ):
   gLogger.info( "Running lastUsed()" )
   msg = "lastUsed() for %s@%s" % ( getUsername() , getSelectedGroup() )
   result = self.__getHistory( "Load" )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return S_ERROR( result[ "Message" ] )
   history = result[ "Value" ]
   if not len( history ) > 0:
     err = "Load history is empty"
     gLogger.error( "Result %s: %s" % ( msg , err ) )
     return S_ERROR( err )
   args = history[ 0 ]
   name = args[ "name" ]
   user = args[ "user" ]
   group = args[ "group" ]
   upc = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   result = upc.retrieveVarFromUser( user , group, name )
   gLogger.debug( result )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return S_ERROR( result[ "Message" ] )
   layout = result[ "Value" ]
   for i in LOAD_LAYOUT_ARGS : # Add params to layout if they are absent
     if not layout.has_key( i ):
       layout[ i ] = args[ i ]
   gLogger.info( "Result %s: %s" % ( msg , layout ) )
   return S_OK( layout )
Esempio n. 14
0
 def display(self):
   gLogger.info( "Running display()" )
   msg = "display() for %s@%s" % ( getUsername() , getSelectedGroup() )
   if not authorizeAction():
     gLogger.info( "Result %s: %s" % ( msg , "Not authorized" ) )
     return render( "/login.mako" )
   result = self.__convert()
   if not result[ "OK" ]:
     c.error = result[ "Message" ]
     gLogger.error( "Result %s: %s" % ( msg , c.error ) )
     return render( "/error.mako" )
   c.select = dict()
   history = dict()
   for i in [ "Save" , "Load" ]:
     result = self.__getHistory( i )
     if not result[ "OK" ]:
       history[ i ] = result[ "Message" ]
     else:
       history[ i ] = result[ "Value" ]
   c.select[ "history" ] = history
   result = self.__lastUsed()
   if not result[ "OK" ]:
     c.select[ "layout" ] = ""
     c.select[ "error" ] = result[ "Message" ]
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return render("web/Presenter.mako")
   c.select[ "layout" ] = result[ "Value" ]
   gLogger.info( "Result %s: %s" % ( msg , c.select ) )
   return render("web/Presenter.mako")
Esempio n. 15
0
def __prepareArgs(kwargs):
    if credentials.getUserDN():
        kwargs["delegatedGroup"] = str(credentials.getSelectedGroup())
        kwargs["delegatedDN"] = str(credentials.getUserDN())
    kwargs["useCertificates"] = True
    kwargs["setup"] = credentials.getSelectedSetup()
    return kwargs
Esempio n. 16
0
 def __getUserLayout(self):
     gLogger.info("Running getUserLayout()")
     msg = "getUserLayout() for %s@%s" % (getUsername(), getSelectedGroup())
     upc = UserProfileClient(USER_PROFILE_NAME, getRPCClient)
     result = upc.retrieveAllVars()
     gLogger.debug(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return {"success": "false", "error": result["Message"]}
     layouts = result["Value"]
     data = list()
     for name, value in layouts.items():
         result = self.__getPermissions(name)
         if not result["OK"]:
             perm = result["Message"]
         else:
             perm = result["Value"]
             if perm.has_key("ReadAccess"):
                 perm = perm["ReadAccess"]
             else:
                 perm = "Undefined"
         if value.has_key("group"):
             group = value["group"]
         else:
             group = "Undefined"
         perm = perm.capitalize()
         data.append({"name": name, "permission": perm, "group": group})
     gLogger.info("Result %s: %s" % (msg, data))
     return {"success": "true", "result": data}
Esempio n. 17
0
 def __getUserLayout( self ) :
   gLogger.info( "Running getUserLayout()" )
   msg = "getUserLayout() for %s@%s" % ( getUsername() , getSelectedGroup() )
   upc = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   result = upc.retrieveAllVars()
   gLogger.debug( result )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return { "success" : "false" , "error" : result[ "Message" ] }
   layouts = result[ "Value" ]
   data = list()
   for name , value in layouts.items():
     result = self.__getPermissions( name )
     if not result[ "OK" ]:
       perm = result[ "Message" ]
     else:
       perm = result[ "Value" ]
       if perm.has_key( "ReadAccess" ):
         perm = perm[ "ReadAccess" ]
       else:
         perm = "Undefined"
     if value.has_key( "group" ):
       group = value[ "group" ]
     else:
       group = "Undefined"
     data.append( { "name" : name , "permission" : perm , "group" : group } )
   gLogger.info( "Result %s: %s" % ( msg , data ) )
   return { "success" : "true" , "result" : data }
Esempio n. 18
0
 def display(self):
     gLogger.info("Running display()")
     msg = "display() for %s@%s" % (getUsername(), getSelectedGroup())
     if not authorizeAction():
         gLogger.info("Result %s: %s" % (msg, "Not authorized"))
         return render("/login.mako")
     result = self.__convert()
     if not result["OK"]:
         c.error = result["Message"]
         gLogger.error("Result %s: %s" % (msg, c.error))
         return render("/error.mako")
     c.select = dict()
     history = dict()
     for i in ["Save", "Load"]:
         result = self.__getHistory(i)
         if not result["OK"]:
             history[i] = result["Message"]
         else:
             history[i] = result["Value"]
     c.select["history"] = history
     result = self.__lastUsed()
     if not result["OK"]:
         c.select["layout"] = ""
         c.select["error"] = result["Message"]
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return render("web/Presenter.mako")
     c.select["layout"] = result["Value"]
     gLogger.info("Result %s: %s" % (msg, c.select))
     return render("web/Presenter.mako")
Esempio n. 19
0
 def __lastUsed(self):
     gLogger.info("Running lastUsed()")
     msg = "lastUsed() for %s@%s" % (getUsername(), getSelectedGroup())
     result = self.__getHistory("Load")
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return S_ERROR(result["Message"])
     history = result["Value"]
     if not len(history) > 0:
         err = "Load history is empty"
         gLogger.error("Result %s: %s" % (msg, err))
         return S_ERROR(err)
     args = history[0]
     name = args["name"]
     user = args["user"]
     group = args["group"]
     upc = UserProfileClient(USER_PROFILE_NAME, getRPCClient)
     result = upc.retrieveVarFromUser(user, group, name)
     gLogger.debug(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return S_ERROR(result["Message"])
     layout = result["Value"]
     for i in LOAD_LAYOUT_ARGS:  # Add params to layout if they are absent
         if not layout.has_key(i):
             layout[i] = args[i]
     gLogger.info("Result %s: %s" % (msg, layout))
     return S_OK(layout)
Esempio n. 20
0
def __prepareArgs( kwargs ):
  if ( 'static' not in kwargs or not kwargs[ 'static' ] ) and credentials.getUserDN():
    kwargs[ 'delegatedGroup' ] =  str( credentials.getSelectedGroup() )
    kwargs[ 'delegatedDN' ] = str( credentials.getUserDN() )
  kwargs[ 'useCertificates' ] = True
  kwargs[ 'setup' ] = credentials.getSelectedSetup()
  return kwargs
Esempio n. 21
0
 def submit(self):
   pagestart = time()
   RPC = getRPCClient("WorkloadManagement/JobMonitoring")
   user = str(credentials.getUsername())
   result = RPC.getOwners()
   if result["OK"]:
     defaultGroup = gConfig.getValue("/Registry/DefaultGroup","")
     if defaultGroup == "":
       return {"success":"false","error":"Option /Registry/DefaultGroup is undefined, please set the default group in the CS"}
     group = str(credentials.getSelectedGroup())
     groupProperty = credentials.getProperties(group)
     if user not in result["Value"] and ( "JobAdministrator" or "JobSharing" ) not in groupProperty:
       c.result = {"success":"false","error":"You don't have any jobs in the DIRAC system"}
       return c.result
   else:
     c.result = {"success":"false","error":result["Message"]}
     return c.result
   req = self.__request()
   gLogger.always("getJobPageSummaryWeb(%s,%s,%s,%s)" % (req,globalSort,pageNumber,numberOfJobs))
   result = RPC.getJobPageSummaryWeb(req,globalSort,pageNumber,numberOfJobs)
   gLogger.always(" - REZ: " %result)
   if result["OK"]:
     result = result["Value"]
     gLogger.info("ReS",result)
     if result.has_key("TotalRecords"):
       if  result["TotalRecords"] > 0:
         if result.has_key("ParameterNames") and result.has_key("Records"):
           if len(result["ParameterNames"]) > 0:
             if len(result["Records"]) > 0:
               c.result = []
               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]
                 c.result.append(tmp)
               total = result["TotalRecords"]
               timestamp = Time.dateTime().strftime("%Y-%m-%d %H:%M [UTC]")
               if result.has_key("Extras"):
                 st = self.__dict2string(req)
                 extra = result["Extras"]
                 c.result = {"success":"true","result":c.result,"total":total,"extra":extra,"request":st,"date":timestamp}
               else:
                 c.result = {"success":"true","result":c.result,"total":total,"date":timestamp}
             else:
               c.result = {"success":"false","result":"","error":"There are no data to display"}
           else:
             c.result = {"success":"false","result":"","error":"ParameterNames field is missing"}
         else:
           c.result = {"success":"false","result":"","error":"Data structure is corrupted"}
       else:
         c.result = {"success":"false","result":"","error":"There were no data matching your selection"}
     else:
       c.result = {"success":"false","result":"","error":"Data structure is corrupted"}
   else:
     c.result = {"success":"false","error":result["Message"]}
   gLogger.info("\033[0;31mJOB SUBMIT REQUEST:\033[0m %s" % (time() - pagestart))
   return c.result
Esempio n. 22
0
  def __getUniqueKeyValues( self, typeName ):
    userGroup = getSelectedGroup()
    if 'NormalUser' in CS.getPropertiesForGroup( userGroup ):
      cacheKey = ( getUsername(), userGroup, getSelectedSetup(), typeName )
    else:
      cacheKey = ( userGroup, getSelectedSetup(), typeName )
    data = AcctController.__keysCache.get( cacheKey )
    if not data:
      rpcClient = getRPCClient( "Accounting/ReportGenerator" )
      retVal = rpcClient.listUniqueKeyValues( typeName )
      if 'rpcStub' in retVal:
        del( retVal[ 'rpcStub' ] )
      if not retVal[ 'OK' ]:
        return retVal

      #Site ordering based on TierLevel / alpha
      if 'Site' in retVal[ 'Value' ]:
        siteLevel = {}
        for siteName in retVal[ 'Value' ][ 'Site' ]:
          sitePrefix = siteName.split( "." )[0].strip()
          level = gConfig.getValue( "/Resources/Sites/%s/%s/MoUTierLevel" % ( sitePrefix, siteName ), 10 )
          if level not in siteLevel:
            siteLevel[ level ] = []
          siteLevel[ level ].append( siteName )
        orderedSites = []
        for level in sorted( siteLevel ):
          orderedSites.extend( sorted( siteLevel[ level ] ) )
        retVal[ 'Value' ][ 'Site' ] = orderedSites
      data = retVal
      AcctController.__keysCache.add( cacheKey, 300, data )
    return data
Esempio n. 23
0
  def __getSelectionData(self):
    callback = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    RPC = getRPCClient( "ResourceStatus/ResourceStatus" )
    client = ResourceStatusClient( serviceIn = RPC )
    if len(request.params) > 0:
      tmp = {}
      for i in request.params:
        tmp[i] = str(request.params[i])
      callback["extra"] = tmp
####
    result = client.getSitePresent( meta = { 'columns' : 'SiteName' } )
    if result["OK"]:
      sites = result["Value"]
      try:
        sites = list(sites)
      except Exception,x:
        gLogger.error("Exception during convertion to a list: %s" % str(x))
        sites = [] # Will return error on length check
      tier1 = gConfig.getValue("/Website/PreferredSites",[]) # Always return a list
      if len(sites)>0:
        tier1.reverse()
        tier1 = [[x] for x in tier1]
        sites = [x for x in sites if x not in tier1] # Removes sites which are in tier1 list
        for i in tier1:
          sites.insert(0,i)
        sites.insert(0,["All"])
      else:
        sites = [["Nothing to display"]]
Esempio n. 24
0
def htmlUserInfo():
    username = credentials.getUsername()
    if not username or username == "anonymous":
        htmlData = "Anonymous"
    else:
        selectedGroup = credentials.getSelectedGroup()
        availableGroups = [(groupName,
                            diracURL(controller='web/userdata',
                                     action='changeGroup',
                                     id=groupName))
                           for groupName in credentials.getAvailableGroups()]
        htmlData = "%s@%s" % (username,
                              yuiWidgets.dropDownMenu("UserGroupPos",
                                                      selectedGroup,
                                                      availableGroups))
    dn = credentials.getUserDN()
    if dn:
        htmlData += " (%s)" % dn
    else:
        if 'REQUEST_URI' in request.environ:
            uri = str(request.environ['REQUEST_URI'])
        else:
            uri = ""
        htmlData += " (<a href='https://%s%s'>certificate login</a>)" % (str(
            request.environ['HTTP_HOST']), uri)
    return htmlData
Esempio n. 25
0
def htmlShortcuts():
    htmlData = ""
    for entryTuple in gWebConfig.getShortcutsForGroup(
            credentials.getSelectedGroup()):
        htmlData += " %s |" % helpers.link_to(entryTuple[0],
                                              url=diracURL(entryTuple[1]))
    return htmlData[:-2]
Esempio n. 26
0
 def __canRunJobs(self):
     groupPropertie = credentials.getProperties(
         credentials.getSelectedGroup())
     if "NormalUser" in groupPropertie:
         return True
     else:
         return False
Esempio n. 27
0
 def display(self):
   lhcbGroup = credentials.getSelectedGroup()
   if lhcbGroup == "visitor":
     return render("/login.mako")
   c.select = self.__getSelectionData()
   gLogger.info("SELECTION RESULTS:",c.select)
   return render("jobs/SiteGateway.mako")
Esempio n. 28
0
 def display(self):
   pagestart = time()
   lhcbGroup = credentials.getSelectedGroup()
   if lhcbGroup == "visitor":
     return render("/login.mako")
   c.select = self.__getSelectionData()
   return render("jobs/PilotSummary.mako")
Esempio n. 29
0
  def sysinfo( self ):

    DN = getUserDN()
    group = getSelectedGroup()

    #TODO: remove hosts code after v6r7 since it will be built-in
    result = gConfig.getSections( "/Registry/Hosts" )
    if not result[ "Value" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    hosts = result[ "Value" ]

    client = SystemAdministratorIntegrator( hosts = hosts , delegatedDN=DN ,
                                          delegatedGroup=group )
    result = client.getHostInfo()
    gLogger.debug( result )
    if not result[ "OK" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    result = result[ "Value" ]

    callback = list()
    for i in result:
      if result[ i ][ "OK" ]:
        tmp = result[ i ][ "Value" ]
      else:
        tmp = dict()
      tmp[ "Host" ] = i
      callback.append( tmp )

    total = len( callback )
    if not total > 0:
      return { "success" : "false" , "error" : "No system information found" }
    return { "success" : "true" , "result" : callback , "total" : total }
Esempio n. 30
0
  def submit( self ):

    """
    Returns flatten list of components (services, agents) installed on hosts
    returned by getHosts function
    """

    checkUserCredentials()
    DN = getUserDN()
    group = getSelectedGroup()

    callback = list()
    
    request = self.request()
    if not 'Hostname' in request:
      return { "success" : "false" , "error" : "Name of the host is absent" }
    
    host = request[ 'Hostname' ]
    client = SystemAdministratorClient( host , None , delegatedDN=DN ,
                                          delegatedGroup=group )
    result = client.getOverallStatus()
    gLogger.debug( "Result of getOverallStatus(): %s" % result )

    if not result[ "OK" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    overall = result[ "Value" ]

    for record in self.flatten( overall ):
      record[ "Host" ] = host
      callback.append( record )

    return { "success" : "true" , "result" : callback }
Esempio n. 31
0
  def showHostErrors( self ):

    DN = getUserDN()
    group = getSelectedGroup()
    
    if not "host" in request.params:
      return { "success" : "false" , "error" : "Name of the host is missing or not defined" }
    host = str( request.params[ "host" ] )

    client = SystemAdministratorClient( host , None , delegatedDN=DN , delegatedGroup=group )

    result = client.checkComponentLog( "*" )
    gLogger.debug( result )
    if not result[ "OK" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    result = result[ "Value" ]
    
    callback = list()
    for key, value in result.items():
      system, component = key.split( "/" )
      value[ "System" ] = system
      value[ "Name" ] = component
      value[ "Host" ] = host
      callback.append( value )
    total = len( callback )

    return { "success" : "true" , "result" : callback , "total" : total }
Esempio n. 32
0
  def showLog( self ):

    DN = getUserDN()
    group = getSelectedGroup()
    
    if not "host" in request.params:
      return "Name of the host is missing or not defined"
    host = str( request.params[ "host" ] )

    if not "system" in request.params:
      return "Name of the system is missing or not defined"
    system = str( request.params[ "system" ] )

    if not "component" in request.params:
      return "Name of component is missing or not defined"
    name = str( request.params[ "component" ] )

    client = SystemAdministratorClient( host , None , delegatedDN=DN , delegatedGroup=group )

    result = client.getLogTail( system , name )
    gLogger.debug( result )
    if not result[ "OK" ]:
      return result[ "Message" ]
    result = result[ "Value" ]

    key = system + "_" + name
    if not key in result:
      return "%s key is absent in service response" % key
    log = result[ key ]

    return log.replace( "\n" , "<br>" )
Esempio n. 33
0
 def display(self):
     lhcbGroup = credentials.getSelectedGroup()
     if lhcbGroup == "visitor":
         return render("/login.mako")
     c.select = self.__getSelectionData()
     gLogger.info("SELECTION RESULTS:", c.select)
     return render("jobs/SiteGateway.mako")
Esempio n. 34
0
def __prepareArgs(kwargs):
    if credentials.getUserDN():
        kwargs['delegatedGroup'] = str(credentials.getSelectedGroup())
        kwargs['delegatedDN'] = str(credentials.getUserDN())
    kwargs['useCertificates'] = True
    kwargs['setup'] = credentials.getSelectedSetup()
    return kwargs
Esempio n. 35
0
    def __getSelectionData(self):
        callback = {}
        lhcbGroup = credentials.getSelectedGroup()
        lhcbUser = str(credentials.getUsername())
        RPC = getRPCClient("ResourceStatus/ResourceStatus")
        client = ResourceStatusClient(serviceIn=RPC)
        if len(request.params) > 0:
            tmp = {}
            for i in request.params:
                tmp[i] = str(request.params[i])
            callback["extra"] = tmp
####
        result = client.getSitePresent(meta={'columns': 'SiteName'})
        if result["OK"]:
            sites = result["Value"]
            try:
                sites = list(sites)
            except Exception, x:
                gLogger.error("Exception during convertion to a list: %s" %
                              str(x))
                sites = []  # Will return error on length check
            tier1 = gConfig.getValue("/Website/PreferredSites",
                                     [])  # Always return a list
            if len(sites) > 0:
                tier1.reverse()
                tier1 = [[x] for x in tier1]
                sites = [x for x in sites if x not in tier1
                         ]  # Removes sites which are in tier1 list
                for i in tier1:
                    sites.insert(0, i)
                sites.insert(0, ["All"])
            else:
                sites = [["Nothing to display"]]
    def getSandbox(self):
        """ Get job sandbox 
    """
        if 'jobID' not in request.params:
            c.error = "Maybe you forgot the jobID ?"
            return render("/error.mako")
        jobID = int(request.params['jobID'])
        sbType = 'Output'
        if 'sandbox' in request.params:
            sbType = str(request.params['sandbox'])

        client = SandboxStoreClient(useCertificates=True,
                                    delegatedDN=str(credentials.getUserDN()),
                                    delegatedGroup=str(
                                        credentials.getSelectedGroup()),
                                    setup=credentials.getSelectedSetup())
        result = client.downloadSandboxForJob(jobID, sbType, inMemory=True)
        if not result['OK']:
            c.error = "Error: %s" % result['Message']
            return render("/error.mako")

        data = result['Value']
        fname = "%s_%sSandbox.tar" % (str(jobID), sbType)
        response.headers['Content-type'] = 'application/x-tar'
        response.headers[
            'Content-Disposition'] = 'attachment; filename="%s"' % fname
        response.headers['Content-Length'] = len(data)
        return data
Esempio n. 37
0
 def display(self):
     pagestart = time()
     lhcbGroup = credentials.getSelectedGroup()
     if lhcbGroup == "visitor":
         return render("/login.mako")
     c.select = self.__getSelectionData()
     gLogger.info("\033[0;31m !!!! \033[0m %s" % c.select)
     return render("jobs/PilotMonitor.mako")
Esempio n. 38
0
 def display(self):
   pagestart = time()
   lhcbGroup = credentials.getSelectedGroup()
   if lhcbGroup == "visitor":
     return render("/login.mako")
   c.select = self.__getSelectionData()
   gLogger.info("\033[0;31m !!!! \033[0m %s" % c.select)
   return render("jobs/PilotMonitor.mako")
Esempio n. 39
0
 def __getModificator(self):
     rpcClient = getRPCClient(gConfig.getValue("/DIRAC/Configuration/MasterServer", "Configuration/Server"))
     commiter = "%s@%s - %s" % (
         credentials.getUsername(),
         credentials.getSelectedGroup(),
         Time.dateTime().strftime("%Y-%m-%d %H:%M:%S"),
     )
     return Modificator(rpcClient, commiter)
 def __getModificator(self):
     rpcClient = getRPCClient(
         gConfig.getValue("/DIRAC/Configuration/MasterServer",
                          "Configuration/Server"))
     commiter = "%s@%s - %s" % (
         credentials.getUsername(), credentials.getSelectedGroup(),
         Time.dateTime().strftime("%Y-%m-%d %H:%M:%S"))
     return Modificator(rpcClient, commiter)
Esempio n. 41
0
  def __request(self):
    req = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    global pageNumber
    if request.params.has_key("id") and len(request.params["id"]) > 0:
      pageNumber = 0
      req["JobID"] = str(request.params["id"])
    elif request.params.has_key("expand") and len(request.params["expand"]) > 0:
      globalSort = [["GridSite","ASC"]]
      numberOfJobs = 500
      pageNumber = 0
      req["ExpandSite"] = str(request.params["expand"])
    else:
      result = gConfig.getOption("/Website/ListSeparator")
      if result["OK"]:
        separator = result["Value"]
      else:
        separator = ":::"
      pageNumber = 0
      numberOfJobs = 500
      if request.params.has_key("prod") and len(request.params["prod"]) > 0:
        if str(request.params["prod"]) != "All":
          req["JobGroup"] = str(request.params["prod"]).split(separator)
      if request.params.has_key("site") and len(request.params["site"]) > 0:
        if str(request.params["site"]) != "All":
          tmp = str(request.params["site"]).split(separator)
          if len(tmp) == 1:
            req["ExpandSite"] = tmp[0]
          else:
            req["GridSite"] = tmp
      if request.params.has_key("stat") and len(request.params["stat"]) > 0:
        if str(request.params["stat"]) != "All":
          req["Status"] = str(request.params["stat"]).split(separator)
      if request.params.has_key("minorstat") and len(request.params["minorstat"]) > 0:
        if str(request.params["minorstat"]) != "All":
          req["MinorStatus"] = str(request.params["minorstat"]).split(separator)
      if request.params.has_key("app") and len(request.params["app"]) > 0:
        if str(request.params["app"]) != "All":
          req["ApplicationStatus"] = str(request.params["app"]).split(separator)
#      if lhcbGroup == "lhcb" or lhcbGroup == "lhcb_user":
#        req["Owner"] = str(lhcbUser)
      else:
        if request.params.has_key("owner") and len(request.params["owner"]) > 0:
          if str(request.params["owner"]) != "All":
            req["Owner"] = str(request.params["owner"]).split(separator)
      if request.params.has_key("date") and len(request.params["date"]) > 0:
        if str(request.params["date"]) != "YYYY-mm-dd":
          req["LastUpdate"] = str(request.params["date"])
      if request.params.has_key("sort") and len(request.params["sort"]) > 0:
        globalSort = str(request.params["sort"])
        key,value = globalSort.split(" ")
        globalSort = [[str(key),str(value)]]
      else:
#        globalSort = [["JobID","DESC"]]
        globalSort = [["GridSite","ASC"]]
    gLogger.info("REQUEST:",req)
    return req
Esempio n. 42
0
def checkPropertiesWithUser( properties ):
  if 'all' in properties:
    return True
  if credentials.getSelectedGroup() != 'visitor' and 'authenticated' in properties:
    return True
  for userProp in credentials.getProperties():
    if userProp in properties:
      return True
  return False
Esempio n. 43
0
def checkPropertiesWithUser(properties):
    if "all" in properties:
        return True
    if credentials.getSelectedGroup() != "visitor" and "authenticated" in properties:
        return True
    for userProp in credentials.getProperties():
        if userProp in properties:
            return True
    return False
Esempio n. 44
0
def checkPropertiesWithUser( properties ):
  if 'all' in properties:
    return True
  if credentials.getSelectedGroup() != 'visitor' and 'authenticated' in properties:
    return True
  for userProp in credentials.getProperties():
    if userProp in properties:
      return True
  return False
  def display(self):
    group = credentials.getSelectedGroup()
    if group == "visitor" and credentials.getUserDN == "":
      return render("/login.mako")
    c.select = self.__getSelectionData()
#    if not c.select.has_key("extra"):
#      groupProperty = credentials.getProperties(group)
#      if ( "JobAdministrator" or "JobSharing" ) not in groupProperty: #len(groupProperty) == 1 and groupProperty[0] == "NormalUser":
#        c.select["extra"] = {"owner":credentials.getUsername()}
    return render("jobs/RequestMonitor.mako")
Esempio n. 46
0
 def __loadLast( self ):
   gLogger.info( "Running loadLast()" )
   msg = "loadLast() for %s@%s" % ( getUsername() , getSelectedGroup() )
   result = self.__lastUsed()
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return { "success" : "false" , "error" : result[ "Message" ] }
   layout = result[ "Value" ]
   gLogger.info( "Result %s: %s" % ( msg , layout ) )
   return { "success" : "true" , "result" : layout }
Esempio n. 47
0
 def __loadLast(self):
     gLogger.info("Running loadLast()")
     msg = "loadLast() for %s@%s" % (getUsername(), getSelectedGroup())
     result = self.__lastUsed()
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return {"success": "false", "error": result["Message"]}
     layout = result["Value"]
     gLogger.info("Result %s: %s" % (msg, layout))
     return {"success": "true", "result": layout}
Esempio n. 48
0
  def getProjectsList( self ):
    try:
      start = int( request.params[ 'start' ] )
    except:
      start = 0
    try:
      limit = int( request.params[ 'limit' ] )
    except:
      limit = 0
    try:
      sortField = str( request.params[ 'sortField' ] ).replace( "_", "." )
      sortDir = str( request.params[ 'sortDirection' ] )
      sort = [ ( sortField, sortDir ) ]
    except:
      return S_ERROR( "Oops! Couldn't understand the request" )
    condDict = {}
    #This is our connection to the Job database
    rpcClient = getRPCClient( "WorkloadManagement/JobMonitoring" )
    # use the last 2 weeks of job data, to speed loading time
    #lastFortnight =  (datetime.today() - timedelta(365/26)).isoformat()
    lastFortnight =  (datetime.today() - timedelta(365/360)).isoformat()
    username = credentials.getUsername()
    group = credentials.getSelectedGroup()

    if group != 'dirac_admin':
        condDict = {'Owner': username}
    result = rpcClient.getJobGroups( condDict, lastFortnight )
    #result = rpcClient.getJobGroups()
    if not result[ 'OK' ]:
      return result
    data = { 'numRecords' : len(result[ 'Value' ]), 'projects' : [] }
    for record in result['Value']:
      rD = {}
      counters = rpcClient.getCounters(['Status', 'Owner','OwnerGroup','LastUpdateTime','SubmissionTime'], {'JobGroup' : record})
      if not counters['OK']:
        return counters
      else:
        rD['LastUpdate'] = self.timeToNUnitAgo(self.mostRecentTime(counters['Value'], 'LastUpdateTime'))
        #rD['counters'] = counters['Value']
        rD['percentage'] = self.statusToPercentage(counters['Value'])
        rD['colours'] = self.statusToColours(counters['Value'])
	if rD['percentage'] == 1:
          if rD['colours'][0] > 0:
            rD['status'] = "Done - with failures"
          else:
            rD['status'] = "Done"
        else:
          rD['status'] = "Running"
      rD['SubmissionTime'] = str(self.mostRecentTime(counters['Value'],'SubmissionTime'))
      #cheat - get the first owner as they're all the same
      rD['Owner'] = counters["Value"][0][0]["Owner"]
      rD['OwnerGroup'] = counters["Value"][0][0]["OwnerGroup"]
      rD['proj_Name'] = record
      data['projects'].append( rD )
    return data
Esempio n. 49
0
 def __deleteHistory(self, name, state):
     """
 Deleting item from Load and Save history list
 Return resulting list
 "name" is a string
 "state" can be either "Save" or "Load"
 """
     gLogger.info("Running deleteHistory( %s )" % name)
     msg = "deleteHistory() for %s@%s" % (getUsername(), getSelectedGroup())
     opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
     history_length = gConfig.getOptions(opt, 5)
     upc = UserProfileClient("Default", getRPCClient)
     group = str(getSelectedGroup())
     profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
     result = upc.retrieveVar(profile_name)
     gLogger.info(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
         gLogger.info("Result %s: %s" % (msg, result["Message"]))
         return S_OK(list())  # Nothing to delete, return an empty list
     else:
         result = result["Value"]
     if not isinstance(result, list):
         err = "List expected at: %s" % profile_name
         gLogger.error("Result %s: %s" % (msg, err))
         return S_ERROR(err)
     history = list()
     for i in result:
         if i.has_key("name") and not i["name"] == name:
             history.append(i)
     if (len(history) > history_length):
         history = result[history_length]
     gLogger.error("History: %s" % history)
     result = upc.storeVar(profile_name, history)
     gLogger.info(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return S_ERROR(result["Message"])
     gLogger.info("Result %s: %s" % (msg, history))
     return S_OK(history)
Esempio n. 50
0
  def __request(self):
    req = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    global pageNumber
    if request.params.has_key("id") and len(request.params["id"]) > 0:
      pageNumber = 0
      req["JobID"] = str(request.params["id"])
    elif request.params.has_key("expand") and len(request.params["expand"]) > 0:
      globalSort = [["GridSite","ASC"]]
      numberOfJobs = 500
      pageNumber = 0
      req["ExpandSite"] = str(request.params["expand"])
    else:
      pageNumber = 0
      numberOfJobs = 500
      if request.params.has_key("prod") and len(request.params["prod"]) > 0:
        if str(request.params["prod"]) != "All":
          req["JobGroup"] = str(request.params["prod"]).split('::: ')
      if request.params.has_key("site") and len(request.params["site"]) > 0:
        if str(request.params["site"]) != "All":
          tmp = str(request.params["site"]).split('::: ')
          if len(tmp) == 1:
            req["ExpandSite"] = tmp[0]
          else:
            req["GridSite"] = tmp
      if request.params.has_key("stat") and len(request.params["stat"]) > 0:
        if str(request.params["stat"]) != "All":
          req["Status"] = str(request.params["stat"]).split('::: ')
      if request.params.has_key("minorstat") and len(request.params["minorstat"]) > 0:
        if str(request.params["minorstat"]) != "All":
          req["MinorStatus"] = str(request.params["minorstat"]).split('::: ')
      if request.params.has_key("app") and len(request.params["app"]) > 0:
        if str(request.params["app"]) != "All":
          req["ApplicationStatus"] = str(request.params["app"]).split('::: ')
#      if lhcbGroup == "lhcb" or lhcbGroup == "lhcb_user":
#        req["Owner"] = str(lhcbUser)
      else:
        if request.params.has_key("owner") and len(request.params["owner"]) > 0:
          if str(request.params["owner"]) != "All":
            req["Owner"] = str(request.params["owner"]).split('::: ')
      if request.params.has_key("date") and len(request.params["date"]) > 0:
        if str(request.params["date"]) != "YYYY-mm-dd":
          req["LastUpdate"] = str(request.params["date"])
      if request.params.has_key("sort") and len(request.params["sort"]) > 0:
        globalSort = str(request.params["sort"])
        key,value = globalSort.split(" ")
        globalSort = [[str(key),str(value)]]
      else:
#        globalSort = [["JobID","DESC"]]
        globalSort = [["GridSite","ASC"]]
    gLogger.info("REQUEST:",req)
    return req
Esempio n. 51
0
 def __setHistory(self, item, state):
     """
 Insert item to  Load or Save history list in first position and checking for
 duplications.
 Return resulting list
 "item" is a dict
 "state" should be either "Save" or "Load" but can be any other value
 """
     gLogger.info("Running setHistory( %s , %s )" % (item, state))
     msg = "setHistory() for %s@%s" % (getUsername(), getSelectedGroup())
     opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
     history_length = gConfig.getOptions(opt, 5)
     upc = UserProfileClient("Default", getRPCClient)
     group = str(getSelectedGroup())
     profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
     result = upc.retrieveVar(profile_name)
     gLogger.info(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
         history = list()
     else:
         history = result["Value"]
     if not isinstance(history, list):
         err = "List expected at: %s" % profile_name
         gLogger.error("Result %s: %s" % (msg, err))
         return S_ERROR(err)
     if (len(history) > history_length):
         history = result[history_length]
     history.insert(0, item)
     history = uniqueElements(history)
     gLogger.error("History: %s" % history)
     result = upc.storeVar(profile_name, history)
     gLogger.info(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return S_ERROR(result["Message"])
     gLogger.info("Result %s: %s" % (msg, history))
     return S_OK(history)
Esempio n. 52
0
    def display(self):
        checkUserCredentials()
        dn = getUserDN()
        user = getUsername()
        group = getSelectedGroup()
        gLogger.always("User: %s, Group: %s, DN: %s" % (user, group, dn))
        templates = ["reg_%s.mako" % i for i in ["done", "form", "info"]]
        html = [
            "reg_%s.html" % i
            for i in ["footer", "header", "conditions", "form", "done"]
        ]
        files = templates + html
        basedir = os.path.join(rootPath, "Web", "dirac", "templates")
        for i in files:
            f = os.path.join(basedir, i)
            if not os.path.exists(f):
                gLogger.error("File does not exists: %s" % f)
                return render("web/External.mako")
        if dn and user == "anonymous":
            upc = UserProfileClient("Registration", getRPCClient)
            result = upc.retrieveVar(dn)
            if result["OK"]:
                c.sent = result["Value"]
                return render("/reg_done.mako")
            else:
                return render("/reg_form.mako")
        if not dn or dn == "":
            return render("/reg_info.mako")

        if "site" not in request.params:
            c.select = gConfig.getValue("/Website/DefaultExternalURL",
                                        "http://diracgrid.org")
            return render("web/External.mako")

        # No idea what this code should do...
        if request.params.has_key("site") and len(request.params["site"]) > 0:
            if str(request.params["site"]) != "All":
                c.select = str(request.params["site"])
                gLogger.debug("Request's body:")
                for key in request.params.keys():
                    if not key == "site" and len(request.params[key]) > 0:
                        c.select = c.select + "&" + key + "=" + request.params[
                            key]
                        try:
                            gLogger.debug("%s - %s" %
                                          (key, request.params[key]))
                        except Exception, x:
                            gLogger.error("Exception: %s" % str(x))
                            pass