Skip to content

Commit

Permalink
Blitz - User Service & Deploy from git fixes (#4062)
Browse files Browse the repository at this point in the history
* Move createDefaultUserRelations to core file

* Fix user service
- ensure action builder constructors are correct (were fetching users for all endpoints instead of contextual one)
- removed duplicate cf-user-service

* Fix super sluggish behaviour when deploying from github
- most of the git actions included the scm object
- scm objects included httpClient
- this lead to very large actions being dispatched
- fix is to supply httpClient when needed

* Fix getMatchingRepositories
  • Loading branch information
richard-cox authored and nwmac committed Dec 13, 2019
1 parent 9d1751b commit d9e7fc5
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 498 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HttpHeaders, HttpRequest } from '@angular/common/http';

import { IUpdateOrganization } from '../../../core/src/core/cf-api.types';
import { getActions } from '../../../store/src/actions/action.helper';
import { PaginatedAction } from '../../../store/src/types/pagination.types';
Expand All @@ -17,8 +19,7 @@ import {
EntityInlineParentAction,
} from '../entity-relations/entity-relations.types';
import { CFStartAction } from './cf-action.types';
import { createDefaultUserRelations } from './user.actions.helpers';
import { HttpRequest, HttpHeaders } from '@angular/common/http';
import { createDefaultUserRelations } from './users.actions';

export const GET_ORGANIZATION = '[Organization] Get one';
export const GET_ORGANIZATION_SUCCESS = '[Organization] Get one success';
Expand Down

This file was deleted.

24 changes: 20 additions & 4 deletions src/frontend/packages/cloud-foundry/src/actions/users.actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { HttpRequest } from '@angular/common/http';

import { getActions } from '../../../store/src/actions/action.helper';
import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory';
import { EntitySchema } from '../../../store/src/helpers/entity-schema';
import { PaginatedAction } from '../../../store/src/types/pagination.types';
import { EntityRequestAction } from '../../../store/src/types/request.types';
import { cfEntityFactory } from '../cf-entity-factory';
import { cfUserEntityType, organizationEntityType, spaceEntityType } from '../cf-entity-types';
import { createEntityRelationPaginationKey, EntityInlineParentAction } from '../entity-relations/entity-relations.types';
import { OrgUserRoleNames, SpaceUserRoleNames } from '../store/types/user.types';
import {
createEntityRelationKey,
createEntityRelationPaginationKey,
EntityInlineParentAction,
} from '../entity-relations/entity-relations.types';
import { CfUserRoleParams, OrgUserRoleNames, SpaceUserRoleNames } from '../store/types/user.types';
import { CFStartAction } from './cf-action.types';
import { createDefaultUserRelations } from './user.actions.helpers';
import { HttpRequest } from '@angular/common/http';

export const GET_ALL = '[Users] Get all';
export const GET_ALL_SUCCESS = '[Users] Get all success';
Expand All @@ -30,6 +34,18 @@ export const GET_CF_USER_FAILED = '[Users] Get cf user failed';
export const GET_CF_USERS_AS_NON_ADMIN = '[Users] Get cf users by org ';
export const GET_CF_USERS_AS_NON_ADMIN_SUCCESS = '[Users] Get cf users by org success';

export function createDefaultUserRelations() {
return [
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.ORGANIZATIONS),
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.AUDITED_ORGS),
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.MANAGED_ORGS),
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.BILLING_MANAGER_ORGS),
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.SPACES),
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.MANAGED_SPACES),
createEntityRelationKey(cfUserEntityType, CfUserRoleParams.AUDITED_SPACES)
];
}


export class GetAllUsersAsAdmin extends CFStartAction implements PaginatedAction, EntityInlineParentAction {
isGetAllUsersAsAdmin = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Store } from '@ngrx/store';
import { Observable, of as observableOf, Subscription } from 'rxjs';
import { distinctUntilChanged, filter, map, take, tap } from 'rxjs/operators';

import { FetchBranchesForProject } from '../../../../../../../../cloud-foundry/src/actions/deploy-applications.actions';
import { GitCommit, GitRepo } from '../../../../../../../../cloud-foundry/src/store/types/git.types';
import { entityCatalogue } from '../../../../../../../../core/src/core/entity-catalogue/entity-catalogue.service';
import { EntityService } from '../../../../../../../../core/src/core/entity-service';
Expand Down Expand Up @@ -112,10 +111,9 @@ export class GitSCMTabComponent implements OnInit, OnDestroy {
const branchID = `${scmType}-${projectName}-${stProject.deploySource.branch}`;
const gitBranchesEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, gitBranchesEntityType);
const fetchBranchesActionBuilder = gitBranchesEntity.actionOrchestrator.getActionBuilder('get');
const fetchBranchesAction = fetchBranchesActionBuilder(branchID, null, { projectName, scm });
this.gitBranchEntityService = this.entityServiceFactory.create(
branchID,
new FetchBranchesForProject(scm, projectName)
fetchBranchesActionBuilder(branchID, null, { projectName, scm })
);

this.gitSCMRepo$ = this.gitSCMRepoEntityService.waitForEntity$.pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { AfterContentInit, Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
Expand Down Expand Up @@ -123,7 +124,8 @@ export class DeployApplicationStep2Component
private store: Store<CFAppState>,
route: ActivatedRoute,
private paginationMonitorFactory: PaginationMonitorFactory,
private scmService: GitSCMService
private scmService: GitSCMService,
private httpClient: HttpClient
) {
this.selectedSourceType = getAutoSelectedDeployType(route);
if (this.selectedSourceType) {
Expand Down Expand Up @@ -320,7 +322,7 @@ export class DeployApplicationStep2Component

return observableTimer(500).pipe(
take(1),
switchMap(() => this.scm.getMatchingRepositories(name)),
switchMap(() => this.scm.getMatchingRepositories(this.httpClient, name)),
catchError(e => observableOf(null)),
tap(suggestions => this.cachedSuggestions[cacheName] = suggestions)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Store } from '@ngrx/store';
import { Observable, of as observableOf } from 'rxjs';
import { filter, first, map, publishReplay, refCount, switchMap } from 'rxjs/operators';

import { GetAllUsersAsAdmin } from '../../../../cloud-foundry/src/actions/users.actions';
import { CFAppState } from '../../../../cloud-foundry/src/cf-app-state';
import { cfUserEntityType, organizationEntityType, spaceEntityType } from '../../../../cloud-foundry/src/cf-entity-types';
import { createEntityRelationPaginationKey } from '../../../../cloud-foundry/src/entity-relations/entity-relations.types';
Expand Down Expand Up @@ -47,6 +46,8 @@ import {
export class CfUserService {
private allUsers$: Observable<PaginationObservables<APIResource<CfUser>>>;

private userCatalogueEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, cfUserEntityType);

users: { [guid: string]: Observable<APIResource<CfUser>> } = {};

constructor(
Expand Down Expand Up @@ -83,8 +84,7 @@ export class CfUserService {
return observableOf(users.filter(o => o.metadata.guid === userGuid)[0]);
}
if (!this.users[userGuid]) {
const userEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, cfUserEntityType);
const actionBuilder = userEntity.actionOrchestrator.getActionBuilder('get');
const actionBuilder = this.userCatalogueEntity.actionOrchestrator.getActionBuilder('get');
const getUserAction = actionBuilder(userGuid, endpointGuid);
this.users[userGuid] = this.entityServiceFactory.create<APIResource<CfUser>>(
userGuid,
Expand Down Expand Up @@ -371,34 +371,25 @@ export class CfUserService {
}

private createCfGetUsersAction = (cfGuid: string): PaginatedAction => {
const userEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, cfUserEntityType);
const actionBuilder = userEntity.actionOrchestrator.getActionBuilder('getMultiple');
const action = actionBuilder(undefined, cfGuid) as GetAllUsersAsAdmin;
return action;
return this.userCatalogueEntity.actionOrchestrator.getActionBuilder('getMultiple')(cfGuid, null);
}

private createOrgGetUsersAction = (isAdmin: boolean, cfGuid: string, orgGuid: string): PaginatedAction => {
const userEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, cfUserEntityType);
const actionBuilder = userEntity.actionOrchestrator.getActionBuilder('getAllInOrganization');
const action = actionBuilder(
return this.userCatalogueEntity.actionOrchestrator.getActionBuilder('getAllInOrganization')(
orgGuid,
cfGuid,
createEntityRelationPaginationKey(organizationEntityType, orgGuid),
isAdmin
) as PaginatedAction;
return action;
}

private createSpaceGetUsersAction = (isAdmin: boolean, cfGuid: string, spaceGuid: string, ): PaginatedAction => {
const userEntity = entityCatalogue.getEntity(CF_ENDPOINT_TYPE, cfUserEntityType);
const actionBuilder = userEntity.actionOrchestrator.getActionBuilder('getAllInSpace');
const action = actionBuilder(
return this.userCatalogueEntity.actionOrchestrator.getActionBuilder('getAllInSpace')(
spaceGuid,
cfGuid,
createEntityRelationPaginationKey(spaceEntityType, spaceGuid),
isAdmin
) as PaginatedAction;
return action;
}

public isConnectedUserAdmin = (cfGuid: string): Observable<boolean> =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
Expand Down Expand Up @@ -59,17 +60,18 @@ export class DeployAppEffects {
private actions$: Actions,
private store: Store<CFAppState>,
private logger: LoggerService,
private httpClient: HttpClient
) { }

@Effect()
checkAppExists$ = this.actions$.pipe(
ofType<CheckProjectExists>(CHECK_PROJECT_EXISTS),
withLatestFrom(this.store.select(selectDeployAppState)),
filter(([action, state]) => {
filter(([, state]) => {
return state.projectExists && state.projectExists.checking;
}),
switchMap(([action, state]: any) => {
return action.scm.getRepository(action.projectName).pipe(
switchMap(([action, state]: [CheckProjectExists, any]) => {
return action.scm.getRepository(this.httpClient, action.projectName).pipe(
map(res => new ProjectExists(action.projectName, res)),
catchError(err => observableOf(err.status === 404 ?
new ProjectDoesntExist(action.projectName) :
Expand All @@ -91,7 +93,7 @@ export class DeployAppEffects {
paginationKey: action.paginationKey
} as PaginatedAction;
this.store.dispatch(new StartRequestAction(apiAction, actionType));
return action.scm.getBranches(action.projectName).pipe(
return action.scm.getBranches(this.httpClient, action.projectName).pipe(
mergeMap(branches => {
const entityKey = entityCatalogue.getEntity(apiAction).entityKey;
const mappedData = {
Expand Down Expand Up @@ -131,7 +133,7 @@ export class DeployAppEffects {
type: action.type,
} as ICFAction;
this.store.dispatch(new StartRequestAction(apiAction, actionType));
return action.scm.getCommit(action.projectName, action.commitSha).pipe(
return action.scm.getCommit(this.httpClient, action.projectName, action.commitSha).pipe(
mergeMap(commit => {
const entityKey = entityCatalogue.getEntity(apiAction).entityKey;
const mappedData = {
Expand Down Expand Up @@ -160,7 +162,7 @@ export class DeployAppEffects {
paginationKey: action.paginationKey
} as PaginatedAction;
this.store.dispatch(new StartRequestAction(apiAction, actionType));
return action.scm.getCommits(action.projectName, action.sha).pipe(
return action.scm.getCommits(this.httpClient, action.projectName, action.sha).pipe(
mergeMap((commits: GitCommit[]) => {
const entityKey = entityCatalogue.getEntity(apiAction).entityKey;
const mappedData = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
Expand All @@ -16,7 +17,6 @@ import { FETCH_GITHUB_REPO, FetchGitHubRepoInfo } from '../../actions/github.act
import { CFAppState } from '../../cf-app-state';
import { gitRepoEntityType } from '../../cf-entity-types';
import { createFailedGithubRequestMessage } from './deploy-app.effects';
import { HttpClient } from '@angular/common/http';

// TODO: Remove this in favour of action builder config.
// https://github.com/cloudfoundry-incubator/stratos/issues/3770
Expand All @@ -29,7 +29,8 @@ export class GithubEffects {
private actions$: Actions,
private store: Store<CFAppState>,
private scmService: GitSCMService,
private logger: LoggerService
private logger: LoggerService,
private httpClient: HttpClient
) { }
@Effect()
fetchRep$ = this.actions$.pipe(
Expand All @@ -45,7 +46,7 @@ export class GithubEffects {
this.store.dispatch(new StartRequestAction(apiAction, actionType));
const scmType = action.stProject.deploySource.scm || action.stProject.deploySource.type;
const scm = this.scmService.getSCM(scmType as GitSCMType);
return scm.getRepository(action.stProject.deploySource.project).pipe(
return scm.getRepository(this.httpClient, action.stProject.deploySource.project).pipe(
mergeMap(repoDetails => {
const mappedData = {
entities: { cfGitRepo: {} },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { cfUserEntityType } from '../../cf-entity-types';
import { IOrganization, ISpace } from '../../../../core/src/core/cf-api.types';
import { DISCONNECT_ENDPOINTS_SUCCESS, DisconnectEndpoint } from '../../../../store/src/actions/endpoint.actions';
import { GET_ORGANIZATION_USERS_SUCCESS, GetAllOrgUsers } from '../../actions/organization.actions';
import { createDefaultUserRelations } from '../../actions/user.actions.helpers';
import { ADD_ROLE_SUCCESS, ChangeUserRole, REMOVE_ROLE_SUCCESS } from '../../actions/users.actions';
import { IRequestEntityTypeState } from '../../../../store/src/app-state';
import { deepMergeState } from '../../../../store/src/helpers/reducer.helper';
import { APIResource, NormalizedResponse } from '../../../../store/src/types/api.types';
import { APISuccessOrFailedAction } from '../../../../store/src/types/request.types';
import { GET_ORGANIZATION_USERS_SUCCESS, GetAllOrgUsers } from '../../actions/organization.actions';
import {
ADD_ROLE_SUCCESS,
ChangeUserRole,
createDefaultUserRelations,
REMOVE_ROLE_SUCCESS,
} from '../../actions/users.actions';
import { cfUserEntityType } from '../../cf-entity-types';
import {
CfUser,
CfUserMissingOrgRoles,
Expand Down
Loading

0 comments on commit d9e7fc5

Please sign in to comment.