Discovery Result Service
This commit is contained in:
parent
c4220866ff
commit
517c765868
|
@ -93,7 +93,7 @@ export class Discovery extends React.Component<Props, State> {
|
|||
|
||||
let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
|
||||
|
||||
idx = 2;
|
||||
idx = 3;
|
||||
|
||||
switch(idx) {
|
||||
case 1:
|
||||
|
@ -161,18 +161,86 @@ export class Discovery extends React.Component<Props, State> {
|
|||
|
||||
port.host = cHost;
|
||||
|
||||
let pChkObj: Object = port;
|
||||
if(pChkObj.hasOwnProperty('services')) {
|
||||
port.services = null;
|
||||
}
|
||||
|
||||
this.props.onTestDiscovery('2', port);
|
||||
}
|
||||
public testService(): void {
|
||||
|
||||
let service: Service = null;
|
||||
|
||||
do {
|
||||
let host: Host = this.testRandomHost();
|
||||
let port: Port = this.testRandomPort(host);
|
||||
service = this.testRandomService(port);
|
||||
} while(service === null);
|
||||
|
||||
this.props.onTestDiscovery('3', service);
|
||||
}
|
||||
|
||||
public testRandomHost(): Host {
|
||||
|
||||
let min: number = 0;
|
||||
let max: number = this.exDisHosts.length - 1;
|
||||
|
||||
let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
|
||||
|
||||
console.log('idx ----' + idx);
|
||||
let host: Host = this.exDisHosts[idx];
|
||||
console.log(host);
|
||||
this.props.onTestDiscovery('1', this.exDisHosts[idx]);
|
||||
return host;
|
||||
}
|
||||
public testRandomPort(host: Host): Port {
|
||||
if(host === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let cHost: Host = _.clone(host);
|
||||
let chkObj: Object = cHost;
|
||||
if(chkObj.hasOwnProperty('ports') === false
|
||||
|| host.ports === null) {
|
||||
cHost.ports = null;
|
||||
return null;
|
||||
} else {
|
||||
|
||||
|
||||
let portmin: number = 0;
|
||||
let portmax: number = host.ports.length - 1;
|
||||
|
||||
let portIdx: number = Math.floor(Math.random() * (portmax - portmin + 1) + portmin);
|
||||
let port: Port = host.ports[portIdx];
|
||||
cHost.ports = null;
|
||||
port.host = cHost;
|
||||
return port;
|
||||
}
|
||||
|
||||
}
|
||||
public testRandomService(port: Port): Service {
|
||||
|
||||
if(port === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let cPort: Port = _.clone(port);
|
||||
let chkObj: Object = cPort;
|
||||
if(chkObj.hasOwnProperty('services') === false
|
||||
|| port.services === null) {
|
||||
return null;
|
||||
} else {
|
||||
let min: number = 0;
|
||||
let max: number = port.services.length - 1;
|
||||
|
||||
let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
|
||||
|
||||
let service: Service = port.services[idx];
|
||||
|
||||
cPort.services = null;
|
||||
service.port = cPort;
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public handlePopupClose = () => this.setState({ startPopup: false });
|
||||
|
|
|
@ -87,11 +87,141 @@ const reducer: ReducersMapObject = {
|
|||
[IngActionTypes.RECEIVE_SERVICE]: (state: DiscoveryIngState = DiscoveryIngDefaultState,
|
||||
action: Action<Service>): DiscoveryIngState => {
|
||||
|
||||
let obj: any = action.payload;
|
||||
let service: Service = JSON.parse(obj);
|
||||
|
||||
let hostList: Host[] = null;
|
||||
|
||||
if(state.hostList === null || state.hostList === undefined) {
|
||||
hostList = new Array();
|
||||
let host: Host = _.clone(service.port.host);
|
||||
let port: Port = _.clone(service.port);
|
||||
port.host = host;
|
||||
service.port = port;
|
||||
port.services = new Array();
|
||||
port.services.push(service);
|
||||
host.ports = new Array();
|
||||
host.ports.push(port);
|
||||
|
||||
hostList.push(host);
|
||||
} else {
|
||||
hostList = _.clone(state.hostList);
|
||||
let tHost: Host = null;
|
||||
let tPort: Port = null;
|
||||
let tService: Service = null;
|
||||
for(let h of hostList) {
|
||||
if(h.ip === service.port.host.ip) {
|
||||
tHost = h;
|
||||
|
||||
let chkObj: Object = h;
|
||||
if(chkObj.hasOwnProperty('ports') === false
|
||||
|| h.ports === null) {
|
||||
let nPort: Port = _.clone(service.port);
|
||||
let nHost: Host = _.clone(h);
|
||||
nPort.host = nHost;
|
||||
service.port = nPort;
|
||||
nHost.ports = new Array();
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
break;
|
||||
}
|
||||
|
||||
tPort = null;
|
||||
for(let p of h.ports) {
|
||||
if(p.portNumber === service.port.portNumber) {
|
||||
tPort = p;
|
||||
|
||||
let pChkObj: Object = p;
|
||||
if(pChkObj.hasOwnProperty('services') === false
|
||||
|| p.services === null) {
|
||||
let nHost: Host = _.clone(h);
|
||||
let nPort: Port = _.clone(p);
|
||||
nPort.services = new Array();
|
||||
nPort.host = nHost;
|
||||
service.port = nPort;
|
||||
|
||||
let dIdx: number = hostList.indexOf(h, 0);
|
||||
if(dIdx > -1) {
|
||||
hostList.slice(dIdx, 1);
|
||||
}
|
||||
dIdx = nHost.ports.indexOf(p, 0);
|
||||
if(dIdx > -1) {
|
||||
nHost.ports.slice(dIdx, 1);
|
||||
}
|
||||
nPort.services.push(service);
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
tService = null;
|
||||
for(let s of p.services) {
|
||||
if(s.serviceName === service.serviceName) {
|
||||
tService = null;
|
||||
console.log('중복된 서비스 -' + service.serviceName);
|
||||
return {
|
||||
...state,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
if(tService === null) {
|
||||
let nHost: Host = _.clone(h);
|
||||
let nPort: Port = _.clone(p);
|
||||
|
||||
nPort.services.push(service);
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(tPort === null) {
|
||||
let nHost: Host = _.clone(h);
|
||||
let nPort: Port = _.clone(service.port);
|
||||
nPort.services = new Array();
|
||||
nPort.host = nHost;
|
||||
service.port = nPort;
|
||||
|
||||
let dIdx: number = hostList.indexOf(h, 0);
|
||||
if(dIdx > -1) {
|
||||
hostList.slice(dIdx, 1);
|
||||
}
|
||||
nPort.services.push(service);
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
}
|
||||
|
||||
// service.port.host = h;
|
||||
// if(h.ports === null || h.ports === undefined) {
|
||||
// h.ports = new Array();
|
||||
// }
|
||||
// h.ports.push(port);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(tHost === null) {
|
||||
let nHost: Host = _.clone(service.port.host);
|
||||
let nPort: Port = _.clone(service.port);
|
||||
|
||||
nPort.host = nHost;
|
||||
service.port = nPort;
|
||||
|
||||
nHost.ports = new Array();
|
||||
nPort.services = new Array();
|
||||
nPort.services.push(service);
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
// service: action.payload,
|
||||
hostList: hostList,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user