def _discoverDatabase(client, baseTopology): r'@types: BaseSapJmxClient, BaseTopology -> oshv' logger.info("Discover DB information") vector = ObjectStateHolderVector() try: dbInfo = _getDatabase(client) except (Exception, JException): logger.warnException("Failed to get DB info using new MBean model") else: if dbInfo: try: logger.info("Resolve DB address: ", dbInfo.hostname) dnsResolver = netutils.JavaDnsResolver() ips = dnsResolver.resolveIpsByHostname(dbInfo.hostname) hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, hVector = hostReporter.reportHostWithIps(*ips) vector.addAll(hVector) hVector.clear() except netutils.ResolveException: logger.warn("DB won't be reported as DB addr is not resolved") else: try: logger.info("Discovered: ", dbInfo) systemOsh = baseTopology.systemOsh vector.addAll(sap_db.report_db_info(dbInfo, systemOsh, hostOsh)) except ValueError, ve: logger.warn("%s: %s" % (ve, dbInfo.type))
def reportInstanceInfo(instInfo, ips, system, credsId=None, connectionClientNr=None, application_ip=None, system_osh=None): r'@types: InstanceInfo, list[ip_addr._BaseIP, System, str, str -> tuple[ObjectStateHolder, ObjectStateHolderVector]' vector = ObjectStateHolderVector() hostReporter = sap.HostReporter(sap.HostBuilder()) ascsReporter = sap_abap.InstanceReporter(sap_abap.AscsInstanceBuilder()) instReporter = sap_abap.InstanceReporter(sap_abap.InstanceBuilder()) # report host of instInfo hostOsh, iVector = hostReporter.reportHostWithIps(*ips) vector.addAll(iVector) # report SAP system if system_osh: system_osh.setStringAttribute( 'data_note', 'This SAP System link to ' + hostOsh.getAttributeValue('host_key')) vector.add(system_osh) # report r3 server on host applicationIp = application_ip isScs = sap_abap.isCentralServicesInstance(instInfo.instance) serverOsh = None if isScs: pdo = sap_abap.AscsInstanceBuilder.createPdo( instInfo.instance, system, homeDirPath=instInfo.homeDirPath, codePage=instInfo.codePage, versionInfo=instInfo.versionInfo, startDate=instInfo.startDate, applicationIp=applicationIp, credId=credsId, connectionClientNr=connectionClientNr) serverOsh = ascsReporter.reportInstance(pdo, hostOsh) else: isCentral = None pdo = sap_abap.InstanceBuilder.createPdo( instInfo.instance, system, homeDirPath=instInfo.homeDirPath, dbLibraryInfo=instInfo.dbLibraryInfo, codePage=instInfo.codePage, numberOfProcesses=instInfo.numberOfProcesses, versionInfo=instInfo.versionInfo, startDate=instInfo.startDate, machineType=instInfo.host.machineType, osInfo=instInfo.host.osInfo, applicationIp=applicationIp, credId=credsId, connectionClientNr=connectionClientNr, isCentral=isCentral) serverOsh = instReporter.reportInstance(pdo, hostOsh) vector.add(serverOsh) return serverOsh, vector
def _reportHostByEndpoints(endpoints): ''' Return node osh, list of endpoint OSHs and all oshs in one list @types: list[Endpoint] -> osh, list[osh], oshv''' hostReporter = sap.HostReporter(sap.HostBuilder()) ips = map(netutils.Endpoint.getAddress, endpoints) hostOsh, vector = hostReporter.reportHostWithIps(*ips) reporter = netutils.EndpointReporter(netutils.ServiceEndpointBuilder()) oshs = [reporter.reportEndpoint(e, hostOsh) for e in endpoints] return hostOsh, oshs, oshs + [hostOsh] + list(vector)
def _reportDatabase(dbInfo): dbServer, platform, ips = dbInfo hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, hVector = hostReporter.reportHostWithIps(*ips) builder = db_builder.getBuilderByPlatform(platform) reporter = db.TopologyReporter(builder) serverOsh = reporter.reportServer(dbServer, hostOsh) vector = ObjectStateHolderVector() vector.add(serverOsh) vector.addAll(hVector) return vector
def _discoverInstanceDetails(client, baseTopology): r'@types: BaseSapJmxClient, str, System, osh, osh -> oshv' system, hostname, clusterOSH, systemOsh = baseTopology inst, servers = ServerProcessQuery().getSystemDetails(client) if not inst.hostname and hostname: inst = sap.Instance.replaceHostname(inst, hostname) instanceReporter = sap_jee.InstanceReporter(sap_jee.InstanceBuilder()) # report host by resolved IPs hostname = inst.hostname if not hostname: logger.warn("Failed to determine hostname for %s" % inst) return ObjectStateHolderVector() dnsResolver = netutils.JavaDnsResolver() vector = ObjectStateHolderVector() try: ips = dnsResolver.resolveIpsByHostname(hostname) except netutils.ResolveException: logger.warn("Failed to resolve hostname of %s" % inst) else: hostReporter = sap.HostReporter(sap.HostBuilder()) hostOSH, vector = hostReporter.reportHostWithIps(*ips) # report instance pdo = sap_jee.InstanceBuilder.InstancePdo(inst, system) instOsh = instanceReporter.reportInstancePdo(pdo, hostOSH) vector.add(instOsh) #report sap system systemOsh.setStringAttribute('data_note', 'This SAP System link to ' + hostOSH.getAttributeValue('host_key')) vector.add(systemOsh) # report j2ee_cluster -membership-> sap_app_server linkReporter = sap.LinkReporter() vector.add(linkReporter.reportMembership(clusterOSH, instOsh)) vector.add(linkReporter.reportMembership(systemOsh, instOsh)) # report server processes oshs = [_reportServerProcess(s, inst, instOsh) for s in servers] each(vector.add, oshs) # discover applications serverToOshs = filter(comp(_isWorkerProcess, first), zip(servers, oshs)) for server, osh in serverToOshs: id_ = server.id appNameToOsh = Sf(discoverEjbApplications)(client, id_, osh, clusterOSH, vector) Sf(buildWebApplications)(client, id_, osh, clusterOSH, appNameToOsh, vector) return vector
def _reportGatewayTopology(ips, port, clientOsh): '@types: list[_BaseIP], str, osh -> list[osh]' oshs = [] linker = sap.LinkReporter() hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, vector = hostReporter.reportHostWithIps(*ips) oshs.extend([osh for osh in vector.iterator()]) gtwOsh = _reportAnonymouseGateway(hostOsh) oshs.append(gtwOsh) oshs.append(hostOsh) for ip in ips: endpointOsh = _reportGatewayEndpoint(ip, port, hostOsh) oshs.append(linker.reportClientServerRelation(clientOsh, endpointOsh)) oshs.append(linker.reportUsage(gtwOsh, endpointOsh)) return oshs
def reportScsBasedOnMsgPort(system, hostname, msgEndpoints, systemOsh, clusterOsh, enqEndpoints=(), reportName=False): r''' @param reportName: influence on `name` attribute reporting. In some cases composite name attribute may contain not correct host information that has impact on reconciliation. Better do not report data we are not sure @types: sap.System, str, list[Endpoint], osh, list[Endpoint], bool -> oshv ''' vector = ObjectStateHolderVector() if not msgEndpoints: logger.warn("Failed to discover SCS - no message server information") return vector ips = (map(netutils.Endpoint.getAddress, msgEndpoints) + map(netutils.Endpoint.getAddress, enqEndpoints)) hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, hVector = hostReporter.reportHostWithIps(*ips) vector.addAll(hVector) systemOsh.setStringAttribute('data_note', 'This SAP System link to ' + hostOsh.getAttributeValue('host_key')) vector.add(systemOsh) instIp = sap.createIp(first(ips)) msgEndpoint = first(msgEndpoints) number = sap_discoverer.parseInstNrInMsgServerPort(msgEndpoint.getPort()) inst = sap.Instance('SCS', number, hostname=hostname) pdo = sap_jee.InstanceBuilder.InstancePdo(inst, system, ipAddress=instIp) scsBuilder = sap_jee.ScsInstanceBuilder(reportName=reportName) instReporter = sap_jee.InstanceReporter(scsBuilder) instOsh = instReporter.reportInstancePdo(pdo, hostOsh) vector.add(instOsh) linkReporter = sap.LinkReporter() vector.add(linkReporter.reportMembership(clusterOsh, instOsh)) vector.add(linkReporter.reportMembership(systemOsh, instOsh)) for endpoint in (msgEndpoints + enqEndpoints): _, eVector = sap._reportEndpointLinkedToSoftware(endpoint, hostOsh, instOsh) vector.addAll(eVector) return vector
def _reportServer(server, parsedName, ips, system, systemOsh): ''' @types: GetServers.Server, tuple, list[ip_addr._BaseIP], System, osh -> oshv ''' vector = ObjectStateHolderVector() isScs, hostname, _, nr, _ = parsedName hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, hVector = hostReporter.reportHostWithIps(*ips) # 1) name of instance will be ignore during reporting # 2) hostname used from name not from `hostname` field of server # as usually name contains alias that is interesting in different # business cases inst = sap.Instance('fake', nr, hostname) serverType = GetServers.getServerTypeByRole(server.role) reportFn = (serverType == sap.SystemType.JAVA and _reportJavaServer or _reportAbapServer) vector.addAll(hVector) vector.addAll(reportFn(inst, system, isScs, hostOsh, systemOsh)) return vector
def reportInst(inst, system, systemOsh, clusterOsh, ips, reportInstName=False): r'@types: sap.Instance, sap.System, osh, osh, list[str], bool -> oshv' hostReporter = sap.HostReporter(sap.HostBuilder()) hostOsh, hVector = hostReporter.reportHostWithIps(*ips) instBuilder = InstanceBuilder(reportInstName=reportInstName) instReporter = InstanceReporter(instBuilder) linkReporter = sap.LinkReporter() vector = ObjectStateHolderVector() vector.addAll(hVector) #report systemOsh systemOsh.setStringAttribute( 'data_note', 'This SAP System link to ' + hostOsh.getAttributeValue('host_key')) vector.add(systemOsh) pdo = InstanceBuilder.InstancePdo(inst, system) instOsh = instReporter.reportInstancePdo(pdo, hostOsh) vector.add(linkReporter.reportMembership(clusterOsh, instOsh)) vector.add(linkReporter.reportMembership(systemOsh, instOsh)) vector.add(instOsh) return instOsh, hostOsh, vector
def _reportDbServer(server, datasource, systemOsh): '@types: db.DatabaseServer, jdbc.Datasource, osh -> list[osh]' oshs = [] hostReporter = sap.HostReporter(sap.HostBuilder()) resolver = dns_resolver.SocketDnsResolver() ips = Sfn(resolver.resolve_ips)(server.address) or () if ips: ds_reporter = jdbc.JdbcTopologyReporter(jdbc.DataSourceBuilder()) ds_osh = ds_reporter.reportDatasource(datasource, systemOsh) oshs.append(ds_osh) server.address = first(ips) logger.info("Report %s" % server) host_osh, oshs_ = hostReporter.reportHostWithIps(*ips) oshs.extend(oshs_) _, oshs_ = sap_db.report_db(server, host_osh, (systemOsh, ds_osh)) oshs.extend(oshs_) else: logger.warn("Failed to report %s. Hostname is not resolved" % server) return oshs
def _report_host(address): '@types: sap.Address -> osh, list[osh]' host_reporter = sap.HostReporter(sap.HostBuilder()) host_osh, vector_ = host_reporter.reportHostWithIps(*address.ips) return host_osh, list(vector_)
else: return None else: return None # TODO replace this by reportInstances function def _report_ascs_osh(host_name, instance_number, system): resolver = dns_resolver.SocketDnsResolver() ips = [] try: ips = resolver.resolve_ips(host_name) except netutils.ResolveException, re: logger.warn("Failed to resolve %s" % host_name) if ips: hostReporter = sap.HostReporter(sap.HostBuilder()) host_osh, vector = hostReporter.reportHostWithIps(*ips) instance = sap.Instance('ASCS', instance_number, host_name) ascs_pdo = sap_abap.AscsInstanceBuilder.createPdo(instance, system) ascs_builder = sap_abap.AscsInstanceBuilder() reporter = sap_abap.InstanceReporter(ascs_builder) ascs_osh = reporter.reportInstance(ascs_pdo, host_osh) vector.add(ascs_osh) vector.add(host_osh) return ascs_osh, vector return None, None