Skip to content

Commit

Permalink
feat(managed): add 'managedResources' data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Munson authored and erikmunson committed Oct 30, 2019
1 parent 4ed015a commit efcceb3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/scripts/modules/core/src/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import { INSIGHT_MODULE } from './insight/insight.module';
import { INTERCEPTOR_MODULE } from './interceptor/interceptor.module';
import { LOAD_BALANCER_MODULE } from './loadBalancer/loadBalancer.module';
import { MANAGED_RESOURCE_CONFIG } from './application/config/managedResources/ManagedResourceConfig';
import { MANAGED_RESOURCES_DATA_SOURCE } from './managed';
import { FUNCTION_MODULE } from './function/function.module';

import { NETWORK_INTERCEPTOR } from './api/network.interceptor';

import { PAGE_TITLE_MODULE } from './pageTitle/pageTitle.module';
Expand Down Expand Up @@ -116,6 +118,7 @@ module(CORE_MODULE, [
LOAD_BALANCER_MODULE,
FUNCTION_MODULE,
MANAGED_RESOURCE_CONFIG,
MANAGED_RESOURCES_DATA_SOURCE,
require('./modal/modal.module').name,

NETWORK_INTERCEPTOR,
Expand Down
22 changes: 22 additions & 0 deletions app/scripts/modules/core/src/managed/ManagedReader.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import { IPromise } from 'angular';

import { API } from 'core/api';
import { IMoniker } from 'core/naming';

export enum ManagedResourceStatus {
ACTUATING = 'ACTUATING',
DIFF = 'DIFF',
ERROR = 'ERROR',
HAPPY = 'HAPPY',
UNHAPPY = 'UNHAPPY',
}

export interface IManagedResourceSummary {
id: string;
kind: string;
status: ManagedResourceStatus;
moniker: IMoniker;
locations: {
accountName: string;
regions: string[];
};
}

export interface IManagedApplicationSummary {
hasManagedResources: boolean;
resources: IManagedResourceSummary[];
}

export class ManagedReader {
public static getApplicationSummary(app: string): IPromise<IManagedApplicationSummary> {
return API.one('managed')
.one('application', app)
.withParams({ includeDetails: true })
.get();
}

Expand Down
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/managed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './ManagedReader';
export * from './ManagedWriter';
export * from './ManagedResourceDetailsIndicator';
export * from './managedResourceDetailsIndicator.component';
export * from './managed.dataSource';
31 changes: 31 additions & 0 deletions app/scripts/modules/core/src/managed/managed.dataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { module, IQService } from 'angular';

import { SETTINGS } from 'core/config/settings';
import { ApplicationDataSourceRegistry } from 'core/application/service/ApplicationDataSourceRegistry';
import { Application } from 'core/application';
import { ManagedReader, IManagedApplicationSummary } from './ManagedReader';

export const MANAGED_RESOURCES_DATA_SOURCE = 'spinnaker.core.managed.dataSource';
module(MANAGED_RESOURCES_DATA_SOURCE, []).run([
'$q',
($q: IQService) => {
if (!SETTINGS.feature.managedResources) {
return;
}
const loadManagedResources = (application: Application) => {
return ManagedReader.getApplicationSummary(application.name);
};

const addManagedResources = (_application: Application, data: IManagedApplicationSummary) => {
return $q.when(data);
};

ApplicationDataSourceRegistry.registerDataSource({
key: 'managedResources',
visible: false,
loader: loadManagedResources,
onLoad: addManagedResources,
defaultData: { hasManagedResources: false, resources: [] },
});
},
]);

0 comments on commit efcceb3

Please sign in to comment.