aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/@core-xds
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/app/@core-xds')
-rw-r--r--webapp/src/app/@core-xds/services/sdk.service.ts187
-rw-r--r--webapp/src/app/@core-xds/services/xdsagent.service.ts72
2 files changed, 209 insertions, 50 deletions
diff --git a/webapp/src/app/@core-xds/services/sdk.service.ts b/webapp/src/app/@core-xds/services/sdk.service.ts
index 2d54d4e..8fa6ad2 100644
--- a/webapp/src/app/@core-xds/services/sdk.service.ts
+++ b/webapp/src/app/@core-xds/services/sdk.service.ts
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-import { Injectable, SecurityContext } from '@angular/core';
+import { Injectable, SecurityContext, isDevMode } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@@ -25,60 +25,159 @@ import { XDSAgentService } from '../services/xdsagent.service';
import 'rxjs/add/observable/throw';
export interface ISdk {
- id: string;
- profile: string;
- version: string;
- arch: number;
- path: string;
+ id: string;
+ name: string;
+ description: string;
+ profile: string;
+ version: string;
+ arch: string;
+ path: string;
+ url: string;
+ status: string;
+ date: string;
+ size: string;
+ md5sum: string;
+ setupFile: string;
+ lastError: string;
+}
+
+export interface ISdkManagementMsg {
+ cmdID: string;
+ timestamp: string;
+ sdk: ISdk;
+ stdout: string;
+ stderr: string;
+ progress: number;
+ exited: boolean;
+ code: number;
+ error: string;
}
@Injectable()
export class SdkService {
- public Sdks$: Observable<ISdk[]>;
-
- private _sdksList = [];
- private current: ISdk;
- private sdksSubject = <BehaviorSubject<ISdk[]>>new BehaviorSubject(this._sdksList);
-
- constructor(private xdsSvr: XDSAgentService) {
- this.current = null;
- this.Sdks$ = this.sdksSubject.asObservable();
-
- this.xdsSvr.XdsConfig$.subscribe(cfg => {
- if (!cfg || cfg.servers.length < 1) {
- return;
- }
- // FIXME support multiple server
- // cfg.servers.forEach(svr => {
- this.xdsSvr.getSdks(cfg.servers[0].id).subscribe((s) => {
- this._sdksList = s;
- this.sdksSubject.next(s);
- });
- });
- }
+ public Sdks$: Observable<ISdk[]>;
+ public curSdk$: Observable<ISdk>;
- public setCurrent(s: ISdk) {
- this.current = s;
- }
+ private _sdksList = [];
+ private sdksSubject = <BehaviorSubject<ISdk[]>>new BehaviorSubject(this._sdksList);
+ private current: ISdk;
+ private curSdkSubject = <BehaviorSubject<ISdk>>new BehaviorSubject(this.current);
+ private curServerID;
- public getCurrent(): ISdk {
- return this.current;
- }
+ constructor(private xdsSvr: XDSAgentService) {
+ this.current = null;
+ this.Sdks$ = this.sdksSubject.asObservable();
+ this.curSdk$ = this.curSdkSubject.asObservable();
- public getCurrentId(): string {
- if (this.current && this.current.id) {
- return this.current.id;
+ this.xdsSvr.XdsConfig$.subscribe(cfg => {
+ if (!cfg || cfg.servers.length < 1) {
+ return;
+ }
+ // FIXME support multiple server
+ // cfg.servers.forEach(svr => {
+ this.curServerID = cfg.servers[0].id;
+ this.xdsSvr.getSdks(this.curServerID).subscribe((sdks) => {
+ this._sdksList = [];
+ sdks.forEach(s => {
+ this._addSdk(s, true);
+ });
+
+ // TODO: get previous val from xds-config service / cookie
+ if (this._sdksList.length > 0) {
+ this.current = this._sdksList[0];
+ this.curSdkSubject.next(this.current);
}
- return '';
+
+ this.sdksSubject.next(this._sdksList);
+ });
+ });
+
+ // Add listener on sdk creation, deletion and change events
+ this.xdsSvr.onSdkInstall().subscribe(evMgt => {
+ this._addSdk(evMgt.sdk);
+ });
+ this.xdsSvr.onSdkRemove().subscribe(evMgt => {
+ if (evMgt.sdk.status !== 'Not Installed') {
+ /* tslint:disable:no-console */
+ console.log('Error: received event:sdk-remove with invalid status: evMgt=', evMgt);
+ return;
+ }
+ this._delSdk(evMgt.sdk);
+ });
+
+ }
+
+ public setCurrent(s: ISdk) {
+ this.current = s;
+ }
+
+ public getCurrent(): ISdk {
+ return this.current;
+ }
+
+ public getCurrentId(): string {
+ if (this.current && this.current.id) {
+ return this.current.id;
}
+ return '';
+ }
+
+ public install(sdk: ISdk): Observable<ISdk> {
+ return this.xdsSvr.installSdk(this.curServerID, sdk.id);
+ }
+
+ public onInstall(): Observable<ISdkManagementMsg> {
+ return this.xdsSvr.onSdkInstall();
+ }
+
+ public abortInstall(sdk: ISdk): Observable<ISdk> {
+ return this.xdsSvr.abortInstall(this.curServerID, sdk.id);
+ }
+
+ public remove(sdk: ISdk): Observable<ISdk> {
+ return this.xdsSvr.removeSdk(this.curServerID, sdk.id);
+ }
+
+ /** Private **/
- public add(sdk: ISdk): Observable<ISdk> {
- // TODO SEB
- return Observable.throw('Not implement yet');
+ private _addSdk(sdk: ISdk, noNext?: boolean): ISdk {
+
+ // add new sdk
+ this._sdksList.push(sdk);
+
+ // sort sdk array
+ this._sdksList.sort((a, b) => {
+ if (a.name < b.name) {
+ return -1;
+ }
+ if (a.name > b.name) {
+ return 1;
+ }
+ return 0;
+ });
+
+ if (!noNext) {
+ this.sdksSubject.next(this._sdksList);
}
- public delete(sdk: ISdk): Observable<ISdk> {
- // TODO SEB
- return Observable.throw('Not implement yet');
+ return sdk;
+ }
+
+ private _delSdk(sdk: ISdk) {
+ const idx = this._sdksList.findIndex(item => item.id === sdk.id);
+ if (idx === -1) {
+ if (isDevMode) {
+ /* tslint:disable:no-console */
+ console.log('Warning: Try to delete sdk unknown id: sdk=', sdk);
+ }
+ return;
+ }
+ const delId = this._sdksList[idx].id;
+ this._sdksList.splice(idx, 1);
+ if (delId === this.current.id) {
+ this.setCurrent(this._sdksList[0]);
}
+ this.sdksSubject.next(this._sdksList);
+ }
+
}
diff --git a/webapp/src/app/@core-xds/services/xdsagent.service.ts b/webapp/src/app/@core-xds/services/xdsagent.service.ts
index 94d3dec..9f8385a 100644
--- a/webapp/src/app/@core-xds/services/xdsagent.service.ts
+++ b/webapp/src/app/@core-xds/services/xdsagent.service.ts
@@ -25,7 +25,7 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import * as io from 'socket.io-client';
import { AlertService } from './alert.service';
-import { ISdk } from './sdk.service';
+import { ISdk, ISdkManagementMsg } from './sdk.service';
import { ProjectType, ProjectTypeEnum } from './project.service';
// Import RxJs required methods
@@ -34,7 +34,7 @@ import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/observable/of';
-import 'rxjs/add/operator/retryWhen';
+import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
export interface IXDSConfigProject {
@@ -133,6 +133,9 @@ export class XDSAgentService {
protected projectDel$ = new Subject<IXDSProjectConfig>();
protected projectChange$ = new Subject<IXDSProjectConfig>();
+ protected sdkInstall$ = new Subject<ISdkManagementMsg>();
+ protected sdkRemove$ = new Subject<ISdkManagementMsg>();
+
private baseUrl: string;
private wsUrl: string;
private httpSessionID: string;
@@ -249,7 +252,7 @@ export class XDSAgentService {
this.socket.on('event:project-add', (ev) => {
if (ev && ev.data && ev.data.id) {
this.projectAdd$.next(Object.assign({}, ev.data));
- if (ev.sessionID !== this.httpSessionID && ev.data.label) {
+ if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && ev.data.label) {
this.alert.info('Project "' + ev.data.label + '" has been added by another tool.');
}
} else if (isDevMode) {
@@ -261,7 +264,7 @@ export class XDSAgentService {
this.socket.on('event:project-delete', (ev) => {
if (ev && ev.data && ev.data.id) {
this.projectDel$.next(Object.assign({}, ev.data));
- if (ev.sessionID !== this.httpSessionID && ev.data.label) {
+ if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && ev.data.label) {
this.alert.info('Project "' + ev.data.label + '" has been deleted by another tool.');
}
} else if (isDevMode) {
@@ -273,10 +276,36 @@ export class XDSAgentService {
if (ev && ev.data) {
this.projectChange$.next(Object.assign({}, ev.data));
} else if (isDevMode) {
- console.log('Warning: received event:project-state-change with unknown data: ev=', ev);
+ console.log('Warning: received event:project-state-change with unkn220own data: ev=', ev);
+ }
+ });
+
+ this.socket.on('event:sdk-install', (ev) => {
+ if (ev && ev.data && ev.data.sdk) {
+ const evt = <ISdkManagementMsg>ev.data;
+ this.sdkInstall$.next(Object.assign({}, evt));
+
+ if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && evt.sdk.name) {
+ this.alert.info('SDK "' + evt.sdk.name + '" has been installed by another tool.');
+ }
+ } else if (isDevMode) {
+ /* tslint:disable:no-console */
+ console.log('Warning: received event:sdk-install with unknown data: ev=', ev);
}
});
+ this.socket.on('event:sdk-remove', (ev) => {
+ if (ev && ev.data && ev.data.sdk) {
+ const evt = <ISdkManagementMsg>ev.data;
+ this.sdkRemove$.next(Object.assign({}, evt));
+
+ if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && evt.sdk.name) {
+ this.alert.info('SDK "' + evt.sdk.name + '" has been removed by another tool.');
+ }
+ } else if (isDevMode) {
+ console.log('Warning: received event:sdk-remove with unknown data: ev=', ev);
+ }
+ });
}
/**
@@ -294,6 +323,14 @@ export class XDSAgentService {
return this.projectChange$.asObservable();
}
+ onSdkInstall(): Observable<ISdkManagementMsg> {
+ return this.sdkInstall$.asObservable();
+ }
+
+ onSdkRemove(): Observable<ISdkManagementMsg> {
+ return this.sdkRemove$.asObservable();
+ }
+
/**
** Misc / Version
***/
@@ -355,10 +392,22 @@ export class XDSAgentService {
if (!svr || !svr.connected) {
return Observable.of([]);
}
-
return this._get(svr.partialUrl + '/sdks');
}
+ installSdk(serverID: string, id: string, filename?: string, force?: boolean): Observable<ISdk> {
+ return this._post(this._getServerUrl(serverID) + '/sdks', { id: id, filename: filename, force: force });
+ }
+
+ abortInstall(serverID: string, id: string): Observable<ISdk> {
+ return this._post(this._getServerUrl(serverID) + '/sdks/abortinstall', { id: id });
+ }
+
+ removeSdk(serverID: string, id: string): Observable<ISdk> {
+ return this._delete(this._getServerUrl(serverID) + '/sdks/' + id);
+ }
+
+
/***
** Projects
***/
@@ -420,6 +469,17 @@ export class XDSAgentService {
return svr[0];
}
+ private _getServerUrl(serverID: string): string | ErrorObservable {
+ const svr = this._getServer(serverID);
+ if (!svr || !svr.connected) {
+ if (isDevMode) {
+ console.log('ERROR: XDS Server unknown: serverID=' + serverID);
+ }
+ return Observable.throw('Cannot identify XDS Server');
+ }
+ return svr.partialUrl;
+ }
+
private _attachAuthHeaders(options?: any) {
options = options || {};
const headers = options.headers || new HttpHeaders();