8000 Resource tree selector refactor by javierfz1980 · Pull Request #561 · vmware/vic-ui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Resource tree selector refactor #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions h5c/vic/src/vic-webapp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ import { AppRoutingModule, routedComponents } from './app-routing.module';
import { AppComponent } from './app.component';
import { DisableCookieXSRFStrategy } from './shared/utils/disable-cookie-xsrf-strategy';
import { HttpInterceptorService } from './services/http-interceptor.service';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
HttpModule,
HttpClientModule,
ClarityModule.forRoot()
],
declarations: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {CreateVchWizardService} from '../create-vch-wizard.service';
import {HttpModule} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {ReactiveFormsModule} from '@angular/forms';
import {TestScheduler} from 'rxjs/Rx';
import {AppAlertService, GlobalsService, I18nService} from '../../shared';
import {mockedDcClustersAndStandAloneHostsList} from '../mocks/create-vch-wizard-mocked-data';

describe('ComputeCapacityComponent', () => {

Expand All @@ -34,7 +34,7 @@ describe('ComputeCapacityComponent', () => {
const MaxLimit = 4096;

function setDefaultRequiredValues() {
component.loadResources(component.clusters[0].text);
component.resources = mockedDcClustersAndStandAloneHostsList;
component.selectComputeResource({datacenterObj: component.datacenter, obj: component.resources[0]});
}

Expand All @@ -56,7 +56,7 @@ describe('ComputeCapacityComponent', () => {
text: 'datacenter'
}]);
},
getClustersList(serviceGuid: string) {
getDcClustersAndStandAloneHosts(serviceGuid: string) {
return Observable.of([{
text: 'cluster'
}]);
Expand Down Expand Up @@ -130,9 +130,7 @@ describe('ComputeCapacityComponent', () => {
service = fixture.debugElement.injector.get(CreateVchWizardService);

spyOn(service, 'getDatacenter').and.callThrough();
spyOn(service, 'getClustersList').and.callThrough();
spyOn(service, 'getResourceAllocationsInfo').and.callThrough();
spyOn(service, 'getHostsAndResourcePools').and.callThrough();
});

it('should be created', () => {
Expand Down Expand Up @@ -224,14 +222,9 @@ describe('ComputeCapacityComponent', () => {
});
});

it('should extract the datacenter moid from the object reference string', () => {
const dc = component.getDataCenterId('urn:vmomi:Datacenter:dc-test:00000000-0000-0000-0000-000000000000');
expect(dc).toEqual('dc-test');
});

it('should validate advanced fields defaults values', () => {
component.toggleAdvancedMode();
component.selectComputeResource({datacenterObj: component.datacenter, obj: {text: ''}});
component.selectComputeResource({datacenterObj: component.datacenter, obj: mockedDcClustersAndStandAloneHostsList[0]});
component.onCommit();
expect(component.form.valid).toBe(true);

Expand Down
A8F3
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import {

import { ComputeResourceTreenodeComponent } from './compute-resource-treenode.component';
import { CreateVchWizardService } from '../create-vch-wizard.service';
import { DC_CLUSTER } from '../../shared/constants';
import { Observable } from 'rxjs/Observable';
import { GlobalsService } from './../../shared/globals.service';
import { ComputeResource } from '../../interfaces/compute.resource';
import { getMorIdFromObjRef } from '../../shared/utils/object-reference';
import 'rxjs/add/observable/timer';
import { getMorIdFromObjRef, resourceIsCluster, resourceIsHost, resourceIsResourcePool } from '../../shared/utils/object-reference';
import { ServerInfo } from '../../shared/vSphereClientSdkTypes';
import { flattenArray } from '../../shared/utils/array-utils';
import { I18nService } from '../../shared';
Expand Down Expand Up @@ -60,14 +58,14 @@ export class ComputeCapacityComponent implements OnInit {
memory: { maxUsage: null, minUsage: null, unreservedForPool: null }
};
public selectedObject: ComputeResource;
public selectedResourceObjRef: string;
public serversInfo: ServerInfo[];
public selectedResourceIsCluster = false;
public vmGroupNameIsValid = false;
public isClusterDrsEnabled = false;
public vmsGroups = [];
public selectedId: string;
public selectedName: string;

private _selectedComputeResource: string;
private _currentVchName: string;

@ViewChildren(ComputeResourceTreenodeComponent)
Expand Down Expand Up @@ -125,33 +123,7 @@ export class Comp 6DB6 uteCapacityComponent implements OnInit {
});
}

/**
* Get the latest list of Hosts, VirtualApps and ResourcePools
* @param {string} clusterValue
*/
loadResources(clusterValue: string) {
this.isTreeLoading = true;
this.createWzService
.getHostsAndResourcePools(clusterValue)
.subscribe(resources => {
this.resources = resources;
this.isTreeLoading = false;
});
}

/**
* extract the datacenter moid from the object reference string
*
*/
getDataCenterId (dcObj: string) {
const dcIds = dcObj.split(':');
if (dcIds[2] === 'Datacenter') {
// e.g: urn:vmomi:Datacenter:dc-test:00000000-0000-0000-0000-000000000000
return dcIds[3];
}
}

get dcId () {
get dcId() {
return getMorIdFromObjRef(this.dcObj.objRef);
}

Expand All @@ -164,48 +136,41 @@ export class ComputeCapacityComponent implements OnInit {
parentClusterObj?: ComputeResource | any;
datacenterObj: ComputeResource | any
}) {
const nodeTypeId = payload.obj.nodeTypeId;
const isCluster = nodeTypeId === DC_CLUSTER;
const resourceObj = payload.obj.objRef;
const dcObj = payload.datacenterObj.objRef;
const isCluster = resourceIsCluster(payload.obj.nodeTypeId);
const isHost = resourceIsHost(payload.obj.nodeTypeId);
const isResourcePool = resourceIsResourcePool(payload.obj.nodeTypeId);
const resourceObjForResourceAllocations =
((isCluster || isResourcePool) && payload.obj.aliases[0]) ? payload.obj.aliases[0] : payload.obj.objRef;

this.dcObj = payload.datacenterObj;
this.selectedObject = payload.obj;
this.selectedResourceIsCluster = isCluster;
this.selectedId = payload.obj.value;
this.selectedName = payload.obj.name;

let computeResource = `/${this.dcObj.text}/host`;
let resourceObjForResourceAllocations = resourceObj;

if (isCluster) {
computeResource = `${computeResource}/${payload.obj.realName}`;
resourceObjForResourceAllocations = payload.obj.aliases[0];
} else {
if (!isCluster) {
this.form.controls['vmHostAffinity'].setValue(false);
computeResource = payload.parentClusterObj ?
`${computeResource}/${payload.parentClusterObj.text}/${payload.obj.realName}` :
`${computeResource}/${payload.obj.realName}`;
}
this.selectedResourceObjRef = resourceObj;
this.selectedObject = payload.obj;
this._selectedComputeResource = computeResource;

// set active class on the treenodecomponent whose datacenter object reference is
// the same as datacenterObj.objRef
if (this.treenodeComponents) {
this.treenodeComponents
.filter(component => component.datacenter.objRef !== dcObj)
.filter(component => component.datacenter.objRef !== payload.datacenterObj.objRef)
.forEach(component => {
component.unselectComputeResource();
});
}

// if it is a cluster, we get the cluster vm groups, otherwise set to empty array observable
const vmGroupsObs: Observable<any[]> = isCluster ?
this.createWzService.getClusterVMGroups(this.selectedResourceObjRef) : Observable.of([]);
this.createWzService.getClusterVMGroups(this.selectedObject.objRef) : Observable.of([]);

const isDrsEnabled: Observable<boolean> = isCluster ?
this.createWzService.getClusterDrsStatus(this.selectedResourceObjRef) : Observable.of(false);
this.createWzService.getClusterDrsStatus(this.selectedObject.objRef) : Observable.of(false);

const allocationsObs: Observable<any[]> = this.createWzService
.getResourceAllocationsInfo(resourceObjForResourceAllocations, isCluster);
.getResourceAllocationsInfo(resourceObjForResourceAllocations, isHost);

Observable.zip(allocationsObs, vmGroupsObs, isDrsEnabled)
.subscribe(([allocationsInfo, groups, drsStatus]) => {
Expand Down Expand Up @@ -283,23 +248,14 @@ export class ComputeCapacityComponent implements OnInit {
}
}

get selectedComputeResource() {
return this._selectedComputeResource;
}

onPageLoad() {
// if compute resource is already selected return here
if (this.selectedComputeResource) {
return;
}
}
onPageLoad() {}

onCommit(): Observable<any> {
const errs: string[] = [];
let formErrors = null;
const results: any = {};

if (!this.selectedComputeResource) {
if (!this.selectedId) {
errs.push('Please choose a valid compute resource');
formErrors = { invalidComputeResource: true };
}
Expand All @@ -312,7 +268,8 @@ export class ComputeCapacityComponent implements OnInit {
const cpuLimitValue = this.form.get('cpuLimit').value;
const memoryLimitValue = this.form.get('memoryLimit').value;

results['computeResource'] = this.selectedComputeResource;
results['computeResource'] = this.selectedId;
results['computeResourceName'] = this.selectedName;
results['cpu'] = unlimitedPattern.test(cpuLimitValue) ? '0' : cpuLimitValue;
results['memory'] = unlimitedPattern.test(memoryLimitValue) ? '0' : memoryLimitValue;
if (this.inAdvancedMode) {
Expand All @@ -331,8 +288,4 @@ export class ComputeCapacityComponent implements OnInit {
toggleAdvancedMode() {
this.inAdvancedMode = !this.inAdvancedMode;
}

getDcs (serverInfo: ServerInfo): ComputeResource[] {
return this.datacenter.filter((item: ComputeResource) => item.objRef.indexOf(serverInfo.serviceGuid) > -1);
}
}
Loading
0