Skip to content
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

When no space quota has been assigned fall back on more realistive quota #3541

Merged
merged 2 commits into from
Apr 30, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
generateTestCfEndpointServiceProvider,
} from '../../../../test-framework/cloud-foundry-endpoint-service.helper';
import { ActiveRouteCfOrgSpace } from '../cf-page.types';
import { CloudFoundryOrganizationService } from '../services/cloud-foundry-organization.service';
import { EditSpaceStepComponent } from './edit-space-step/edit-space-step.component';
import { EditSpaceComponent } from './edit-space.component';

Expand All @@ -17,7 +18,7 @@ describe('EditSpaceComponent', () => {
TestBed.configureTestingModule({
declarations: [EditSpaceComponent, EditSpaceStepComponent],
imports: [...BaseTestModules],
providers: [ActiveRouteCfOrgSpace, generateTestCfEndpointServiceProvider(), TabNavService]
providers: [ActiveRouteCfOrgSpace, generateTestCfEndpointServiceProvider(), TabNavService, CloudFoundryOrganizationService]
})
.compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ import { ActiveRouteCfOrgSpace } from '../cf-page.types';
import { getOrgRolesString } from '../cf.helpers';
import { CloudFoundryEndpointService } from './cloud-foundry-endpoint.service';

export const createQuotaDefinition = (orgGuid: string): APIResource<IQuotaDefinition> => ({
entity: {
memory_limit: -1,
app_instance_limit: -1,
instance_memory_limit: -1,
name: 'None assigned',
organization_guid: orgGuid,
total_services: -1,
total_routes: -1
},
metadata: null
export const createQuotaDefinition = (orgGuid: string): IQuotaDefinition => ({
memory_limit: -1,
app_instance_limit: -1,
instance_memory_limit: -1,
name: 'None assigned',
organization_guid: orgGuid,
total_services: -1,
total_routes: -1
});

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { filter, map, publishReplay, refCount, switchMap } from 'rxjs/operators';

import { GetSpace } from '../../../../../store/src/actions/space.actions';
Expand Down Expand Up @@ -30,7 +30,7 @@ import { fetchServiceInstancesCount } from '../../service-catalog/services-helpe
import { ActiveRouteCfOrgSpace } from '../cf-page.types';
import { getSpaceRolesString } from '../cf.helpers';
import { CloudFoundryEndpointService } from './cloud-foundry-endpoint.service';
import { createQuotaDefinition } from './cloud-foundry-organization.service';
import { CloudFoundryOrganizationService, createQuotaDefinition } from './cloud-foundry-organization.service';

@Injectable()
export class CloudFoundrySpaceService {
Expand All @@ -39,7 +39,7 @@ export class CloudFoundrySpaceService {
orgGuid: string;
spaceGuid: string;
userRole$: Observable<string>;
quotaDefinition$: Observable<APIResource<IQuotaDefinition>>;
quotaDefinition$: Observable<IQuotaDefinition>;
allowSsh$: Observable<string>;
totalMem$: Observable<number>;
routes$: Observable<APIResource<IRoute>[]>;
Expand All @@ -59,7 +59,8 @@ export class CloudFoundrySpaceService {
private cfUserService: CfUserService,
private paginationMonitorFactory: PaginationMonitorFactory,
private cfEndpointService: CloudFoundryEndpointService,
private cfUserProvidedServicesService: CloudFoundryUserProvidedServicesService
private cfUserProvidedServicesService: CloudFoundryUserProvidedServicesService,
private cfOrgService: CloudFoundryOrganizationService
) {

this.spaceGuid = activeRouteCfOrgSpace.spaceGuid;
Expand Down Expand Up @@ -133,13 +134,17 @@ export class CloudFoundrySpaceService {
this.cfUserProvidedServicesService.fetchUserProvidedServiceInstancesCount(this.cfGuid, this.orgGuid, this.spaceGuid);
this.routes$ = this.space$.pipe(map(o => o.entity.entity.routes));
this.allowSsh$ = this.space$.pipe(map(o => o.entity.entity.allow_ssh ? 'true' : 'false'));
this.quotaDefinition$ = this.space$.pipe(map(q => {
if (q.entity.entity.space_quota_definition) {
return q.entity.entity.space_quota_definition;
} else {
return createQuotaDefinition(this.orgGuid);
}
}));
this.quotaDefinition$ = this.space$.pipe(
map(q => q.entity.entity.space_quota_definition),
switchMap(def => def ? of(def.entity) : this.cfOrgService.quotaDefinition$),
map(def => def ?
{
...def,
organization_guid: this.orgGuid
} :
createQuotaDefinition(this.orgGuid)
)
);
}

private initialiseAppObservables() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
<app-tile *ngIf="cfEndpointService.appsPagObs.hasEntities$ | async">
<app-card-number-metric icon="content_copy" label="App Instances"
value="{{ (cfSpaceService.appInstances$ | async) }}"
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.entity.app_instance_limit}}"></app-card-number-metric>
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.app_instance_limit}}"></app-card-number-metric>
</app-tile>
<app-tile>
<app-card-number-metric
link="/cloud-foundry/{{cfSpaceService.cfGuid}}/organizations/{{cfSpaceService.orgGuid}}/spaces/{{cfSpaceService.spaceGuid}}/routes"
iconFont="stratos-icons" icon="network_route" label="Routes"
value="{{ (cfSpaceService.routes$ | async)?.length }}"
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.entity.total_routes}}"></app-card-number-metric>
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.total_routes}}"></app-card-number-metric>
</app-tile>
</app-tile-group>

Expand All @@ -59,7 +59,7 @@
link="/cloud-foundry/{{cfSpaceService.cfGuid}}/organizations/{{cfSpaceService.orgGuid}}/spaces/{{cfSpaceService.spaceGuid}}/service-instances"
iconFont="stratos-icons" icon="service" label="Service Instances"
value="{{ (cfSpaceService.serviceInstancesCount$ | async)}}"
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.entity.total_services }}"></app-card-number-metric>
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.total_services }}"></app-card-number-metric>
</app-tile>
<app-tile *ngIf="(cfSpaceService.userProvidedServiceInstancesCount$ | async) > 0">
<app-card-number-metric iconFont="stratos-icons" icon="service" label="User Service Instances"
Expand All @@ -68,7 +68,7 @@
<app-tile *ngIf="cfEndpointService.appsPagObs.hasEntities$ | async">
<app-card-number-metric icon="memory" label="Memory Usage" units="mb"
value="{{ (cfSpaceService.totalMem$ | async) }}"
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.entity.memory_limit }}"></app-card-number-metric>
limit="{{ (cfSpaceService.quotaDefinition$ | async)?.memory_limit }}"></app-card-number-metric>
</app-tile>
</app-tile-group>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
{{ (cfSpaceService.userRole$ | async) }}
</app-metadata-item>
<app-metadata-item label="Quota Definition Name">
{{ (cfSpaceService.quotaDefinition$ | async)?.entity.name }}
{{ (cfSpaceService.quotaDefinition$ | async)?.name }}
</app-metadata-item>
<app-metadata-item label="Provision Paid Services">
<app-boolean-indicator [isTrue]="(cfSpaceService.quotaDefinition$ | async)?.non_basic_services_allowed" type="yes-no">
<app-boolean-indicator [isTrue]="(cfSpaceService.quotaDefinition$ | async)?.non_basic_services_allowed"
type="yes-no">
</app-boolean-indicator>
</app-metadata-item>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, OnInit } from '@angular/core';

import { CloudFoundrySpaceService } from '../../../../features/cloud-foundry/services/cloud-foundry-space.service';
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { CloudFoundrySpaceService } from '../../../../features/cloud-foundry/services/cloud-foundry-space.service';

@Component({
selector: 'app-card-cf-space-details',
templateUrl: './card-cf-space-details.component.html',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { createQuotaDefinition } from '../../../../../../features/cloud-foundry/
import { CfUserService } from '../../../../../data-services/cf-user.service';
import { EntityMonitorFactory } from '../../../../../monitors/entity-monitor.factory.service';
import { PaginationMonitorFactory } from '../../../../../monitors/pagination-monitor.factory';
import { StratosStatus, ComponentEntityMonitorConfig } from '../../../../../shared.types';
import { ComponentEntityMonitorConfig, StratosStatus } from '../../../../../shared.types';
import { ConfirmationDialogConfig } from '../../../../confirmation-dialog.config';
import { ConfirmationDialogService } from '../../../../confirmation-dialog.service';
import { MetaCardMenuItem } from '../../../list-cards/meta-card/meta-card-base/meta-card.component';
Expand Down Expand Up @@ -128,7 +128,7 @@ export class CfOrgCardComponent extends CardCell<APIResource<IOrganization>> imp

setValues = (role: string, apps: APIResource<IApp>[]) => {
this.userRolesInOrg = role;
const quotaDefinition = this.row.entity.quota_definition || createQuotaDefinition(this.orgGuid);
const quotaDefinition = this.row.entity.quota_definition || { entity: createQuotaDefinition(this.orgGuid), metadata: null };

if (apps) {
this.setAppsDependentCounts(apps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { SpaceQuotaHelper } from '../../../../../../features/cloud-foundry/servi
import { CfUserService } from '../../../../../data-services/cf-user.service';
import { EntityMonitorFactory } from '../../../../../monitors/entity-monitor.factory.service';
import { PaginationMonitorFactory } from '../../../../../monitors/pagination-monitor.factory';
import { StratosStatus, ComponentEntityMonitorConfig } from '../../../../../shared.types';
import { ComponentEntityMonitorConfig, StratosStatus } from '../../../../../shared.types';
import { ConfirmationDialogConfig } from '../../../../confirmation-dialog.config';
import { ConfirmationDialogService } from '../../../../confirmation-dialog.service';
import { MetaCardMenuItem } from '../../../list-cards/meta-card/meta-card-base/meta-card.component';
Expand Down Expand Up @@ -140,14 +140,15 @@ export class CfSpaceCardComponent extends CardCell<APIResource<ISpace>> implemen

setValues = (roles: string, apps: APIResource<IApp>[]) => {
this.userRolesInSpace = roles;
const quotaDefinition = this.row.entity.space_quota_definition || createQuotaDefinition(this.orgGuid);
const quotaDefinition = this.row.entity.space_quota_definition ?
this.row.entity.space_quota_definition.entity : createQuotaDefinition(this.orgGuid);
if (apps) {
this.setAppsDependentCounts(apps);
this.memoryTotal = this.cfEndpointService.getMetricFromApps(apps, 'memory');
this.normalisedMemoryUsage = this.memoryTotal / quotaDefinition.entity.memory_limit * 100;
this.normalisedMemoryUsage = this.memoryTotal / quotaDefinition.memory_limit * 100;
}
this.appInstancesLimit = truthyIncludingZeroString(quotaDefinition.entity.app_instance_limit);
this.memoryLimit = truthyIncludingZeroString(quotaDefinition.entity.memory_limit);
this.appInstancesLimit = truthyIncludingZeroString(quotaDefinition.app_instance_limit);
this.memoryLimit = truthyIncludingZeroString(quotaDefinition.memory_limit);
}

ngOnDestroy = () => this.subscriptions.forEach(p => p.unsubscribe());
Expand Down