Merge branch 'master' of https://git.loafle.net/overflow/overflow-webapp
This commit is contained in:
commit
9b70c21822
|
@ -2,7 +2,7 @@ import { TestBed, inject } from '@angular/core/testing';
|
||||||
|
|
||||||
import { DiscoveryService } from './discovery.service';
|
import { DiscoveryService } from './discovery.service';
|
||||||
|
|
||||||
describe('MemberService', () => {
|
describe('DiscoveryService', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [DiscoveryService]
|
providers: [DiscoveryService]
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { DiscoveryService } from './discovery.service';
|
import { DiscoveryService } from './discovery.service';
|
||||||
|
import { TargetDiscoveryService } from './target-discovery.service';
|
||||||
|
|
||||||
export const SERVICES = [
|
export const SERVICES = [
|
||||||
DiscoveryService,
|
DiscoveryService,
|
||||||
|
TargetDiscoveryService,
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { TestBed, inject } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { TargetDiscoveryService } from './target-discovery.service';
|
||||||
|
|
||||||
|
describe('TargetDiscoveryService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [TargetDiscoveryService]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([TargetDiscoveryService], (service: TargetDiscoveryService) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
31
src/packages/discovery/service/target-discovery.service.ts
Normal file
31
src/packages/discovery/service/target-discovery.service.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { RPCClient } from 'packages/core/rpc/client/RPCClient';
|
||||||
|
import {
|
||||||
|
DiscoveryStartInfo,
|
||||||
|
DiscoveryZone,
|
||||||
|
DiscoveryHost,
|
||||||
|
DiscoveryPort,
|
||||||
|
DiscoveryService as M_DiscoveryService,
|
||||||
|
Zone,
|
||||||
|
Host,
|
||||||
|
Port,
|
||||||
|
Service,
|
||||||
|
} from '../model';
|
||||||
|
import { Probe } from 'packages/probe/model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TargetDiscoveryService {
|
||||||
|
|
||||||
|
public constructor(
|
||||||
|
private rpcClient: RPCClient,
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public saveAllTarget(hosts: Host[], probe: Probe): Observable<Boolean> {
|
||||||
|
|
||||||
|
return this.rpcClient.call('TargetDiscoveryService.saveAllTarget', hosts, probe);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,84 +0,0 @@
|
||||||
// import { Action } from '@ngrx/store';
|
|
||||||
|
|
||||||
// import { notificationActionEnum } from 'packages/core/rpc/store/notification';
|
|
||||||
// import { RPCError } from 'packages/core/rpc/error';
|
|
||||||
|
|
||||||
// import {
|
|
||||||
// Zone,
|
|
||||||
// Host,
|
|
||||||
// Port,
|
|
||||||
// Service,
|
|
||||||
// DiscoveryZone,
|
|
||||||
// DiscoveryHost,
|
|
||||||
// DiscoveryPort,
|
|
||||||
// DiscoveryService as MDiscoveryService,
|
|
||||||
// } from '../../model';
|
|
||||||
|
|
||||||
// export enum ActionType {
|
|
||||||
// DiscoverZone = '[@@NOTIFICATION] DiscoveryService.discoverZone',
|
|
||||||
// DiscoverHost = '[@@NOTIFICATION] DiscoveryService.discoverHost',
|
|
||||||
// DiscoverPort = '[@@NOTIFICATION] DiscoveryService.discoverPort',
|
|
||||||
// DiscoverService = '[@@NOTIFICATION] DiscoveryService.discoverService',
|
|
||||||
// DiscoveredZone = '[@@NOTIFICATION] DiscoveryService.discoveredZone',
|
|
||||||
// DiscoveredHost = '[@@NOTIFICATION] DiscoveryService.discoveredHost',
|
|
||||||
// DiscoveredPort = '[@@NOTIFICATION] DiscoveryService.discoveredPort',
|
|
||||||
// DiscoveredService = '[@@NOTIFICATION] DiscoveryService.discoveredService',
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export class DiscoverZone implements Action {
|
|
||||||
// readonly type = ActionType.DiscoverZone;
|
|
||||||
|
|
||||||
// constructor(public payload: {probeID: string, discoveryZone: DiscoveryZone}) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export class DiscoverHost implements Action {
|
|
||||||
// readonly type = ActionType.DiscoverHost;
|
|
||||||
|
|
||||||
// constructor(public payload: {probeID: string, zone: Zone, discoveryHost: DiscoveryHost}) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export class DiscoverPort implements Action {
|
|
||||||
// readonly type = ActionType.DiscoverPort;
|
|
||||||
|
|
||||||
// constructor(public payload: {probeID: string, host: Host, discoveryPort: DiscoveryPort}) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export class DiscoverService implements Action {
|
|
||||||
// readonly type = ActionType.DiscoverService;
|
|
||||||
// constructor(public payload: {probeID: string, port: Port, discoveryService: MDiscoveryService}) {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// | DiscoveredZone
|
|
||||||
// | DiscoveredHost
|
|
||||||
// | DiscoveredPort
|
|
||||||
// | DiscoveredService
|
|
||||||
// ;
|
|
4
src/packages/discovery/store/regist/index.ts
Normal file
4
src/packages/discovery/store/regist/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export * from './regist.action';
|
||||||
|
export * from './regist.effect';
|
||||||
|
export * from './regist.reducer';
|
||||||
|
export * from './regist.state';
|
46
src/packages/discovery/store/regist/regist.action.ts
Normal file
46
src/packages/discovery/store/regist/regist.action.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import { Action } from '@ngrx/store';
|
||||||
|
|
||||||
|
import { notificationActionEnum } from 'packages/core/rpc/store/notification';
|
||||||
|
import { RPCError } from 'packages/core/rpc/error';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Zone,
|
||||||
|
Host,
|
||||||
|
Port,
|
||||||
|
Service,
|
||||||
|
DiscoveryZone,
|
||||||
|
DiscoveryHost,
|
||||||
|
DiscoveryPort,
|
||||||
|
DiscoveryService as MDiscoveryService,
|
||||||
|
} from '../../model';
|
||||||
|
import { Probe } from 'packages/probe/model';
|
||||||
|
|
||||||
|
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: RPCError) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Actions =
|
||||||
|
| DiscoverySaveAllTarget
|
||||||
|
| DiscoverySaveAllTargetSuccess
|
||||||
|
| DiscoverySaveAllTargetFailure
|
||||||
|
;
|
15
src/packages/discovery/store/regist/regist.effect.spec.ts
Normal file
15
src/packages/discovery/store/regist/regist.effect.spec.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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();
|
||||||
|
}));
|
||||||
|
});
|
51
src/packages/discovery/store/regist/regist.effect.ts
Normal file
51
src/packages/discovery/store/regist/regist.effect.ts
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
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 { RPCError } from 'packages/core/rpc/error';
|
||||||
|
|
||||||
|
import { DiscoveryStartInfo } from '../../model';
|
||||||
|
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: RPCError) => {
|
||||||
|
console.log(error.response.message);
|
||||||
|
return of(new DiscoverySaveAllTargetFailure(error));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
47
src/packages/discovery/store/regist/regist.reducer.ts
Normal file
47
src/packages/discovery/store/regist/regist.reducer.ts
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import { RPCError } from 'packages/core/rpc/error';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Actions,
|
||||||
|
ActionType,
|
||||||
|
} from './regist.action';
|
||||||
|
|
||||||
|
import {
|
||||||
|
State,
|
||||||
|
initialState,
|
||||||
|
} from './regist.state';
|
||||||
|
|
||||||
|
import { DiscoveryStartInfo } from '../../model';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
src/packages/discovery/store/regist/regist.state.ts
Normal file
18
src/packages/discovery/store/regist/regist.state.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { RPCError } from 'packages/core/rpc/error';
|
||||||
|
|
||||||
|
import { DiscoveryStartInfo } from '../../model';
|
||||||
|
|
||||||
|
export interface State {
|
||||||
|
error: RPCError | null;
|
||||||
|
isPending: boolean;
|
||||||
|
isSuccess: Boolean | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initialState: State = {
|
||||||
|
error: null,
|
||||||
|
isPending: false,
|
||||||
|
isSuccess: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getSuccess = (state: State) => state.isSuccess;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user