X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=webapp%2Fsrc%2Fapp%2Fcommon%2Fconfig.service.ts;h=091ee06bc0ef14a84d8274ef6459894166f65af8;hb=271ffeae46af55459270c3480816c76aa9c80638;hp=201ee8b005353d7701c49443f5fdadf9b32759f5;hpb=2c9ae6a5a27ae2f2e23495c613e7a53aed8e786c;p=src%2Fxds%2Fxds-server.git diff --git a/webapp/src/app/common/config.service.ts b/webapp/src/app/common/config.service.ts index 201ee8b..091ee06 100644 --- a/webapp/src/app/common/config.service.ts +++ b/webapp/src/app/common/config.service.ts @@ -14,8 +14,10 @@ import 'rxjs/add/operator/mergeMap'; import { XDSServerService, IXDSConfigProject } from "../common/xdsserver.service"; +import { XDSAgentService } from "../common/xdsagent.service"; import { SyncthingService, ISyncThingProject, ISyncThingStatus } from "../common/syncthing.service"; import { AlertService, IAlert } from "../common/alert.service"; +import { UtilsService } from "../common/utils.service"; export enum ProjectType { NATIVE = 1, @@ -38,6 +40,11 @@ export interface IProject { defaultSdkID?: string; } +export interface IXDSAgentConfig { + URL: string; + retry: number; +} + export interface ILocalSTConfig { ID: string; URL: string; @@ -47,6 +54,8 @@ export interface ILocalSTConfig { export interface IConfig { xdsServerURL: string; + xdsAgent: IXDSAgentConfig; + xdsAgentZipUrl: string; projectsRootDir: string; projects: IProject[]; localSThg: ILocalSTConfig; @@ -59,13 +68,17 @@ export class ConfigService { private confSubject: BehaviorSubject; private confStore: IConfig; + private AgentConnectObs = null; private stConnectObs = null; + private xdsAgentZipUrl = ""; constructor(private _window: Window, private cookie: CookieService, - private sdkSvr: XDSServerService, + private xdsServerSvr: XDSServerService, + private xdsAgentSvr: XDSAgentService, private stSvr: SyncthingService, private alert: AlertService, + private utils: UtilsService, ) { this.load(); this.confSubject = >new BehaviorSubject(this.confStore); @@ -85,6 +98,11 @@ export class ConfigService { // Set default config this.confStore = { xdsServerURL: this._window.location.origin + '/api/v1', + xdsAgent: { + URL: 'http://localhost:8000', + retry: 10, + }, + xdsAgentZipUrl: "", projectsRootDir: "", projects: [], localSThg: { @@ -95,6 +113,17 @@ export class ConfigService { } }; } + + // Update XDS Agent tarball url + this.confStore.xdsAgentZipUrl = ""; + this.xdsServerSvr.getXdsAgentInfo().subscribe(nfo => { + let os = this.utils.getOSName(true); + let zurl = nfo.tarballs.filter(elem => elem.os === os); + if (zurl && zurl.length) { + this.confStore.xdsAgentZipUrl = zurl[0].fileUrl; + this.confSubject.next(Object.assign({}, this.confStore)); + } + }); } // Save config into cookie @@ -103,12 +132,27 @@ export class ConfigService { this.confSubject.next(Object.assign({}, this.confStore)); // Don't save projects in cookies (too big!) - let cfg = this.confStore; - delete(cfg.projects); + let cfg = Object.assign({}, this.confStore); + delete (cfg.projects); this.cookie.putObject("xds-config", cfg); } loadProjects() { + // Setup connection with local XDS agent + if (this.AgentConnectObs) { + try { + this.AgentConnectObs.unsubscribe(); + } catch (err) { } + this.AgentConnectObs = null; + } + + let cfg = this.confStore.xdsAgent; + this.AgentConnectObs = this.xdsAgentSvr.connect(cfg.retry, cfg.URL) + .subscribe((sts) => { + //console.log("Agent sts", sts); + }, error => this.alert.error(error) + ); + // Remove previous subscriber if existing if (this.stConnectObs) { try { @@ -117,7 +161,8 @@ export class ConfigService { this.stConnectObs = null; } - // First setup connection with local SyncThing + // FIXME: move this code and all logic about syncthing inside XDS Agent + // Setup connection with local SyncThing let retry = this.confStore.localSThg.retry; let url = this.confStore.localSThg.URL; this.stConnectObs = this.stSvr.connect(retry, url).subscribe((sts) => { @@ -130,7 +175,7 @@ export class ConfigService { // Rebuild projects definition from local and remote syncthing this.confStore.projects = []; - this.sdkSvr.getProjects().subscribe(remotePrj => { + this.xdsServerSvr.getProjects().subscribe(remotePrj => { this.stSvr.getProjects().subscribe(localPrj => { remotePrj.forEach(rPrj => { let lPrj = localPrj.filter(item => item.id === rPrj.id); @@ -150,7 +195,20 @@ export class ConfigService { }), error => this.alert.error('Could not load initial state of local projects.'); }), error => this.alert.error('Could not load initial state of remote projects.'); - }, error => this.alert.error(error)); + }, error => { + if (error.indexOf("Syncthing local daemon not responding") !== -1) { + let msg = "" + error + "
"; + msg += "You may need to download and execute XDS-Agent.
"; + if (this.confStore.xdsAgentZipUrl !== "") { + msg += ""; + msg += " Download XDS-Agent tarball."; + } + msg += "
"; + this.alert.error(msg); + } else { + this.alert.error(error); + } + }); } set syncToolURL(url: string) { @@ -158,11 +216,18 @@ export class ConfigService { this.save(); } - set syncToolRetry(r: number) { + set xdsAgentRetry(r: number) { this.confStore.localSThg.retry = r; + this.confStore.xdsAgent.retry = r; this.save(); } + set xdsAgentUrl(url: string) { + this.confStore.xdsAgent.URL = url; + this.save(); + } + + set projectsRootDir(p: string) { if (p.charAt(0) === '~') { p = this.confStore.localSThg.tilde + p.substring(1); @@ -219,7 +284,7 @@ export class ConfigService { // Send config to XDS server let newPrj = prj; - this.sdkSvr.addProject(sdkPrj) + this.xdsServerSvr.addProject(sdkPrj) .subscribe(resStRemotePrj => { newPrj.remotePrjDef = resStRemotePrj; @@ -258,7 +323,7 @@ export class ConfigService { if (idx === -1) { throw new Error("Invalid project id (id=" + prj.id + ")"); } - this.sdkSvr.deleteProject(prj.id) + this.xdsServerSvr.deleteProject(prj.id) .subscribe(res => { this.stSvr.deleteProject(prj.id) .subscribe(res => {