fixed dicovery reducer

This commit is contained in:
snoop 2018-03-29 21:17:32 +09:00
parent 36497b1455
commit cadbb23893

View File

@ -56,8 +56,13 @@ export function reducer(state = initialState, action: Actions): State {
} }
if (null === zone.hosts || undefined === zone.hosts) { if (null === zone.hosts || undefined === zone.hosts) {
zone.hosts = new Map(); zone.hosts = new Map();
}
zone.hosts.set(host.ip, host); zone.hosts.set(host.ip, host);
} else {
if (zone.hosts.has(host.ip) === false) {
zone.host.set(host.ip, host);
}
}
zones.set(zone.network, zone); zones.set(zone.network, zone);
const newZones: Map<string, Zone> = new Map(); const newZones: Map<string, Zone> = new Map();
@ -74,42 +79,116 @@ export function reducer(state = initialState, action: Actions): State {
case ActionType.DiscoveredPort: { case ActionType.DiscoveredPort: {
const port: Port = <Port>action.payload; const port: Port = <Port>action.payload;
const zone = state.zones.get(port.host.zone.network); let zone = state.zones.get(port.host.zone.network);
if (undefined === zone) {
console.error(`Discovery.DiscoveredPort: Zone[${port.host.zone.network}] is not exist`); let zones: Map<string, Zone> = state.zones;
if (zones === undefined || zones === null) {
zones = new Map();
} }
if (null === zone.hosts || undefined === zone.hosts.get(port.host.ip)) {
console.error(`Discovery.DiscoveredPort: Host[${port.host.ip}] is not exist`); if (zone === undefined || zone === null) {
zone = port.host.zone;
}
// if (undefined === zone) {
// console.error(`Discovery.DiscoveredPort: Zone[${port.host.zone.network}] is not exist`);
// }
// if (null === zone.hosts || undefined === zone.hosts.get(port.host.ip)) {
// console.error(`Discovery.DiscoveredPort: Host[${port.host.ip}] is not exist`);
// return state;
// }
if (zone.hosts === undefined || zone.hosts === null) {
zone.hosts = new Map();
}
let host: Host = null;
host = zone.hosts.get(port.host.ip);
if (host === undefined || host === null) {
host = port.host;
} }
const host: Host = zone.hosts.get(port.host.ip);
if (null === host.ports) { if (null === host.ports) {
host.ports = new Map(); host.ports = new Map();
}
host.ports.set(port.portNumber, port); host.ports.set(port.portNumber, port);
return state; } else {
if (host.ports.has(port.portNumber) === false) {
host.ports.set(port.portNumber, port);
}
}
zone.hosts.set(host.ip, host);
zones.set(zone.network, zone);
const newZones: Map<string, Zone> = new Map();
zones.forEach(function(value, key) {
newZones.set(key, value);
});
return {
...state,
zones: newZones
};
} }
case ActionType.DiscoveredService: { case ActionType.DiscoveredService: {
const service: Service = <Service>action.payload; const service: Service = <Service>action.payload;
const zone = state.zones.get(service.port.host.zone.network); let zone = state.zones.get(service.port.host.zone.network);
if (undefined === zone) {
console.error(`Discovery.DiscoveredService: Zone[${service.port.host.zone.network}] is not exist`); let zones: Map<string, Zone> = state.zones;
if (zones === undefined || zones === null) {
zones = new Map();
} }
if (null === zone.hosts || undefined === zone.hosts.get(service.port.host.ip)) {
console.error(`Discovery.DiscoveredPort: Host[${service.port.host.ip}] is not exist`); if (zone === undefined || zone === null) {
zone = service.port.host.zone;
} }
if (zone.hosts === undefined || zone.hosts === null) {
zone.hosts = new Map();
}
zone.hosts.set(service.port.host.ip, service.port.host);
// if (undefined === zone) {
// console.error(`Discovery.DiscoveredService: Zone[${service.port.host.zone.network}] is not exist`);
// }
// if (null === zone.hosts || undefined === zone.hosts.get(service.port.host.ip)) {
// console.error(`Discovery.DiscoveredPort: Host[${service.port.host.ip}] is not exist`);
// }
const host: Host = zone.hosts.get(service.port.host.ip); const host: Host = zone.hosts.get(service.port.host.ip);
if (null === host.ports || undefined === host.ports.get(service.port.portNumber)) { if (null === host.ports || undefined === host.ports.get(service.port.portNumber)) {
console.error(`Discovery.DiscoveredPort: Port[${service.port.portNumber}] is not exist`); // console.error(`Discovery.DiscoveredPort: Port[${service.port.portNumber}] is not exist`);
host.ports = new Map();
} }
host.ports.set(service.port.portNumber, service.port);
const port: Port = host.ports.get(service.port.portNumber); const port: Port = host.ports.get(service.port.portNumber);
if (null === port.services) { if (null === port.services) {
port.services = new Map(); port.services = new Map();
} }
port.services.set(service.serviceName, service); port.services.set(service.serviceName, service);
return state;
zones.set(zone.network, zone);
const newZones: Map<string, Zone> = new Map();
zones.forEach(function(value, key) {
newZones.set(key, value);
});
return {
...state,
zones: newZones
};
} }
default: { default: {
@ -117,3 +196,9 @@ export function reducer(state = initialState, action: Actions): State {
} }
} }
} }
// function checkZone(state, pZone: Zone) : {
// }