Esempio n. 1
0
def main():
  Script.parseCommandLine(ignoreErrors=True)
  args = Script.getPositionalArgs()

  arg = "".join(args)

  if not len(arg) > 0:
    gLogger.error("Missing argument")
    DIRACexit(2)

  try:
    head, body = arg.split("\\n\\n")
  except Exception as x:
    head = "To: %s" % arg
    body = sys.stdin.read()

  try:
    tmp, body = body.split("\\n\\n")
    head = tmp + "\\n" + head
  except Exception as x:
    pass

  body = "".join(body.strip())

  try:
    headers = dict((i.strip(), j.strip()) for i, j in
                   (item.split(':') for item in head.split('\\n')))
  except BaseException:
    gLogger.error("Failed to convert string: %s to email headers" % head)
    DIRACexit(4)

  if "To" not in headers:
    gLogger.error("Failed to get 'To:' field from headers %s" % head)
    DIRACexit(5)
  to = headers["To"]

  origin = "%s@%s" % (os.getenv("LOGNAME", "dirac"), socket.getfqdn())
  if "From" in headers:
    origin = headers["From"]

  subject = "Sent from %s" % socket.getfqdn()
  if "Subject" in headers:
    subject = headers["Subject"]

  ntc = NotificationClient()
  print("sendMail(%s,%s,%s,%s,%s)" % (to, subject, body, origin, False))
  result = ntc.sendMail(to, subject, body, origin, localAttempt=False)
  if not result["OK"]:
    gLogger.error(result["Message"])
    DIRACexit(6)

  DIRACexit(0)
Esempio n. 2
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()
Esempio n. 3
0
def main():
    global vo
    global noVOFlag
    global allVOsFlag

    Script.registerSwitch("V:", "vo=", "Virtual Organization", setVO)
    Script.registerSwitch("a", "all", "All Virtual Organizations flag",
                          setAllVO)
    Script.registerSwitch("n", "noVO",
                          "No Virtual Organizations assigned flag", setNoVO)

    Script.parseCommandLine()

    from DIRAC import gConfig, gLogger
    from DIRAC.ResourceStatusSystem.Client.ResourceStatus import ResourceStatus
    from DIRAC.Core.Utilities.PrettyPrint import printTable
    from DIRAC.Core.Security.ProxyInfo import getVOfromProxyGroup

    storageCFGBase = "/Resources/StorageElements"

    res = gConfig.getSections(storageCFGBase, True)
    if not res['OK']:
        gLogger.error('Failed to get storage element info')
        gLogger.error(res['Message'])
        DIRACexit(1)

    gLogger.info("%s %s %s" %
                 ('Storage Element'.ljust(25), 'Read Status'.rjust(15),
                  'Write Status'.rjust(15)))

    seList = sorted(res['Value'])

    resourceStatus = ResourceStatus()

    res = resourceStatus.getElementStatus(seList, "StorageElement")
    if not res['OK']:
        gLogger.error("Failed to get StorageElement status for %s" %
                      str(seList))
        DIRACexit(1)

    fields = ['SE', 'ReadAccess', 'WriteAccess', 'RemoveAccess', 'CheckAccess']
    records = []

    if vo is None and not allVOsFlag:
        result = getVOfromProxyGroup()
        if not result['OK']:
            gLogger.error('Failed to determine the user VO')
            DIRACexit(1)
        vo = result['Value']

    for se, statusDict in res['Value'].items():

        # Check if the SE is allowed for the user VO
        if not allVOsFlag:
            voList = gConfig.getValue('/Resources/StorageElements/%s/VO' % se,
                                      [])
            if noVOFlag and voList:
                continue
            if voList and vo not in voList:
                continue

        record = [se]
        for status in fields[1:]:
            value = statusDict.get(status, 'Unknown')
            record.append(value)
        records.append(record)

    printTable(fields, records, numbering=False, sortField='SE')

    DIRACexit(0)
Esempio n. 4
0
componentType = args[0]

if len(args) == 2:
    system, component = args[1].split("/")
else:
    system = args[1]
    component = args[2]

# imports
from DIRAC import gConfig
from DIRAC import exit as DIRACexit

from DIRAC.Core.Utilities.Extensions import extensionsByPriority
from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

#

gComponentInstaller.exitOnError = True

result = gComponentInstaller.addDefaultOptionsToCS(gConfig,
                                                   componentType,
                                                   system,
                                                   component,
                                                   extensionsByPriority(),
                                                   specialOptions={},
                                                   overwrite=False)
if not result["OK"]:
    print("ERROR:", result["Message"])
else:
    DIRACexit()
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']:
Esempio n. 6
0
def main():
    global excludedHosts
    Script.registerSwitch(
        "e:", "exclude=",
        "Comma separated list of hosts to be excluded from the scanning process",
        setExcludedHosts)
    Script.parseCommandLine(ignoreErrors=False)

    componentType = ""

    # Get my setup
    mySetup = gConfig.getValue("DIRAC/Setup")

    # Retrieve information from all the hosts
    client = SystemAdministratorIntegrator(exclude=excludedHosts)
    resultAll = client.getOverallStatus()
    if not resultAll["OK"]:
        gLogger.error(resultAll["Message"])
        DIRACexit(-1)

    # Retrieve user installing the component
    result = getProxyInfo()
    if result["OK"]:
        user = result["Value"]["username"]
    else:
        DIRACexit(-1)
    if not user:
        user = "******"

    for host in resultAll["Value"]:
        if not resultAll["Value"][host]["OK"]:
            # If the host cannot be contacted, exclude it and send message
            excludedHosts.append(host)

            result = NotificationClient().sendMail(
                Operations().getValue("EMail/Production", []),
                "Unreachable host",
                "\ndirac-populate-component-db: Could not fill the database with the components from unreachable host %s\n"
                % host,
            )
            if not result["OK"]:
                gLogger.error(
                    "Can not send unreachable host notification mail: %s" %
                    result["Message"])

    resultHosts = client.getHostInfo()
    if not resultHosts["OK"]:
        gLogger.error(resultHosts["Message"])
        DIRACexit(-1)
    resultInfo = client.getInfo()
    if not resultInfo["OK"]:
        gLogger.error(resultInfo["Message"])
        DIRACexit(-1)
    resultMySQL = client.getMySQLStatus()
    if not resultMySQL["OK"]:
        gLogger.error(resultMySQL["Message"])
        DIRACexit(-1)
    resultAllDB = client.getDatabases()
    if not resultAllDB["OK"]:
        gLogger.error(resultAllDB["Message"])
        DIRACexit(-1)
    resultAvailableDB = client.getAvailableDatabases()
    if not resultAvailableDB["OK"]:
        gLogger.error(resultAvailableDB["Message"])
        DIRACexit(-1)

    records = []
    finalSet = list(set(resultAll["Value"]) - set(excludedHosts))
    for host in finalSet:
        hasMySQL = True
        result = resultAll["Value"][host]
        hostResult = resultHosts["Value"][host]
        infoResult = resultInfo["Value"][host]
        mySQLResult = resultMySQL["Value"][host]
        allDBResult = resultAllDB["Value"][host]
        availableDBResult = resultAvailableDB["Value"][host]

        if not result["OK"]:
            gLogger.error("Host %s: %s" % (host, result["Message"]))
            continue
        if not hostResult["OK"]:
            gLogger.error("Host %s: %s" % (host, hostResult["Message"]))
            continue
        if not infoResult["OK"]:
            gLogger.error("Host %s: %s" % (host, infoResult["Message"]))
            continue
        if mySQLResult["OK"]:
            if not allDBResult["OK"]:
                gLogger.error("Host %s: %s" % (host, allDBResult["Message"]))
                continue
            if not availableDBResult["OK"]:
                gLogger.error("Host %s: %s" %
                              (host, availableDBResult["Message"]))
                continue
        else:
            hasMySQL = False

        setup = infoResult["Value"]["Setup"]
        if setup != mySetup:
            continue

        cpu = hostResult["Value"]["CPUModel"].strip()
        rDict = result["Value"]
        # Components other than databases
        for compType in rDict:
            if componentType and componentType != compType:
                continue
            for system in rDict[compType]:
                components = sorted(rDict[compType][system])
                for component in components:
                    record = {"Installation": {}, "Component": {}, "Host": {}}
                    if rDict[compType][system][component][
                            "Installed"] and component != "ComponentMonitoring":
                        runitStatus = str(
                            rDict[compType][system][component]["RunitStatus"])
                        if runitStatus != "Unknown":
                            module = str(
                                rDict[compType][system][component]["Module"])
                            record["Component"]["System"] = system
                            record["Component"]["Module"] = module
                            # Transform 'Services' into 'service', 'Agents' into 'agent' ...
                            record["Component"]["Type"] = compType.lower()[:-1]
                            record["Host"]["HostName"] = host
                            record["Host"]["CPU"] = cpu
                            record["Installation"]["Instance"] = component
                            record["Installation"][
                                "InstallationTime"] = datetime.utcnow()
                            record["Installation"]["InstalledBy"] = user
                            records.append(record)

        # Databases
        csClient = CSAPI()
        cfg = csClient.getCurrentCFG()["Value"]

        if hasMySQL:
            allDB = allDBResult["Value"]
            availableDB = availableDBResult["Value"]

            for db in allDB:
                # Check for DIRAC only databases
                if db in availableDB and db != "InstalledComponentsDB":
                    # Check for 'installed' databases
                    isSection = cfg.isSection(
                        "Systems/" + availableDB[db]["System"] + "/" +
                        cfg.getOption("DIRAC/Setups/" + setup + "/" +
                                      availableDB[db]["System"]) +
                        "/Databases/" + db + "/")
                    if isSection:
                        record = {
                            "Installation": {},
                            "Component": {},
                            "Host": {}
                        }
                        record["Component"]["System"] = availableDB[db][
                            "System"]
                        record["Component"]["Module"] = db
                        record["Component"]["Type"] = "DB"
                        record["Host"]["HostName"] = host
                        record["Host"]["CPU"] = cpu
                        record["Installation"]["Instance"] = db
                        record["Installation"][
                            "InstallationTime"] = datetime.utcnow()
                        record["Installation"]["InstalledBy"] = user
                        records.append(record)

    monitoringClient = ComponentMonitoringClient()

    # Add the installations to the database
    for record in records:
        result = MonitoringUtilities.monitorInstallation(
            record["Component"]["Type"],
            record["Component"]["System"],
            record["Installation"]["Instance"],
            record["Component"]["Module"],
            record["Host"]["CPU"],
            record["Host"]["HostName"],
        )
        if not result["OK"]:
            gLogger.error(result["Message"])
Esempio n. 7
0
pr.outConfigName = pr.configName
# Other parameters from the request page
pr.dqFlag = '{{inDataQualityFlag}}'  # UNCHECKED
pr.dataTakingConditions = '{{simDesc}}'
pr.processingPass = '******'
if p1[0] == 1 and pr.prodsTypeList[0].lower() != 'mcsimulation':
  pr.bkFileType = '{{inFileType}}'
  pr.bkQueries = ['Full']
elif p1[0] == 1 and pr.prodsTypeList[0].lower() == 'mcsimulation':
  pr.bkQueries = ['']
  pr.prodGroup = '{{pDsc}}'
elif p1[0] != 1 and pr.prodsTypeList[0].lower() != 'mcsimulation':
  pr.bkQueries = ['fromPreviousProd']
  if not pr.previousProdID:
    gLogger.error( "Please specify an input production" )
    DIRACexit( 2 )
pr.eventType = '{{eventType}}'

if modulesList:
  pr.modulesList = modulesList.replace( ' ', '' ).split( ',' )

if localTestFlag:
  pr.testFlag = True
  pr.publishFlag = False
  pr.prodsToLaunch = [1]

if validationFlag:
  pr.outConfigName = 'validation'

if enablePopularityReport:
  pr.modulesList.append( 'FileUsage' )
Esempio n. 8
0
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

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

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    Script.parseCommandLine()
    args = Script.getPositionalArgs()

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

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

    cType = None
    system = args[0]
    component = args[1]
    compOrMod = module if module else component

    result = gComponentInstaller.getSoftwareComponents(getCSExtensions())
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)
    else:
        availableComponents = result['Value']

    for compType in availableComponents:
        if system in availableComponents[
                compType] and compOrMod in availableComponents[compType][
                    system]:
            cType = compType[:-1].lower()
            break

    if not cType:
        gLogger.error('Component %s/%s is not available for installation' %
                      (system, component))
        DIRACexit(1)

    if module:
        result = gComponentInstaller.addDefaultOptionsToCS(gConfig,
                                                           cType,
                                                           system,
                                                           module,
                                                           getCSExtensions(),
                                                           overwrite=overwrite)
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            getCSExtensions(),
            specialOptions=specialOptions,
            overwrite=overwrite,
            addDefaultOptions=False)
    else:
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            getCSExtensions(),
            specialOptions=specialOptions,
            overwrite=overwrite)

    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)
    else:
        result = gComponentInstaller.installComponent(cType, system, component,
                                                      getCSExtensions(),
                                                      module)
        if not result['OK']:
            gLogger.error(result['Message'])
            DIRACexit(1)
        else:
            gLogger.notice(
                'Successfully installed component %s in %s system, now setting it up'
                % (component, system))
            result = gComponentInstaller.setupComponent(
                cType, system, component, getCSExtensions(), module)
            if not result['OK']:
                gLogger.error(result['Message'])
                DIRACexit(1)
            if component == 'ComponentMonitoring':
                result = MonitoringUtilities.monitorInstallation(
                    'DB', system, 'InstalledComponentsDB')
                if not result['OK']:
                    gLogger.error(result['Message'])
                    DIRACexit(1)
            result = MonitoringUtilities.monitorInstallation(
                cType, system, component, module)
            if not result['OK']:
                gLogger.error(result['Message'])
                DIRACexit(1)
            gLogger.notice('Successfully completed the installation of %s/%s' %
                           (system, component))
            DIRACexit()
Esempio n. 9
0
import socket , sys , os

from DIRAC                                              import gLogger, exit as DIRACexit
from DIRAC.Core.Base                                    import Script
from DIRAC.FrameworkSystem.Client.NotificationClient    import NotificationClient

Script.setUsageMessage( ''.join( __doc__ ) )

Script.parseCommandLine( ignoreErrors = True )
args = Script.getPositionalArgs()

arg = "".join( args )

if not len( arg ) > 0:
  gLogger.error( "Missing argument" )
  DIRACexit( 2 )

try:
  head , body = arg.split( "\\n\\n" )
except Exception , x:
  head = "To: %s" % arg
  body = sys.stdin.read()

try:
  tmp , body = body.split( "\\n\\n" )
  head = tmp + "\\n" + head
except Exception , x:
  pass

body = "".join( body.strip() )
Esempio n. 10
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()
Esempio n. 11
0
from DIRAC import gLogger, exit as DIRACexit
from DIRAC.Core.Base import Script
from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient

Script.setUsageMessage(''.join(__doc__))

Script.parseCommandLine(ignoreErrors=True)
args = Script.getPositionalArgs()

arg = "".join(args)

try:
    head, body = arg.split("\\n\\n")
except Exception, x:
    gLogger.error("Failed to get e-mail header and body from: %s" % arg)
    DIRACexit(2)

body = "".join(body)

try:
    headers = dict((i.strip(), j.strip())
                   for i, j in (item.split(':') for item in head.split('\\n')))
except:
    gLogger.error("Failed to convert string: %s to email headers" % head)
    DIRACexit(3)

if not "To" in headers:
    gLogger.error("Failed to get 'To:' field from headers %s" % head)
    DIRACexit(4)
to = headers["To"]
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    # 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)
    Script.parseCommandLine()
    args = Script.getPositionalArgs()

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

    if len(args) != 2:
        Script.showHelp()
        DIRACexit(1)

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

    result = gComponentInstaller.addDefaultOptionsToCS(
        gConfig,
        "service",
        system,
        component,
        extensionsByPriority(),
        specialOptions=specialOptions,
        overwrite=overwrite,
    )

    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = gComponentInstaller.addTornadoOptionsToCS(gConfig)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = gComponentInstaller.installTornado()
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    gLogger.notice(
        "Successfully installed component %s in %s system, now setting it up" %
        (component, system))
    result = gComponentInstaller.setupTornadoService(system, component,
                                                     extensionsByPriority(),
                                                     module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = MonitoringUtilities.monitorInstallation("service", system,
                                                     component, module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice("Successfully completed the installation of %s/%s" %
                   (system, component))
    DIRACexit()
Esempio n. 13
0
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

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

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    Script.parseCommandLine()
    args = Script.getPositionalArgs()

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

    if len(args) != 2:
        Script.showHelp()
        DIRACexit(1)

    system = args[0]
    component = args[1]
    compOrMod = module if module else component

    result = gComponentInstaller.addDefaultOptionsToCS(
        gConfig,
        'service',
        system,
        component,
        getCSExtensions(),
        specialOptions=specialOptions,
        overwrite=overwrite)

    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    result = gComponentInstaller.addTornadoOptionsToCS(gConfig)
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    result = gComponentInstaller.installTornado()
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    gLogger.notice(
        'Successfully installed component %s in %s system, now setting it up' %
        (component, system))
    result = gComponentInstaller.setupTornadoService(system, component,
                                                     getCSExtensions(), module)
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    result = MonitoringUtilities.monitorInstallation('service', system,
                                                     component, module)
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)
    gLogger.notice('Successfully completed the installation of %s/%s' %
                   (system, component))
    DIRACexit()
Esempio n. 14
0
def main():
    global excludedHosts
    Script.registerSwitch(
        "e:", "exclude=",
        "Comma separated list of hosts to be excluded from the scanning process",
        setExcludedHosts)
    Script.parseCommandLine(ignoreErrors=False)

    componentType = ''

    # Get my setup
    mySetup = gConfig.getValue('DIRAC/Setup')

    # Retrieve information from all the hosts
    client = SystemAdministratorIntegrator(exclude=excludedHosts)
    resultAll = client.getOverallStatus()

    # Retrieve user installing the component
    result = getProxyInfo()
    if result['OK']:
        user = result['Value']['username']
    else:
        DIRACexit(-1)
    if not user:
        user = '******'

    notificationClient = NotificationClient()
    for host in resultAll['Value']:
        if not resultAll['Value'][host]['OK']:
            # If the host cannot be contacted, exclude it and send message
            excludedHosts.append(host)

            result = notificationClient.sendMail(
                Operations().getValue('EMail/Production',
                                      []), 'Unreachable host',
                '\ndirac-populate-component-db: Could not fill the database with the components from unreachable host %s\n'
                % host)
            if not result['OK']:
                gLogger.error(
                    'Can not send unreachable host notification mail: %s' %
                    result['Message'])

    if not resultAll['OK']:
        gLogger.error(resultAll['Message'])
        DIRACexit(-1)
    resultHosts = client.getHostInfo()
    if not resultHosts['OK']:
        gLogger.error(resultHosts['Message'])
        DIRACexit(-1)
    resultInfo = client.getInfo()
    if not resultInfo['OK']:
        gLogger.error(resultInfo['Message'])
        DIRACexit(-1)
    resultMySQL = client.getMySQLStatus()
    if not resultMySQL['OK']:
        gLogger.error(resultMySQL['Message'])
        DIRACexit(-1)
    resultAllDB = client.getDatabases()
    if not resultAllDB['OK']:
        gLogger.error(resultAllDB['Message'])
        DIRACexit(-1)
    resultAvailableDB = client.getAvailableDatabases()
    if not resultAvailableDB['OK']:
        gLogger.error(resultAvailableDB['Message'])
        DIRACexit(-1)

    records = []
    finalSet = list(set(resultAll['Value']) - set(excludedHosts))
    for host in finalSet:
        hasMySQL = True
        result = resultAll['Value'][host]
        hostResult = resultHosts['Value'][host]
        infoResult = resultInfo['Value'][host]
        mySQLResult = resultMySQL['Value'][host]
        allDBResult = resultAllDB['Value'][host]
        availableDBResult = resultAvailableDB['Value'][host]

        if not result['OK']:
            gLogger.error('Host %s: %s' % (host, result['Message']))
            continue
        if not hostResult['OK']:
            gLogger.error('Host %s: %s' % (host, hostResult['Message']))
            continue
        if not infoResult['OK']:
            gLogger.error('Host %s: %s' % (host, infoResult['Message']))
            continue
        if mySQLResult['OK']:
            if not allDBResult['OK']:
                gLogger.error('Host %s: %s' % (host, allDBResult['Message']))
                continue
            if not availableDBResult['OK']:
                gLogger.error('Host %s: %s' %
                              (host, availableDBResult['Message']))
                continue
        else:
            hasMySQL = False

        setup = infoResult['Value']['Setup']
        if setup != mySetup:
            continue

        cpu = hostResult['Value']['CPUModel'].strip()
        rDict = result['Value']
        # Components other than databases
        for compType in rDict:
            if componentType and componentType != compType:
                continue
            for system in rDict[compType]:
                components = sorted(rDict[compType][system])
                for component in components:
                    record = {'Installation': {}, 'Component': {}, 'Host': {}}
                    if rDict[compType][system][component]['Installed'] and \
                            component != 'ComponentMonitoring':
                        runitStatus = \
                            str(rDict[compType][system][component]['RunitStatus'])
                        if runitStatus != 'Unknown':
                            module = \
                                str(rDict[compType][system][component]['Module'])
                            record['Component']['System'] = system
                            record['Component']['Module'] = module
                            # Transform 'Services' into 'service', 'Agents' into 'agent' ...
                            record['Component']['Type'] = compType.lower()[:-1]
                            record['Host']['HostName'] = host
                            record['Host']['CPU'] = cpu
                            record['Installation']['Instance'] = component
                            record['Installation'][
                                'InstallationTime'] = datetime.utcnow()
                            record['Installation']['InstalledBy'] = user
                            records.append(record)

        # Databases
        csClient = CSAPI()
        cfg = csClient.getCurrentCFG()['Value']

        if hasMySQL:
            allDB = allDBResult['Value']
            availableDB = availableDBResult['Value']

            for db in allDB:
                # Check for DIRAC only databases
                if db in availableDB and db != 'InstalledComponentsDB':
                    # Check for 'installed' databases
                    isSection = cfg.isSection(
                        'Systems/' + availableDB[db]['System'] + '/' +
                        cfg.getOption('DIRAC/Setups/' + setup + '/' +
                                      availableDB[db]['System']) +
                        '/Databases/' + db + '/')
                    if isSection:
                        record = {
                            'Installation': {},
                            'Component': {},
                            'Host': {}
                        }
                        record['Component']['System'] = availableDB[db][
                            'System']
                        record['Component']['Module'] = db
                        record['Component']['Type'] = 'DB'
                        record['Host']['HostName'] = host
                        record['Host']['CPU'] = cpu
                        record['Installation']['Instance'] = db
                        record['Installation'][
                            'InstallationTime'] = datetime.utcnow()
                        record['Installation']['InstalledBy'] = user
                        records.append(record)

    monitoringClient = ComponentMonitoringClient()

    # Add the installations to the database
    for record in records:
        result = MonitoringUtilities.monitorInstallation(
            record['Component']['Type'], record['Component']['System'],
            record['Installation']['Instance'], record['Component']['Module'],
            record['Host']['CPU'], record['Host']['HostName'])
        if not result['OK']:
            gLogger.error(result['Message'])
Esempio n. 15
0
    if not resultAll['Value'][host]['OK']:
        # If the host cannot be contacted, exclude it and send message
        excludedHosts.append(host)

        result = notificationClient.sendMail(
            Operations().getValue('EMail/Production', []), 'Unreachable host',
            '\ndirac-populate-component-db: Could not fill the database with the components from unreachable host %s\n'
            % host)
        if not result['OK']:
            gLogger.error(
                'Can not send unreachable host notification mail: %s' %
                result['Message'])

if not resultAll['OK']:
    gLogger.error(resultAll['Message'])
    DIRACexit(-1)
resultHosts = client.getHostInfo()
if not resultHosts['OK']:
    gLogger.error(resultHosts['Message'])
    DIRACexit(-1)
resultInfo = client.getInfo()
if not resultInfo['OK']:
    gLogger.error(resultInfo['Message'])
    DIRACexit(-1)
resultMySQL = client.getMySQLStatus()
if not resultMySQL['OK']:
    gLogger.error(resultMySQL['Message'])
    DIRACexit(-1)
resultAllDB = client.getDatabases()
if not resultAllDB['OK']:
    gLogger.error(resultAllDB['Message'])
Esempio n. 16
0
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    # 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)

    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]
    compOrMod = module or component

    result = gComponentInstaller.getSoftwareComponents(extensionsByPriority())
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    availableComponents = result["Value"]

    for compType in availableComponents:
        if system in availableComponents[
                compType] and compOrMod in availableComponents[compType][
                    system]:
            cType = compType[:-1].lower()
            break
    else:
        gLogger.error("Component %s/%s is not available for installation" %
                      (system, component))
        DIRACexit(1)

    if module:
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            module,
            extensionsByPriority(),
            overwrite=overwrite)
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            extensionsByPriority(),
            specialOptions=specialOptions,
            overwrite=overwrite,
            addDefaultOptions=False,
        )
    else:
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            extensionsByPriority(),
            specialOptions=specialOptions,
            overwrite=overwrite,
        )

    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    result = gComponentInstaller.installComponent(cType, system, component,
                                                  extensionsByPriority(),
                                                  module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice(
        "Successfully installed component %s in %s system, now setting it up" %
        (component, system))
    result = gComponentInstaller.setupComponent(cType, system, component,
                                                extensionsByPriority(), module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    if component == "ComponentMonitoring":
        result = MonitoringUtilities.monitorInstallation(
            "DB", system, "InstalledComponentsDB")
        if not result["OK"]:
            gLogger.error(result["Message"])
            DIRACexit(1)
    result = MonitoringUtilities.monitorInstallation(cType, system, component,
                                                     module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice("Successfully completed the installation of %s/%s" %
                   (system, component))
    DIRACexit()
Esempio n. 17
0
#!/usr/bin/env python
########################################################################
# $HeadURL$
# File :    dirac-dms-add-file
# Author :  Stuart Paterson
########################################################################
"""
  Obsoleted
"""
__RCSID__ = "$Id$"

from DIRAC.Core.Base import Script

Script.setUsageMessage('\n'.join([
    __doc__.split('\n')[1], 'Usage:',
    '  This is an obsoleted command, use dirac-dms-add-file instead'
]))
Script.parseCommandLine(ignoreErrors=True)
args = Script.getPositionalArgs()

from DIRAC import gLogger, exit as DIRACexit

if len(args) < 3 or len(args) > 4:
    Script.showHelp()

gLogger.notice('This is an obsoleted command, use dirac-dms-add-file instead')

DIRACexit(0)
            '$s -T [email protected] -F [email protected] -S subject -B "My Body\n is ace"'
        )


if __name__ == "__main__":
    cli = Params()
    cli.registerSwitchs()
    Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import gLogger, exit as DIRACexit

    from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient

    if not cli.to or not cli.fr or not cli.subject:
        gLogger.error("Missing argument")
        DIRACexit(2)
    if not cli.body and not cli.filename:
        gLogge.error("Missing body")
        DIRACexit(2)

    if cli.filename:
        cli.body = "".join(file(cli.filename, "r").readlines())

    ntc = NotificationClient()
    gLogger.verbose("Sending:",
                    " ".join([cli.to, cli.subject, cli.body, cli.fr]))
    print "sendMail(%s,%s,%s,%s,%s)" % (cli.to, cli.subject, cli.body, cli.fr,
                                        False)
    if not cli.debugMail:
        gLogger.info("trying to first submit locally - debug mode.")
        result = ntc.sendMail(cli.debugMail,