Skip to content

Commit

Permalink
Update log request to always use datacenter in request path (#209) (#239
Browse files Browse the repository at this point in the history
) (#244)

* Update log request to always use datacenter in request path

Also, fix error handling for log requests since errors come in text form

* Fix VCH log view unit tests
  • Loading branch information
jak-atx authored Dec 14, 2017
1 parent ade1b8c commit 4f5cd2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,28 @@ export class CreateVchWizardService {
.map(response => ip);
});
}

/**
* Recursively queries the H5 Client for a datacenter associated with the resource
* @param resourceObjRef
*/
getDatacenterForResource(resourceObjRef: string) {
if (resourceObjRef.split(':')[2] === 'Datacenter') {
return this.http.get(`/ui/data/properties/${resourceObjRef}?properties=name`)
.catch(e => Observable.throw(e))
.map(response => response.json())
} else {
return this.http.get(`/ui/data/properties/${resourceObjRef}?properties=parent`)
.catch(e => Observable.throw(e))
.map(response => response.json())
.switchMap((response) => {
if (typeof response.parent === 'object') {
return this.getDatacenterForResource(
`urn:vmomi:${response.parent.type}:${response.parent.value}:${response.parent.serverGuid}`
);
}
return Observable.throw(`Error getting Datacenter for resource '${resourceObjRef}'`);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ describe('VicVchLogViewComponent', () => {
},
acquireCloneTicket(): Observable<string> {
return Observable.of('ticket');
},
getDatacenterForResource(): Observable<any> {
return Observable.of({
id: 'urn:vmomi:Datacenter:dc-test:00000000-0000-0000-0000-000000000000'
})
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ export class VicVchLogViewComponent implements OnInit {
this.loading = true;
Observable.combineLatest(
this.createWzService.getVicApplianceIp(),
this.createWzService.acquireCloneTicket()
).catch(err => {
this.createWzService.acquireCloneTicket(),
this.createWzService.getDatacenterForResource(this.vch.id)
).catch(err => {
return Observable.throw(err);
}).subscribe(([serviceHost, cloneTicket]) => {
}).subscribe(([serviceHost, cloneTicket, datacenter]) => {
const vchId = this.vch.id.split(':')[3];
const servicePort = VIC_APPLIANCE_PORT;
const targetHost = this.extSessionService.getVcenterServersInfo()[0];
const targetHostname = targetHost.name;
const targetThumbprint = targetHost.thumbprint;
const targetDatacenter = datacenter.id.split(':')[3];
const url =
`https://${serviceHost}:${servicePort}/container/target/${targetHostname}/vch/${vchId}/log?thumbprint=${targetThumbprint}`;
`https://${serviceHost}:${servicePort}/container/target/${targetHostname}/datacenter/${targetDatacenter}` +
`/vch/${vchId}/log?thumbprint=${targetThumbprint}`;

const headers = new Headers({
'Content-Type': 'application/json',
Expand All @@ -69,13 +72,11 @@ export class VicVchLogViewComponent implements OnInit {

const options = new RequestOptions({ headers: headers });
this.http.get(url, options)
.catch(error => Observable.of(error))
.map(response => response.text())
.subscribe(response => {
this.log = response;
this.loading = false;
}, error => {
this.log = error.message || 'Error loading VCH log!';
this.loading = false;
});
});
}
Expand Down

0 comments on commit 4f5cd2b

Please sign in to comment.