This commit is contained in:
crusader 2018-05-31 22:35:13 +09:00
parent 1ba83a802d
commit 2936533187
22 changed files with 0 additions and 857 deletions

View File

@ -1,19 +0,0 @@
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import {
REDUCERS,
EFFECTS,
} from './store';
import { MODULE } from './discovery.constant';
@NgModule({
imports: [
StoreModule.forFeature(MODULE.name, REDUCERS),
EffectsModule.forFeature(EFFECTS),
],
})
export class DiscoveryStoreModule { }

View File

@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DiscoveryStoreModule } from './discovery-store.module';
import { DiscoveryRPCModule } from './discovery-rpc.module';
import { DiscoveryLoggerModule } from './discovery-logger.module';
@ -19,7 +18,6 @@ import { MetaModule } from '@overflow/meta/meta.module';
FormsModule,
ReactiveFormsModule,
UIModule,
DiscoveryStoreModule,
DiscoveryRPCModule,
DiscoveryLoggerModule,
ProbeModule,

View File

@ -1,97 +0,0 @@
import { Action } from '@ngrx/store';
import {
Zone,
Host,
Port,
Service,
DiscoverZone as MDDiscoverZone,
DiscoverHost as MDDiscoverHost,
DiscoverPort as MDDiscoverPort,
DiscoverService as MDiscoverService,
} from '@overflow/commons-typescript/model/discovery';
export enum ActionType {
DiscoverZone = '[discovery.discovery] discoverZone',
DiscoverHost = '[discovery.discovery] discoverHost',
DiscoverPort = '[discovery.discovery] discoverPort',
DiscoverService = '[discovery.discovery] discoverService',
DiscoveryStart = '[discovery.discovery] DiscoveryService.discoveryStart',
DiscoveryStop = '[discovery.discovery] DiscoveryService.discoveryStop',
DiscoveredZone = '[discovery.discovery] DiscoveryService.discoveredZone',
DiscoveredHost = '[discovery.discovery] DiscoveryService.discoveredHost',
DiscoveredPort = '[discovery.discovery] DiscoveryService.discoveredPort',
DiscoveredService = '[discovery.discovery] DiscoveryService.discoveredService',
}
export class DiscoverZone implements Action {
readonly type = ActionType.DiscoverZone;
constructor(public payload: {probeID: string, discoverZone: MDDiscoverZone}) {}
}
export class DiscoverHost implements Action {
readonly type = ActionType.DiscoverHost;
constructor(public payload: {probeID: string, zone: Zone, discoverHost: MDDiscoverHost}) {}
}
export class DiscoverPort implements Action {
readonly type = ActionType.DiscoverPort;
constructor(public payload: {probeID: string, host: Host, discoverPort: MDDiscoverPort}) {}
}
export class DiscoverService implements Action {
readonly type = ActionType.DiscoverService;
constructor(public payload: {probeID: string, port: Port, discoverService: MDiscoverService}) {}
}
export class DiscoveryStart implements Action {
readonly type = ActionType.DiscoveryStart;
constructor(public payload: Date) {}
}
export class DiscoveryStop implements Action {
readonly type = ActionType.DiscoveryStop;
constructor(public payload: Date) {}
}
export class DiscoveredZone implements Action {
readonly type = ActionType.DiscoveredZone;
constructor(public payload: Zone) {}
}
export class DiscoveredHost implements Action {
readonly type = ActionType.DiscoveredHost;
constructor(public payload: Host) {}
}
export class DiscoveredPort implements Action {
readonly type = ActionType.DiscoveredPort;
constructor(public payload: Port) {}
}
export class DiscoveredService implements Action {
readonly type = ActionType.DiscoveredService;
constructor(public payload: Service) {}
}
export type Actions =
| DiscoverZone
| DiscoverHost
| DiscoverPort
| DiscoverService
| DiscoveryStart
| DiscoveryStop
| DiscoveredZone
| DiscoveredHost
| DiscoveredPort
| DiscoveredService
;

View File

@ -1,15 +0,0 @@
import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './discover.effect';
describe('Discover.Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [Effects]
});
});
it('should be created', inject([Effects], (effects: Effects) => {
expect(effects).toBeTruthy();
}));
});

View File

@ -1,66 +0,0 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import {
DiscoverZone,
DiscoverHost,
DiscoverPort,
DiscoverService,
ActionType
} from './discover.action';
import {DiscoveryService} from '../../service/discovery.service';
@Injectable()
export class Effects {
constructor(private actions$: Actions,
private discoveryService: DiscoveryService,
private router: Router) {
}
@Effect({ dispatch: false })
discoveryZone$ = this.actions$
.ofType(ActionType.DiscoverZone)
.map((action: DiscoverZone) => action.payload)
.do(payload => {
this.discoveryService.discoverZone(payload.probeID, payload.discoverZone);
});
@Effect({ dispatch: false })
discoveryHost$ = this.actions$
.ofType(ActionType.DiscoverHost)
.map((action: DiscoverHost) => action.payload)
.do(payload => {
this.discoveryService.discoverHost(payload.probeID, payload.zone, payload.discoverHost);
});
@Effect({ dispatch: false })
discoveryPort$ = this.actions$
.ofType(ActionType.DiscoverPort)
.map((action: DiscoverPort) => action.payload)
.do(payload => {
this.discoveryService.discoverPort(payload.probeID, payload.host, payload.discoverPort);
});
@Effect({ dispatch: false })
discoveryService$ = this.actions$
.ofType(ActionType.DiscoverService)
.map((action: DiscoverService) => action.payload)
.do(payload => {
this.discoveryService.discoverService(payload.probeID, payload.port, payload.discoverService);
});
}

View File

@ -1,227 +0,0 @@
import {
Actions,
ActionType,
} from './discover.action';
import {
State,
initialState,
} from './discover.state';
import {
Zone,
Host,
Port,
Service,
} from '@overflow/commons-typescript/model/discovery';
// import * as _ 'lodash';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.DiscoveryStart: {
return {
...state,
isStart: true
};
}
case ActionType.DiscoveryStop: {
return {
...state,
isEnd: true
};
}
case ActionType.DiscoveredZone: {
const zone: Zone = <Zone>action.payload;
const zones: Map<string, Zone> = null === state.zones ? new Map() : state.zones;
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.DiscoveredHost: {
const host: Host = <Host>action.payload;
let zone = null;
let zones: Map<string, Zone> = state.zones;
if (zones === undefined || zones === null) {
zones = new Map();
zone = host.zone;
// zones.set(zone.network, zone);
} else {
zone = zones.get(host.zone.network);
}
if (undefined === zone) {
// console.error(`Discovery.discoveredHost: Zone[${host.zone.network}] is not exist`);
zone = new Map();
}
if (null === zone.hosts || undefined === zone.hosts) {
zone.hosts = new Map();
zone.hosts.set(host.ipv4, host);
} else {
if (zone.hosts.has(host.ipv4) === false) {
zone.hosts.set(host.ipv4, 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.DiscoveredPort: {
const port: Port = <Port>action.payload;
let zone = state.zones.get(port.host.zone.network);
let zones: Map<string, Zone> = state.zones;
if (zones === undefined || zones === null) {
zones = new Map();
}
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.ipv4);
if (host === undefined || host === null) {
host = port.host;
}
if (null === host.ports || undefined === host.ports) {
host.ports = new Map();
host.ports.set(port.portNumber, port);
} else {
if (host.ports.has(port.portNumber) === false) {
host.ports.set(port.portNumber, port);
}
}
zone.hosts.set(host.ipv4, 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: {
const service: Service = <Service>action.payload;
let zone = state.zones.get(service.port.host.zone.network);
let zones: Map<string, Zone> = state.zones;
if (zones === undefined || zones === null) {
zones = new Map();
}
if (zone === undefined || zone === null) {
zone = service.port.host.zone;
}
if (zone.hosts === undefined || zone.hosts === null) {
zone.hosts = new Map();
}
// 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`);
// }
let host: Host = null;
host = zone.hosts.get(service.port.host.ipv4);
if (host === undefined || host === null) {
zone.hosts.set(service.port.host.ipv4, service.port.host);
host = service.port.host;
}
if (undefined === host.ports || null === host.ports) {
host.ports = new Map();
host.ports.set(service.port.portNumber, service.port);
}
let port: Port = null;
port = host.ports.get(service.port.portNumber);
if (undefined === port || null === port) {
port = service.port;
}
if ( undefined === port.services || null === port.services) {
port.services = new Map();
}
port.services.set(service.serviceName, service);
host.ports.set(service.port.portNumber, port);
zone.hosts.set(host.ipv4, 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
};
}
default: {
return state;
}
}
}
// function checkZone(state, pZone: Zone) : {
// }

View File

@ -1,22 +0,0 @@
import { RPCClientError } from '@loafer/ng-rpc';
import { Zone } from '@overflow/commons-typescript/model/discovery';
export interface State {
error: RPCClientError | null;
processing: boolean;
zones: Map<string, Zone> | null;
isReq: boolean;
isStart: boolean;
isEnd: boolean;
}
export const initialState: State = {
error: null,
processing: false,
zones: null,
isReq: false,
isStart: false,
isEnd: false
};

View File

@ -1,4 +0,0 @@
export * from './discover.action';
export * from './discover.reducer';
export * from './discover.state';
export * from './discover.effect';

View File

@ -1,42 +0,0 @@
import {
createSelector,
createFeatureSelector,
ActionReducerMap,
Selector,
} from '@ngrx/store';
import { StateSelector } from '@overflow/core/ngrx/store';
import { MODULE } from '../discovery.constant';
import * as DiscoverStore from './discover';
import * as SettingStore from './setting';
export interface State {
discover: DiscoverStore.State;
setting: SettingStore.State;
}
export const REDUCERS = {
discover: DiscoverStore.reducer,
setting: SettingStore.reducer,
};
export const EFFECTS = [
SettingStore.Effects,
DiscoverStore.Effects,
];
export const selectDiscoveryState = createFeatureSelector<State>(MODULE.name);
export const DiscoverSelector = new StateSelector<DiscoverStore.State>(createSelector(
selectDiscoveryState,
(state: State) => state.discover
));
export const SettingSelector = new StateSelector<SettingStore.State>(createSelector(
selectDiscoveryState,
(state: State) => state.setting
));

View File

@ -1,4 +0,0 @@
export * from './regist.action';
export * from './regist.effect';
export * from './regist.reducer';
export * from './regist.state';

View File

@ -1,45 +0,0 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import {
Zone,
Host,
Port,
Service,
DiscoverZone as MDDiscoverZone,
DiscoverHost as MDDiscoverHost,
DiscoverPort as MDDiscoverPort,
DiscoverService as MDiscoverService,
} from '@overflow/commons-typescript/model/discovery';
import { Probe } from '@overflow/commons-typescript/model/probe';
export enum ActionType {
SaveAllTarget = '[@@REGIST] TargetDiscoveryService.saveAllTarget',
SaveAllTargetSuccess = '[@@REGIST] TargetDiscoveryService.SaveAllTargetSuccess',
SaveAllTargetFailure = '[@@REGIST] TargetDiscoveryService.SaveAllTargetFailure',
}
export class DiscoverySaveAllTarget implements Action {
readonly type = ActionType.SaveAllTarget;
constructor(public payload: {hosts: Host[], probe: Probe}) {}
}
export class DiscoverySaveAllTargetSuccess implements Action {
readonly type = ActionType.SaveAllTargetSuccess;
constructor(public payload: Boolean) {}
}
export class DiscoverySaveAllTargetFailure implements Action {
readonly type = ActionType.SaveAllTargetFailure;
constructor(public payload: RPCClientError) {}
}
export type Actions =
| DiscoverySaveAllTarget
| DiscoverySaveAllTargetSuccess
| DiscoverySaveAllTargetFailure
;

View File

@ -1,15 +0,0 @@
import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './regist.effect';
describe('Regist.Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [Effects]
});
});
it('should be created', inject([Effects], (effects: Effects) => {
expect(effects).toBeTruthy();
}));
});

View File

@ -1,51 +0,0 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import { RPCClientError } from '@loafer/ng-rpc';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
import { TargetDiscoveryService } from '../../service/target-discovery.service';
import {
DiscoverySaveAllTarget,
DiscoverySaveAllTargetSuccess,
DiscoverySaveAllTargetFailure,
ActionType
} from './regist.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private targetDiscoveryService: TargetDiscoveryService,
private router: Router
) { }
@Effect()
saveAllTargetResult$: Observable<Action> = this.actions$
.ofType(ActionType.SaveAllTarget)
.map((action: DiscoverySaveAllTarget) => action.payload)
.switchMap(payload => this.targetDiscoveryService.saveAllTarget(payload.hosts, payload.probe))
.map(result => {
return new DiscoverySaveAllTargetSuccess(result);
})
.catch((error: RPCClientError) => {
console.log(error.response.message);
return of(new DiscoverySaveAllTargetFailure(error));
});
}

View File

@ -1,45 +0,0 @@
import {
Actions,
ActionType,
} from './regist.action';
import {
State,
initialState,
} from './regist.state';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.SaveAllTarget: {
return {
...state,
error: null,
isPending: true,
};
}
case ActionType.SaveAllTargetSuccess: {
return {
...state,
error: null,
isPending: false,
isSuccess: action.payload,
};
}
case ActionType.SaveAllTargetFailure: {
return {
...state,
error: action.payload,
isPending: false,
isSuccess: null,
};
}
default: {
return state;
}
}
}

View File

@ -1,18 +0,0 @@
import { RPCClientError } from '@loafer/ng-rpc';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
export interface State {
error: RPCClientError | null;
isPending: boolean;
isSuccess: Boolean | null;
}
export const initialState: State = {
error: null,
isPending: false,
isSuccess: null,
};
export const getSuccess = (state: State) => state.isSuccess;

View File

@ -1,4 +0,0 @@
export * from './setting.action';
export * from './setting.effect';
export * from './setting.reducer';
export * from './setting.state';

View File

@ -1,42 +0,0 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
export enum ActionType {
Setting = '[discovery.setting] Setting',
SettingSuccess = '[discovery.setting] SettingSuccess',
SettingFailure = '[discovery.setting] SettingFailure',
SettingRedirect = '[discovery.setting] SettingRedirect',
}
export class Setting implements Action {
readonly type = ActionType.Setting;
constructor(public payload: DiscoveryStartInfo) {}
}
export class SettingSuccess implements Action {
readonly type = ActionType.SettingSuccess;
constructor(public payload: DiscoveryStartInfo) {}
}
export class SettingFailure implements Action {
readonly type = ActionType.SettingFailure;
constructor(public payload: RPCClientError) {}
}
export class SettingRedirect implements Action {
readonly type = ActionType.SettingRedirect;
}
export type Actions =
| Setting
| SettingSuccess
| SettingFailure
| SettingRedirect
;

View File

@ -1,15 +0,0 @@
import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './setting.effect';
describe('Auth.Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [Effects]
});
});
it('should be created', inject([Effects], (effects: Effects) => {
expect(effects).toBeTruthy();
}));
});

View File

@ -1,51 +0,0 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import { RPCClientError } from '@loafer/ng-rpc';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
import { DiscoveryService } from '../../service/discovery.service';
import {
Setting,
SettingSuccess,
SettingFailure,
ActionType,
} from './setting.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private discoveryService: DiscoveryService,
private router: Router
) { }
// @Effect()
// startDiscovery$: Observable<Action> = this.actions$
// .ofType(ActionType.Setting)
// .map((action: Setting) => action.payload)
// .switchMap(payload => this.discoveryService.start(payload))
// .map(discoveryStartInfo => {
// return new SettingSuccess(discoveryStartInfo);
// })
// .catch((error: RPCClientError) => {
// console.log(error.response.message);
// return of(new SettingFailure(error));
// });
}

View File

@ -1,48 +0,0 @@
import {
Actions,
ActionType,
Setting,
} from './setting.action';
import {
State,
initialState,
} from './setting.state';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.Setting: {
return {
...state,
error: null,
isPending: true,
};
}
case ActionType.SettingSuccess: {
return {
...state,
isStart: true,
error: null,
isPending: false,
discoveryStartInfo: action.payload,
};
}
case ActionType.SettingFailure: {
return {
...state,
isStart: false,
error: action.payload,
isPending: false,
discoveryStartInfo: null,
};
}
default: {
return state;
}
}
}

View File

@ -1,22 +0,0 @@
import { RPCClientError } from '@loafer/ng-rpc';
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
export interface State {
isStart: boolean;
error: RPCClientError | null;
isPending: boolean;
discoveryStartInfo: DiscoveryStartInfo | null;
}
export const initialState: State = {
isStart: false,
error: null,
isPending: false,
discoveryStartInfo: null,
};
export const isStart = (state: State) => state.isStart;
export const getDiscoveryStartInfo = (state: State) => state.discoveryStartInfo;
export const getError = (state: State) => state.error;
export const isPending = (state: State) => state.isPending;

View File

@ -5,9 +5,6 @@ import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger';
import { DiscoverSelector } from '../store';
import * as DiscoverStore from '../store/discover';
import {
Zone,
Host,