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

Commit

Permalink
Final TODO's
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed May 15, 2020
1 parent 54534a9 commit 81db83c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ import { StepOnNextFunction, StepOnNextResult } from '../../../shared/components
import { kubeEntityCatalog } from '../../kubernetes/kubernetes-entity-catalog';
import { KUBERNETES_ENDPOINT_TYPE } from '../../kubernetes/kubernetes-entity-factory';
import { KubernetesNamespace } from '../../kubernetes/store/kube.types';
import { workloadsEntityCatalog } from '../../kubernetes/workloads/workloads-entity-catalog';
import { helmEntityCatalog } from '../helm-entity-catalog';
import { HelmInstallValues } from '../store/helm.types';


// private pmf: PaginationMonitorFactory, // TODO: RC search and destroy
// private emf: EntityMonitorFactory // TODO: RC search and destroy
// store.dispatch

@Component({
selector: 'app-create-release',
templateUrl: './create-release.component.html',
Expand Down Expand Up @@ -263,7 +258,7 @@ export class CreateReleaseComponent implements OnInit, OnDestroy {
};

// Make the request
return workloadsEntityCatalog.release.api.install<RequestInfoState>(values).pipe(
return helmEntityCatalog.chart.api.install<RequestInfoState>(values).pipe(
// Wait for result of request
filter(state => !!state),
pairwise(),
Expand Down
21 changes: 18 additions & 3 deletions custom-src/frontend/app/custom/helm/helm-entity-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
helmVersionsEntityType,
monocularChartsEntityType,
} from './helm-entity-factory';
import { HelmChartActionBuilders, HelmVersionActionBuilders } from './store/helm.action-builders';
import {
HelmChartActionBuilders,
helmChartActionBuilders,
HelmVersionActionBuilders,
helmVersionActionBuilders,
} from './store/helm.action-builders';
import { HelmVersion, MonocularChart } from './store/helm.types';


Expand Down Expand Up @@ -51,7 +56,12 @@ function generateChartEntity(endpointDefinition: StratosEndpointExtensionDefinit
schema: helmEntityFactory(monocularChartsEntityType),
endpoint: endpointDefinition
};
helmEntityCatalog.chart = new StratosCatalogEntity<IFavoriteMetadata, MonocularChart, HelmChartActionBuilders>(definition);
helmEntityCatalog.chart = new StratosCatalogEntity<IFavoriteMetadata, MonocularChart, HelmChartActionBuilders>(
definition,
{
actionBuilders: helmChartActionBuilders
}
);
return helmEntityCatalog.chart;
}

Expand All @@ -61,7 +71,12 @@ function generateVersionEntity(endpointDefinition: StratosEndpointExtensionDefin
schema: helmEntityFactory(helmVersionsEntityType),
endpoint: endpointDefinition
};
helmEntityCatalog.version = new StratosCatalogEntity<IFavoriteMetadata, HelmVersion, HelmVersionActionBuilders>(definition);
helmEntityCatalog.version = new StratosCatalogEntity<IFavoriteMetadata, HelmVersion, HelmVersionActionBuilders>(
definition,
{
actionBuilders: helmVersionActionBuilders
}
);
return helmEntityCatalog.version;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class MonocularChartsDataSource extends ListDataSource<MonocularChart> {
store,
action,
schema: action.entity[0],
getRowUniqueId: action.entity[0].getId,
getRowUniqueId: (row) => action.entity[0].getId(row),
paginationKey: action.paginationKey,
isLocal: true,
listConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { OrchestratedActionBuilders } from '../../../../../store/src/entity-catalog/action-orchestrator/action-orchestrator';
import { GetHelmVersions, GetMonocularCharts } from './helm.actions';
import { GetHelmVersions, GetMonocularCharts, HelmInstall } from './helm.actions';
import { HelmInstallValues } from './helm.types';

export interface HelmChartActionBuilders extends OrchestratedActionBuilders {
getMultiple: () => GetMonocularCharts
getMultiple: () => GetMonocularCharts,
// Helm install added to chart action builder and not helm release/workload to ensure action & effect are available in this module
// (others may not have loaded)
install: (values: HelmInstallValues) => HelmInstall
}

export const helmChartActionBuilders: HelmChartActionBuilders = {
getMultiple: () => new GetMonocularCharts()
getMultiple: () => new GetMonocularCharts(),
install: (values: HelmInstallValues) => new HelmInstall(values)
}

export interface HelmVersionActionBuilders extends OrchestratedActionBuilders {
Expand Down
14 changes: 14 additions & 0 deletions custom-src/frontend/app/custom/helm/store/helm.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
monocularChartsEntityType,
} from '../helm-entity-factory';
import { PaginatedAction } from './../../../../../store/src/types/pagination.types';
import { HelmInstallValues } from './helm.types';

export const GET_MONOCULAR_CHARTS = '[Monocular] Get Charts';
export const GET_MONOCULAR_CHARTS_SUCCESS = '[Monocular] Get Charts Success';
Expand All @@ -15,6 +16,10 @@ export const GET_HELM_VERSIONS = '[Helm] Get Versions';
export const GET_HELM_VERSIONS_SUCCESS = '[Helm] Get Versions Success';
export const GET_HELM_VERSIONS_FAILURE = '[Helm] Get Versions Failure';

export const HELM_INSTALL = '[Helm] Install';
export const HELM_INSTALL_SUCCESS = '[Helm] Install Success';
export const HELM_INSTALL_FAILURE = '[Helm] Install Failure';

export interface MonocularPaginationAction extends PaginatedAction, EntityRequestAction { }

export class GetMonocularCharts implements MonocularPaginationAction {
Expand All @@ -38,6 +43,15 @@ export class GetMonocularCharts implements MonocularPaginationAction {
flattenPagination = true;
}

export class HelmInstall implements EntityRequestAction {
type = HELM_INSTALL;
endpointType = HELM_ENDPOINT_TYPE;
entityType = monocularChartsEntityType;
guid: string;
constructor(public values: HelmInstallValues) {
this.guid = '<New Release>' + this.values.releaseName;
}
}

export class GetHelmVersions implements MonocularPaginationAction {
constructor() {
Expand Down
45 changes: 42 additions & 3 deletions custom-src/frontend/app/custom/helm/store/helm.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ import {
import { Observable } from 'rxjs';
import { catchError, flatMap, mergeMap } from 'rxjs/operators';

import { ClearPaginationOfType } from '../../../../../store/src/actions/pagination.actions';
import { ApiRequestTypes } from '../../../../../store/src/reducers/api-request-reducer/request-helpers';
import { environment } from '../../../environments/environment';
import { isJetstreamError } from '../../../jetstream.helpers';
import { helmEntityCatalog } from '../helm-entity-catalog';
import { getHelmVersionId, getMonocularChartId, HELM_ENDPOINT_TYPE } from '../helm-entity-factory';
import { GET_HELM_VERSIONS, GET_MONOCULAR_CHARTS, GetHelmVersions, GetMonocularCharts } from './helm.actions';
import {
GET_HELM_VERSIONS,
GET_MONOCULAR_CHARTS,
GetHelmVersions,
GetMonocularCharts,
HELM_INSTALL,
HelmInstall,
} from './helm.actions';
import { HelmVersion } from './helm.types';

@Injectable()
Expand Down Expand Up @@ -118,7 +128,36 @@ export class HelmEffects {
})
);


@Effect()
helmInstall$ = this.actions$.pipe(
ofType<HelmInstall>(HELM_INSTALL),
flatMap(action => {
const requestType: ApiRequestTypes = 'create';
const url = '/pp/v1/helm/install';
this.store.dispatch(new StartRequestAction(action, requestType));
return this.httpClient.post(url, action.values).pipe(
mergeMap(() => {
return [
new ClearPaginationOfType(action),
new WrapperRequestActionSuccess(null, action)
];
}),
catchError(error => {
const { status, message } = HelmEffects.createHelmError(error);
const errorMessage = `Failed to install helm chart: ${message}`;
return [
new WrapperRequestActionFailed(errorMessage, action, requestType, {
endpointIds: [action.values.endpoint],
url: error.url || url,
eventCode: status,
message: errorMessage,
error
})
];
})
);
})
);

private makeRequest(
action: EntityRequestAction,
Expand Down Expand Up @@ -204,7 +243,7 @@ export class HelmEffects {
this.syncing = syncing;
if (remaining !== existing) {
// Dispatch action to refresh charts
this.store.dispatch(new GetMonocularCharts());
helmEntityCatalog.chart.api.getMultiple();
}
if (remaining > 0) {
this.scheduleSyncStatusCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export class KubernetesEndpointService {
}

public refreshKubernetesDashboardStatus() {
// this.store.dispatch(new GetKubernetesDashboard(this.kubeGuid)); // TODO: RC store.dispatch
kubeEntityCatalog.dashboard.api.get(this.kubeGuid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { SafeResourceUrl } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { combineLatest, interval, Observable, Subscription } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { first, map, startWith } from 'rxjs/operators';

import { AppState } from '../../../../../../store/src/app-state';
import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog';
import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory';
import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper';
import { PaginatedAction } from '../../../../../../store/src/types/pagination.types';
import { getCurrentPageRequestInfo } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.types';
import { PaginatedAction, PaginationEntityState } from '../../../../../../store/src/types/pagination.types';
import { safeUnsubscribe } from '../../../../core/utils.service';
import {
IChartThresholds,
Expand Down Expand Up @@ -113,14 +113,15 @@ export class KubernetesSummaryTabComponent implements OnInit, OnDestroy {
ngOnInit() {
const guid = this.kubeEndpointService.baseKube.guid;



const podCountAction = kubeEntityCatalog.pod.actions.getMultiple(guid);
const nodeCountAction = kubeEntityCatalog.node.actions.getMultiple(guid);
const namespacesCountAction = kubeEntityCatalog.namespace.actions.getMultiple(guid);
const pods$ = this.getPaginationObservable(podCountAction);
const nodes$ = this.getPaginationObservable(nodeCountAction);
const namespaces$ = this.getPaginationObservable(namespacesCountAction);
const podsObs = kubeEntityCatalog.pod.store.getPaginationService(guid);
const pods$ = podsObs.entities$;
this.poll(kubeEntityCatalog.pod.actions.getMultiple(guid), podsObs.pagination$)
const nodesObs = kubeEntityCatalog.node.store.getPaginationService(guid);
const nodes$ = nodesObs.entities$;
this.poll(kubeEntityCatalog.node.actions.getMultiple(guid), nodesObs.pagination$)
const namespacesObs = kubeEntityCatalog.namespace.store.getPaginationService(guid);
const namespaces$ = namespacesObs.entities$;
this.poll(kubeEntityCatalog.namespace.actions.getMultiple(guid), namespacesObs.pagination$)

this.podCount$ = this.kubeEndpointService.getCountObservable(pods$);
this.nodeCount$ = this.kubeEndpointService.getCountObservable(nodes$);
Expand Down Expand Up @@ -177,29 +178,22 @@ export class KubernetesSummaryTabComponent implements OnInit, OnDestroy {
);
}

private getPaginationObservable(action: PaginatedAction) {
const paginationMonitor = this.paginationMonitorFactory.create(
action.paginationKey,
action,
true
);

// TODO: RC this could easily get backed up, would entityService .poll be better??
this.ngZone.runOutsideAngular(() => {
private poll(action: PaginatedAction, pagination$: Observable<PaginationEntityState>) {
this.ngZone.runOutsideAngular(() =>
this.polls.push(
interval(10000).subscribe(() => {
this.ngZone.run(() => {
this.store.dispatch(action);
});
this.ngZone.run(() => this.updateList(action, pagination$));
})
);
});
)
);
}

return getPaginationObservables({
store: this.store,
action,
paginationMonitor
}).entities$;
private updateList(action: PaginatedAction, pagination$: Observable<PaginationEntityState>) {
pagination$.pipe(first()).subscribe(pag => {
if (!getCurrentPageRequestInfo(pag, { busy: true, error: false, message: '' }).busy) {
this.store.dispatch(action);
}
})
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import {
OrchestratedActionBuilders,
} from '../../../../../../store/src/entity-catalog/action-orchestrator/action-orchestrator';
import { HelmInstallValues } from '../../../helm/store/helm.types';
import {
GetHelmRelease,
GetHelmReleaseGraph,
GetHelmReleaseResource,
GetHelmReleases,
HelmInstall,
} from './workloads.actions';
import { GetHelmRelease, GetHelmReleaseGraph, GetHelmReleaseResource, GetHelmReleases } from './workloads.actions';

export interface WorkloadReleaseBuilders extends OrchestratedActionBuilders {
get: (
Expand All @@ -17,15 +10,13 @@ export interface WorkloadReleaseBuilders extends OrchestratedActionBuilders {
extraArgs: { namespace: string }
) => GetHelmRelease;
getMultiple: () => GetHelmReleases;
install: (values: HelmInstallValues) => HelmInstall
}

export const workloadReleaseBuilders: WorkloadReleaseBuilders = {
get: (title: string, endpointGuid: string, { namespace }: { namespace: string }) => {
return new GetHelmRelease(endpointGuid, namespace, title);
},
getMultiple: () => new GetHelmReleases(),
install: (values: HelmInstallValues) => new HelmInstall(values)
getMultiple: () => new GetHelmReleases()
}

export interface WorkloadGraphBuilders extends OrchestratedActionBuilders {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EntityRequestAction } from 'frontend/packages/store/src/types/request.t

import { PaginatedAction } from '../../../../../../store/src/types/pagination.types';
import { MonocularPaginationAction } from '../../../helm/store/helm.actions';
import { HelmInstallValues } from '../../../helm/store/helm.types';
import {
KUBERNETES_ENDPOINT_TYPE,
kubernetesEntityFactory,
Expand Down Expand Up @@ -39,10 +38,6 @@ export const UPDATE_HELM_RELEASE = '[Helm] Update Release';
export const UPDATE_HELM_RELEASE_SUCCESS = '[Helm] Update Release Success';
export const UPDATE_HELM_RELEASE_FAILURE = '[Helm] Update Release Failure';

export const HELM_INSTALL = '[Helm] Install';
export const HELM_INSTALL_SUCCESS = '[Helm] Install Success';
export const HELM_INSTALL_FAILURE = '[Helm] Install Failure';

interface HelmReleaseSingleEntity extends EntityRequestAction {
guid: string;
}
Expand All @@ -51,16 +46,6 @@ interface HelmReleasePaginated extends PaginatedAction, EntityRequestAction {

}

export class HelmInstall implements HelmReleaseSingleEntity {
type = HELM_INSTALL;
endpointType = KUBERNETES_ENDPOINT_TYPE;
entityType = helmReleaseEntityKey;
guid: string;
constructor(public values: HelmInstallValues) {
this.guid = '<New Release>' + this.values.releaseName;
}
}

export class GetHelmReleases implements MonocularPaginationAction {
constructor() {
this.paginationKey = 'helm-releases';
Expand Down
Loading

0 comments on commit 81db83c

Please sign in to comment.