Skip to content

Commit

Permalink
feat(md): Types and new data source for environments (#8020)
Browse files Browse the repository at this point in the history
* feat(md): Types and new data source for environments

* feat(md): Types and new data source for environments
  • Loading branch information
alanmquach committed Mar 10, 2020
2 parents 3d74ab5 + 599eb6a commit 41c96b6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 16 deletions.
54 changes: 51 additions & 3 deletions app/scripts/modules/core/src/domain/IManagedEntity.ts
Expand Up @@ -24,12 +24,60 @@ export interface IManagedResourceSummary {
};
}

export interface IManagedApplicationSummary {
applicationPaused: boolean;
hasManagedResources: boolean;
export interface IManagedEnviromentSummary {
name: string;
resources: string[];
artifacts: Array<{
name: string;
type: string;
statuses: string[];
versions: {
current?: string;
deploying?: string;
pending: string[];
approved: string[];
previous: string[];
vetoed: string[];
};
}>;
}

export interface IManagedArtifactVersion {
version: string;
environments: Array<{
name: string;
state: string;
deployedAt?: string;
replacedAt?: string;
replacedBy?: string;
}>;
}

export interface IManagedArtifactSummary {
name: string;
type: string;
versions: IManagedArtifactVersion[];
}

export interface IManagedApplicationEnvironmentsSummary extends IManagedApplicationSummary {
environments: IManagedEnviromentSummary[];
artifacts: IManagedArtifactSummary[];
}

export interface IManagedApplicationEntities {
resources: IManagedResourceSummary[];
environments: IManagedEnviromentSummary[];
artifacts: IManagedArtifactSummary[];
}

export type IManagedApplicationSummary<T extends keyof IManagedApplicationEntities = 'resources'> = Pick<
IManagedApplicationEntities,
T
> & {
applicationPaused: boolean;
hasManagedResources: boolean;
};

export interface IManagedResource {
managedResourceSummary?: IManagedResourceSummary;
isManaged?: boolean;
Expand Down
36 changes: 24 additions & 12 deletions app/scripts/modules/core/src/managed/ManagedReader.ts
Expand Up @@ -69,22 +69,34 @@ const transformManagedResourceDiff = (diff: IManagedResourceEventHistoryResponse
}, {} as IManagedResourceDiff);

export class ManagedReader {
public static getApplicationSummary(app: string): IPromise<IManagedApplicationSummary> {
private static decorateResources(response: IManagedApplicationSummary) {
// Individual resources don't update their status when an application is paused/resumed,
// so for now let's swap to a PAUSED status and keep things simpler in downstream components.
if (response.applicationPaused) {
response.resources.forEach(resource => (resource.status = ManagedResourceStatus.PAUSED));
}

response.resources.forEach(resource => (resource.isPaused = resource.status === ManagedResourceStatus.PAUSED));

return response;
}

public static getApplicationSummary(app: string): IPromise<IManagedApplicationSummary<'resources'>> {
return API.one('managed')
.one('application', app)
.withParams({ includeDetails: true })
.withParams({ includeDetails: true, entities: 'resources' })
.get()
.then((response: IManagedApplicationSummary) => {
// Individual resources don't update their status when an application is paused/resumed,
// so for now let's swap to a PAUSED status and keep things simpler in downstream components.
if (response.applicationPaused) {
response.resources.forEach(resource => (resource.status = ManagedResourceStatus.PAUSED));
}

response.resources.forEach(resource => (resource.isPaused = resource.status === ManagedResourceStatus.PAUSED));
.then(this.decorateResources);
}

return response;
});
public static getEnvironmentsSummary(
app: string,
): IPromise<IManagedApplicationSummary<'resources' | 'artifacts' | 'environments'>> {
return API.one('managed')
.one('application', app)
.withParams({ includeDetails: true, entities: ['resources', 'artifacts', 'environments'] })
.get()
.then(this.decorateResources);
}

public static getResourceHistory(resourceId: string): IPromise<IManagedResourceEventHistory> {
Expand Down
29 changes: 28 additions & 1 deletion app/scripts/modules/core/src/managed/managed.dataSource.ts
Expand Up @@ -3,7 +3,7 @@ import { IQService, module } from 'angular';
import { noop } from 'core/utils';
import { SETTINGS } from 'core/config/settings';
import { ApplicationDataSourceRegistry } from 'core/application/service/ApplicationDataSourceRegistry';
import { Application } from 'core/application';
import { Application, DELIVERY_KEY } from 'core/application';
import { IManagedApplicationSummary } from 'core/domain';
import { ManagedReader } from './ManagedReader';
import {
Expand Down Expand Up @@ -34,6 +34,14 @@ module(MANAGED_RESOURCES_DATA_SOURCE, []).run([
application.securityGroups.ready().then(() => addManagedResourceMetadataToSecurityGroups(application), noop);
};

const loadEnvironments = (application: Application) => {
return ManagedReader.getEnvironmentsSummary(application.name);
};

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

ApplicationDataSourceRegistry.registerDataSource({
key: 'managedResources',
visible: false,
Expand All @@ -42,5 +50,24 @@ module(MANAGED_RESOURCES_DATA_SOURCE, []).run([
afterLoad: addManagedMetadataToResources,
defaultData: { applicationPaused: false, hasManagedResources: false, resources: [] },
});

ApplicationDataSourceRegistry.registerDataSource({
key: 'environments',
sref: '.environments',
category: DELIVERY_KEY,
optional: true,
optIn: true,
hidden: true,
icon: 'fa fa-fw fa-xs fa-code-branch',
loader: loadEnvironments,
onLoad: addEnvironments,
defaultData: {
applicationPaused: false,
hasManagedResources: false,
environments: [],
artifacts: [],
resources: [],
},
});
},
]);

0 comments on commit 41c96b6

Please sign in to comment.