Skip to content

Commit

Permalink
Merge pull request #2548 from cloudfoundry-incubator/fix-routes
Browse files Browse the repository at this point in the history
Update App Summary entity after carrying out App Route actions
  • Loading branch information
richard-cox authored Jun 29, 2018
2 parents 9fd1ea0 + de9b2f8 commit 6fbc52a
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 23 deletions.
39 changes: 38 additions & 1 deletion src/frontend/app/core/cf-api.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IRoute } from './cf-api.types';
import { APIResource } from '../store/types/api.types';
import { IServiceBinding } from './cf-api-svc.types';
import { IServiceBinding, IService } from './cf-api-svc.types';

export interface IRoute {
host: string;
Expand Down Expand Up @@ -255,3 +255,40 @@ export interface IUpdateOrganization {
quota_definition_guid?: string;
default_isolation_segment_guid?: string;
}

export interface IAppSummary {
guid: string;
name: string;
routes: APIResource<IRoute>[];
running_instances: number;
services: IService[];
available_domains: IDomain[];
production: boolean;
space_guid: string;
stack_guid: string;
buildpack?: any;
detected_buildpack: string;
detected_buildpack_guid: string;
environment_json: {};
memory: number;
instances: number;
disk_quota: number;
state: string;
version: string;
command?: any;
console: boolean;
debug?: any;
staging_task_id: string;
package_state: string;
health_check_type: string;
health_check_timeout?: any;
health_check_http_endpoint: string;
staging_failed_reason?: any;
staging_failed_description?: any;
diego: boolean;
docker_image?: any;
package_updated_at: Date;
detected_start_command: string;
enable_ssh: boolean;
ports?: any;
}
8 changes: 3 additions & 5 deletions src/frontend/app/core/entity-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import { Store, compose } from '@ngrx/store';
import { tag } from 'rxjs-spy/operators/tag';
import { interval, Observable, combineLatest } from 'rxjs';
import { filter, map, publishReplay, refCount, share, tap, withLatestFrom, switchMap, first, distinctUntilChanged } from 'rxjs/operators';
import { compose, Store } from '@ngrx/store';
import { combineLatest, interval, Observable } from 'rxjs';
import { filter, first, map, publishReplay, refCount, switchMap, tap, withLatestFrom } from 'rxjs/operators';

import { EntityMonitor } from '../shared/monitors/entity-monitor';
import { ValidateEntitiesStart } from '../store/actions/request.actions';
Expand All @@ -17,7 +16,6 @@ import {
import { getEntityUpdateSections, getUpdateSectionById } from '../store/selectors/api.selectors';
import { APIResource, EntityInfo } from '../store/types/api.types';
import { ICFAction, IRequestAction } from '../store/types/request.types';
import { composeFn } from './../store/helpers/reducer.helper';

type PollUntil = (apiResource: APIResource, updatingState: ActionState) => boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class ApplicationDeleteComponent<T> {
if (success) {
if (this.selectedRoutes && this.selectedRoutes.length) {
this.selectedRoutes.forEach(route => {
this.store.dispatch(new DeleteRoute(route.metadata.guid, this.applicationService.cfGuid));
this.store.dispatch(new DeleteRoute(route.metadata.guid, this.applicationService.cfGuid, this.applicationService.appGuid));
});
}
if (this.selectedServiceInstances && this.selectedServiceInstances.length) {
Expand Down
19 changes: 12 additions & 7 deletions src/frontend/app/features/applications/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,18 @@ export class ApplicationService {
}
return null;
}),
filter(entRoute => !!entRoute && !!entRoute.entity && !!entRoute.entity.domain),
map(entRoute => getRoute(entRoute, true, false, {
entityRequestInfo: undefined,
entity: entRoute.entity.domain
}))
);
}
map(entRoute => {
if (!!entRoute && !!entRoute.entity && !!entRoute.entity.domain) {
return getRoute(entRoute, true, false, {
entityRequestInfo: undefined,
entity: entRoute.entity.domain
});
}
return null;
})
);
}


isEntityComplete(value, requestInfo: { fetching: boolean }): boolean {
if (requestInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class CfAppRoutesListConfigService extends ListConfig<APIResource> {

dispatchDeleteAction(route) {
return this.store.dispatch(
new DeleteRoute(route.metadata.guid, this.routesDataSource.cfGuid)
new DeleteRoute(route.metadata.guid, this.routesDataSource.cfGuid, this.appService.appGuid)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ export class CfSpaceRoutesListConfigService implements IListConfig<APIResource>
};

dispatchDeleteAction(route) {
const appGuids = route.entity.apps.map(a => a.metadata.guid);
return this.store.dispatch(
new DeleteRoute(route.metadata.guid, this.dataSource.cfGuid)
new DeleteRoute(route.metadata.guid, this.dataSource.cfGuid, null, appGuids)
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/frontend/app/store/actions/route.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export class DeleteRoute extends BaseRouteAction {
constructor(
public guid: string,
public endpointGuid: string,
appGuid?: string,
public appGuids?: string[],
public async: boolean = false,
public recursive: boolean = true,
appGuid?: string
public recursive: boolean = true
) {
super(guid, endpointGuid, appGuid);
this.options = new RequestOptions();
Expand All @@ -81,7 +82,6 @@ export class DeleteRoute extends BaseRouteAction {
];
removeEntityOnDelete = true;
}

export class UnmapRoute extends BaseRouteAction {
constructor(
public routeGuid: string,
Expand Down
26 changes: 26 additions & 0 deletions src/frontend/app/store/effects/app.effects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';
import { Actions, Effect } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { map } from 'rxjs/operators';

import { GetAppSummaryAction } from '../actions/app-metadata.actions';
import { ASSIGN_ROUTE, AssociateRouteWithAppApplication, ASSIGN_ROUTE_SUCCESS } from '../actions/application-service-routes.actions';
import { AppState } from '../app-state';
import { APISuccessOrFailedAction } from '../types/request.types';


@Injectable()
export class AppEffects {

constructor(
private actions$: Actions,
private store: Store<AppState>,
) { }

@Effect({ dispatch: false }) upateSummary$ = this.actions$.ofType<APISuccessOrFailedAction>(ASSIGN_ROUTE_SUCCESS).pipe(
map(action => {
this.store.dispatch(new GetAppSummaryAction(action.apiAction.guid, action.apiAction.endpointGuid));
}),

);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { appStatsReducer } from './app-stats-request.reducer';
import { updateApplicationRoutesReducer } from './application-route.reducer';
import { endpointDisconnectApplicationReducer } from './endpoint-disconnect-application.reducer';
import { updateOrganizationSpaceReducer } from './organization-space.reducer';
import { routeReducer } from './routes.reducer';
import { routeReducer, updateAppSummaryRoutesReducer } from './routes.reducer';
import { serviceInstanceReducer } from './service-instance.reducer';
import { systemEndpointsReducer } from './system-endpoints.reducer';
import { userReducer, userSpaceOrgReducer, endpointDisconnectUserReducer } from './users.reducer';
Expand Down Expand Up @@ -129,6 +129,7 @@ export function requestDataReducer(state, action) {
[routeSchemaKey]: [routeReducer],
[serviceInstancesSchemaKey]: [serviceInstanceReducer],
[endpointStoreNames.type]: [systemEndpointsReducer],
[appSummarySchemaKey]: [updateAppSummaryRoutesReducer],
[applicationSchemaKey]: [
updateApplicationRoutesReducer(),
endpointDisconnectApplicationReducer('application')
Expand Down
54 changes: 52 additions & 2 deletions src/frontend/app/store/reducers/routes.reducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AppState, IRequestEntityTypeState } from '../app-state';
import { Action } from '@ngrx/store';
import { APIResource } from '../types/api.types';
import { RouteEvents, UnmapRoute } from '../actions/route.actions';
import { RouteEvents, UnmapRoute, DeleteRoute } from '../actions/route.actions';
import { APISuccessOrFailedAction } from '../types/request.types';
import { IRoute } from '../../core/cf-api.types';
import { IRoute, IAppSummary } from '../../core/cf-api.types';
import { ASSIGN_ROUTE_SUCCESS, AssociateRouteWithAppApplication } from '../actions/application-service-routes.actions';

export function routeReducer(state: IRequestEntityTypeState<APIResource<IRoute>>, action: APISuccessOrFailedAction) {
Expand Down Expand Up @@ -32,6 +32,56 @@ export function routeReducer(state: IRequestEntityTypeState<APIResource<IRoute>>
return state;
}
}
export function updateAppSummaryRoutesReducer(state: IRequestEntityTypeState<APIResource<IAppSummary>>, action: APISuccessOrFailedAction) {
let currentState, routeGuid;
switch (action.type) {
case RouteEvents.UNMAP_ROUTE_SUCCESS:
const unmapRouteAction = action.apiAction as UnmapRoute;
currentState = state[unmapRouteAction.appGuid];
routeGuid = unmapRouteAction.routeGuid;
return newState(currentState, unmapRouteAction.appGuid, routeGuid, state);
case RouteEvents.DELETE_SUCCESS:
const deleteAction = action.apiAction as DeleteRoute;
routeGuid = deleteAction.guid;
if (deleteAction.appGuids) {
// Mutate state for each App
let mutatedState = state;
deleteAction.appGuids.forEach(appGuid => {
currentState = state[appGuid];
mutatedState = newState(currentState, appGuid, routeGuid, mutatedState);
});
return mutatedState;
} else if (deleteAction.appGuid) {
currentState = state[deleteAction.appGuid];
return newState(currentState, deleteAction.appGuid, routeGuid, state);
}
return state;
default:
return state;
}

}
function newState(
currentState: APIResource<IAppSummary>,
appGuid: string,
routeGuid: string,
state: IRequestEntityTypeState<APIResource<IAppSummary>>
) {

if (!currentState) {
return state;
}
return {
...state,
[appGuid]: {
...currentState,
entity: {
...currentState.entity,
routes: currentState.entity.routes.filter(r => r.entity.guid !== routeGuid)
}
}
};
}

function addAppFromRoute(entity: IRoute, appGuid: string) {
const oldApps = entity.apps ? entity.apps : [];
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/app/store/store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { UpdateAppEffects } from './effects/update-app-effects';
import { UserProfileEffect } from './effects/user-profile.effects';
import { UsersRolesEffects } from './effects/users-roles.effects';
import { AppReducersModule } from './reducers.module';
import { AppEffects } from './effects/app.effects';
import { UsersEffects } from './effects/users.effects';
import { RecursiveDeleteEffect } from './effects/recursive-entity-delete.effect';

Expand Down Expand Up @@ -57,7 +58,8 @@ import { RecursiveDeleteEffect } from './effects/recursive-entity-delete.effect'
PermissionsEffects,
PermissionEffects,
UsersEffects,
RecursiveDeleteEffect
RecursiveDeleteEffect,
AppEffects
])
]
})
Expand Down

0 comments on commit 6fbc52a

Please sign in to comment.