예제 #1
0
 def __promptForParameter(self,
                          parameter,
                          choices=[],
                          default='',
                          insert=True):
     res = promptUser("Please enter %s" % parameter,
                      choices=choices,
                      default=default)
     if not res['OK']:
         return self._errorReport(res)
     gLogger.notice("%s will be set to '%s'" % (parameter, res['Value']))
     paramValue = res['Value']
     if insert:
         setter = None
         setterName = "set%s" % parameter
         if hasattr(self, setterName) and callable(getattr(
                 self, setterName)):
             setter = getattr(self, setterName)
         if not setter:
             return S_ERROR(
                 "Unable to invoke %s, it isn't a member function of Transformation!"
             )
         res = setter(paramValue)
         if not res['OK']:
             return res
     return S_OK(paramValue)
예제 #2
0
    def setSiteProtocols(self, site, protocolsList, printOutput=False):
        """
    Allows to set the defined protocols for each SE for a given site.
    """
        result = self.__checkSiteIsValid(site)
        if not result["OK"]:
            return result

        siteSection = "/Resources/Sites/%s/%s/SE" % (site.split(".")[0], site)
        siteSEs = gConfig.getValue(siteSection, [])
        if not siteSEs:
            return S_ERROR("No SEs found for site %s in section %s" % (site, siteSection))

        defaultProtocols = gConfig.getValue("/Resources/StorageElements/DefaultProtocols", [])
        self.log.verbose("Default list of protocols are", ", ".join(defaultProtocols))

        for protocol in protocolsList:
            if not protocol in defaultProtocols:
                return S_ERROR(
                    "Requested to set protocol %s in list but %s is not "
                    "in default list of protocols:\n%s" % (protocol, protocol, ", ".join(defaultProtocols))
                )

        modifiedCS = False
        result = promptUser(
            "Do you want to add the following default protocols:"
            " %s for SE(s):\n%s" % (", ".join(protocolsList), ", ".join(siteSEs))
        )
        if not result["OK"]:
            return result
        if result["Value"].lower() != "y":
            self.log.always("No protocols will be added")
            return S_OK()

        for se in siteSEs:
            sections = gConfig.getSections("/Resources/StorageElements/%s/" % (se))
            if not sections["OK"]:
                return sections
            for section in sections["Value"]:
                if gConfig.getValue("/Resources/StorageElements/%s/%s/ProtocolName" % (se, section), "") == "SRM2":
                    path = "/Resources/StorageElements/%s/%s/ProtocolsList" % (se, section)
                    self.log.verbose("Setting %s to %s" % (path, ", ".join(protocolsList)))
                    result = self.csSetOption(path, ", ".join(protocolsList))
                    if not result["OK"]:
                        return result
                    modifiedCS = True

        if modifiedCS:
            result = self.csCommitChanges(False)
            if not result["OK"]:
                return S_ERROR("CS Commit failed with message = %s" % (result["Message"]))
            else:
                if printOutput:
                    print "Successfully committed changes to CS"
        else:
            if printOutput:
                print "No modifications to CS required"

        return S_OK()
예제 #3
0
    def production(self, productionID, command, disableCheck=True):
        """Allows basic production management by supporting the following commands:
       - start : set production status to Active, job submission possible
       - stop : set production status to Stopped, no job submissions
       - automatic: set production submission mode to Automatic, e.g. submission via Agent
       - manual: set produciton submission mode to manual, e.g. dirac-production-submit
    """
        commands = self.commands

        if not isinstance(productionID, (int, long, str)):
            return self._errorReport(
                'Expected string, long or int for production ID')

        productionID = long(productionID)
        if not isinstance(command, str):
            return self._errorReport('Expected string, for command')
        if not command.lower() in commands:
            return self._errorReport('Expected one of: %s for command string' %
                                     (', '.join(commands)))

        self.log.verbose(
            'Requested to change production %s with command "%s"' %
            (productionID, command.lower().capitalize()))
        if not disableCheck:
            result = promptUser(
                'Do you wish to change production %s with command "%s"? ' %
                (productionID, command.lower().capitalize()))
            if not result['OK']:
                self.log.info('Action cancelled')
                return S_OK('Action cancelled')
            if result['Value'] != 'y':
                self.log.info('Doing nothing')
                return S_OK('Doing nothing')

        actions = commands[command]
        self.log.info(
            'Setting production status to %s and submission mode to %s for productionID %s'
            % (actions[0], actions[1], productionID))
        result = self.transformationClient.setTransformationParameter(
            long(productionID), "Status", actions[0])
        if not result['OK']:
            self.log.warn(
                'Problem updating transformation status with result:\n%s' %
                result)
            return result
        self.log.verbose('Setting transformation status to %s successful' %
                         (actions[0]))
        result = self.transformationClient.setTransformationParameter(
            long(productionID), 'AgentType', actions[1])
        if not result['OK']:
            self.log.warn(
                'Problem updating transformation agent type with result:\n%s' %
                result)
            return result
        self.log.verbose('Setting transformation agent type to %s successful' %
                         (actions[1]))
        return S_OK('Production %s status updated' % productionID)
예제 #4
0
def main():
  global force

  from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
  gComponentInstaller.exitOnError = True

  Script.registerSwitch("f", "force", "Forces the removal of the logs", setForce)
  Script.parseCommandLine()
  args = Script.getPositionalArgs()

  if len(args) == 1:
    args = args[0].split('/')

  if len(args) < 2:
    Script.showHelp(exitCode=1)

  system = args[0]
  component = args[1]

  monitoringClient = ComponentMonitoringClient()
  result = monitoringClient.getInstallations({'Instance': component, 'UnInstallationTime': None},
                                             {'System': system},
                                             {'HostName': socket.getfqdn()}, True)
  if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)
  if len(result['Value']) < 1:
    gLogger.warn('Given component does not exist')
    DIRACexit(1)
  if len(result['Value']) > 1:
    gLogger.error('Too many components match')
    DIRACexit(1)

  removeLogs = False
  if force:
    removeLogs = True
  else:
    if result['Value'][0]['Component']['Type'] in gComponentInstaller.componentTypes:
      result = promptUser('Remove logs?', ['y', 'n'], 'n')
      if result['OK']:
        removeLogs = result['Value'] == 'y'
      else:
        gLogger.error(result['Message'])
        DIRACexit(1)

  result = gComponentInstaller.uninstallComponent(system, component, removeLogs)
  if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)

  result = MonitoringUtilities.monitorUninstallation(system, component)
  if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)
  gLogger.notice('Successfully uninstalled component %s/%s' % (system, component))
  DIRACexit()
예제 #5
0
  def setSiteProtocols( self, site, protocolsList, printOutput = False ):
    """
    Allows to set the defined protocols for each SE for a given site.
    """
    result = self.__checkSiteIsValid( site )
    if not result['OK']:
      return result

    siteSection = '/Resources/Sites/%s/%s/SE' % ( site.split( '.' )[0], site )
    siteSEs = gConfig.getValue( siteSection, [] )
    if not siteSEs:
      return S_ERROR( 'No SEs found for site %s in section %s' % ( site, siteSection ) )

    defaultProtocols = gConfig.getValue( '/Resources/StorageElements/DefaultProtocols', [] )
    self.log.verbose( 'Default list of protocols are', ', '.join( defaultProtocols ) )

    for protocol in protocolsList:
      if not protocol in defaultProtocols:
        return S_ERROR( 'Requested to set protocol %s in list but %s is not '
                        'in default list of protocols:\n%s' % ( protocol, protocol, ', '.join( defaultProtocols ) ) )

    modifiedCS = False
    result = promptUser( 'Do you want to add the following default protocols:'
                         ' %s for SE(s):\n%s' % ( ', '.join( protocolsList ), ', '.join( siteSEs ) ) )
    if not result['OK']:
      return result
    if result['Value'].lower() != 'y':
      self.log.always( 'No protocols will be added' )
      return S_OK()

    for se in siteSEs:
      sections = gConfig.getSections( '/Resources/StorageElements/%s/' % ( se ) )
      if not sections['OK']:
        return sections
      for section in sections['Value']:
        if gConfig.getValue( '/Resources/StorageElements/%s/%s/ProtocolName' % ( se, section ), '' ) == 'SRM2':
          path = '/Resources/StorageElements/%s/%s/ProtocolsList' % ( se, section )
          self.log.verbose( 'Setting %s to %s' % ( path, ', '.join( protocolsList ) ) )
          result = self.csSetOption( path, ', '.join( protocolsList ) )
          if not result['OK']:
            return result
          modifiedCS = True

    if modifiedCS:
      result = self.csCommitChanges( False )
      if not result[ 'OK' ]:
        return S_ERROR( 'CS Commit failed with message = %s' % ( result[ 'Message' ] ) )
      else:
        if printOutput:
          print 'Successfully committed changes to CS'
    else:
      if printOutput:
        print 'No modifications to CS required'

    return S_OK()
예제 #6
0
  def setSiteProtocols( self, site, protocolsList, printOutput = False ):
    """
    Allows to set the defined protocols for each SE for a given site.
    """
    result = self.__checkSiteIsValid( site )
    if not result['OK']:
      return result

    siteSection = '/Resources/Sites/%s/%s/SE' % ( site.split( '.' )[0], site )
    siteSEs = gConfig.getValue( siteSection, [] )
    if not siteSEs:
      return S_ERROR( 'No SEs found for site %s in section %s' % ( site, siteSection ) )

    defaultProtocols = gConfig.getValue( '/Resources/StorageElements/DefaultProtocols', [] )
    self.log.verbose( 'Default list of protocols are', ', '.join( defaultProtocols ) )

    for protocol in protocolsList:
      if not protocol in defaultProtocols:
        return S_ERROR( 'Requested to set protocol %s in list but %s is not '
                        'in default list of protocols:\n%s' % ( protocol, protocol, ', '.join( defaultProtocols ) ) )

    modifiedCS = False
    result = promptUser( 'Do you want to add the following default protocols:'
                         ' %s for SE(s):\n%s' % ( ', '.join( protocolsList ), ', '.join( siteSEs ) ) )
    if not result['OK']:
      return result
    if result['Value'].lower() != 'y':
      self.log.always( 'No protocols will be added' )
      return S_OK()

    for se in siteSEs:
      sections = gConfig.getSections( '/Resources/StorageElements/%s/' % ( se ) )
      if not sections['OK']:
        return sections
      for section in sections['Value']:
        if gConfig.getValue( '/Resources/StorageElements/%s/%s/ProtocolName' % ( se, section ), '' ) == 'SRM2':
          path = '/Resources/StorageElements/%s/%s/ProtocolsList' % ( se, section )
          self.log.verbose( 'Setting %s to %s' % ( path, ', '.join( protocolsList ) ) )
          result = self.csSetOption( path, ', '.join( protocolsList ) )
          if not result['OK']:
            return result
          modifiedCS = True

    if modifiedCS:
      result = self.csCommitChanges( False )
      if not result[ 'OK' ]:
        return S_ERROR( 'CS Commit failed with message = %s' % ( result[ 'Message' ] ) )
      else:
        if printOutput:
          print 'Successfully committed changes to CS'
    else:
      if printOutput:
        print 'No modifications to CS required'

    return S_OK()
예제 #7
0
 def __promptForParameter( self, parameter, choices = [], default = '', insert = True ):
   res = promptUser( "Please enter %s" % parameter, choices = choices, default = default )
   if not res['OK']:
     return self._errorReport( res )
   gLogger.notice( "%s will be set to '%s'" % ( parameter, res['Value'] ) )
   paramValue = res['Value']
   if insert:
     setter = None
     setterName = "set%s" % parameter
     if hasattr( self, setterName ) and callable( getattr( self, setterName ) ):
       setter = getattr( self, setterName )
     if not setter:
       return S_ERROR( "Unable to invoke %s, it isn't a member function of Transformation!" )
     res = setter( paramValue )
     if not res['OK']:
       return res
   return S_OK( paramValue )
예제 #8
0
파일: Job.py 프로젝트: hamzazafar/ILCDIRAC
 def _askUser(self):
     """ Private function
 
 Called from :mod:`~ILCDIRAC.Interfaces.API.DiracILC` class to prompt the user
 """
     if not self.check:
         return S_OK()
     for app in self.applicationlist:
         self.log.notice(app)
         app.listAttributes()
         self.log.notice("\n")
     res = promptUser('Proceed and submit job(s)?', logger=self.log)
     if not res['OK']:
         return S_ERROR("User did not validate")
     if res['Value'] == 'n':
         return S_ERROR("User did not validate")
     # no more debug output in further loops
     self.check = False
     return S_OK()
예제 #9
0
파일: Job.py 프로젝트: LCDgit/ILCDIRAC
 def _askUser(self):
   """ Private function
   
   Called from DiracILC class to prompt the user
   """
   if not self.check:
     return S_OK()
   for app in self.applicationlist:
     print app
     app.listAttributes()
     print "\n"
   res = promptUser('Proceed and submit job(s)?', logger = self.log)
   if not res['OK']:
     return S_ERROR("User did not validate")
   if res['Value'] == 'n':
     return S_ERROR("User did not validate")
   # no more debug output in further loops
   self.check = False
   return S_OK()
예제 #10
0
 def _askUser(self):
   """ Private function
   
   Called from :mod:`~ILCDIRAC.Interfaces.API.DiracILC` class to prompt the user
   """
   if not self.check:
     return S_OK()
   for app in self.applicationlist:
     self.log.notice(app)
     app.listAttributes()
     self.log.notice("\n")
   res = promptUser('Proceed and submit job(s)?', logger = self.log)
   if not res['OK']:
     return S_ERROR("User did not validate")
   if res['Value'] == 'n':
     return S_ERROR("User did not validate")
   # no more debug output in further loops
   self.check = False
   return S_OK()
예제 #11
0
def _getProdLogs():
  """get production log files from LogSE"""
  clip = _Params()
  clip.registerSwitch()
  Script.parseCommandLine()
  if not ( clip.logF or clip.logD or clip.prodid ):
    Script.showHelp()
    dexit(1)
  from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
  ops = Operations()
  storageElementName = ops.getValue('/LogStorage/LogSE', 'LogSE')
  from DIRAC.Resources.Storage.StorageElement import StorageElementItem as StorageElement
  logSE = StorageElement(storageElementName)

  if clip.prodid and not ( clip.logD or clip.logF ):
    result = _getLogFolderFromID( clip )
    if not result['OK']:
      gLogger.error( result['Message'] )
      dexit(1)

  if clip.logD:
    if not clip.noPromptBeforeDL:
      res = promptUser('Are you sure you want to get ALL the files in this directory?')
      if not res['OK']:
        dexit()
      choice = res['Value']
      if choice.lower()=='n':
        dexit(0)
  
    if isinstance(clip.logD, str):
      res = logSE.getDirectory(clip.logD, localPath=clip.outputdir)
      _printErrorReport(res)
    elif isinstance(clip.logD, list):
      for logdir in clip.logD:
        gLogger.notice('Getting log files from '+str(logdir))
        res = logSE.getDirectory(logdir, localPath=clip.outputdir)
        _printErrorReport(res)

  if clip.logF:
    res = logSE.getFile(clip.logF, localPath = clip.outputdir)
    _printErrorReport(res)
예제 #12
0
def _getProdLogs():
  """get production log files from LogSE"""
  clip = _Params()
  clip.registerSwitch()
  Script.parseCommandLine()
  if not ( clip.logF or clip.logD or clip.prodid ):
    Script.showHelp()
    dexit(1)
  from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
  ops = Operations()
  storageElementName = ops.getValue('/LogStorage/LogSE', 'LogSE')
  from DIRAC.Resources.Storage.StorageElement import StorageElementItem as StorageElement
  logSE = StorageElement(storageElementName)

  if clip.prodid and not ( clip.logD or clip.logF ):
    result = _getLogFolderFromID( clip )
    if not result['OK']:
      gLogger.error( result['Message'] )
      dexit(1)

  if clip.logD:
    if not clip.noPromptBeforeDL:
      res = promptUser('Are you sure you want to get ALL the files in this directory?')
      if not res['OK']:
        dexit()
      choice = res['Value']
      if choice.lower()=='n':
        dexit(0)
  
    if isinstance(clip.logD, str):
      res = logSE.getDirectory(clip.logD, localPath=clip.outputdir)
      _printErrorReport(res)
    elif isinstance(clip.logD, list):
      for logdir in clip.logD:
        gLogger.notice('Getting log files from '+str(logdir))
        res = logSE.getDirectory(logdir, localPath=clip.outputdir)
        _printErrorReport(res)

  if clip.logF:
    res = logSE.getFile(clip.logF, localPath = clip.outputdir)
    _printErrorReport(res)
예제 #13
0
 gLogger.notice("Will eventually upload %s file(s)" % len(flist))
   
 from DIRAC.Core.Utilities.PromptUser import promptUser
   
 from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
 basepath = Operations().getValue('Production/ILC_ILD/BasePath','')
 if not basepath:
   gLogger.error('Failed to contact CS, please try again')
   dexit(1)
 
 basepath = "/".join(basepath.split("/")[:-2])+"/" #need to get rid of the ild/ part at the end
   
 finalpath = os.path.join(basepath, 'generated', clip.energy+"-"+clip.machineParams, clip.evtclass, str(clip.fmeta['GenProcessID']))
 gLogger.notice("Will upload the file(s) under %s" % finalpath)
 if not clip.force:
   res = promptUser('Continue?', ['y','n'], 'n')
   if not res['OK']:
     gLogger.error(res['Message'])
     dexit(1)
   if not res['Value'].lower()=='y':
     dexit(0)
 
 dirmeta = []
 dirmeta.append({'path':os.path.join(basepath, 'generated'), 'meta':{'Datatype':'gen'}})
 dirmeta.append({'path':os.path.join(basepath, 'generated', clip.energy+"-"+clip.machineParams), 'meta':{'Energy':clip.energy, 'MachineParams':clip.machineParams}})
 dirmeta.append({'path':os.path.join(basepath, 'generated', clip.energy+"-"+clip.machineParams, clip.evtclass), 'meta':{'EvtClass':clip.evtclass }})
 dirmeta.append({'path':finalpath, 'meta': {'EvtType':clip.evttype ,'Luminosity':clip.lumi, 'ProcessID': clip.fmeta['GenProcessID']} })
 
 final_fname_base = 'E'+clip.energy+"-"+clip.machineParams+".P"+clip.fmeta['GenProcessName']+".G"+clip.fmeta['ProgramNameVersion'] + "."+clip.p1+clip.pol1+"."+clip.p2+clip.pol2+".I"+str(clip.fmeta['GenProcessID'])
 gLogger.notice("Final file name(s) will be %s where XXX will be replaced by file number, and ext by the input file extension" % (final_fname_base+".XXX.ext") )
 if not clip.force:
예제 #14
0
  def do_uninstall( self, args ):
    """
        Uninstall a DIRAC component or host along with all its components

        usage:

          uninstall db <database>
          uninstall host <hostname>
          uninstall <-f ForceLogUninstall> <system> <component>
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_uninstall.__doc__ )
      return

    # Retrieve user uninstalling the component
    result = getProxyInfo()
    if not result[ 'OK' ]:
      self._errMsg( result[ 'Message'] )
    user = result[ 'Value' ][ 'username' ]

    option = argss[0]
    if option == 'db':
      del argss[0]
      if not argss:
        gLogger.notice( self.do_uninstall.__doc__ )
        return
      component = argss[0]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = client.getAvailableDatabases()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      system = result[ 'Value' ][ component ][ 'System' ]
      result = MonitoringUtilities.monitorUninstallation( system , component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return

      result = client.uninstallDatabase( component )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s" % ( component ) )
    elif option == 'host':
      del argss[0]
      if not argss:
        gLogger.notice( self.do_uninstall.__doc__ )
        return
      hostname = argss[0]

      client = ComponentMonitoringClient()
      result = client.hostExists( { 'HostName': hostname } )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
      else:
        if not result[ 'Value' ]:
          self._errMsg( 'Given host does not exist' )
        else:
          result = client.getHosts( {'HostName': hostname }, True, False )
          if not result[ 'OK' ]:
            self._errMsg( result[ 'Message' ] )
          else:
            host = result[ 'Value' ][0]
            # Remove every installation associated with the host
            for installation in host[ 'Installations' ]:
              result = client.removeInstallations( installation, {}, { 'HostName': hostname } )
              if not result[ 'OK' ]:
                self._errMsg( result[ 'Message' ] )
                break
            # Finally remove the host
            result = client.removeHosts( { 'HostName': hostname } )
            if not result[ 'OK' ]:
              self._errMsg( result[ 'Message' ] )
            else:
              gLogger.notice( 'Host %s was successfully removed' % hostname )
    else:
      if option == '-f':
        force = True
        del argss[0]
      else:
        force = False

      if len( argss ) != 2:
        gLogger.notice( self.do_uninstall.__doc__ )
        return

      system, component = argss
      client = SystemAdministratorClient( self.host, self.port )

      monitoringClient = ComponentMonitoringClient()
      result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': self.host }, True )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      if len( result[ 'Value' ] ) < 1:
        self._errMsg( "Given component does not exist" )
        return
      if len( result[ 'Value' ] ) > 1:
        self._errMsg( "Too many components match" )
        return

      removeLogs = False
      if force:
        removeLogs = True
      else:
        if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in self.runitComponents:
          result = promptUser( 'Remove logs?', ['y', 'n'], 'n' )
          if result[ 'OK' ]:
            removeLogs = result[ 'Value' ] == 'y'

      result = client.uninstallComponent( system, component, removeLogs )
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s/%s" % ( system, component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = MonitoringUtilities.monitorUninstallation( system, component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        return result
예제 #15
0
if not result[ 'OK' ]:
  gLogger.error( result[ 'Message' ] )
  DIRACexit( 1 )
if len( result[ 'Value' ] ) < 1:
  gLogger.error( 'Given component does not exist' )
  DIRACexit( 1 )
if len( result[ 'Value' ] ) > 1:
  gLogger.error( 'Too many components match' )
  DIRACexit( 1 )

removeLogs = False
if force:
  removeLogs = True
else:
  if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in InstallTools.COMPONENT_TYPES:
    result = promptUser( 'Remove logs?', [ 'y', 'n' ], 'n' )
    if result[ 'OK' ]:
      removeLogs = result[ 'Value' ] == 'y'
    else:
      gLogger.error( result[ 'Message' ] )
      DIRACexit( 1 )

result = InstallTools.uninstallComponent( system, component, removeLogs )
if not result['OK']:
  gLogger.error( result[ 'Message' ] )
  DIRACexit( 1 )

result = MonitoringUtilities.monitorUninstallation( system, component )
if not result['OK']:
  gLogger.error( result[ 'Message' ] )
  DIRACexit( 1 )
예제 #16
0
    gLogger.error(result['Message'])
    DIRACexit(1)
if len(result['Value']) < 1:
    gLogger.warn('Given component does not exist')
    DIRACexit(1)
if len(result['Value']) > 1:
    gLogger.error('Too many components match')
    DIRACexit(1)

removeLogs = False
if force:
    removeLogs = True
else:
    if result['Value'][0]['Component'][
            'Type'] in gComponentInstaller.componentTypes:
        result = promptUser('Remove logs?', ['y', 'n'], 'n')
        if result['OK']:
            removeLogs = result['Value'] == 'y'
        else:
            gLogger.error(result['Message'])
            DIRACexit(1)

result = gComponentInstaller.uninstallComponent(system, component, removeLogs)
if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)

result = MonitoringUtilities.monitorUninstallation(system, component)
if not result['OK']:
    gLogger.error(result['Message'])
    DIRACexit(1)
예제 #17
0
  def do_uninstall( self, args ):
    """
        Uninstall DIRAC component

        usage:

          uninstall db <database>
          uninstall <-f ForceLogUninstall> <system> <component>
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_uninstall.__doc__ )
      return

    # Retrieve user uninstalling the component
    result = getProxyInfo()
    if not result[ 'OK' ]:
      self.__errMsg( result[ 'Message'] )
    user = result[ 'Value' ][ 'username' ]

    option = argss[0]
    if option == 'db':
      component = argss[1]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = client.getAvailableDatabases()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      system = result[ 'Value' ][ component ][ 'System' ]
      result = MonitoringUtilities.monitorUninstallation( system , component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return

      result = client.uninstallDatabase( component )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s" % ( component ) )
    else:
      if option == '-f':
        force = True
        del argss[0]
      else:
        force = False

      if len( argss ) != 2:
        gLogger.notice( self.do_uninstall.__doc__ )
        return

      system, component = argss
      client = SystemAdministratorClient( self.host, self.port )

      monitoringClient = ComponentMonitoringClient()
      result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': self.host }, True )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      if len( result[ 'Value' ] ) < 1:
        self.__errMsg( "Given component does not exist" )
        return
      if len( result[ 'Value' ] ) > 1:
        self.__errMsg( "Too many components match" )
        return

      removeLogs = False
      if force:
        removeLogs = True
      else:
        if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in self.runitComponents:
          result = promptUser( 'Remove logs?', ['y', 'n'], 'n' )
          if result[ 'OK' ]:
            removeLogs = result[ 'Value' ] == 'y'

      result = client.uninstallComponent( system, component, removeLogs )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s/%s" % ( system, component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = MonitoringUtilities.monitorUninstallation( system, component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        return result
예제 #18
0
    def setSiteProtocols(self, site, protocolsList, printOutput=False):
        """
        Allows to set the defined protocols for each SE for a given site.
        """
        result = self._checkSiteIsValid(site)
        if not result["OK"]:
            return result

        siteSection = "/Resources/Sites/%s/%s/SE" % (site.split(".")[0], site)
        siteSEs = gConfig.getValue(siteSection, [])
        if not siteSEs:
            return S_ERROR("No SEs found for site %s in section %s" %
                           (site, siteSection))

        defaultProtocols = gConfig.getValue(
            "/Resources/StorageElements/DefaultProtocols", [])
        self.log.verbose("Default list of protocols are",
                         ", ".join(defaultProtocols))

        for protocol in protocolsList:
            if protocol not in defaultProtocols:
                return S_ERROR(
                    "Requested to set protocol %s in list but %s is not "
                    "in default list of protocols:\n%s" %
                    (protocol, protocol, ", ".join(defaultProtocols)))

        modifiedCS = False
        result = promptUser(
            "Do you want to add the following default protocols:"
            " %s for SE(s):\n%s" %
            (", ".join(protocolsList), ", ".join(siteSEs)))
        if not result["OK"]:
            return result
        if result["Value"].lower() != "y":
            self.log.always("No protocols will be added")
            return S_OK()

        for se in siteSEs:
            sections = gConfig.getSections("/Resources/StorageElements/%s/" %
                                           (se))
            if not sections["OK"]:
                return sections
            for section in sections["Value"]:
                if gConfig.getValue(
                        "/Resources/StorageElements/%s/%s/ProtocolName" %
                    (se, section), "") == "SRM2":
                    path = "/Resources/StorageElements/%s/%s/ProtocolsList" % (
                        se, section)
                    self.log.verbose("Setting %s to %s" %
                                     (path, ", ".join(protocolsList)))
                    result = self.csSetOption(path, ", ".join(protocolsList))
                    if not result["OK"]:
                        return result
                    modifiedCS = True

        if modifiedCS:
            result = self.csCommitChanges(False)
            if not result["OK"]:
                return S_ERROR("CS Commit failed with message = %s" %
                               (result["Message"]))
            else:
                if printOutput:
                    gLogger.notice("Successfully committed changes to CS")
        else:
            if printOutput:
                gLogger.notice("No modifications to CS required")

        return S_OK()
예제 #19
0
  def do_uninstall( self, args ):
    """
        Uninstall DIRAC component

        usage:

          uninstall db <database>
          uninstall <-f ForceLogUninstall> <system> <component>
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_uninstall.__doc__ )
      return
    
    option = argss[0]
    if option == 'db':
      component = argss[1]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.uninstallDatabase( component )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s" % ( component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = client.getAvailableDatabases()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      system = result[ 'Value' ][ component ][ 'System' ]
      result = MonitoringUtilities.monitorUninstallation( system , component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
    else:
      if option == '-f':
        force = True
        del argss[0]
      else:
        force = False

      if len( argss ) != 2:
        gLogger.notice( self.do_uninstall.__doc__ )
        return

      system, component = argss
      client = SystemAdministratorClient( self.host, self.port )

      monitoringClient = ComponentMonitoringClient()
      result = monitoringClient.getInstallations( { 'Instance': component, 'UnInstallationTime': None },
                                                  { 'System': system },
                                                  { 'HostName': self.host }, True )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      if len( result[ 'Value' ] ) < 1:
        self.__errMsg( "Given component does not exist" )
        return
      if len( result[ 'Value' ] ) > 1:
        self.__errMsg( "Too many components match" )
        return

      removeLogs = False
      if force:
        removeLogs = True
      else:
        if result[ 'Value' ][0][ 'Component' ][ 'Type' ] in self.runitComponents:
          result = promptUser( 'Remove logs?', ['y', 'n'], 'n' )
          if result[ 'OK' ]:
            removeLogs = result[ 'Value' ] == 'y'

      result = client.uninstallComponent( system, component, removeLogs )
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
      else:
        gLogger.notice( "Successfully uninstalled %s/%s" % ( system, component ) )

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self.__errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      result = MonitoringUtilities.monitorUninstallation( system, component, hostname = hostname, cpu = cpu )
      if not result[ 'OK' ]:
        return result
예제 #20
0
def main():
    global force

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True

    Script.registerSwitch("f", "force", "Forces the removal of the logs",
                          setForce)
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument((
        "System/Component: Full component name (ie: WorkloadManagement/Matcher)",
        "System:           Name of the DIRAC system (ie: WorkloadManagement)",
    ))
    Script.registerArgument(
        " Component:        Name of the DIRAC service (ie: Matcher)",
        mandatory=False)
    _, args = Script.parseCommandLine()

    if len(args) == 1:
        args = args[0].split("/")

    if len(args) < 2:
        Script.showHelp(exitCode=1)

    system = args[0]
    component = args[1]

    monitoringClient = ComponentMonitoringClient()
    result = monitoringClient.getInstallations(
        {
            "Instance": component,
            "UnInstallationTime": None
        }, {"System": system}, {"HostName": socket.getfqdn()}, True)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    if len(result["Value"]) < 1:
        gLogger.warn("Given component does not exist")
        DIRACexit(1)
    if len(result["Value"]) > 1:
        gLogger.error("Too many components match")
        DIRACexit(1)

    removeLogs = False
    if force:
        removeLogs = True
    else:
        if result["Value"][0]["Component"][
                "Type"] in gComponentInstaller.componentTypes:
            result = promptUser("Remove logs?", ["y", "n"], "n")
            if result["OK"]:
                removeLogs = result["Value"] == "y"
            else:
                gLogger.error(result["Message"])
                DIRACexit(1)

    result = gComponentInstaller.uninstallComponent(system, component,
                                                    removeLogs)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = MonitoringUtilities.monitorUninstallation(system, component)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice("Successfully uninstalled component %s/%s" %
                   (system, component))
    DIRACexit()
def _uploadGenFiles():
  """uploads the generator files"""
  clip = _Params()
  clip.registerSwitches()
  Script.parseCommandLine()

  
  from DIRAC import gLogger, exit as dexit

  if not clip.dir:
    gLogger.error('You need to set the path')
    Script.showHelp()
    dexit(1)
  if not clip.storageElement:
    gLogger.error('You need a storage element')
    Script.showHelp()
    dexit(1)
  
  for key in MANDATORY_KEYS:
    if key not in clip.fmeta:
      gLogger.error("Not all mandatory meta data defined, please check and add key: ", key)
      Script.showHelp()
      dexit(1)
    
  #resolve the inout files
  flist = []
  if os.path.isdir(clip.dir):
    flistd = os.listdir(clip.dir)
    for filename in flistd:
      if filename.count(".stdhep"):
        flist.append( os.path.join(clip.dir, filename) )
  elif os.path.isfile(clip.dir):
    flist.append(clip.dir)
  else:
    gLogger.error("%s is not a file nor a directory" % clip.dir)
    dexit(1)  
  
  gLogger.notice("Will eventually upload %s file(s)" % len(flist))
    
  from DIRAC.Core.Utilities.PromptUser import promptUser
    
  from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
  basepath = Operations().getValue('Production/ILC_ILD/BasePath','')
  if not basepath:
    gLogger.error('Failed to contact CS, please try again')
    dexit(1)
  
  basepath = "/".join(basepath.split("/")[:-2])+"/" #need to get rid of the ild/ part at the end
    
  finalpath = os.path.join(basepath, 'generated', clip.energy+"-"+clip.machineParams, clip.evtclass, str(clip.fmeta['GenProcessID']))
  gLogger.notice("Will upload the file(s) under %s" % finalpath)
  if not clip.force:
    res = promptUser('Continue?', ['y','n'], 'n')
    if not res['OK']:
      gLogger.error(res['Message'])
      dexit(1)
    if not res['Value'].lower()=='y':
      dexit(0)
  
  dirmeta = []
  dirmeta.append({'path':os.path.join(basepath, 'generated'), 'meta':{'Datatype':'gen'}})
  dirmeta.append({'path':os.path.join(basepath, 'generated', clip.energy+"-"+clip.machineParams), 'meta':{'Energy':clip.energy, 'MachineParams':clip.machineParams}})
  dirmeta.append({'path':os.path.join(basepath, 'generated', clip.energy+"-"+clip.machineParams, clip.evtclass), 'meta':{'EvtClass':clip.evtclass }})
  dirmeta.append({'path':finalpath, 'meta': {'EvtType':clip.evttype ,'Luminosity':clip.lumi, 'ProcessID': clip.fmeta['GenProcessID']} })
  
  final_fname_base = 'E'+clip.energy+"-"+clip.machineParams+".P"+clip.fmeta['GenProcessName']+".G"+clip.fmeta['ProgramNameVersion'] + "."+clip.particle1+clip.pol1+"."+clip.particle2+clip.pol2+".I"+str(clip.fmeta['GenProcessID'])
  gLogger.notice("Final file name(s) will be %s where XX will be replaced by file number, and ext by the input file extension" % (final_fname_base+".XX.ext") )
  if not clip.force:
    res = promptUser('Continue?', ['y','n'], 'n')
    if not res['OK']:
      gLogger.error(res['Message'])
      dexit(1)
    if not res['Value'].lower()=='y':
      dexit(0)    

  
  from DIRAC.DataManagementSystem.Client.DataManager import DataManager
  from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient
  fc = FileCatalogClient()
  
  for pathdict in dirmeta:
    res = fc.createDirectory(pathdict['path'])
    if not res['OK']:
      gLogger.error("Could not create this directory in FileCatalog, abort:", pathdict['path'] )
      dexit(0)

    res = fc.setMetadata(pathdict['path'], pathdict['meta'])
    if not res['OK']:
      gLogger.error( "Failed to set meta data %s to %s\n" %(pathdict['meta'], pathdict['path']), res['Message'] )

  datMan = DataManager()
  for filename in flist:
    fnum = filename.split(".")[-2]
    fext = filename.split(".")[-1]
    final_fname = final_fname_base + '.' + fnum + "." + fext
    gLogger.notice("Uploading %s to" % filename, finalpath+"/"+final_fname)
    if not clip.force:
      res = promptUser('Continue?', ['y','n'], 'n')
      if not res['OK']:
        gLogger.error(res['Message'])
        break
      if not res['Value'].lower()=='y':
        break    

    res = datMan.putAndRegister(finalpath+"/"+final_fname, filename, clip.storageElement)
    if not res['OK']:
      gLogger.error("Failed to upload %s:" % filename, res['Message'])
      continue
    res = fc.setMetadata(finalpath+"/"+final_fname, clip.fmeta)
    if not res['OK']:
      gLogger.error("Failed setting the metadata to %s:" % filename, res['Message'])
      
  dexit(0)
예제 #22
0
 clip = Params()
 clip.registerSwitch()
 Script.parseCommandLine()
 if not clip.logF and not clip.logD:
   Script.showHelp()
   dexit(1)
 from DIRAC import gConfig
 from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
 ops = Operations()
 storageElementName = ops.getValue('/LogStorage/LogSE', 'LogSE')
 
 from DIRAC.DataManagementSystem.Client.ReplicaManager import ReplicaManager
 rm = ReplicaManager()
 from DIRAC.Core.Utilities.PromptUser import promptUser
 if clip.logD:
   res = promptUser('Are you sure you want to get ALL the files in this directory?')
   if not res['OK']:
     dexit()
   choice = res['Value']
   if choice.lower()=='n':
     dexit(0)
   res = rm.getStorageDirectory(clip.logD, storageElementName, clip.outputdir, singleDirectory=True)
   if not res['OK']:
     gLogger.error(res['Message'])
     dexit(1)
 if clip.logF:
   res = rm.getStorageFile(clip.logF, storageElementName, clip.outputdir, singleFile = True)
   if not res['OK']:
     gLogger.error(res['Message'])
     dexit(1)