Skip to content

Commit

Permalink
Cherry-pick: Fix issue with networks population when host name contai…
Browse files Browse the repository at this point in the history
…ns 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)'
  • Loading branch information
javierfz1980 authored May 18, 2018
1 parent d438814 commit 69803cc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any>(service, 'getDcClustersAndStandAloneHosts').and.returnValue(Observable.of(dcClustersAndStandAloneHosts));
spyOn<any>(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);
});

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,54 @@ export class CreateVchWizardService {
});
}

/**
* Queries the H5 Client to obtain the name of a Compute Resource
*/
private getComputeResourceRealName(crObjectRef: string): Observable<ComputeResource> {
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<ComputeResource[]> {
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<any> {
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;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface ComputeResource {
objRef: string;
aliases: string[];
isEmpty: boolean;
realName?: string;
}

0 comments on commit 69803cc

Please sign in to comment.