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

Commit

Permalink
Fix org/space shemas (#1601)
Browse files Browse the repository at this point in the history
* Fix org/space shemas
- Selecting cf/org/spaces in filter or add/deploy app should work again
- Only have one type of Space/Org Schema

* Add missing file
  • Loading branch information
richard-cox authored and Irfan Habib committed Feb 14, 2018
1 parent 9b571c6 commit 3e20eb0
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 182 deletions.
15 changes: 10 additions & 5 deletions src/frontend/app/features/applications/application.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';
import { map, mergeMap } from 'rxjs/operators';

import { EntityService } from '../../core/entity-service';
import { EntityServiceFactory } from '../../core/entity-service-factory.service';
Expand All @@ -18,7 +18,6 @@ import {
} from '../../store/actions/app-metadata.actions';
import { GetApplication, UpdateApplication, UpdateExistingApplication } from '../../store/actions/application.actions';
import { ApplicationSchema } from '../../store/actions/application.actions';
import { SpaceSchema } from '../../store/actions/space.action';
import { AppState } from '../../store/app-state';
import { ActionState } from '../../store/reducers/api-request-reducer/types';
import { selectEntity } from '../../store/selectors/api.selectors';
Expand Down Expand Up @@ -46,6 +45,7 @@ import {
} from './application/application-tabs-base/tabs/build-tab/application-env-vars.service';
import { getRoute, isTCPRoute } from './routes/routes.helper';
import { PaginationMonitor } from '../../shared/monitors/pagination-monitor';
import { spaceSchemaKey, organisationSchemaKey } from '../../store/actions/action-types';

export interface ApplicationData {
fetching: boolean;
Expand Down Expand Up @@ -157,9 +157,14 @@ export class ApplicationService {
.filter(entityInfo => entityInfo.entity && entityInfo.entity.entity && entityInfo.entity.entity.cfGuid)
.map(entityInfo => entityInfo.entity.entity)
.do(app => {
this.appSpace$ = this.store.select(selectEntity(SpaceSchema.key, app.space_guid));
// See https://github.com/SUSE/stratos/issues/158 (Failing to populate entity store with a space's org)
this.appOrg$ = this.store.select(selectEntity(SpaceSchema.key, app.space_guid)).map(space => space.entity.organization);

this.appSpace$ = this.store.select(selectEntity(spaceSchemaKey, app.space_guid));
this.appOrg$ = this.appSpace$.pipe(
map(space => space.entity.organization_guid),
mergeMap(orgGuid => {
return this.store.select(selectEntity(organisationSchemaKey, orgGuid));
})
);
})
.take(1)
.subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { AppState } from '../../../../store/app-state';
import { selectNewAppState } from '../../../../store/effects/create-app-effects';
import { CreateNewApplicationState } from '../../../../store/types/create-application.types';
import { RouterNav } from '../../../../store/actions/router.actions';
import { OrganisationSchema } from '../../../../store/actions/organisation.action';
import { RequestInfoState } from '../../../../store/reducers/api-request-reducer/types';
import { organisationSchemaKey } from '../../../../store/actions/action-types';

@Component({
selector: 'app-create-application-step3',
Expand Down Expand Up @@ -124,7 +124,7 @@ export class CreateApplicationStep3Component implements OnInit {
})
.filter(state => state.cloudFoundryDetails && state.cloudFoundryDetails.org)
.mergeMap(state => {
return this.store.select(selectEntity(OrganisationSchema.key, state.cloudFoundryDetails.org))
return this.store.select(selectEntity(organisationSchemaKey, state.cloudFoundryDetails.org))
.first()
.map(org => org.entity.domains);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { Store } from '@ngrx/store';
import { AppState } from '../../../../store/app-state';
import { tap, filter, map, mergeMap, combineLatest, switchMap, share, catchError } from 'rxjs/operators';
import { getEntityById, selectEntity, selectEntities } from '../../../../store/selectors/api.selectors';
import { OrganizationSchema } from '../../../../store/actions/organization.actions';
import { DeleteDeployAppSection } from '../../../../store/actions/deploy-applications.actions';
import { SpaceSchema } from '../../../../store/actions/space.actions';
import websocketConnect from 'rxjs-websockets';
import { QueueingSubject } from 'queueing-subject/lib';
import { Subscription } from 'rxjs/Subscription';
Expand All @@ -20,6 +18,7 @@ import { RouterNav } from '../../../../store/actions/router.actions';
import { GetAllApplications } from '../../../../store/actions/application.actions';
import { environment } from '../../../../../environments/environment';
import { CfOrgSpaceDataService } from '../../../../shared/data-services/cf-org-space-service.service';
import { organisationSchemaKey, spaceSchemaKey } from '../../../../store/actions/action-types';

@Component({
selector: 'app-deploy-application-step3',
Expand Down Expand Up @@ -58,9 +57,9 @@ export class DeployApplicationStep3Component implements OnInit, OnDestroy {
&& !!appDetail.applicationSource
&& !!appDetail.applicationSource.projectName),
mergeMap(p => {
const orgSubscription = this.store.select(selectEntity(OrganizationSchema.key, p.cloudFoundryDetails.org));
const spaceSubscription = this.store.select(selectEntity(SpaceSchema.key, p.cloudFoundryDetails.space));
return Observable.of(p).combineLatest(orgSubscription, spaceSubscription );
const orgSubscription = this.store.select(selectEntity(organisationSchemaKey, p.cloudFoundryDetails.org));
const spaceSubscription = this.store.select(selectEntity(spaceSchemaKey, p.cloudFoundryDetails.space));
return Observable.of(p).combineLatest(orgSubscription, spaceSubscription);
}),
tap(p => {
const host = window.location.host;
Expand All @@ -70,10 +69,10 @@ export class DeployApplicationStep3Component implements OnInit, OnDestroy {
`?org=${p[1].entity.name}&space=${p[2].entity.name}`
);

const inputStream = new QueueingSubject<string>();
const inputStream = new QueueingSubject<string>();
this.messages = websocketConnect(streamUrl, inputStream)
.messages.pipe(
catchError(e => {
.messages.pipe(
catchError(e => {
return [];
}),
share(),
Expand All @@ -88,21 +87,21 @@ export class DeployApplicationStep3Component implements OnInit, OnDestroy {
this.updateTitle(log);
}
}),
filter((log ) => log.type === SocketEventTypes.DATA),
filter((log) => log.type === SocketEventTypes.DATA),
map((log) => {
const timesString = moment(log.timestamp * 1000).format('DD/MM/YYYY hh:mm:ss A');
return (
`${timesString}: ${log.message}`
);
})
);
);
inputStream.next(this.sendProjectInfo(p[0].applicationSource));

})
).subscribe();
}

sendProjectInfo = (appSource: DeployApplicationSource) => {
sendProjectInfo = (appSource: DeployApplicationSource) => {
if (appSource.type.id === 'git') {
if (appSource.type.subType === 'github') {
return this.sendGitHubSourceMetadata(appSource);
Expand All @@ -114,7 +113,7 @@ export class DeployApplicationStep3Component implements OnInit, OnDestroy {
return '';
}

sendGitHubSourceMetadata = (appSource: DeployApplicationSource) => {
sendGitHubSourceMetadata = (appSource: DeployApplicationSource) => {
const github = {
project: appSource.projectName,
branch: appSource.branch.name,
Expand All @@ -129,7 +128,7 @@ export class DeployApplicationStep3Component implements OnInit, OnDestroy {
return JSON.stringify(msg);
}

sendGitUrlSourceMetadata = (appSource: DeployApplicationSource) => {
sendGitUrlSourceMetadata = (appSource: DeployApplicationSource) => {
const giturl = {
url: appSource.projectName,
branch: appSource.branch.name,
Expand All @@ -155,62 +154,62 @@ export class DeployApplicationStep3Component implements OnInit, OnDestroy {
this.appData.org = this.cfOrgSpaceService.org.select.getValue();
this.appData.space = this.cfOrgSpaceService.space.select.getValue();
break;
case SocketEventTypes.EVENT_PUSH_STARTED :
this.streamTitle = 'Deploying...';
this.store.dispatch(new GetAllApplications('applicationWall'));
break;
case SocketEventTypes.EVENT_PUSH_COMPLETED :
this.streamTitle = 'Deployed';
this.apps$ = this.store.select(selectEntities('application')).pipe(
tap(apps => {
Object.values(apps).forEach(app => {
if (
app.entity.space_guid === this.appData.space &&
app.entity.cfGuid === this.appData.cloudFoundry &&
app.entity.name === this.appData.Name
) {
this.appGuid = app.entity.guid;
this.validate = Observable.of(true);
}
});
})
).subscribe();
break;
case SocketEventTypes.CLOSE_SUCCESS :
this.close(log, null, null, true);
break;
case SocketEventTypes.EVENT_PUSH_STARTED:
this.streamTitle = 'Deploying...';
this.store.dispatch(new GetAllApplications('applicationWall'));
break;
case SocketEventTypes.EVENT_PUSH_COMPLETED:
this.streamTitle = 'Deployed';
this.apps$ = this.store.select(selectEntities('application')).pipe(
tap(apps => {
Object.values(apps).forEach(app => {
if (
app.entity.space_guid === this.appData.space &&
app.entity.cfGuid === this.appData.cloudFoundry &&
app.entity.name === this.appData.Name
) {
this.appGuid = app.entity.guid;
this.validate = Observable.of(true);
}
});
})
).subscribe();
break;
case SocketEventTypes.CLOSE_SUCCESS:
this.close(log, null, null, true);
break;
case SocketEventTypes.CLOSE_INVALID_MANIFEST:
this.close(log, 'Deploy Failed - Invalid manifest!',
'Failed to deploy app! Please make sure that a valid manifest.yaml was provided!', true);
'Failed to deploy app! Please make sure that a valid manifest.yaml was provided!', true);
break;
case SocketEventTypes.CLOSE_NO_MANIFEST:
this.close(log, 'Deploy Failed - No manifest present!',
'Failed to deploy app! Please make sure that a valid manifest.yaml is present!', true);
this.close(log, 'Deploy Failed - No manifest present!',
'Failed to deploy app! Please make sure that a valid manifest.yaml is present!', true);
break;
case SocketEventTypes.CLOSE_FAILED_CLONE:
this.close(log, 'Deploy Failed - Failed to clone repository!',
'Failed to deploy app! Please make sure the repository is public!', true);
this.close(log, 'Deploy Failed - Failed to clone repository!',
'Failed to deploy app! Please make sure the repository is public!', true);
break;
case SocketEventTypes.CLOSE_FAILED_NO_BRANCH:
this.close(log, 'Deploy Failed - Failed to located branch!',
'Failed to deploy app! Please make sure that branch exists!', true);
this.close(log, 'Deploy Failed - Failed to located branch!',
'Failed to deploy app! Please make sure that branch exists!', true);
break;
case SocketEventTypes.CLOSE_FAILURE:
case SocketEventTypes.CLOSE_PUSH_ERROR:
case SocketEventTypes.CLOSE_NO_SESSION:
case SocketEventTypes.CLOSE_NO_CNSI:
case SocketEventTypes.CLOSE_NO_CNSI_USERTOKEN:
this.close(log, 'Deploy Failed!',
'Failed to deploy app!', true);
this.close(log, 'Deploy Failed!',
'Failed to deploy app!', true);
break;
case SocketEventTypes.SOURCE_REQUIRED:
case SocketEventTypes.EVENT_CLONED:
case SocketEventTypes.EVENT_FETCHED_MANIFEST:
case SocketEventTypes.MANIFEST:
break;
default:
// noop
}
// noop
}
}

close(log, title, error, deleteAppSection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { Store } from '@ngrx/store';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';

import { GetAllOrganizations, OrganizationSchema } from '../../store/actions/organization.actions';
import { AppState } from '../../store/app-state';
import { getPaginationObservables, getCurrentPageRequestInfo } from '../../store/reducers/pagination-reducer/pagination-reducer.helper';
import { endpointsRegisteredEntitiesSelector } from '../../store/selectors/endpoint.selectors';
import { EndpointModel } from '../../store/types/endpoint.types';
import { PaginationMonitorFactory } from '../monitors/pagination-monitor.factory';
import { GetAllOrganisations } from '../../store/actions/organisation.actions';
import { OrganisationWithSpaceSchema } from '../../store/actions/action-types';

export interface CfOrgSpaceItem {
list$: Observable<EndpointModel[] | any[]>;
Expand All @@ -25,7 +26,7 @@ export class CfOrgSpaceDataService {
public org: CfOrgSpaceItem;
public space: CfOrgSpaceItem;

public paginationAction = new GetAllOrganizations(CfOrgSpaceDataService.CfOrgSpaceServicePaginationKey);
public paginationAction = new GetAllOrganisations(CfOrgSpaceDataService.CfOrgSpaceServicePaginationKey);

// TODO: We should optimise this to only fetch the orgs for the current endpoint
// (if we inline depth the get orgs request it could be hefty... or we could use a different action to only fetch required data..
Expand All @@ -35,7 +36,7 @@ export class CfOrgSpaceDataService {
action: this.paginationAction,
paginationMonitor: this.paginationMonitorFactory.create(
this.paginationAction.paginationKey,
OrganizationSchema
OrganisationWithSpaceSchema
)
});

Expand Down
28 changes: 28 additions & 0 deletions src/frontend/app/store/actions/action-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { schema } from 'normalizr';
import { getAPIResourceGuid } from '../selectors/api.selectors';

export const organisationSchemaKey = 'organization';
export const OrganisationSchema = new schema.Entity(organisationSchemaKey, {}, {
idAttribute: getAPIResourceGuid
});

export const spaceSchemaKey = 'space';
export const SpaceSchema = new schema.Entity(spaceSchemaKey, {}, {
idAttribute: getAPIResourceGuid
});

export const OrganisationWithSpaceSchema = new schema.Entity(organisationSchemaKey, {
entity: {
spaces: [SpaceSchema]
}
}, {
idAttribute: getAPIResourceGuid
});

export const SpaceWithOrganisationSchema = new schema.Entity(spaceSchemaKey, {
entity: {
organization: OrganisationSchema
}
}, {
idAttribute: getAPIResourceGuid
});
4 changes: 2 additions & 2 deletions src/frontend/app/store/actions/application.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Headers, RequestOptions, URLSearchParams } from '@angular/http';
import { schema } from 'normalizr';

import { ApiActionTypes } from './request.actions';
import { SpaceSchema } from './space.actions';
import { StackSchema } from './stack.action';
import { ActionMergeFunction } from '../types/api.types';
import { PaginatedAction } from '../types/pagination.types';
Expand All @@ -14,6 +13,7 @@ import { pick } from '../helpers/reducer.helper';
import { AppMetadataTypes } from './app-metadata.actions';
import { AppStatSchema } from '../types/app-metadata.types';
import { getPaginationKey } from './pagination.actions';
import { SpaceWithOrganisationSchema } from './action-types';

export const GET_ALL = '[Application] Get all';
export const GET_ALL_SUCCESS = '[Application] Get all success';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const DELETE_INSTANCE_FAILED = '[Application Instance] Delete failed';
const ApplicationEntitySchema = {
entity: {
stack: StackSchema,
space: SpaceSchema
space: SpaceWithOrganisationSchema
}
};

Expand Down
30 changes: 0 additions & 30 deletions src/frontend/app/store/actions/organisation.action.ts

This file was deleted.

Loading

0 comments on commit 3e20eb0

Please sign in to comment.