Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(moniker): aws server group clone stage uses moniker instead of naming service based on frigga #4166

Merged
merged 3 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const angular = require('angular');
import _ from 'lodash';

import { ACCOUNT_SERVICE, NAMING_SERVICE, StageConstants } from '@spinnaker/core';
import { ACCOUNT_SERVICE, LIST_EXTRACTOR_SERVICE, StageConstants } from '@spinnaker/core';

module.exports = angular.module('spinnaker.amazon.pipeline.stage.cloneServerGroupStage', [
ACCOUNT_SERVICE,
NAMING_SERVICE,
LIST_EXTRACTOR_SERVICE,
require('./cloneServerGroupExecutionDetails.controller.js').name,
])
.config(function(pipelineConfigProvider) {
Expand All @@ -25,7 +25,7 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.cloneServerGrou
{ type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account'}
],
});
}).controller('awsCloneServerGroupStageCtrl', function($scope, accountService, namingService) {
}).controller('awsCloneServerGroupStageCtrl', function($scope, accountService, appListExtractorService) {

let stage = $scope.stage;

Expand Down Expand Up @@ -60,9 +60,9 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.cloneServerGrou

this.targetClusterUpdated = () => {
if (stage.targetCluster) {
let clusterName = namingService.parseServerGroupName(stage.targetCluster);
stage.stack = clusterName.stack;
stage.freeFormDetails = clusterName.freeFormDetails;
let moniker = _.first(appListExtractorService.getMonikers([$scope.application]));
stage.stack = moniker.stack;
stage.freeFormDetails = moniker.detail;
} else {
stage.stack = '';
stage.freeFormDetails = '';
Expand Down Expand Up @@ -118,4 +118,3 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.cloneServerGrou
}
};
});

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IInstance, IServerGroup } from 'core/domain';
import { Application } from '../application.model';
import { APPLICATION_MODEL_BUILDER, ApplicationModelBuilder } from '../applicationModel.builder';
import { AppListExtractor, LIST_EXTRACTOR_SERVICE } from './listExtractor.service';
import { IMoniker } from 'core/naming/IMoniker';

describe('appListExtractorService', function () {

Expand Down Expand Up @@ -34,6 +35,38 @@ describe('appListExtractorService', function () {
})
);

describe('Get Monikers from a list of applications', function () {
it('should get a empty list for one application w/ no monikers', function () {
const application: Application = buildApplication([ {stack: 'prod'}, {stack: 'test'} ]);
const result = service.getMonikers([application]);
expect(result.length).toEqual(0);
expect(result).toEqual([]);
});

it('should return an list of a single moniker for one application with a moniker', function () {
let moniker: IMoniker = {
cluster: 'test-cluster',
application: 'test-application'
};
const application: Application = buildApplication([ {moniker: moniker} ]);
const result = service.getMonikers([application]);
expect(result.length).toEqual(1);
expect(result).toEqual([moniker]);
});

it('should return a single moniker for two applications but only one has a moniker', function () {
let moniker: IMoniker = {
cluster: 'test-cluster',
application: 'test-application'
};
const applicationA: Application = buildApplication([ {moniker: moniker} ]);
const applicationB: Application = buildApplication();
const result = service.getMonikers([applicationA, applicationB]);
expect(result.length).toEqual(1);
expect(result).toEqual([moniker]);
})
});

describe('Get Regions from a list of applications', function () {

it('should get a empty list for one application w/ no clusters', function () {
Expand Down Expand Up @@ -375,5 +408,3 @@ describe('appListExtractorService', function () {
});
});
});


Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { module } from 'angular';
import { compact, flatten, uniq } from 'lodash';
import { IInstance, IServerGroup } from 'core/domain';
import { Application } from '../application.model';
import { IMoniker } from 'core/naming/IMoniker';

export interface IServerGroupFilter {
(s: IServerGroup): boolean;
Expand All @@ -15,6 +16,12 @@ const defaultFilter = () => true;

export class AppListExtractor {

public getMonikers(applications: Application[]): IMoniker[] {
const allMonikers: IMoniker[][] = applications.map(a => a.getDataSource('serverGroups').data
.map((serverGroup: IServerGroup) => serverGroup.moniker));
return compact(flatten(allMonikers));
}

public getRegions(applications: Application[], filter: IServerGroupFilter = defaultFilter): string[] {
const allRegions: string[][] = applications.map(a => a.getDataSource('serverGroups').data
.filter(filter)
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/domain/IServerGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IExecution } from './IExecution';
import { IInstance } from './IInstance';
import { IInstanceCounts } from './IInstanceCounts';
import { ITask } from './ITask';
import { IMoniker } from 'core/naming/IMoniker';

// remnant from legacy code
export interface IAsg {
Expand Down Expand Up @@ -30,6 +31,7 @@ export interface IServerGroup {
launchConfig?: any;
loadBalancers?: string[];
name: string;
moniker?: IMoniker;
provider?: string;
providerMetadata?: any;
region: string;
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/modules/core/src/naming/IMoniker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export interface IMoniker {
application: string;
cluster: string;
detail?: string;
stack?: string;
sequence?: number;
}