def findHdbsqlPathBySid(fs, installationPath, dbSid, is_cmd_exist, shell_executor): binName = _HDBSQL_BINARY_NAME if fs._shell.isWinOs(): binName = '%s.exe' % binName pathTool = file_system.getPath(fs) alternatives = ( file_system.Path(installationPath, pathTool) + _HDBCLIENT_FOLDER_NAME + binName, file_system.Path('/usr/sap', pathTool) + _HDBCLIENT_FOLDER_NAME + binName, file_system.Path('/usr/sap', pathTool) + dbSid + _HDBCLIENT_FOLDER_NAME + binName, file_system.Path('/usr/sap', pathTool) + dbSid + 'exe' + 'linuxx86_64' + 'hdb' + binName, file_system.Path('/usr/sap', pathTool) + dbSid + r'SYS' + r'global' + _HDBCLIENT_FOLDER_NAME + binName, file_system.Path('/sapmnt', pathTool) + dbSid + _HDBCLIENT_FOLDER_NAME + binName, file_system.Path('/sapmnt', pathTool) + dbSid + r'global' + _HDBCLIENT_FOLDER_NAME + binName, ) alternatives = imap(shell_interpreter.normalizePath, alternatives) binpath = findFirst(Sfn(fs.exists), alternatives) if not binpath: bin_in_path = is_cmd_exist(binName) | shell_executor if not bin_in_path: raise NoHdbsqlException('Hdbsql binary not found') binpath = binName return binpath
def report(host_id, mgr_version, server_configs, vm_configs): '@types: str, str, list[ShowServerCmd.Config], list[ShowVmCmd.Config] -> list[osh]' # take manager from one of discovered server configs # if present build in one way otherwise in other get_manager_uuid = ovm_cli.ShowServerCmd.Config.manager_uuid.fget config = findFirst(get_manager_uuid, server_configs) mgr_osh, oshs = _report_manager(config.manager_uuid, mgr_version, host_id) get_server_id = comp(first, ShowVmCmd.Config.server.fget) vm_configs_by_server_id = groupby(get_server_id, vm_configs) for server_config in server_configs: # report server pool p_osh = report_server_pool(server_config.server_pool, mgr_osh) oshs.append(p_osh) # report OVM server ips = (server_config.server.ip_address,) server_name = server_config.server.name host_osh, h_oshs = report_server_node(server_name, ips, p_osh) oshs.extend(h_oshs) # report hypervisor hypervisor_osh = report_hypervisor(server_config, host_osh) oshs.append(hypervisor_osh) # report domain config oshs.append(report_server_domain_config(server_config, host_osh)) server_id = server_config.server.id # report VMs vms = vm_configs_by_server_id.get(server_id, ()) for vm_config in vms: vm_host_osh, _oshs = report_vm_node(vm_config, hypervisor_osh) if _oshs: oshs.extend(_oshs) oshs.append(report_vm_domain_config(vm_config, vm_host_osh)) return filter(None, oshs)
def report(host_id, mgr_version, server_configs, vm_configs): '@types: str, str, list[ShowServerCmd.Config], list[ShowVmCmd.Config] -> list[osh]' # take manager from one of discovered server configs # if present build in one way otherwise in other get_manager_uuid = ovm_cli.ShowServerCmd.Config.manager_uuid.fget config = findFirst(get_manager_uuid, server_configs) mgr_osh, oshs = _report_manager(config.manager_uuid, mgr_version, host_id) get_server_id = comp(first, ShowVmCmd.Config.server.fget) vm_configs_by_server_id = groupby(get_server_id, vm_configs) for server_config in server_configs: # report server pool p_osh = report_server_pool(server_config.server_pool, mgr_osh) oshs.append(p_osh) # report OVM server ips = (server_config.server.ip_address, ) server_name = server_config.server.name host_osh, h_oshs = report_server_node(server_name, ips, p_osh) oshs.extend(h_oshs) # report hypervisor hypervisor_osh = report_hypervisor(server_config, host_osh) oshs.append(hypervisor_osh) # report domain config oshs.append(report_server_domain_config(server_config, host_osh)) server_id = server_config.server.id # report VMs vms = vm_configs_by_server_id.get(server_id, ()) for vm_config in vms: vm_host_osh, _oshs = report_vm_node(vm_config, hypervisor_osh) if _oshs: oshs.extend(_oshs) oshs.append(report_vm_domain_config(vm_config, vm_host_osh)) return filter(None, oshs)
def handler(self, items): is_db2_home_dir = Fn(operator.eq, self.db2_home_path, fptools._) create_path = Fn(file_system.Path, fptools._, self.db2_home_path.path_tool) get_path_name = operator.attrgetter('DB2 Path Name') item = iteratortools.findFirst( comp(is_db2_home_dir, create_path, get_path_name), items) return item and RegistryPath(item.keyPath)
def isApplicable(cls, context): r'''Applicable only in case if * profile information is known and contained in the `sap_instance_profile` attribute of application * machine is of Windows type * one of supported processes is found in component ''' processes = context.application.getProcesses() return bool(findFirst(cls.is_required_process, processes))
def handler(self, items): is_db2_home_dir = Fn(operator.eq, self.db2_home_path, fptools._) create_path = Fn(file_system.Path, fptools._, self.db2_home_path.path_tool) get_path_name = operator.attrgetter('DB2 Path Name') item = iteratortools.findFirst(comp(is_db2_home_dir, create_path, get_path_name), items) return item and RegistryPath(item.keyPath)
def _inDiscoveredSystems(pairs, sysPairsBySysName): ''' Check whether usage pair has system that belongs discovered systems @types: list[tuple[str, str]], dict[str, tuple[System, osh]] -> bool ''' if pairs: getSystemName = first systems = imap(getSystemName, pairs) r = truth(findFirst(sysPairsBySysName.has_key, systems)) if not r: logger.debug("Databases that do not serve discovered systems: %s" % pairs) return r
def _discoverServers(solman, hostnameToAddress, sysPairsBySysName, sendVector, reportError, resolveIps): ''' Discover SAP instances related to already discovered systems @type hostnameToAddress: dict[str, sap.Address] @type sysPairsBySysName: dict[str, tuple[System, osh]] ''' try: # get servers by one of the specified queries queries = (GetServersWithNotActiveFlag(), GetServers()) queryExecutor = TableQueryExecutor(solman) result = imap(Sfn(queryExecutor.executeQuery), queries) servers = findFirst(truth, result) or () # group servers by system name pairsBySysName = groupby(GetServers.Server.systemName.fget, servers) inDiscoveredSystems = comp(sysPairsBySysName.get, first) pairs = ifilter(inDiscoveredSystems, pairsBySysName.iteritems()) resolveIps = comp(resolveIps, GetServers.Server.hostname.fget) for sysName, servers in pairs: logger.info("Found %s servers for %s system" % (len(servers), sysName)) # collect parsed names for each server parseServerName = comp(GetServers.parseServerName, GetServers.Server.name.fget) parsedServerNames = imap(parseServerName, servers) # resolve IPs for each server ips = imap(resolveIps, servers) # get information for each server where name and IPs are present infoSeq = ifilter(all, izip(servers, parsedServerNames, ips)) # not interested in server nodes - only instances infoSeq = ifilterfalse(isServerNode, infoSeq) # report each server system, systemOsh = sysPairsBySysName.get(sysName) reportServer = F(_reportServer, fptools._, fptools._, fptools._, system, systemOsh) vector = ObjectStateHolderVector() each(vector.addAll, starmap(reportServer, infoSeq)) sendVector(vector) except (Exception, JException): msg = "Failed to discover servers" logger.warnException(msg) reportError(msg)
def process(cls, context): logger.info("Discover kernel version of SAP Java AS") app = context.application osh = app.applicationOsh shell = context.client processes = ifilter(cls.is_required_process, app.getProcesses()) def _discoverVersion(process): if process.executablePath: use_ld_library_path = not shell.isWinOs() cmd = GetKernelVersionInfo(process.executablePath, use_ld_library_path) return sap_discoverer_by_shell.execute_cmd(shell, cmd) version_info = findFirst(bool, imap(Sfn(_discoverVersion), processes)) if version_info: logger.info("Found kernel version is: %s" % version_info) sap_jee.InstanceBuilder.updateKernelVersion(osh, version_info) else: logger.info("Failed to determine kernel version")
def parseServerName(name): ''' Parse server name that can be of several formats 1) <hostname>_<SID>_<NR> or with spaces unstead of underscore 2) Central Service Instance <NR> of <SID> on <hostname> 3) Dispatcher|Server Node <ID> of <SID> on <hostname> @types: str -> tuple[bool, str, str, str?, str?]? @return: tuple that constitutes from isSCS, hostname, sid, NR?, ID? None returned in case if none of mentioned patterns are supported ''' functions = (GetServers._parseServerFullName, GetServers._parseServerNameWithSpaces, GetServers._parseInstanceName, GetServers._parseScsName, GetServers._parseServerNodeName) callFn = F(applyFn, fptools._, name) return findFirst(truth, imap(callFn, functions))
def findBinPathBySid(binName, mainProcessPath, dbSid, fs): if fs._shell.isWinOs(): binName = '%s.exe' % binName alternatives = () if mainProcessPath: pathTool = file_system.getPath(fs) maxDbHomePath = getMaxDbHomeDir(mainProcessPath, dbSid) if maxDbHomePath: alternatives = (file_system.Path(maxDbHomePath, pathTool) + 'programs' + 'bin' + binName, file_system.Path(maxDbHomePath, pathTool) + 'globalprograms' + 'bin' + binName) else: mainProcessFolder = pathTool.dirName(mainProcessPath).strip('" ') alternatives = (file_system.Path(mainProcessFolder, pathTool) + binName, ) alternatives = (shell_interpreter.normalizePath(path_) for path_ in alternatives) return findFirst(Sfn(fs.exists), alternatives) or binName
def findBinPathBySid(binName, mainProcessPath, dbSid, fs): if fs._shell.isWinOs(): binName = '%s.exe' % binName alternatives = () if mainProcessPath: pathTool = file_system.getPath(fs) maxDbHomePath = getMaxDbHomeDir(mainProcessPath, dbSid) if maxDbHomePath: alternatives = ( file_system.Path(maxDbHomePath, pathTool) + 'programs' + 'bin' + binName, file_system.Path(maxDbHomePath, pathTool) + 'globalprograms' + 'bin' + binName ) else: mainProcessFolder = pathTool.dirName(mainProcessPath).strip('" ') alternatives = ( file_system.Path(mainProcessFolder, pathTool) + binName, ) alternatives = (shell_interpreter.normalizePath(path_) for path_ in alternatives) return findFirst(Sfn(fs.exists), alternatives) or binName
def _determine_system_version(cmps): '@types: list[sap.SoftwareComponent] -> str?' cls = sap_abap_discoverer.SoftwareComponentDiscovererByJco cmp_ = findFirst(cls.containsSapSystemVersion, cmps) return cmp_ and cls.extractSystemVersionFromComponent(cmp_)
def executeAlternateCmds(shell, cmdList): _executeCmd = fptools.partiallyApply(executeCmd, shell, fptools._) return iteratortools.findFirst(isCommandSuccessful, imap(_executeCmd, cmdList))
def isApplicable(self, context): return bool(findFirst(context.application.getProcess, self.PROCESSES))
def _discover_business_objects(framework, solman, component_to_system, should_discover_processes, should_discover_steps, reportCIsInChunks, sap_system_osh): queryExecutor = TableQueryExecutor(solman) execute = queryExecutor.executeQuery # get projects projects = execute(sap_solman_discoverer.GetProjects()) processesByScenarioId = {} business_objects_tree = [] for projectId, responsible in projects: # get project objects objectIds = execute(sap_solman_discoverer.GetProjectObjects(projectId)) if not objectIds: continue objectId = first(objectIds) logger.debug("Project Name %s" % projectId) logger.debug("Project ObjectId %s" % objectId) project = BusinessProject(projectId, responsible, objectId) business_objects_tree.append(project) nameToIdPairs = discoverNodeIdToName(execute, objectId) scenarioInfo = findFirst(_isBusinessScenario, nameToIdPairs) if scenarioInfo: scenarioId, _, _, _ = scenarioInfo logger.debug("Scenario Structure ID %s" % scenarioId) businessScenarious = discoverNodeIdToName(execute, scenarioId) for sId, sName, s_node_id, s_ref_node_id in businessScenarious: logger.debug("Scenario Name %s" % sName) logger.debug("Scenario Node ID %s" % s_node_id) logger.debug("Scenario Ref. Node ID %s" % s_ref_node_id) logger.debug("Scenario Ref. Structure ID %s" % sId) scenario = BusinessScenario(sName, s_node_id, s_ref_node_id) project.add_child(scenario) if not should_discover_processes: continue buisinessProcesses = discoverNodeIdToName(execute, sId) processInfo = findFirst(_isBusinessProcess, buisinessProcesses) if processInfo: processId, _, _, _ = processInfo logger.debug("Process Structure ID %s" % processId) processes = discoverNodeIdToName(execute, processId) processesByScenarioId[sName] = processes for pId, pName, p_node_id, p_ref_node_id in processes: logger.debug("Process Name %s" % pName) logger.debug("Process Node ID %s" % p_node_id) logger.debug("Process Ref. Node ID %s" % p_ref_node_id) logger.debug("Process Ref. Structure ID %s" % pId) process = BusinessProcess(pName, p_node_id) scenario.add_child(process) if not should_discover_steps: continue process_steps = discoverProcessStepNodeIdToName( execute, pId) process_steps_tree = [] process_steps_tree.append(process) if process_steps: for step_ref_tree_id, step_name, step_node_id, step_ref_node_id in process_steps: logger.debug("Process Step Name %s" % step_name) logger.debug("Process Step Node ID %s" % step_node_id) logger.debug("Process Step Ref. Node ID %s" % step_ref_node_id) logger.debug( "Process Step Ref. Structure ID %s" % step_ref_tree_id) process_step = BusinessProcessStep( step_name, step_node_id) process.add_child(process_step) process_step_info = execute( sap_solman_discoverer. GetProcessSubStepById(step_ref_tree_id)) process_sub_steps_node_ids = [] system_name = None # process_step_info should have length of 1 for process_step_ref_tree_id, node_id, tree_id, ref_node_id, component in process_step_info: logger.debug("Component %s" % component) process_step.set_component(component) process_sub_steps_node_ids.append(node_id) system_name = component_to_system.get( component) logger.debug('unit test:', process_sub_steps_node_ids) process_sub_sub_steps = execute( sap_solman_discoverer. GetProcessRefIdsByNodeIds( process_sub_steps_node_ids, only_tree=True)) process_sub_sub_steps_ref_objects = [ a[0] for a in process_sub_sub_steps ] if process_sub_sub_steps_ref_objects: process_sub_sub_steps_tree = execute( sap_solman_discoverer. GetProcessNodeByTreeIds( process_sub_sub_steps_ref_objects)) process_sub_sub_steps_tree_node_ids = [ a[0] for a in process_sub_sub_steps_tree ] if process_sub_sub_steps_tree_node_ids: transactions = execute( sap_solman_discoverer. GetProcessRefIdsByNodeIds( process_sub_sub_steps_tree_node_ids )) for transaction_ref_obj, transaction_node in transactions: logger.debug( "Transaction Ref Object %s" % transaction_ref_obj) transaction = BusinessTransaction( transaction_ref_obj, system_name) process_step.add_child(transaction) if reportCIsInChunks: report_chunk(framework, project, scenario, process_steps_tree, sap_system_osh) process.clear_children() return business_objects_tree
def _discover_business_objects(framework, solman, component_to_system, should_discover_processes, should_discover_steps, reportCIsInChunks, sap_system_osh): queryExecutor = TableQueryExecutor(solman) execute = queryExecutor.executeQuery # get projects projects = execute(sap_solman_discoverer.GetProjects()) processesByScenarioId = {} business_objects_tree = [] for projectId, responsible in projects: # get project objects objectIds = execute(sap_solman_discoverer.GetProjectObjects(projectId)) if not objectIds: continue objectId = first(objectIds) logger.debug("Project Name %s" % projectId) logger.debug("Project ObjectId %s" % objectId) project = BusinessProject(projectId, responsible, objectId) business_objects_tree.append(project) nameToIdPairs = discoverNodeIdToName(execute, objectId) scenarioInfo = findFirst(_isBusinessScenario, nameToIdPairs) if scenarioInfo: scenarioId, _, _, _ = scenarioInfo logger.debug("Scenario Structure ID %s" % scenarioId) businessScenarious = discoverNodeIdToName(execute, scenarioId) for sId, sName, s_node_id, s_ref_node_id in businessScenarious: logger.debug("Scenario Name %s" % sName) logger.debug("Scenario Node ID %s" % s_node_id) logger.debug("Scenario Ref. Node ID %s" % s_ref_node_id) logger.debug("Scenario Ref. Structure ID %s" % sId) scenario = BusinessScenario(sName, s_node_id, s_ref_node_id) project.add_child(scenario) if not should_discover_processes: continue buisinessProcesses = discoverNodeIdToName(execute, sId) processInfo = findFirst(_isBusinessProcess, buisinessProcesses) if processInfo: processId, _, _, _ = processInfo logger.debug("Process Structure ID %s" % processId) processes = discoverNodeIdToName(execute, processId) processesByScenarioId[sName] = processes for pId, pName, p_node_id, p_ref_node_id in processes: logger.debug("Process Name %s" % pName) logger.debug("Process Node ID %s" % p_node_id) logger.debug("Process Ref. Node ID %s" % p_ref_node_id) logger.debug("Process Ref. Structure ID %s" % pId) process = BusinessProcess(pName, p_node_id) scenario.add_child(process) if not should_discover_steps: continue process_steps = discoverProcessStepNodeIdToName(execute, pId) process_steps_tree = [] process_steps_tree.append(process) if process_steps: for step_ref_tree_id, step_name, step_node_id, step_ref_node_id in process_steps: logger.debug("Process Step Name %s" % step_name) logger.debug("Process Step Node ID %s" % step_node_id) logger.debug("Process Step Ref. Node ID %s" % step_ref_node_id) logger.debug("Process Step Ref. Structure ID %s" % step_ref_tree_id) process_step = BusinessProcessStep(step_name, step_node_id) process.add_child(process_step) process_step_info = execute(sap_solman_discoverer.GetProcessSubStepById(step_ref_tree_id)) process_sub_steps_node_ids = [] system_name = None # process_step_info should have length of 1 for process_step_ref_tree_id, node_id, tree_id, ref_node_id, component in process_step_info: logger.debug("Component %s" % component) process_step.set_component(component) process_sub_steps_node_ids.append(node_id) system_name = component_to_system.get(component) logger.debug('unit test:', process_sub_steps_node_ids) process_sub_sub_steps = execute(sap_solman_discoverer.GetProcessRefIdsByNodeIds(process_sub_steps_node_ids, only_tree=True)) process_sub_sub_steps_ref_objects = [a[0] for a in process_sub_sub_steps] if process_sub_sub_steps_ref_objects: process_sub_sub_steps_tree = execute(sap_solman_discoverer.GetProcessNodeByTreeIds(process_sub_sub_steps_ref_objects)) process_sub_sub_steps_tree_node_ids = [a[0] for a in process_sub_sub_steps_tree] if process_sub_sub_steps_tree_node_ids: transactions = execute(sap_solman_discoverer.GetProcessRefIdsByNodeIds(process_sub_sub_steps_tree_node_ids)) for transaction_ref_obj, transaction_node in transactions: logger.debug("Transaction Ref Object %s" % transaction_ref_obj) transaction = BusinessTransaction(transaction_ref_obj, system_name) process_step.add_child(transaction) if reportCIsInChunks: report_chunk(framework, project, scenario, process_steps_tree, sap_system_osh) process.clear_children() return business_objects_tree