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

Commit

Permalink
Merge pull request #3913 from cloudfoundry-incubator/fix-include-rela…
Browse files Browse the repository at this point in the history
…tion-references

Fix two actionBuilder params issues
  • Loading branch information
KlapTrap committed Sep 24, 2019
2 parents 8058008 + 0659b5a commit e4dd9b4
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class CsiModeService {
const servceBindingEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, serviceBindingEntityType);
const actionBuilder = servceBindingEntity.actionOrchestrator.getActionBuilder('create');
const createServiceBindingAction = actionBuilder(
cfGuid,
guid,
cfGuid,
{ applicationGuid: appGuid, serviceInstanceGuid, params }
);
this.store.dispatch(createServiceBindingAction);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Store } from '@ngrx/store';

import { GetAppServiceBindings } from '../../../../../../../cloud-foundry/src/actions/application-service-routes.actions';
import { CFAppState } from '../../../../../../../cloud-foundry/src/cf-app-state';
import {
applicationEntityType,
Expand All @@ -10,34 +9,37 @@ import {
serviceInstancesEntityType,
servicePlanEntityType,
} from '../../../../../../../cloud-foundry/src/cf-entity-factory';
import {
createEntityRelationKey,
createEntityRelationPaginationKey,
} from '../../../../../../../cloud-foundry/src/entity-relations/entity-relations.types';
import { ApplicationService } from '../../../../../../../cloud-foundry/src/features/applications/application.service';
import { getRowMetadata } from '../../../../../../../cloud-foundry/src/features/cloud-foundry/cf.helpers';
import { IServiceBinding } from '../../../../../../../core/src/core/cf-api-svc.types';
import { entityCatalogue } from '../../../../../../../core/src/core/entity-catalogue/entity-catalogue.service';
import {
ListDataSource,
} from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source';
import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types';
import {
createEntityRelationKey,
createEntityRelationPaginationKey,
} from '../../../../../../../cloud-foundry/src/entity-relations/entity-relations.types';
import { APIResource } from '../../../../../../../store/src/types/api.types';
import { entityCatalogue } from '../../../../../../../core/src/core/entity-catalogue/entity-catalogue.service';
import { CF_ENDPOINT_TYPE } from '../../../../../../cf-types';
import { PaginatedAction } from '../../../../../../../store/src/types/pagination.types';
import { CF_ENDPOINT_TYPE } from '../../../../../../cf-types';

export class AppServiceBindingDataSource extends ListDataSource<APIResource<IServiceBinding>> {
static createGetAllServiceBindings(appGuid: string, cfGuid: string) {
const paginationKey = createEntityRelationPaginationKey(serviceBindingEntityType, appGuid);
const serviceBindingEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, serviceBindingEntityType);
const actionBuilder = serviceBindingEntity.actionOrchestrator.getActionBuilder('getAllForApplication');
const getAppServiceBindingsAction = actionBuilder(
appGuid, cfGuid, paginationKey, [
createEntityRelationKey(serviceInstancesEntityType, servicePlanEntityType),
createEntityRelationKey(serviceInstancesEntityType, serviceEntityType),
createEntityRelationKey(serviceBindingEntityType, applicationEntityType),
createEntityRelationKey(serviceBindingEntityType, serviceInstancesEntityType),
]) as PaginatedAction;
appGuid, cfGuid, paginationKey, {
includeRelations: [
createEntityRelationKey(serviceInstancesEntityType, servicePlanEntityType),
createEntityRelationKey(serviceInstancesEntityType, serviceEntityType),
createEntityRelationKey(serviceBindingEntityType, applicationEntityType),
createEntityRelationKey(serviceBindingEntityType, serviceInstancesEntityType),
],
populateMissing: true
}) as PaginatedAction;
return getAppServiceBindingsAction;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Store } from '@ngrx/store';

import { CF_ENDPOINT_TYPE } from '../../../../../../../cloud-foundry/cf-types';
import { CFAppState } from '../../../../../../../cloud-foundry/src/cf-app-state';
import {
applicationEntityType,
Expand All @@ -11,33 +12,34 @@ import {
servicePlanEntityType,
spaceEntityType,
} from '../../../../../../../cloud-foundry/src/cf-entity-factory';
import {
ListDataSource,
} from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source';
import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types';
import {
createEntityRelationKey,
createEntityRelationPaginationKey,
} from '../../../../../../../cloud-foundry/src/entity-relations/entity-relations.types';
import { entityCatalogue } from '../../../../../../../core/src/core/entity-catalogue/entity-catalogue.service';
import {
ListDataSource,
} from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source';
import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types';
import { APIResource } from '../../../../../../../store/src/types/api.types';
import { getRowMetadata } from '../../../../../features/cloud-foundry/cf.helpers';

import { CF_ENDPOINT_TYPE } from '../../../../../../../cloud-foundry/cf-types';
import { PaginatedAction } from '../../../../../../../store/src/types/pagination.types';
import { entityCatalogue } from '../../../../../../../core/src/core/entity-catalogue/entity-catalogue.service';
import { getRowMetadata } from '../../../../../features/cloud-foundry/cf.helpers';

export class CfSpacesServiceInstancesDataSource extends ListDataSource<APIResource> {
constructor(cfGuid: string, spaceGuid: string, store: Store<CFAppState>, listConfig?: IListConfig<APIResource>) {
const paginationKey = createEntityRelationPaginationKey(spaceEntityType, spaceGuid);
const serviceInstanceEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, serviceInstancesEntityType);
const actionBuilder = serviceInstanceEntity.actionOrchestrator.getActionBuilder('getAllInSpace');
const action = actionBuilder(spaceGuid, cfGuid, paginationKey, null, [
createEntityRelationKey(serviceInstancesEntityType, serviceBindingEntityType),
createEntityRelationKey(serviceInstancesEntityType, serviceEntityType),
createEntityRelationKey(serviceInstancesEntityType, servicePlanEntityType),
createEntityRelationKey(serviceInstancesEntityType, spaceEntityType),
createEntityRelationKey(serviceBindingEntityType, applicationEntityType),
], true, false) as PaginatedAction;
const action = actionBuilder(spaceGuid, cfGuid, paginationKey, null, {
includeRelations: [
createEntityRelationKey(serviceInstancesEntityType, serviceBindingEntityType),
createEntityRelationKey(serviceInstancesEntityType, serviceEntityType),
createEntityRelationKey(serviceInstancesEntityType, servicePlanEntityType),
createEntityRelationKey(serviceInstancesEntityType, spaceEntityType),
createEntityRelationKey(serviceBindingEntityType, applicationEntityType),
],
populateMissing: true
}) as PaginatedAction;
super({
store,
action,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,12 @@ export class CfOrgSpaceDataService implements OnDestroy {
private createPaginationAction() {
const organizationEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, organizationEntityType);
const actionBuilder = organizationEntity.actionOrchestrator.getActionBuilder('getMultiple');
const getAllOrganizationsAction = actionBuilder(null, CfOrgSpaceDataService.CfOrgSpaceServicePaginationKey, [
createEntityRelationKey(organizationEntityType, spaceEntityType),
]);
const getAllOrganizationsAction = actionBuilder(null, CfOrgSpaceDataService.CfOrgSpaceServicePaginationKey, {
includeRelations: [
createEntityRelationKey(organizationEntityType, spaceEntityType),
],
populateMissing: true
});
return getAllOrganizationsAction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { StratosBaseCatalogueEntity } from '../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { entityCatalogue } from '../../../core/src/core/entity-catalogue/entity-catalogue.service';
import { IStratosEntityDefinition } from '../../../core/src/core/entity-catalogue/entity-catalogue.types';
import { AppState, InternalAppState } from '../app-state';
import { EntityRequestAction } from '../types/request.types';
Expand Down Expand Up @@ -36,7 +37,7 @@ export const baseRequestPipelineFactory: EntityRequestPipeline = (
return makeRequestEntityPipe(
httpClient,
request,
action.endpointType,
entityCatalogue.getEndpoint(action.endpointType, action.subType),
action.endpointGuid,
action.externalRequest
).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
StratosBaseCatalogueEntity,
StratosCatalogueEntity,
} from '../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { entityCatalogue } from '../../../core/src/core/entity-catalogue/entity-catalogue.service';
import { IStratosEntityDefinition } from '../../../core/src/core/entity-catalogue/entity-catalogue.types';
import { AppState, InternalAppState } from '../app-state';
import { PaginationFlattenerConfig } from '../helpers/paginated-request-helpers';
Expand Down Expand Up @@ -44,7 +45,7 @@ function getRequestObservable(
const initialRequest = makeRequestEntityPipe(
httpClient,
request,
action.endpointType,
entityCatalogue.getEndpoint(action.endpointType, action.subType),
action.endpointGuid,
action.externalRequest
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { MakeEntityRequestPipe } from '../entity-request-pipeline.types';
import { HttpRequest } from '@angular/common/http';
import { switchMap } from 'rxjs/operators';

import { StratosCatalogueEndpointEntity } from '../../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { MakeEntityRequestPipe } from '../entity-request-pipeline.types';

export const makeRequestEntityPipe: MakeEntityRequestPipe = (
httpClient,
requestOrObservable,
endpointType,
endpointGuids,
endpointConfig: StratosCatalogueEndpointEntity,
endpointGuids: string[],
externalRequest: boolean = false
) => {
if (requestOrObservable instanceof HttpRequest) {
return httpClient.pipelineRequest(
requestOrObservable,
endpointType,
endpointConfig,
endpointGuids,
externalRequest
);
}
return requestOrObservable.pipe(
switchMap(request => httpClient.pipelineRequest(
request,
endpointType,
endpointConfig,
endpointGuids,
externalRequest
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { entityCatalogue } from '../../../core/src/core/entity-catalogue/entity-
import { AppState, InternalAppState } from '../app-state';
import { RecursiveDelete } from '../effects/recursive-entity-delete.effect';
import { ApiRequestTypes, getRequestTypeFromMethod } from '../reducers/api-request-reducer/request-helpers';
import { PaginatedAction } from '../types/pagination.types';
import { EntityRequestAction } from '../types/request.types';
import { failedEntityHandler } from './entity-request-base-handlers/fail-entity-request.handler';
import { patchActionWithForcedConfig } from './entity-request-base-handlers/forced-action-type.helpers';
import { jetstreamErrorHandler } from './entity-request-base-handlers/jetstream-error.handler';
import { startEntityHandler } from './entity-request-base-handlers/start-entity-request.handler';
import { successEntityHandler } from './entity-request-base-handlers/success-entity-request.handler';
import { EntityRequestPipeline, PreApiRequest, SuccessfulApiResponseDataMapper } from './entity-request-pipeline.types';
import { PipelineHttpClient } from './pipline-http-client.service';
import { patchActionWithForcedConfig } from './entity-request-base-handlers/forced-action-type.helpers';
import { PaginatedAction } from '../types/pagination.types';

export interface PipelineFactoryConfig<T extends AppState = InternalAppState> {
store: Store<AppState>;
Expand Down Expand Up @@ -46,7 +46,7 @@ export const apiRequestPipelineFactory = (
const actionDispatcher = (actionToDispatch: Action) => store.dispatch(actionToDispatch);
const requestType = getRequestTypeFromMethod(patchedAction);

const catalogueEntity = entityCatalogue.getEntity(patchedAction.endpointType, patchedAction.entityType);
const catalogueEntity = entityCatalogue.getEntity(patchedAction);
const recursivelyDelete = shouldRecursivelyDelete(requestType, patchedAction);

if (recursivelyDelete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { RequestOptions } from '@angular/http';
import { Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs';

import { StratosBaseCatalogueEntity } from '../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import {
StratosBaseCatalogueEntity,
StratosCatalogueEndpointEntity,
} from '../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { JetStreamErrorResponse } from '../../../core/src/jetstream.helpers';
import { AppState, InternalAppState } from '../app-state';
import { ApiRequestTypes } from '../reducers/api-request-reducer/request-helpers';
Expand Down Expand Up @@ -47,7 +50,7 @@ export type MakeEntityRequestPipe<
> = (
httpClient: PipelineHttpClient,
request: HttpRequest<any> | Observable<HttpRequest<any>>,
endpointType: string,
endpointConfig: StratosCatalogueEndpointEntity,
endpointGuids: string | string[],
externalRequest?: boolean
) => Observable<JetstreamResponse<T>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PaginationPageIterator<R = any, E = any> {
private makeRequest(httpRequest: HttpRequest<JetstreamResponse<R>>) {
return this.httpClient.pipelineRequest<JetstreamResponse<R>>(
httpRequest,
this.action.endpointType,
entityCatalogue.getEndpoint(this.action.endpointType, this.action.subType),
this.action.endpointGuid,
this.action.externalRequest
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { filter, first, map, mergeMap } from 'rxjs/operators';
import { InternalAppState } from '../app-state';
import { registeredEndpointsOfTypesSelector } from '../selectors/endpoint.selectors';

import { StratosCatalogueEndpointEntity } from '../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { IStratosEndpointDefinition } from '../../../core/src/core/entity-catalogue/entity-catalogue.types';
import { environment } from '../../../core/src/environments/environment';
import { InternalAppState } from '../app-state';
import { connectedEndpointsOfTypesSelector, registeredEndpointsOfTypesSelector } from '../selectors/endpoint.selectors';

const { proxyAPIVersion, cfAPIVersion } = environment;

Expand All @@ -19,20 +22,32 @@ export class PipelineHttpClient {
private store: Store<InternalAppState>,
) { }

private makeRequest<R>(hr: HttpRequest<any>, endpointType: string, endpointGuids: string | string[] = null, externalRequest = false) {
private makeRequest<R>(
hr: HttpRequest<any>,
endpointConfig: IStratosEndpointDefinition,
endpointGuids: string | string[] = null,
externalRequest = false
) {
if (externalRequest) {
return this.externalRequest(hr);
}
return this.jetstreamRequest(hr, endpointType, endpointGuids);
return this.jetstreamRequest(hr, endpointConfig, endpointGuids);
}

private jetstreamRequest<R>(hr: HttpRequest<any>, endpointType: string, endpointGuids: string | string[]) {
private jetstreamRequest<R>(
hr: HttpRequest<any>,
endpointConfig: IStratosEndpointDefinition,
endpointGuids: string | string[]) {
const url = `/pp/${proxyAPIVersion}/proxy/${cfAPIVersion}/${hr.url}`;
if (endpointGuids && endpointGuids.length) {
const headers = hr.headers.set(PipelineHttpClient.EndpointHeader, endpointGuids);
return this.httpClient.request<R>(hr.clone({ headers, url }));
} else {
return this.store.select(registeredEndpointsOfTypesSelector(endpointType)).pipe(
const selector = endpointConfig.unConnectable ?
registeredEndpointsOfTypesSelector(endpointConfig.type) :
connectedEndpointsOfTypesSelector(endpointConfig.type);

return this.store.select(selector).pipe(
first(),
mergeMap(endpoints => {
const headers = hr.headers.set(PipelineHttpClient.EndpointHeader, Object.keys(endpoints));
Expand All @@ -48,11 +63,11 @@ export class PipelineHttpClient {

public pipelineRequest<R>(
hr: HttpRequest<any>,
endpointType: string,
endpointConfig: StratosCatalogueEndpointEntity,
endpointGuids: string | string[] = null,
externalRequest = false
): Observable<R> {
return this.makeRequest<R>(hr, endpointType, endpointGuids, externalRequest).pipe(
return this.makeRequest<R>(hr, endpointConfig.definition, endpointGuids, externalRequest).pipe(
filter(event => event instanceof HttpResponse),
map((response: HttpResponse<R>) => response.body)
);
Expand Down
32 changes: 24 additions & 8 deletions src/frontend/packages/store/src/selectors/endpoint.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSelector } from '@ngrx/store';
import { compose, createSelector } from '@ngrx/store';

import { STRATOS_ENDPOINT_TYPE } from '../../../core/src/base-entity-schemas';
import { EntityCatalogueHelpers } from '../../../core/src/core/entity-catalogue/entity-catalogue.helper';
Expand All @@ -24,36 +24,52 @@ export const endpointOfTypeSelector = (type: string) =>
return endpointsOfType;
}, {});
};
// TODO More this #3769

// TODO: Move this #3769
export const cfEndpointEntitiesSelector = endpointOfTypeSelector('cf');

export const getRegisteredEndpoints = (endpoints: IRequestEntityTypeState<EndpointModel>) => {
const registered = {} as IRequestEntityTypeState<EndpointModel>;
Object.values(endpoints).map(endpoint => {
export const getRegisteredEndpoints = (endpoints: IRequestEntityTypeState<EndpointModel>) =>
Object.values(endpoints).reduce((registered, endpoint) => {
if (endpoint.registered) {
registered[endpoint.guid] = endpoint;
}
return registered;
});
return registered;
};
}, {} as IRequestEntityTypeState<EndpointModel>);

export const getConnectedEndpoints = (endpoints: IRequestEntityTypeState<EndpointModel>) =>
Object.values(endpoints).reduce((connected, endpoint) => {
if (endpoint.connectionStatus === 'connected') {
connected[endpoint.guid] = endpoint;
}
return connected;
}, {} as IRequestEntityTypeState<EndpointModel>);

// All Registered endpoint request data
export const endpointsRegisteredEntitiesSelector = createSelector(
endpointEntitiesSelector,
getRegisteredEndpoints
);

export const connectedEndpointsOfTypesSelector = (endpointType: string) => compose(
getConnectedEndpoints,
endpointOfTypeSelector(endpointType),
getRegisteredEndpoints,
endpointEntitiesSelector,
);

export const registeredEndpointsOfTypesSelector = (endpointType: string) => createSelector(
endpointEntitiesSelector,
endpointOfTypeSelector(endpointType),
getRegisteredEndpoints
);

// TODO: Move this #3769
export const endpointsCFEntitiesSelector = createSelector(
endpointEntitiesSelector,
cfEndpointEntitiesSelector
);

// TODO: Move this #3769
export const endpointsRegisteredCFEntitiesSelector = createSelector(
endpointsCFEntitiesSelector,
getRegisteredEndpoints
Expand Down

0 comments on commit e4dd9b4

Please sign in to comment.