Skip to content

Commit

Permalink
Fix three quota issues (#3782)
Browse files Browse the repository at this point in the history
* Fix setting of unlimited quota items

* Ensure edit org doesn't send request to all registered cfs

* Fix space summary card space quota link
  • Loading branch information
richard-cox authored and nwmac committed Aug 19, 2019
1 parent 0926662 commit 2e46084
Showing 7 changed files with 64 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -38,21 +38,7 @@ export class CreateQuotaStepComponent {

submit: StepOnNextFunction = () => {
const formValues = this.form.formGroup.value;
const UNLIMITED = -1;

this.store.dispatch(new CreateQuotaDefinition(this.cfGuid, {
name: formValues.name,
total_services: formValues.totalServices || UNLIMITED,
total_routes: formValues.totalRoutes || UNLIMITED,
memory_limit: formValues.memoryLimit,
instance_memory_limit: formValues.instanceMemoryLimit,
app_task_limit: formValues.appTasksLimit,
total_private_domains: formValues.totalPrivateDomains,
total_service_keys: formValues.totalServiceKeys,
non_basic_services_allowed: formValues.nonBasicServicesAllowed,
total_reserved_route_ports: formValues.totalReservedRoutePorts,
app_instance_limit: formValues.appInstanceLimit
}));
this.store.dispatch(new CreateQuotaDefinition(this.cfGuid, formValues));

return this.store.select(selectRequestInfo(quotaDefinitionSchemaKey, formValues.name)).pipe(
filter(requestInfo => !!requestInfo && !requestInfo.creating),
Original file line number Diff line number Diff line change
@@ -41,21 +41,7 @@ export class CreateSpaceQuotaStepComponent {

submit: StepOnNextFunction = () => {
const formValues = this.form.formGroup.value;
const UNLIMITED = -1;

this.store.dispatch(new CreateSpaceQuotaDefinition(this.cfGuid, {
name: formValues.name,
organization_guid: this.orgGuid,
total_services: formValues.totalServices || UNLIMITED,
total_service_keys: formValues.totalServiceKeys,
total_routes: formValues.totalRoutes || UNLIMITED,
memory_limit: formValues.memoryLimit,
instance_memory_limit: formValues.instanceMemoryLimit,
non_basic_services_allowed: formValues.nonBasicServicesAllowed,
total_reserved_route_ports: formValues.totalReservedRoutePorts,
app_instance_limit: formValues.appInstanceLimit,
app_task_limit: formValues.appTasksLimit,
}));
this.store.dispatch(new CreateSpaceQuotaDefinition(this.cfGuid, this.orgGuid, formValues));

return this.store.select(selectRequestInfo(spaceQuotaSchemaKey, formValues.name)).pipe(
filter(requestInfo => !!requestInfo && !requestInfo.creating),
Original file line number Diff line number Diff line change
@@ -13,13 +13,18 @@ import { IQuotaDefinition } from '../../../../core/cf-api.types';
import { EntityServiceFactory } from '../../../../core/entity-service-factory.service';
import { safeUnsubscribe } from '../../../../core/utils.service';
import { StepOnNextFunction } from '../../../../shared/components/stepper/step/step.component';
import { ActiveRouteCfOrgSpace } from '../../cf-page.types';
import { getActiveRouteCfOrgSpaceProvider } from '../../cf.helpers';
import { QuotaDefinitionFormComponent } from '../../quota-definition-form/quota-definition-form.component';


@Component({
selector: 'app-edit-quota-step',
templateUrl: './edit-quota-step.component.html',
styleUrls: ['./edit-quota-step.component.scss']
styleUrls: ['./edit-quota-step.component.scss'],
providers: [
getActiveRouteCfOrgSpaceProvider
]
})
export class EditQuotaStepComponent implements OnDestroy {

@@ -35,9 +40,10 @@ export class EditQuotaStepComponent implements OnDestroy {
constructor(
private store: Store<AppState>,
private activatedRoute: ActivatedRoute,
private entityServiceFactory: EntityServiceFactory
private entityServiceFactory: EntityServiceFactory,
activeRouteCfOrgSpace: ActiveRouteCfOrgSpace,
) {
this.cfGuid = this.activatedRoute.snapshot.params.endpointId;
this.cfGuid = activeRouteCfOrgSpace.cfGuid;
this.quotaGuid = this.activatedRoute.snapshot.params.quotaId;

this.fetchQuotaDefinition();
@@ -62,20 +68,7 @@ export class EditQuotaStepComponent implements OnDestroy {

submit: StepOnNextFunction = () => {
const formValues = this.form.formGroup.value;

this.store.dispatch(new UpdateQuotaDefinition(this.quotaGuid, this.cfGuid, {
name: formValues.name,
total_services: formValues.totalServices,
total_routes: formValues.totalRoutes,
memory_limit: formValues.memoryLimit,
app_task_limit: formValues.appTasksLimit,
total_private_domains: formValues.totalPrivateDomains,
total_service_keys: formValues.totalServiceKeys,
instance_memory_limit: formValues.instanceMemoryLimit,
non_basic_services_allowed: formValues.nonBasicServicesAllowed,
total_reserved_route_ports: formValues.totalReservedRoutePorts,
app_instance_limit: formValues.appInstanceLimit
}));
this.store.dispatch(new UpdateQuotaDefinition(this.quotaGuid, this.cfGuid, formValues));

return this.store.select(selectRequestInfo(quotaDefinitionSchemaKey, this.quotaGuid)).pipe(
filter(o => !!o && !o.updating[UpdateQuotaDefinition.UpdateExistingQuota].busy),
Original file line number Diff line number Diff line change
@@ -65,19 +65,7 @@ export class EditSpaceQuotaStepComponent implements OnDestroy {

submit: StepOnNextFunction = () => {
const formValues = this.form.formGroup.value;

this.store.dispatch(new UpdateSpaceQuotaDefinition(this.spaceQuotaGuid, this.cfGuid, {
name: formValues.name,
total_services: formValues.totalServices,
total_service_keys: formValues.totalServiceKeys,
total_routes: formValues.totalRoutes,
memory_limit: formValues.memoryLimit,
instance_memory_limit: formValues.instanceMemoryLimit,
non_basic_services_allowed: formValues.nonBasicServicesAllowed,
total_reserved_route_ports: formValues.totalReservedRoutePorts,
app_instance_limit: formValues.appInstanceLimit,
app_task_limit: formValues.appTasksLimit,
}));
this.store.dispatch(new UpdateSpaceQuotaDefinition(this.spaceQuotaGuid, this.cfGuid, formValues));

return this.store.select(selectRequestInfo(spaceQuotaSchemaKey, this.spaceQuotaGuid)).pipe(
filter(o => !!o && !o.updating[UpdateSpaceQuotaDefinition.UpdateExistingSpaceQuota].busy),
Original file line number Diff line number Diff line change
@@ -15,6 +15,19 @@ import { IQuotaDefinition } from '../../../core/cf-api.types';
import { safeUnsubscribe } from '../../../core/utils.service';
import { PaginationMonitorFactory } from '../../../shared/monitors/pagination-monitor.factory';

export interface QuotaFormValues {
name: string;
totalServices: number;
totalRoutes: number;
memoryLimit: number;
appTasksLimit: number;
totalPrivateDomains: number;
totalServiceKeys: number;
instanceMemoryLimit: number;
nonBasicServicesAllowed: boolean;
totalReservedRoutePorts: number;
appInstanceLimit: number;
}

@Component({
selector: 'app-quota-definition-form',
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ export class CloudFoundrySpaceService {
)
);
this.quotaLink$ = combineLatest(this.quotaDefinition$, this.spaceQuotaDefinition$).pipe(
map(([quota, spaceQuota]) => {
map(([quota, spaceQuota]) => {
if (!spaceQuota) {
return [
'/cloud-foundry',
@@ -173,12 +173,12 @@ export class CloudFoundrySpaceService {
this.cfGuid,
'organizations',
this.orgGuid,
'space',
'spaces',
this.spaceGuid,
'space-quota'
];
}
)
)
);
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { RequestMethod, RequestOptions, URLSearchParams } from '@angular/http';

import { IQuotaDefinition } from '../../../core/src/core/cf-api.types';
import {
QuotaFormValues,
} from '../../../core/src/features/cloud-foundry/quota-definition-form/quota-definition-form.component';
import {
entityFactory,
organizationSchemaKey,
@@ -62,6 +65,30 @@ export const DELETE_SPACE_QUOTA_DEFINITION_FAILED = '[QuotaDefinitions] Delete s
const quotaDefinitionEntitySchema = entityFactory(quotaDefinitionSchemaKey);
const spaceQuotaEntitySchema = entityFactory(spaceQuotaSchemaKey);

const UNLIMITED = -1;
function orgSpaceQuotaFormValuesToApiObject(formValues: QuotaFormValues, isOrg = true, orgGuid?: string): IQuotaDefinition {
const res: IQuotaDefinition = {
name: formValues.name,
total_services: formValues.totalServices || UNLIMITED,
total_routes: formValues.totalRoutes || UNLIMITED,
memory_limit: formValues.memoryLimit,
app_task_limit: formValues.appTasksLimit || UNLIMITED,
total_service_keys: formValues.totalServiceKeys || UNLIMITED,
instance_memory_limit: formValues.instanceMemoryLimit || UNLIMITED,
non_basic_services_allowed: formValues.nonBasicServicesAllowed,
total_reserved_route_ports: formValues.totalReservedRoutePorts || UNLIMITED,
app_instance_limit: formValues.appInstanceLimit || UNLIMITED,
};
if (isOrg) {
// Required for org quotas
res.total_private_domains = formValues.totalPrivateDomains || UNLIMITED;
} else if (orgGuid) {
// Required for creating space quota
res.organization_guid = orgGuid;
}
return res;
}

export class GetQuotaDefinitions extends CFStartAction implements PaginatedAction {
constructor(
public paginationKey: string,
@@ -202,12 +229,12 @@ export class DisassociateSpaceQuota extends CFStartAction implements ICFAction {
}

export class CreateQuotaDefinition extends CFStartAction implements ICFAction {
constructor(public endpointGuid: string, public createQuota: IQuotaDefinition) {
constructor(public endpointGuid: string, public createQuota: QuotaFormValues) {
super();
this.options = new RequestOptions();
this.options.url = `quota_definitions`;
this.options.method = RequestMethod.Post;
this.options.body = createQuota;
this.options.body = orgSpaceQuotaFormValuesToApiObject(createQuota);
this.guid = createQuota.name;
}
actions = [
@@ -225,12 +252,12 @@ export class UpdateQuotaDefinition extends CFStartAction implements ICFAction {

public static UpdateExistingQuota = 'Updating-Existing-Quota';

constructor(public guid: string, public endpointGuid: string, updateQuota: IQuotaDefinition) {
constructor(public guid: string, public endpointGuid: string, updateQuota: QuotaFormValues) {
super();
this.options = new RequestOptions();
this.options.url = `quota_definitions/${guid}`;
this.options.method = RequestMethod.Put;
this.options.body = updateQuota;
this.options.body = orgSpaceQuotaFormValuesToApiObject(updateQuota);
}
actions = [
UPDATE_QUOTA_DEFINITION,
@@ -265,12 +292,12 @@ export class DeleteQuotaDefinition extends CFStartAction implements ICFAction {
}

export class CreateSpaceQuotaDefinition extends CFStartAction implements ICFAction {
constructor(public endpointGuid: string, public createQuota: IQuotaDefinition) {
constructor(public endpointGuid: string, orgGuid: string, public createQuota: QuotaFormValues) {
super();
this.options = new RequestOptions();
this.options.url = `space_quota_definitions`;
this.options.method = RequestMethod.Post;
this.options.body = createQuota;
this.options.body = orgSpaceQuotaFormValuesToApiObject(createQuota, false, orgGuid);
this.guid = createQuota.name;
}
actions = [
@@ -288,12 +315,12 @@ export class UpdateSpaceQuotaDefinition extends CFStartAction implements ICFActi

public static UpdateExistingSpaceQuota = 'Updating-Existing-Space-Quota';

constructor(public guid: string, public endpointGuid: string, updateQuota: IQuotaDefinition) {
constructor(public guid: string, public endpointGuid: string, updateQuota: QuotaFormValues) {
super();
this.options = new RequestOptions();
this.options.url = `space_quota_definitions/${guid}`;
this.options.method = RequestMethod.Put;
this.options.body = updateQuota;
this.options.body = orgSpaceQuotaFormValuesToApiObject(updateQuota, false);
}
actions = [
UPDATE_SPACE_QUOTA_DEFINITION,

0 comments on commit 2e46084

Please sign in to comment.