aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/@core-xds/services/sdk.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/app/@core-xds/services/sdk.service.ts')
-rw-r--r--webapp/src/app/@core-xds/services/sdk.service.ts187
1 files changed, 143 insertions, 44 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);
+ }
+
}