}).then(() => { // ask mgmNode to watch the file and upload when complete let url = 'http://' + host.address + ':' + host.port + '/saveOar/' + region.uuid + '/' + job.id; return urllib.request(url).then((body) => { let result = JSON.parse(body.data); if (!result.Success) { throw new Error(result.Message); } }); });
export function KillRegion(r: IRegion, h: IHost): Promise<void> { console.log('killing ' + r.uuid); let url = 'http://' + h.address + ':' + h.port + '/kill/' + r.uuid; return urllib.request(url).then((body) => { let result = JSON.parse(body.data); if (!result.Success) { throw new Error(result.Message); } }); }
export function StartRegion(r: IRegion, h: IHost, conf: Config): Promise<void> { console.log('starting ' + r.uuid); let form = formstream(); form.field('xml', RegionXML(r, h)); form.field('ini', RegionINI(r, h, conf)); let url = 'http://' + h.address + ':' + h.port + '/start/' + r.uuid; return urllib.request(url, { method: 'POST', headers: form.headers(), stream: form }).then((body) => { let result = JSON.parse(body.data); if (!result.Success) { throw new Error(result.Message); } }); }
export function LoadOar(r: IRegion, h: IHost, j: IJob, u: IUser, oarPath?: string): Promise<void> { console.log('triggering oar load for ' + r.uuid); let admin: RemoteAdmin let form = formstream(); switch (j.type) { case 'nuke': form.file('oarFile', oarPath, r.name + '.oar'); break; default: let datum = JSON.parse(j.data); form.file('oarFile', datum.File, r.name + '.oar'); break; } form.field('jobID', j.id); let url = 'http://' + h.address + ':' + h.port + '/loadOar/' + r.uuid + '/'; return urllib.request(url, { method: 'POST', headers: form.headers(), stream: form }).then((body) => { let result = JSON.parse(body.data); if (!result.Success) { throw new Error(result.Message); } }).then(() => { return HalcyonJWT.instance().GetAdminToken(u); }).then((token: string) => { admin = new RemoteAdmin(r); return admin.login(token); }).then(() => { return admin.loadOar(r); }).then(() => { return admin.logout(); }) }
export function PutRegionOnHost(store: Store, r: IRegion, h: IHost): Promise<void> { return urllib.request('http://' + h.address + ':' + h.port + '/add/' + r.uuid + '/' + r.name, { timeout: 10000 }); }
export function RemoveRegionFromHost(r: IRegion, h: IHost): Promise<void> { return urllib.request('http://' + h.address + ':' + h.port + '/remove/' + r.uuid); }