func()

in internal/system/appsdiscovery/apps_discovery.go [321:381]


func (d *SapDiscovery) DiscoverSAPApps(ctx context.Context, sapApps *sappb.SAPInstances, conf *cpb.DiscoveryConfiguration) []SapSystemDetails {
	sapSystems := []SapSystemDetails{}
	if sapApps == nil {
		log.CtxLogger(ctx).Debugw("No SAP applications found")
		return sapSystems
	}
	if !d.hasExecutePermission("/usr/sap") {
		log.CtxLogger(ctx).Warnw("No execute permission for /usr/sap directory, some of the discovery operations will fail. Please ensure that the root user has execute permission for /usr/sap directory.")
		return sapSystems
	}
	log.CtxLogger(ctx).Debugw("SAP Apps found", "apps", sapApps)
	for _, app := range sapApps.Instances {
		switch app.Type {
		case sappb.InstanceType_NETWEAVER:
			log.CtxLogger(ctx).Infow("discovering netweaver", "sid", app.Sapsid)
			sys := d.discoverNetweaver(ctx, app, conf)
			log.CtxLogger(ctx).Debugf("Netweaver system: %s", sys)
			// See if a system with the same SID already exists
			found := false
			for i, s := range sapSystems {
				log.CtxLogger(ctx).Infow("Comparing to system", "dbSid", s.DBComponent.GetSid(), "appSID", s.AppComponent.GetSid())
				if (s.AppComponent.GetSid() == "" || s.AppComponent.GetSid() == sys.AppComponent.GetSid()) &&
					(s.DBComponent.GetSid() == "" || s.DBComponent.GetSid() == sys.DBComponent.GetSid()) {

					log.CtxLogger(ctx).Infow("Found existing system", "sid", sys.AppComponent.GetSid())
					sapSystems[i] = mergeSystemDetails(s, sys)
					sapSystems[i].AppOnHost = true
					found = true
					break
				}
			}
			if !found {
				log.CtxLogger(ctx).Infow("No existing system", "sid", app.Sapsid)
				sys.AppOnHost = true
				sapSystems = append(sapSystems, sys)
			}
		case sappb.InstanceType_HANA:
			log.CtxLogger(ctx).Infow("discovering hana", "sid", app.Sapsid)
			for _, sys := range d.discoverHANA(ctx, app) {
				// See if a system with the same SID already exists
				found := false
				for i, s := range sapSystems {
					if s.DBComponent.GetSid() == sys.DBComponent.GetSid() {
						log.CtxLogger(ctx).Infow("Found existing system", "sid", sys.DBComponent.GetSid())
						sapSystems[i] = mergeSystemDetails(s, sys)
						sapSystems[i].DBOnHost = true
						found = true
						break
					}
				}

				if !found {
					log.CtxLogger(ctx).Infow("No existing system", "sid", sys.DBComponent.GetSid())
					sys.DBOnHost = true
					sapSystems = append(sapSystems, sys)
				}
			}
		}
	}
	return sapSystems
}