def _reportSystem(sapUtils, system, domain, isSolMan, tmsDomain): '@types: SapUtils, System, str, bool, sap.TmsDomain -> osh' sapReporter = sap.Reporter(sap.Builder()) userName = fptools.safeFunc(sapUtils.getUserName)() credentialsId = fptools.safeFunc(sapUtils.getCredentialId)() systemOsh = sapReporter.reportSystemPdo(sap.Builder.SystemPdo( system, ipAddress=sapUtils.getIpAddress(), ipDomain=domain, username=userName, credentialsId=credentialsId, connectionClient=sapUtils.getConnectionClient(), router=sapUtils.getRouter(), isSolutionManager=isSolMan, tmsDomain=tmsDomain)) return systemOsh
def get_remote_databases(executor, shell_interpreter, instance_name, db2_home_path=None): r'''@types: command.CmdExecutor, shell_interpreter.Interpreter, unicode, file_topology.Path -> list(db2_model.Database) @raise ExecuteError: on DB2INSTANCE variable setting failure @raise command.ExecuteException: on db2 cmdb execution failure ''' db2cmd = __get_configured_db2_cmd(shell_interpreter, instance_name, db2_home_path) list_db_directory = db2cmd.list_db_directory() dcs_entries = fptools.safeFunc(executor)(db2cmd.list_dcs_directory()) or () lt_names = ((e.local_dbname, e.target_dbname) for e in dcs_entries) is_remote = fptools.comp(partial(operator.eq, DatabaseEntryTypes.REMOTE), Db2.DatabaseEntry.entry_type.fget) remote_db_entries = list_db_directory | executor remote_db_entries = ifilter(is_remote, remote_db_entries) resolve_db_name = partial(_resolve_remotedb_name, dict(lt_names)) remote_db_entries = imap(resolve_db_name, remote_db_entries) get_nodename = Db2.DatabaseEntry.node_name.fget dbs_by_nodename = fptools.groupby(get_nodename, remote_db_entries) get_dbname = Db2.DatabaseEntry.name.fget node_map_pairs = [(node, fptools.groupby(get_dbname, db_entries)) for node, db_entries in dbs_by_nodename.iteritems()] return _parse_remote_databases(node_map_pairs)
def get_version_by_instance_name(shell, instance_name): discover_version = partial(fptools.safeFunc(__version_by_instance_name), shell, instance_name) return fptools.findFirst(lambda x: x, ifilter(None, imap(discover_version, registry.get_discoverers())) )
def parseDatabases(self, doc): 'r@types: org.w3c.dom.Document -> list(JEEDiscovererByHTTP.DbInstance)' dbInstanceNodes = self._evalToNodes('/SAP_J2EE/DB_INSTANCE', doc) buildDbInstanceSafely = fptools.safeFunc(self._parseDbInstance) res = map(buildDbInstanceSafely, dbInstanceNodes) return filter(None, res)
def get_db2_version_by_home_path(reg_provider, db2_home_path): regbased_discoverers = registry.get_discoverers() discover_version = Fn(fptools.safeFunc(__discover_version), reg_provider, fptools._, db2_home_path) return fptools.findFirst(lambda x: x, ifilter(None, imap(discover_version, regbased_discoverers)))
def get_remote_databases(executor, shell_interpreter, instance_name, db2_home_path=None): r"""@types: command.CmdExecutor, shell_interpreter.Interpreter, unicode, file_topology.Path -> list(db2_model.Database) @raise ExecuteError: on DB2INSTANCE variable setting failure @raise command.ExecuteException: on db2 cmdb execution failure """ db2cmd = __get_configured_db2_cmd(shell_interpreter, instance_name, db2_home_path) list_db_directory = db2cmd.list_db_directory() dcs_entries = fptools.safeFunc(executor)(db2cmd.list_dcs_directory()) or () lt_names = ((e.local_dbname, e.target_dbname) for e in dcs_entries) is_remote = fptools.comp(partial(operator.eq, DatabaseEntryTypes.REMOTE), Db2.DatabaseEntry.entry_type.fget) remote_db_entries = list_db_directory | executor remote_db_entries = ifilter(is_remote, remote_db_entries) resolve_db_name = partial(_resolve_remotedb_name, dict(lt_names)) remote_db_entries = imap(resolve_db_name, remote_db_entries) get_nodename = Db2.DatabaseEntry.node_name.fget dbs_by_nodename = fptools.groupby(get_nodename, remote_db_entries) get_dbname = Db2.DatabaseEntry.name.fget node_map_pairs = [ (node, fptools.groupby(get_dbname, db_entries)) for node, db_entries in dbs_by_nodename.iteritems() ] return _parse_remote_databases(node_map_pairs)
def parseCentralServices(self, doc): 'r@types:org.w3c.dom.Document -> list(JEEDiscovererByHTTP.ScsInstance)' scsInstanceNodes = self._evalToNodes('/SAP_J2EE/SCS_INSTANCE', doc) buildScsInstanceSafely = fptools.safeFunc(self._parseScsInstance) res = map(buildScsInstanceSafely, scsInstanceNodes) return filter(None, res)
def _parseOutput(self, ipconfigBuffer, langBund): r'@types: str, ResourceBundle -> list[ip_addr._BaseIP]' keyword = langBund.getString('windows_ipconfig_str_dnsservers').strip() inDns = 0 # order of added IPs is important so we do not use set and just check # for already added IPs ips = [] parseIp = fptools.safeFunc(self.__parseIpInLine) if ipconfigBuffer: for line in ipconfigBuffer.splitlines(): if (line.find(keyword) != -1): inDns = 1 ip = parseIp(line) if ip and not ip in ips and ip_addr.isValidIpAddressNotZero( ip): ips.append(ip) continue if (inDns == 1): if (line.find('. :') == -1): ip = parseIp(line) if ip and not ip in ips and ip_addr.isValidIpAddressNotZero( ip): ips.append(ip) else: inDns = 0 return ips
def getHostNodes(self): r'''@types: -> list[HostNode] @raise TrexTopologyConfig.NodeNotFound: ''' rootHostNode = getUnderlyingNodeByName(self.__rootNode, 'host') return filter(None, map(fptools.safeFunc(self.__parseHostNode), (rootHostNode and rootHostNode.children or [])))
def __parseSystemFromNameserver(self, nameserverNode): r''' Partiall structure of NameServer node n3>nameserver n4>30001 n5>activated_at=2012-01-05 12:20:05.919 n5>info n6>hostname=x2730 x2730c @types: BaseTopologyConfigParser.Node -> sap.System ''' infoNode, nameserverPort = self.__parseNameserverInfoNode( nameserverNode) # /usr/sap/<sid>/<instance_name>/<hostname>/ sapRetrievalPath = infoNode.attributes.get('sap_retrieval_path') # /usr/sap/<sid>/<instance_name> instanceBasePath = infoNode.attributes.get('basepath') # find out instance name from paths parsePath = fptools.safeFunc( sap_discoverer.parseSapSystemFromInstanceBasePath) sapSystem = sapRetrievalPath and parsePath(sapRetrievalPath, parseHostname=True) if not sapSystem and instanceBasePath: sapSystem = parsePath(instanceBasePath) return sap.System(infoNode.attributes.get('sid')).addInstance( sapSystem.getInstances()[0])
def _reportSystem(sapUtils, system, domain, isSolMan, tmsDomain): '@types: SapUtils, System, str, bool, sap.TmsDomain -> osh' sapReporter = sap.Reporter(sap.Builder()) userName = fptools.safeFunc(sapUtils.getUserName)() credentialsId = fptools.safeFunc(sapUtils.getCredentialId)() systemOsh = sapReporter.reportSystemPdo( sap.Builder.SystemPdo(system, ipAddress=sapUtils.getIpAddress(), ipDomain=domain, username=userName, credentialsId=credentialsId, connectionClient=sapUtils.getConnectionClient(), router=sapUtils.getRouter(), isSolutionManager=isSolMan, tmsDomain=tmsDomain)) return systemOsh
def get_userhome_by_username(shell, username): r'shellutils.Shell, basestring -> file_system.Path?' pathtool = file_system.getPathToolByShell(shell) safe_executor = fptools.safeFunc( base_shell_discoverer.get_command_executor(shell)) return safe_executor( base_shell_discoverer.GetUserHomeOnUnix(username, pathtool))
def __parseSystemFromNameserver(self, nameserverNode): r''' Partiall structure of NameServer node n3>nameserver n4>30001 n5>activated_at=2012-01-05 12:20:05.919 n5>info n6>hostname=x2730 x2730c @types: BaseTopologyConfigParser.Node -> sap.System ''' infoNode, nameserverPort = self.__parseNameserverInfoNode(nameserverNode) # /usr/sap/<sid>/<instance_name>/<hostname>/ sapRetrievalPath = infoNode.attributes.get('sap_retrieval_path') # /usr/sap/<sid>/<instance_name> instanceBasePath = infoNode.attributes.get('basepath') # find out instance name from paths parsePath = fptools.safeFunc(sap_discoverer.parseSapSystemFromInstanceBasePath) sapSystem = sapRetrievalPath and parsePath(sapRetrievalPath, parseHostname=True) if not sapSystem and instanceBasePath: sapSystem = parsePath(instanceBasePath) return sap.System(infoNode.attributes.get('sid')).addInstance( sapSystem.getInstances()[0])
def __getProfilePath(self, process): r'@types: process.Process -> str or None' tokens = re.split('[=\s]+', process.commandLine) index = fptools.safeFunc(tokens.index)('pf') filePath = None if index > 0: filePath = tokens[index + 1] return filePath
def parseSoftwareComponents(self, doc): 'r@types:org.w3c.dom.Document -> list(JEEDiscovererByHTTP.SoftwareComponent)' softwareComponentNodes = self._evalToNodes('/SAP_J2EE/SOFTWARE_COMPONENTS/COMPONENT', doc) buildSoftwareComponentSafely = fptools.safeFunc(self._parseSoftwareComponent) res = map(buildSoftwareComponentSafely, softwareComponentNodes) return filter(None, res)
def getHostNodes(self): r'''@types: -> list[HostNode] @raise TrexTopologyConfig.NodeNotFound: ''' rootHostNode = getUnderlyingNodeByName(self.__rootNode, 'host') return filter( None, map(fptools.safeFunc(self.__parseHostNode), (rootHostNode and rootHostNode.children or [])))
def buildEndpointsFromNsOption(nsOption, dnsResolver): r'''@types: NsOption -> list[netutils.Endpoint] ''' ips = fptools.safeFunc(dnsResolver.resolveIpsByHostname)(nsOption.address) if ips: return map(fptools.partiallyApply(netutils.createTcpEndpoint, fptools._, nsOption.port), ips) return []
def discoverExecutablePath(shell, process): r''' @types: shellutils.Shell, process.Process -> str or None ''' if shell.isWinOs(): return process.executablePath else: return fptools.safeFunc(shell.execCmd)( 'readlink /proc/%s/exe' % process.getPid())
def discoverExecutablePath(shell, process): r''' @types: shellutils.Shell, process.Process -> str or None ''' if shell.isWinOs(): return process.executablePath else: return fptools.safeFunc(shell.execCmd)('readlink /proc/%s/exe' % process.getPid())
def parseCentralInstance(self, doc): 'r@types:org.w3c.dom.Document -> JEEDiscovererByHTTP.CentralInstance' centralInstanceNode = self._evalToNode('/SAP_J2EE/CENTRAL_INSTANCE', doc) if centralInstanceNode: buildInstanceSafely = fptools.safeFunc(fptools.curry(self._parseInstance, fptools._, self.CentralInstance)) return buildInstanceSafely(centralInstanceNode)
def parseDialogInstances(self, doc): 'r@types:org.w3c.dom.Document -> list(JEEDiscovererByHTTP.DialogInstance)' dialogInstanceNodes = self._evalToNodes('/SAP_J2EE/DIALOG_INSTANCE', doc) buildInstanceSafely = fptools.safeFunc(fptools.curry(self._parseInstance, fptools._, self.DialogInstance)) res = map(buildInstanceSafely, dialogInstanceNodes) return filter(None, res)
def parseFindIpsOutput(resourceProperties, ipMarkers, ipPattern): createIp = fptools.safeFunc(ip_addr.IPAddress) for ipMarker in ipMarkers: for line in resourceProperties.splitlines(): ipMatcher = re.search(ipPattern % ipMarker, line) if ipMatcher: ip = createIp(ipMatcher.group(1).strip()) if ip: return [ip] return []
def get_db_sessions(executor, db_name=None, db_partition_number=None): r''' @types: command.ExecutorCmdlet, str?, str? -> tuple[db2_sql_v9x_discoverer.Session] ''' parse_session = fptools.safeFunc(_parse_session) parse_sessions = fptools.partiallyApply(keep, parse_session, fptools._) parse_sessions = command.FnCmdlet(parse_sessions) sessions = GetApplInfo(db_name) | executor | parse_sessions return tuple(sessions)
def _buildJavaInstance(system, dlgInstance): r'@types: System, SapJEEMonitoringXmlParser.DialogInstance -> sap.Instance' paths = [] workers = _getInstanceWorkers(dlgInstance) paths.extend(flatten(map(_getPathsWithInstanceBasePath, workers))) _parseInstance = partiallyApply(parseInstFromHomeDir, system, fptools._) _, inst = untilFirstTruth(safeFunc(_parseInstance), paths) if not inst: raise Exception("Not enough information to build instance") hostname = _getDlgInstanceHostname(dlgInstance) return sap.Instance(inst.name, inst.number, hostname)
def __getSystemComponent(self, queriedJ2eeType, serviceClass): r'@types: str, T -> list[T]' parse = fptools.partiallyApply(self.__parseSystemComponent, fptools._, serviceClass) attributes = ("DisplayName", "ProviderName", "MinorVersion", "MicroVersion", "Description", "MajorVersion", "Name", "Jars") pattern = '*:*,j2eeType=%s' % queriedJ2eeType items = self._getClient().getMbeansByNamePattern(pattern, attributes) return keep(fptools.safeFunc(parse), items)
def parseIpsFromResorceParam(self, resourceProperties, ipPattern): ips = [] ipMarker = "Address" createIp = fptools.safeFunc(ip_addr.IPAddress) for line in resourceProperties.splitlines(): ipMatcher = re.search(ipPattern % ipMarker, line.strip()) if ipMatcher: ip = createIp(ipMatcher.group(1).strip()) if ip: ips.append(ip) return ips
def _discover_remote_databases(self, context, instname, db2_home_path, discoverer, executor, interpreter): local_dbserver_osh = context.application.applicationOsh get_remote_databases = safeFn(discoverer.get_remote_databases) node_db_pairs = get_remote_databases(executor, interpreter, instname, db2_home_path=db2_home_path) or () get_node = safeFn(discoverer.get_node) reporter = db2_topology.Reporter() node_reporter = host_topology.Reporter() shell = context.client resolvers = (NsLookupDnsResolver(shell), SocketDnsResolver()) resolve_ips_fn = FallbackResolver(resolvers).resolve_ips for nodename, remote_dbs in node_db_pairs: node = get_node(executor, interpreter, instname, nodename, db2_home_path=db2_home_path) if node: host_osh = None address = None instance_name_ = None if node.is_local(): host_osh = context.hostOsh address = context.application.getApplicationIp() instance_name_ = node.instance_name else: host = host_base_parser.parse_from_address(node.hostname, fptools.safeFunc(resolve_ips_fn)) if host and host.ips: instance_name_ = node.remote_instance_name address = first(host.ips) host_osh, _, oshs_ = node_reporter.report_host_with_ips(host.ips) context.resultsVector.addAll(oshs_) if host_osh: get_port_fn = safeFn(discoverer.get_instance_port_by_node) port = get_port_fn(executor, interpreter, node, db2_home_path=db2_home_path) remote_instance = DatabaseServer(address, port) remote_inst_osh, endpoint_osh, _, vector = reporter.reportServerAndDatabases(remote_instance, host_osh) if instance_name_: SoftwareBuilder.updateName(remote_inst_osh, instance_name_) context.resultsVector.addAll(vector) _, oshs = reporter.reportRemoteDatabases(remote_dbs, local_dbserver_osh, remote_inst_osh) context.resultsVector.addAll(oshs) else: logger.debug('No instance name') if endpoint_osh: context.resultsVector.add(endpoint_osh) else: logger.debug('Host is not resolved %s' % node.hostname) else: logger.debug('No node found with name %s' % nodename)
def discoverHostInfo(self): r'''@types: -> HostDo @raise Exception: WMI query failed ''' systemInfo = self.getSystemInfo() # There's a limitation of 15 chars for host name in AD # while actual host name can be longer dnsHostName = fptools.safeFunc(self.getDnsHostname)() if (dnsHostName and len(systemInfo.hostName) < len(dnsHostName) and dnsHostName.find(systemInfo.hostName) != -1): systemInfo.hostName = dnsHostName return systemInfo
def getDomainRootDirPath(shell, fs, process, getParentProcessByPid): r'@types: Shell, FileSystem, Process, (long -> Process) -> str or None' # find root directory for the process # Root directory may be specified as property in command line # -Dweblogic.RootDirectory cmdLineDescriptor = jee.JvmCommandLineDescriptor(process.commandLine) rootDirPath = cmdLineDescriptor.extractProperty('weblogic\.RootDirectory') if not rootDirPath: # If property is not specified - find out working directory for the process if shell.isWinOs(): # In Windows root directory path can be extracted from the startup script of the. # Command line with path to startup script can be found in the # parent process for current weblogic process parentProcess = getParentProcessByPid(process.getParentPid()) if parentProcess: startupScriptPath = _extractStartupScriptfromCmdPath( parentProcess.commandLine, fs) logger.debug("startupScriptPath:", startupScriptPath) if startupScriptPath: path = file_system.getPath(fs) rootDirPath = path.dirName(startupScriptPath) else: rootDirPath = safeFunc( getWorkingDirByReadlinkInProc, fallbackFn=safeFunc( getWorkingDirByCwd, fallbackFn=safeFunc( getWorkingDirByPwdx, fallbackFn=safeFunc(getWorkingDirByPwdInProc))))( shell, process.getPid()) if rootDirPath: rootDirPath = rootDirPath.strip() # check if path ends with bin (in versions starting from 9th) if rootDirPath.endswith('bin'): rootDirPath = path.dirName(rootDirPath) return rootDirPath raise ValueError( "Domain root directory path cannot be found from the runtime information." )
def getDomainRootDirPath(shell, fs, process, getParentProcessByPid): r'@types: Shell, FileSystem, Process, (long -> Process) -> str or None' # find root directory for the process # Root directory may be specified as property in command line # -Dweblogic.RootDirectory cmdLineDescriptor = jee.JvmCommandLineDescriptor(process.commandLine) rootDirPath = cmdLineDescriptor.extractProperty('weblogic\.RootDirectory') if not rootDirPath: # If property is not specified - find out working directory for the process if shell.isWinOs(): # In Windows root directory path can be extracted from the startup script of the. # Command line with path to startup script can be found in the # parent process for current weblogic process parentProcess = getParentProcessByPid(process.getParentPid()) if parentProcess: startupScriptPath = _extractStartupScriptfromCmdPath(parentProcess.commandLine, fs) logger.debug("startupScriptPath:", startupScriptPath) if startupScriptPath: path = file_system.getPath(fs) rootDirPath = path.dirName(startupScriptPath) else: rootDirPath = safeFunc(getWorkingDirByReadlinkInProc, fallbackFn = safeFunc(getWorkingDirByCwd, fallbackFn = safeFunc(getWorkingDirByPwdx, fallbackFn=safeFunc(getWorkingDirByPwdInProc) ) ) )(shell, process.getPid()) if rootDirPath: rootDirPath = rootDirPath.strip() # check if path ends with bin (in versions starting from 9th) if rootDirPath.endswith('bin'): rootDirPath = path.dirName(rootDirPath) return rootDirPath raise ValueError("Domain root directory path cannot be found from the runtime information.")
def parseCluster(self, clusterBuffer): '''Parses generic Cluster attributes @param clusterBuffer: string @raise ValueError: Failed to discover Service Guard Cluster @return: Cluster with link to Quorum Server if used ''' m = re.search('CLUSTER\s+STATUS\s*\n([\w\-\.]+)\s+(\w+)', clusterBuffer) if m: clusterName = m.group(1) packageIpAddress = netutils.resolveIP(self._shell, clusterName) # Discover Quorum server # all nodes have reference to the same server matchObj = self.QUORUM_SERVER_REGEXP.search(clusterBuffer) quorumServer = None if matchObj: # parse Quorum server information createIp = fptools.safeFunc(ip_addr.IPAddress) serverAddress = createIp(matchObj.group(3)) if not serverAddress: logger.warn("Quorum Server IP address is unknown") else: endpoint = netutils.createTcpEndpoint( serverAddress, service_guard.QuorumServer.DEFAULT_PORT) status = matchObj.group(2).lower() try: quorumServer = service_guard.QuorumServer( endpoint, status) logger.info("Discovered %s" % quorumServer) except ValueError, ve: logger.warn("Failed to create Quorum Server. %s" % ve) return service_guard.Cluster(clusterName, None, packageIpAddress, clusterBuffer, quorumServer=quorumServer)
def parseCluster(self, clusterBuffer): '''Parses generic Cluster attributes @param clusterBuffer: string @raise ValueError: Failed to discover Service Guard Cluster @return: Cluster with link to Quorum Server if used ''' m = re.search('CLUSTER\s+STATUS\s*\n([\w\-\.]+)\s+(\w+)', clusterBuffer) if m: clusterName = m.group(1) packageIpAddress = netutils.resolveIP(self._shell, clusterName) # Discover Quorum server # all nodes have reference to the same server matchObj = self.QUORUM_SERVER_REGEXP.search(clusterBuffer) quorumServer = None if matchObj: # parse Quorum server information createIp = fptools.safeFunc(ip_addr.IPAddress) serverAddress = createIp(matchObj.group(3)) if not serverAddress: logger.warn("Quorum Server IP address is unknown") else: endpoint = netutils.createTcpEndpoint(serverAddress, service_guard.QuorumServer.DEFAULT_PORT) status = matchObj.group(2).lower() try: quorumServer = service_guard.QuorumServer(endpoint, status) logger.info("Discovered %s" % quorumServer) except ValueError, ve: logger.warn("Failed to create Quorum Server. %s" % ve) return service_guard.Cluster(clusterName, None, packageIpAddress, clusterBuffer, quorumServer=quorumServer)
def _parseOutput(self, ipconfigBuffer, langBund): r"@types: str, ResourceBundle -> list[ip_addr._BaseIP]" keyword = langBund.getString("windows_ipconfig_str_dnsservers").strip() inDns = 0 # order of added IPs is important so we do not use set and just check # for already added IPs ips = [] parseIp = fptools.safeFunc(self.__parseIpInLine) if ipconfigBuffer: for line in ipconfigBuffer.splitlines(): if line.find(keyword) != -1: inDns = 1 ip = parseIp(line) if ip and not ip in ips and ip_addr.isValidIpAddressNotZero(ip): ips.append(ip) continue if inDns == 1: if line.find(". :") == -1: ip = parseIp(line) if ip and not ip in ips and ip_addr.isValidIpAddressNotZero(ip): ips.append(ip) else: inDns = 0 return ips
def _parse_databases(databases): return keep(fptools.safeFunc(_parse_database), databases)
def get_instance_host(executor, dns_resolver): r'@types: command.CmdExecutor, dns_resolver.Resolver-> db2_host.Host?' hostname = get_instance_hostname(executor) resolve_ips = fptools.safeFunc(dns_resolver.resolve_ips) return db2_discoverer.get_host(hostname, resolve_ips)
def _parse_remote_databases(pairs): return keep(fptools.safeFunc(_parse_remote_database), pairs)
def _parse_buffer_pools(items): return keep(fptools.safeFunc(_parse_buffer_pool), items)
def _parse_tables(items): return keep(fptools.safeFunc(_parse_table), items)
def _parse_partitions(items): return keep(fptools.safeFunc(_parse_partition), items)
def _parse_partition_id_to_pg_names(items): return keep(fptools.safeFunc(_parse_partition_id_to_pg_name), items)
def _parse_partition_groups(items): return keep(fptools.safeFunc(_parse_partition_group), items)
def _parse_containers(items): return keep(fptools.safeFunc(_parse_container), items)
def _findIps(resourceProperties, ipMarkers): '@types: str, seq[str] -> list[ip_addr._BaseIP]' if resourceProperties: createIp = fptools.safeFunc(ip_addr.IPAddress) ipPattern = '\s+%s\s+(\S*)$' return parseFindIpsOutput(resourceProperties, ipMarkers, ipPattern)
def decorator_fn(main_fn): @wraps(main_fn) def wrapper(framework): vector = ObjectStateHolderVector() framework = RichFramework(framework) creds_manager = CredsManager(framework) creds = get_credentials_fn(framework, creds_manager) if creds is None: return vector first_cred = take(0, 1, creds) if not first_cred: logger.reportErrorObject( _create_missed_creds_error(proto_name)) else: connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False oshs = [] creds = list(itertools.chain(first_cred, creds)) if with_dns_resolver: local_client = framework.createClient( LOCAL_SHELL_PROTOCOL_NAME) local_shell = shellutils.ShellUtils(local_client) dns_resolver = _get_dns_resolver(local_shell) for args in starmap( functools.partial(cred_to_client_args, creds_manager), creds): try: with create_client(framework, *args) as client: args = with_dns_resolver and ( dns_resolver, ) + args or args oshs_, warnings_ = main_fn(client, framework, *args) oshs.extend(oshs_) warnings.extend(warnings_) at_least_once_discovered = True if stop_on_first: break except ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (DiscoveryException, Exception), de: logger.debugException(str(de)) discovery_exs.append(de) if with_dns_resolver: fptools.safeFunc(local_shell.closeClient)() if at_least_once_discovered: each(logger.reportWarningObject, warnings) else: for ex in connection_exs: obj = _create_connection_errorobj( proto_name, ex.message) logger.reportErrorObject(obj) for ex in discovery_exs: obj = _create_discovery_errorobj( proto_name, '', ex.message) logger.reportErrorObject(obj) vector.addAll(oshs)
def _discoverTopology(clusterCmd, languageBundle, dnsResolver): r'@types: ClusterCmd, ResourceBundle, DNSResolver -> ObjectStateHolderVector' vector = ObjectStateHolderVector() # DISCOVER cluster basic topology (cluster + nodes) if clusterCmd.isUsingCmd(): getCluster = clusterCmd.getCluster else: getCluster = clusterCmd.getClusterByPowerShell cluster = ms_cluster.createClusterWithDetails(getCluster(), fptools.safeFunc(clusterCmd.getClusterDetails)()) logger.info("Found ", cluster) # DISCOVER nodes nodes = [] detailsContentByName = {} getNodeAddress = fptools.safeFunc(clusterCmd.getHostAddressesbyNetinterface) ipsByNodeName = {} for node in clusterCmd.findNodes(): logger.info("Discovered %s" % node) # in case if IP of node cannot be resolved there is no need to continue # discovery of this node ips = (dnsResolver.resolve_ips(node.name) or getNodeAddress(node.name)) if not ips: logger.warn("Skip %s due to not resolved address" % node) continue ipsByNodeName[node.name.lower()] = ips details = None try: details = clusterCmd.getNodeDetails(node.name) buffer = clusterCmd.getLastCommandOutput() detailsContentByName[node.name.lower()] = buffer except Exception: logger.warnException("Failed to get details for %s" % node) # if needed re-create node with details in it nodes.append((details and ms_cluster.Node(node.name, details=details) or node)) # REPORT cluster topology clusterBuilder = ms_cluster.Builder() clusterPdo = clusterBuilder.Pdo(cluster, len(nodes)) clusterOsh = clusterBuilder.buildClusterPdo(clusterPdo) vector.add(clusterOsh) # REPORT nodes softwareOshByNodeName = {} for node in nodes: softwareOsh, nodeVector = _reportNode( node, cluster, ipsByNodeName.get(node.name.lower()), clusterOsh, dnsResolver.resolve_fqdn(node.name), detailsContentByName.get(node.name.lower())) vector.addAll(nodeVector) softwareOshByNodeName[node.name.lower()] = softwareOsh # DISCOVER resource groups if len(nodes) > 0: resourceBuilder = ms_cluster.ResourceBuilder() resourceReporter = ms_cluster.ResourceReporter(resourceBuilder) groups = clusterCmd.getResourceGroups() for group in groups: logger.info("Found %s" % group) groupDetails = fptools.safeFunc(clusterCmd.getResourceGroupDetails)(group.name) # update group with details groupDetailsContent = None if groupDetails: groupDetailsContent = clusterCmd.getLastCommandOutput() group = ms_cluster.ResourceGroup(group.name, group.nodeName, groupDetails) else: logger.warn("Failed to get details") if clusterCmd.isUsingCmd(): groupOwners = fptools.safeFunc(clusterCmd.getResourceGroupOwners)(group.name) or () else: groupOwners = fptools.safeFunc(clusterCmd.getResourceGroupOwnersByPowerShell)(group.name) or () if groupOwners: logger.info("Group owners are %s" % groupOwners) # get resources in the group and filter only IP resources resources = [] # for this group resources get their details dependenciesByGroupName = {} privateDetBufferByResourceName = {} publicDetBufferByResourceName = {} logger.info("Discover group resources") try: if clusterCmd.isUsingCmd(): groupResources = clusterCmd.getResourcesByGroup(group.name) else: groupResources = clusterCmd.getResourcesByGroupByPowerShell(group.name) except ms_cluster_discoverer.ClusterCmd.ExecuteException: logger.warn("Failed to find resources for %s" % group) else: for resource in groupResources: logger.info("\tFound %s" % resource) try: resourceDetails = clusterCmd.getResourceDetails(resource.name) publicDetBufferByResourceName[resource.name] = clusterCmd.getLastCommandOutput() resource = ms_cluster.Resource(resource.name, resource.groupName, resource.status, resourceDetails) except Exception: logger.warnException("Failed to get %s details" % resource) try: clusterCmd.getResourcePrivateDetails(resource.name) privateDetBuffer = clusterCmd.getLastCommandOutput() privateDetBufferByResourceName[resource.name.lower()] = privateDetBuffer if resourceDetails.type == 'Network Name': (networkName, fqdn )= ms_cluster_discoverer.getCrgNeworkNames(privateDetBuffer, dnsResolver) if networkName or fqdn: group = ms_cluster.ResourceGroup(group.name, group.nodeName, groupDetails, networkName, fqdn) except Exception: logger.warnException("Failed to get %s private details" % resource) try: dependencies = clusterCmd.getResourceDependencies(resource.name, group.name) dependenciesByGroupName[resource.name.lower()] = dependencies if dependencies: logger.info("\t\tDependencies are %s" % dependencies) except Exception: logger.warnException("Failed to get %s dependencies") resources.append(resource) # REPORT cluster resources # report clustered service builder = ms_cluster.ClusteredServiceBuilder() serviceOsh = builder.buildClusteredService(cluster, group) vector.add(serviceOsh) vector.add(modeling.createLinkOSH('contained', clusterOsh, serviceOsh)) softwareOsh = softwareOshByNodeName.get(group.nodeName.lower()) if not softwareOsh: logger.warn("Failed to find node of %s" % group) else: runOsh = modeling.createLinkOSH('run', softwareOsh, serviceOsh) vector.add(runOsh) for softwareOsh in softwareOshByNodeName.values(): runOsh = modeling.createLinkOSH('potentially_run', softwareOsh, serviceOsh) vector.add(runOsh) groupReporter = ms_cluster.ResourceGroupReporter(ms_cluster.ResourceGroupBuilder()) groupOsh = groupReporter.reportGroup(group, serviceOsh) vector.add(groupOsh) # report group details if groupDetailsContent: vector.add(_reportGroupDetails(group, groupDetailsContent, groupOsh)) # report linkage between group owners for ownerNodeName in groupOwners: # resolve node IPs by owner-node name ips = ( dnsResolver.resolve_ips(ownerNodeName) or fptools.safeFunc(clusterCmd.getHostAddressesbyNetinterface) (ownerNodeName)) if not ips: logger.warn("Failed to resolve address for %s" % node) continue fqdn = dnsResolver.resolve_fqdn(ownerNodeName) vector.addAll(_reportHost(ips, fqdn)[1]) vector.add(_buildOwnerPotentillyRun(softwareOsh, serviceOsh)) # report resources for resource in resources: clusterResourcesPrivBuffer = privateDetBufferByResourceName.get(resource.name.lower()) pdo = ms_cluster.ResourceBuilder.Pdo(resource, clusterResourcesPrivBuffer) resourceOsh = resourceReporter.reportResourcePdo(pdo, groupOsh) vector.add(resourceOsh) # and dependent resources for dependency in dependenciesByGroupName.get(resource.name.lower(), ()): dependencyOsh = resourceReporter.reportResource(dependency, groupOsh) vector.add(dependencyOsh) dependOsh = modeling.createLinkOSH('depend', dependencyOsh, resourceOsh) vector.add(dependOsh) # filter resource of type "IP Address" to gather group IPs ipResources = filter(ms_cluster.isIpAddressResource, resources) addressWord = languageBundle.getString('resource_ip_address_name') # look for the IP value inside private properties groupIps = [] logger.info("Look for the IP resources in %s resources" % len(ipResources)) for resource in ipResources: if clusterCmd.isUsingCmd(): groupIps.extend(_findIps( privateDetBufferByResourceName.get(resource.name.lower()), (addressWord, 'Address', 'Adresse'))) else: groupIps.extend(_findIpsByPowerShell( privateDetBufferByResourceName.get(resource.name.lower()), (addressWord, 'Address', 'Adresse'))) for ip in groupIps: logger.info('Found IP(%s) for virtual cluster group %s' % (ip, group.name)) ipOsh = modeling.createIpOSH(ip) containedOsh = modeling.createLinkOSH('contained', serviceOsh, ipOsh) vector.add(containedOsh) vector.add(ipOsh) #check if CRG name is a valid DNS name fqdn = group.fqdn if not fqdn: fqdn = dnsResolver.resolve_fqdn(group.name) if fqdn: serviceOsh.setStringAttribute('primary_dns_name', fqdn) if not groupIps: logger.warn('Failed to resolve cluster IP for group %s' % group.name) elif not fqdn: primaryIp = groupIps[0] fqdn = dnsResolver.resolve_ips(str(primaryIp)) if fqdn: serviceOsh.setStringAttribute('primary_dns_name', fqdn[0]) else: raise NoInstanceFound() return vector
def __create_valid_ip(ip_string): ip = fptools.safeFunc(ip_addr.IPAddress)(ip_string) if ip and netutils.isRoutableIp(ip): return ip return ip
# discover all processes runningProcesses = processDiscoverer.discoverAllProcesses() # make filtering for Weblogic processes serverProcesses = filter(isWeblogicAsProcess, runningProcesses) # obvious to terminate discovery job without weblogic processes running if not serverProcesses: logger.reportWarning("No Weblogic processes currently running") return ObjectStateHolderVector() # create catalog of processes by PID processByPid = applyMapping(processModule.Process.getPid, runningProcesses) # for each weblogic server process get root directory path getRootDirectoryPath = curry(getDomainRootDirPath, shell, fs, _, processByPid.get ) rootDirectoryPaths = map(safeFunc(getRootDirectoryPath), serverProcesses) # group server processes by root directory path processesByRootDirPath = {} for process, path in zip(serverProcesses, rootDirectoryPaths): processesByRootDirPath.setdefault(path, []).append(process) debugGroups(processesByRootDirPath) # NEXT CASE IS NOT SUPPORTED (as property weblogic.ConfigFile # removed starting from version 9 # important to understand that some processes may specify alternative # path to the configuration # -Dweblogic.ConfigFile=c:\mydir\myfile.xml # OR # Instead, use the following arguments: # -Dweblogic.RootDirectory=c:\mydir # -Dweblogic.ConfigFile=myfile.xml