diff --git a/proxy/target/target_discovery_service.go b/proxy/target/target_discovery_service.go index 99760b9..8e6b1bd 100644 --- a/proxy/target/target_discovery_service.go +++ b/proxy/target/target_discovery_service.go @@ -8,6 +8,8 @@ import ( "strconv" "git.loafle.net/overflow/discovery/discovery/types" + "git.loafle.net/overflow/overflow_service/proxy" + "git.loafle.net/overflow/overflow_service/proxy/utils" ) type TargetInfo struct { @@ -151,10 +153,10 @@ func registInfraPort(port *types.DiscoveryPort, io *infra.InfraOS, p *probe.Prob return nil, err } - err = RegistTarget(port.Target, iip, p) - if err != nil { - return nil, err - } + //err = RegistTarget(port.Target, iip, p) + //if err != nil { + // return nil, err + //} return &ip, nil } @@ -205,50 +207,77 @@ func registInfraService(ih *infra.InfraHost, port *types.DiscoveryPort, service //FIXME: Discovery Result func (t *TargetService) RegistTarget(ti *TargetInfo) (string, error) { + //serviceTarget + m := make(map[string]string) - for _, host := range *ti.Hosts { - - im, err := registInfraMachine(host, ti.Probe) - - if err != nil { - return "", err - } - - io, err := registInfraOS(im, host.Os) - - if err != nil { - return "", err - } - - ih, err := registInfraHost(host, io, ti.Probe) - - if err != nil { - return "", err - } - - for _, port := range host.Ports { - - _, err := registInfraPort(port, io, ti.Probe) - - if err != nil { - return "", err - } - - for _, service := range port.Services { - - _, err := registInfraService(ih, port, service, ti.Probe) - - if err != nil { - return "", err - } - } - - } - + hBy, err := json.Marshal(ti.Hosts) + if err != nil { + return "", err } - return "", nil + pBy, err := json.Marshal(ti.Probe) + if err != nil { + return "", err + } + + m[utils.MODEL_PROBE] = string(pBy) + + hostListStr := utils.MODEL_LIST + hostListStr += "|" + hostListStr += utils.MODEL_HOST + + m[hostListStr] = string(hBy) + + out, err := proxy.InvokeDB("serviceTarget", "saveAllTarget", m) + + if err != nil { + return "",err + } + + + //for _, host := range *ti.Hosts { + // + // im, err := registInfraMachine(host, ti.Probe) + // + // if err != nil { + // return "", err + // } + // + // io, err := registInfraOS(im, host.Os) + // + // if err != nil { + // return "", err + // } + // + // ih, err := registInfraHost(host, io, ti.Probe) + // + // if err != nil { + // return "", err + // } + // + // for _, port := range host.Ports { + // + // _, err := registInfraPort(port, io, ti.Probe) + // + // if err != nil { + // return "", err + // } + // + // for _, service := range port.Services { + // + // _, err := registInfraService(ih, port, service, ti.Probe) + // + // if err != nil { + // return "", err + // } + // } + // + // } + // + //} + + return out, nil } diff --git a/proxy/utils/model_mapping.go b/proxy/utils/model_mapping.go index 090f429..fa35b35 100644 --- a/proxy/utils/model_mapping.go +++ b/proxy/utils/model_mapping.go @@ -19,6 +19,9 @@ const ( MODEL_SENSOR = "com.loafle.overflow.module.sensor.model.Sensor" MODEL_SENSOR_ITEM = "com.loafle.overflow.module.sensor.model.SensorItem" + MODEL_HOST = "com.loafle.overflow.module.discovery.model.Host" + MODEL_STRING = "java.lang.String" MODEL_LONG = "java.lang.Long" + MODEL_LIST = "java.util.List" )