From 69803ccc8f41694a418a72fa8f7ab110ef2b9647 Mon Sep 17 00:00:00 2001 From: javierfz1980 <36636787+javierfz1980@users.noreply.github.com> Date: Fri, 18 May 2018 14:07:36 -0300 Subject: [PATCH] Cherry-pick: Fix issue with networks population when host name contains some extra text (#440) (#484) This commit will fix an error produced when hosts contains some extra text on the name added by the vc like '(reboot required)' --- .../compute-capacity.component.ts | 9 ++- .../create-vch-wizard.service.spec.ts | 21 +++++- .../create-vch-wizard.service.ts | 65 +++++++++++++------ .../mocks/create-vch-wizard-mocked-data.ts | 33 ++++++++++ .../src/app/interfaces/compute.resource.ts | 1 + 5 files changed, 101 insertions(+), 28 deletions(-) diff --git a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/compute-capacity/compute-capacity.component.ts b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/compute-capacity/compute-capacity.component.ts index ff2b67992..fa2d67e82 100644 --- a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/compute-capacity/compute-capacity.component.ts +++ b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/compute-capacity/compute-capacity.component.ts @@ -156,16 +156,15 @@ export class ComputeCapacityComponent implements OnInit { let resourceObjForResourceAllocations = resourceObj; if (isCluster) { - computeResource = `${computeResource}/${payload.obj.text}`; + computeResource = `${computeResource}/${payload.obj.realName}`; resourceObjForResourceAllocations = payload.obj.aliases[0]; } else { computeResource = payload.parentClusterObj ? - `${computeResource}/${payload.parentClusterObj.text}/${payload.obj.text}` : - `${computeResource}/${payload.obj.text}`; + `${computeResource}/${payload.parentClusterObj.text}/${payload.obj.realName}` : + `${computeResource}/${payload.obj.realName}`; } - this.selectedResourceObjRef = resourceObj; - this.selectedObjectName = payload.obj.text; + this.selectedObjectName = payload.obj.realName; this._selectedComputeResource = computeResource; // set active class on the treenodecomponent whose datacenter object reference is diff --git a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.spec.ts b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.spec.ts index 5a2dc02a1..7be8d687c 100644 --- a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.spec.ts +++ b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.spec.ts @@ -31,7 +31,9 @@ import { JASMINE_TIMEOUT } from '../testing/jasmine.constants'; import { CreateVchWizardService } from './create-vch-wizard.service'; import { Globals, GlobalsService } from '../shared'; import { - dcDSwitchPorGroupsList, dvsHostsEntries, + computeResourcesRealName, + dcClustersAndStandAloneHosts, + dcDSwitchPorGroupsList, dcMockData, dvsHostsEntries, folderDSwitchList, folderDSwitchPorGroupsList, netWorkingResources } from './mocks/create-vch-wizard-mocked-data'; @@ -136,5 +138,20 @@ describe('CreateVchWizardService', () => { expect(data.length).toBe(3); }); - }) + }); + + it('should return a list of Compute Resources with a property called realName', async() => { + spyOn(service, 'getDatacenter').and.returnValue(Observable.of(dcMockData)); + spyOn(service, 'getDcClustersAndStandAloneHosts').and.returnValue(Observable.of(dcClustersAndStandAloneHosts)); + spyOn(service, 'getComputeResourceRealName').and.returnValue(Observable.of(computeResourcesRealName[0])); + + service.getClustersList(null) + .subscribe(data => { + expect(data.length).toBe(1); + expect(data[0].realName).toBeTruthy(); + expect(data[0].realName).toBe(computeResourcesRealName[0].name); + }); + + }); + }); diff --git a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.ts b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.ts index 043cc6f16..3f39a877a 100644 --- a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.ts +++ b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/create-vch-wizard.service.ts @@ -128,31 +128,54 @@ export class CreateVchWizardService { }); } + /** + * Queries the H5 Client to obtain the name of a Compute Resource + */ + private getComputeResourceRealName(crObjectRef: string): Observable { + return this.http.get(`/ui/data/properties/${crObjectRef}?properties=name`) + .catch(e => Observable.throw(e)) + .map(response => response.json()); + } + + /** + * Queries the H5 Client for Clusters and stand alone Hosts from the desired DC + */ + private getDcClustersAndStandAloneHosts(dcObjRef: string): Observable { + return this.http.get('/ui/tree/children?nodeTypeId=RefAsRoot' + + `&objRef=${dcObjRef}` + + '&treeId=DcHostsAndClustersTree') + .catch(e => Observable.throw(e)) + .map(response => response.json()); + } + /** * Queries the H5 Client for clusters */ getClustersList(serverGuid: string): Observable { - return this.getDatacenter(serverGuid) - .switchMap(dc => { - const obsArr = dc.map(v => { - return this.http.get('/ui/tree/children?nodeTypeId=RefAsRoot' + - `&objRef=${v.objRef}` + - '&treeId=DcHostsAndClustersTree') - .catch(e => Observable.throw(e)) - .map(response => { - const rsp = response.json(); - rsp.forEach((cluster, i) => rsp[i]['datacenterObjRef'] = v.objRef); - return rsp; - }) - .catch(e => Observable.throw(e)); - }); - return Observable.zip.apply(null, obsArr); - }) - .map((clustersArr: any[]) => { - let flattened = []; - clustersArr.forEach(arr => flattened = flattened.concat(arr)); - return flattened; - }); + return this.getDatacenter(serverGuid) + .switchMap(dc => { + const obsArr = dc.map(v => { + return this.getDcClustersAndStandAloneHosts(v.objRef) + .switchMap((computeResources: ComputeResource[]) => { + return Observable.from(computeResources) + .mergeMap((cr: ComputeResource) => { + cr['datacenterObjRef'] = v.objRef; + return this.getComputeResourceRealName(cr.objRef) + .map(resourceName => { + cr['realName'] = resourceName['name']; + return cr; + }); + }) + .toArray(); + }) + }); + return Observable.zip.apply(null, obsArr); + }) + .map((clustersArr: any[]) => { + let flattened = []; + clustersArr.forEach(arr => flattened = flattened.concat(arr)); + return flattened; + }); } /** diff --git a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/mocks/create-vch-wizard-mocked-data.ts b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/mocks/create-vch-wizard-mocked-data.ts index 327690103..b0b7a56dc 100644 --- a/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/mocks/create-vch-wizard-mocked-data.ts +++ b/h5c/vic/src/vic-webapp/src/app/create-vch-wizard/mocks/create-vch-wizard-mocked-data.ts @@ -237,3 +237,36 @@ export const dvsHostsEntries = [ ]} }) ]; + +export const dcMockData = [ + { + text: 'ha-datacenter', + spriteCssClass: 'vsphere-icon-datacenter', + hasChildren: true, + objRef: 'urn:vmomi:Datacenter:datacenter-2:196f7764-7aec-42d8-9def-6b5899b7e0e1', + nodeTypeId: 'Datacenter', + aliases: [ + 'urn:vmomi:Folder:group-h4:196f7764-7aec-42d8-9def-6b5899b7e0e1', + 'urn:vmomi:Folder:group-v3:196f7764-7aec-42d8-9def-6b5899b7e0e1', + 'urn:vmomi:Folder:group-s5:196f7764-7aec-42d8-9def-6b5899b7e0e1', + 'urn:vmomi:Folder:group-n6:196f7764-7aec-42d8-9def-6b5899b7e0e1'] + } +]; + +export const dcClustersAndStandAloneHosts = [ + { + text: '10.161.75.158 (Reboot Required)', + spriteCssClass: 'vsphere-icon-host-warning', + hasChildren: true, + objRef: 'urn:vmomi:HostSystem:host-15:196f7764-7aec-42d8-9def-6b5899b7e0e1', + nodeTypeId: 'DcStandaloneHost', + aliases: ['urn:vmomi:ResourcePool:resgroup-14:196f7764-7aec-42d8-9def-6b5899b7e0e1'] + } +]; + +export const computeResourcesRealName = [ + { + name: '10.161.75.158', + id: 'urn:vmomi:HostSystem:host-15:196f7764-7aec-42d8-9def-6b5899b7e0e1' + } +]; diff --git a/h5c/vic/src/vic-webapp/src/app/interfaces/compute.resource.ts b/h5c/vic/src/vic-webapp/src/app/interfaces/compute.resource.ts index f234f3e25..caeba3720 100644 --- a/h5c/vic/src/vic-webapp/src/app/interfaces/compute.resource.ts +++ b/h5c/vic/src/vic-webapp/src/app/interfaces/compute.resource.ts @@ -20,4 +20,5 @@ export interface ComputeResource { objRef: string; aliases: string[]; isEmpty: boolean; + realName?: string; }