From 37b1d7a30ae1ffbcaea483b7b5a7aae3153bea88 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Wed, 20 Nov 2024 18:11:54 +0100 Subject: [PATCH] fix: removed dirac-populate-component-db --- .../Framework/ComponentMonitoring/index.rst | 2 - setup.cfg | 1 - .../scripts/dirac_populate_component_db.py | 195 ------------------ 3 files changed, 198 deletions(-) delete mode 100755 src/DIRAC/FrameworkSystem/scripts/dirac_populate_component_db.py diff --git a/docs/source/AdministratorGuide/Systems/Framework/ComponentMonitoring/index.rst b/docs/source/AdministratorGuide/Systems/Framework/ComponentMonitoring/index.rst index 059d1273fc4..6f4155909c6 100644 --- a/docs/source/AdministratorGuide/Systems/Framework/ComponentMonitoring/index.rst +++ b/docs/source/AdministratorGuide/Systems/Framework/ComponentMonitoring/index.rst @@ -20,8 +20,6 @@ Installation The service constitutes of one database (InstalledComponentsDB) and one service (Framework/ComponentMonitoring). These service and DB may have been installed already when DIRAC was installed the first time. -The script ``dirac-populate-component-db`` should then be used to populate the DB tables with the necessary information. - Interacting with the static component monitoring ------------------------------------------------ diff --git a/setup.cfg b/setup.cfg index 31e59d9390d..ab177585786 100644 --- a/setup.cfg +++ b/setup.cfg @@ -174,7 +174,6 @@ console_scripts = dirac-admin-update-pilot = DIRAC.FrameworkSystem.scripts.dirac_admin_update_pilot:main [admin] dirac-admin-users-with-proxy = DIRAC.FrameworkSystem.scripts.dirac_admin_users_with_proxy:main [admin] dirac-install-component = DIRAC.FrameworkSystem.scripts.dirac_install_component:main [server] - dirac-populate-component-db = DIRAC.FrameworkSystem.scripts.dirac_populate_component_db:main [admin] dirac-proxy-destroy = DIRAC.FrameworkSystem.scripts.dirac_proxy_destroy:main dirac-proxy-get-uploaded-info = DIRAC.FrameworkSystem.scripts.dirac_proxy_get_uploaded_info:main dirac-proxy-info = DIRAC.FrameworkSystem.scripts.dirac_proxy_info:main diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_populate_component_db.py b/src/DIRAC/FrameworkSystem/scripts/dirac_populate_component_db.py deleted file mode 100755 index 58d533a06aa..00000000000 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_populate_component_db.py +++ /dev/null @@ -1,195 +0,0 @@ -#!/usr/bin/env python - -""" -Populates the database with the current installations of components -This script assumes that the InstalledComponentsDB, the -ComponentMonitoring service and the Notification service are installed and running -""" -from datetime import datetime - -from DIRAC import S_OK, gLogger -from DIRAC import exit as DIRACexit -from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI -from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations -from DIRAC.Core.Base.Script import Script -from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient -from DIRAC.FrameworkSystem.Client.SystemAdministratorIntegrator import SystemAdministratorIntegrator -from DIRAC.FrameworkSystem.Utilities import MonitoringUtilities - -global excludedHosts -excludedHosts = [] - - -def setExcludedHosts(value): - global excludedHosts - - excludedHosts = value.split(",") - return S_OK() - - -@Script() -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 = "" - - # 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 = "unknown" - - 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(f"Can not send unreachable host notification mail: {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(f"Host {host}: {result['Message']}") - continue - if not hostResult["OK"]: - gLogger.error(f"Host {host}: {hostResult['Message']}") - continue - if not infoResult["OK"]: - gLogger.error(f"Host {host}: {infoResult['Message']}") - continue - if mySQLResult["OK"]: - if not allDBResult["OK"]: - gLogger.error(f"Host {host}: {allDBResult['Message']}") - continue - if not availableDBResult["OK"]: - gLogger.error(f"Host {host}: {availableDBResult['Message']}") - continue - else: - hasMySQL = False - - 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(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) - - # 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"]) - - -if __name__ == "__main__": - main()