Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

feat(service-offering): show all service offerings even those which d… #1299

Merged
merged 13 commits into from
Oct 8, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h3 class="mat-dialog-title">
*ngIf="showRebootMessage"
>{{ "SERVICE_OFFERING.VM_WILL_BE_RESTARTED" | translate }}
</div>
<span class="error-message" *ngIf="!serviceOffering.isAvailableByResources && isSelectedOfferingViewMode()">
<span class="error-message" *ngIf="!serviceOffering?.isAvailableByResources && isSelectedOfferingViewMode()">
{{ 'ERRORS.COMPUTE_OFFERING.RESOURCE_LIMIT_EXCEEDED' | translate }}
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ServiceOfferingDialogComponent implements OnInit, OnChanges {
public isSubmitButtonDisabled(): boolean {
const isOfferingNotSelected = !this.serviceOffering;
const isNoOfferingsInCurrentViewMode = !this.serviceOfferings.length;
const isNotEnoughResourcesForCurrentOffering = !this.serviceOffering.isAvailableByResources;
const isNotEnoughResourcesForCurrentOffering = this.serviceOffering && !this.serviceOffering.isAvailableByResources;
const isSelectedOfferingFromDifferentViewMode = this.serviceOffering
&& this.serviceOffering.iscustomized !== (this.viewMode === ServiceOfferingType.custom);
const isSelectedOfferingDoNotHaveParams = this.serviceOffering
Expand All @@ -88,7 +88,7 @@ export class ServiceOfferingDialogComponent implements OnInit, OnChanges {
}

public isSelectedOfferingViewMode(): boolean {
if (this.serviceOffering.iscustomized && this.viewMode === ServiceOfferingType.custom) {
if (this.serviceOffering && this.serviceOffering.iscustomized && this.viewMode === ServiceOfferingType.custom) {
return true;
}
if (!this.serviceOffering.iscustomized && this.viewMode === ServiceOfferingType.fixed) {
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/models/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './image-group.model';
export * from './service-offering-availability.interface';
export * from './offering-compatibility-policy.interface';
export * from './sidenav-config-element.interface';
export * from './custom-compute-offering-parameters.interface';
10 changes: 6 additions & 4 deletions src/app/vm/selectors/service-offering.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createSelector } from '@ngrx/store';

import { VmCompatibilityPolicy } from '../shared/vm-compatibility-policy';
import { ResourceStats } from '../../shared/services/resource-usage.service';
import { ComputeOfferingViewModel } from '../view-models';
import { isOfferingLocal } from '../../shared/models/offering.model';
import {
Expand All @@ -10,7 +9,6 @@ import {
ServiceOfferingAvailability
} from '../../shared/models/config';
import { ServiceOffering, ServiceOfferingType, Zone } from '../../shared/models';
import { getComputeOfferingViewModel } from './view-models';
import { configSelectors } from '../../root-store';
import * as fromZones from '../../reducers/zones/redux/zones.reducers';
import * as fromAuths from '../../reducers/auth/redux/auth.reducers';
Expand All @@ -21,6 +19,10 @@ import {
filterSelectedViewMode,
getSelectedOffering,
} from '../../reducers/service-offerings/redux/service-offerings.reducers';
import {
getComputeOfferingForVmCreation,
getComputeOfferingForVmEditing
} from './view-models/compute-offering-view-model.selector';

const isComputeOfferingAvailableInZone = (
offering: ServiceOffering,
Expand Down Expand Up @@ -51,7 +53,7 @@ const getOfferingsAvailableInZone = (
};

export const getAvailableOfferingsForVmCreation = createSelector(
getComputeOfferingViewModel,
getComputeOfferingForVmCreation,
configSelectors.get('serviceOfferingAvailability'),
fromVMs.getVMCreationZone,
fromAuths.getUserAccount,
Expand All @@ -65,7 +67,7 @@ export const getAvailableOfferingsForVmCreation = createSelector(
);

export const getAvailableOfferings = createSelector(
getComputeOfferingViewModel,
getComputeOfferingForVmEditing,
getSelectedOffering,
configSelectors.get('serviceOfferingAvailability'),
configSelectors.get('offeringCompatibilityPolicy'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { getComputeOfferingViewModel } from './compute-offering-view-model.selector';
import { customComputeOffering, fixedComputeOffering } from '../../../../testutils/data';
import { account } from '../../../../testutils/data/accounts';
import { account, customComputeOffering, fixedComputeOffering, vm } from '../../../../testutils/data';
import { nonCustomizableProperties } from '../../../core/config/default-configuration';
import { ComputeOfferingViewModel } from '../../view-models';
import { Account } from '../../../shared/models';
import { CustomComputeOfferingParameters } from '../../../shared/models/config/index';
import {
CustomComputeOfferingParameters
} from '../../../shared/models/config/custom-compute-offering-parameters.interface';
getComputeOfferingForVmCreation,
getComputeOfferingForVmEditing
} from './compute-offering-view-model.selector';

describe('ComputeOfferingViewModelSelector', () => {
describe('GetComputeOfferingForVmCreationSelector', () => {
it('isAvailableByResources should be true in fixed compute offering params which satisfy memory and cpu resources',
() => {
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[fixedComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
account,
[fixedComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand All @@ -24,9 +24,9 @@ describe('ComputeOfferingViewModelSelector', () => {

it('should be false in fixed compute offering params which unsatisfied memory resources', () => {
const limitedAccount: Account = { ...account, memoryavailable: String(fixedComputeOffering.memory - 10) };
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[fixedComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
limitedAccount,
[fixedComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand All @@ -37,9 +37,9 @@ describe('ComputeOfferingViewModelSelector', () => {

it('should be false in fixed compute offering params which unsatisfied cpu resources', () => {
const limitedAccount: Account = { ...account, cpuavailable: String(fixedComputeOffering.cpunumber - 1) };
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[fixedComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
limitedAccount,
[fixedComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand All @@ -49,9 +49,9 @@ describe('ComputeOfferingViewModelSelector', () => {
});

it('should be true in custom compute offering params which satisfy memory and cpu resources', () => {
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[customComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
account,
[customComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand All @@ -63,9 +63,9 @@ describe('ComputeOfferingViewModelSelector', () => {
it('should be false in custom compute offering params which unsatisfied memory resources', () => {
const memoryavailable = String(nonCustomizableProperties.customComputeOfferingHardwareValues.memory - 10);
const limitedAccount: Account = { ...account, memoryavailable };
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[customComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
limitedAccount,
[customComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand All @@ -77,9 +77,9 @@ describe('ComputeOfferingViewModelSelector', () => {
it('should be false in custom compute offering params which unsatisfied cpu resources', () => {
const cpuavailable = String(nonCustomizableProperties.customComputeOfferingHardwareValues.cpunumber - 1);
const limitedAccount: Account = { ...account, cpuavailable };
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[customComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
limitedAccount,
[customComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand Down Expand Up @@ -107,9 +107,9 @@ describe('ComputeOfferingViewModelSelector', () => {
}
];

const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[customComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
limitedAccount,
[customComputeOffering],
customComputeOfferingParameters,
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand Down Expand Up @@ -140,9 +140,9 @@ describe('ComputeOfferingViewModelSelector', () => {
}
];

const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingViewModel.projector(
[customComputeOffering],
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmCreation.projector(
limitedAccount,
[customComputeOffering],
customComputeOfferingParameters,
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
Expand All @@ -154,3 +154,59 @@ describe('ComputeOfferingViewModelSelector', () => {
expect(computeOfferingViewModel.customOfferingRestrictions.memory.max).toBe(4000);
});
});

describe('GetComputeOfferingForVmEditingSelector', () => {
it('isAvailableByResources should be true in fixed compute offering params which satisfy memory and cpu resources',
() => {
const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmEditing.projector(
account,
[fixedComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
[],
vm
);
expect(computeOfferingViewModel.isAvailableByResources).toEqual(true);
});

it('isAvailableByResources should be true, cause satisfy resources plus used resources in editing vm',
() => {
const cpuavailable = '0';
const memoryavailable = '512';
const limitedAccount: Account = { ...account, memoryavailable, cpuavailable };
const updatedVm = { ...vm, memory: '512', cpuNumber: 1 };

const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmEditing.projector(
limitedAccount,
[fixedComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
[],
updatedVm
);

expect(computeOfferingViewModel.isAvailableByResources).toEqual(true);
});

it('isAvailableByResources should be false, cause unsatisfy resources plus used resources in editing vm',
() => {
const cpuavailable = '0';
const memoryavailable = '0';
const limitedAccount: Account = { ...account, memoryavailable, cpuavailable };
const updatedVm = { ...vm, memory: '512', cpuNumber: 1 };

const [computeOfferingViewModel]: ComputeOfferingViewModel[] = getComputeOfferingForVmEditing.projector(
limitedAccount,
[fixedComputeOffering],
[],
nonCustomizableProperties.defaultCustomComputeOfferingRestrictions,
nonCustomizableProperties.customComputeOfferingHardwareValues,
[],
updatedVm
);

expect(computeOfferingViewModel.isAvailableByResources).toEqual(false);
});
});
Loading