Skip to content

Commit

Permalink
refactor(*): remove unused local storage caches (#6665)
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Mar 12, 2019
1 parent 49affe7 commit e2b4d8e
Show file tree
Hide file tree
Showing 49 changed files with 101 additions and 1,123 deletions.
4 changes: 0 additions & 4 deletions app/scripts/modules/amazon/src/aws.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,13 @@ module(AMAZON_MODULE, [
AWS_SECURITY_GROUP_MODULE,
SUBNET_RENDERER,
VPC_MODULE,
require('./cache/cacheConfigurer.service').name,
require('./search/searchResultFormatter').name,
]).config(() => {
CloudProviderRegistry.registerProvider('aws', {
name: 'Amazon',
logo: {
path: require('./logo/amazon.logo.svg'),
},
cache: {
configurer: 'awsCacheConfigurer',
},
image: {
reader: AwsImageReader,
},
Expand Down
35 changes: 0 additions & 35 deletions app/scripts/modules/amazon/src/cache/cacheConfigurer.service.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,41 +86,6 @@ describe('Service: awsServerGroupConfiguration', function() {
);

describe('configureCommand', function() {
it('attempts to reload load balancers if some are not found on initialization, but does not set dirty flag', function() {
spyOn(AccountService, 'getCredentialsKeyedByAccount').and.returnValue($q.when([]));
spyOn(securityGroupReader, 'getAllSecurityGroups').and.returnValue($q.when([]));
const listLoadBalancersSpy = spyOn(loadBalancerReader, 'listLoadBalancers').and.returnValue(
$q.when(this.allLoadBalancers),
);
spyOn(SubnetReader, 'listSubnets').and.returnValue($q.when([]));
spyOn(AccountService, 'getPreferredZonesByAccount').and.returnValue($q.when([]));
spyOn(KeyPairsReader, 'listKeyPairs').and.returnValue($q.when([]));
spyOn(awsInstanceTypeService, 'getAllTypesByRegion').and.returnValue($q.when([]));
const refreshCacheSpy = spyOn(cacheInitializer, 'refreshCache').and.returnValue($q.when(null));

const command = {
credentials: 'test',
region: 'us-east-1',
loadBalancers: ['elb-1', 'elb-3'],
vpcId: null,
viewState: {
disableImageSelection: true,
dirty: {},
},
} as any;

service.configureCommand(
applicationModelBuilder.createApplicationForTests('name', { key: 'loadBalancers', lazy: true }),
command,
);
$scope.$digest();

expect(cacheInitializer.refreshCache).toHaveBeenCalledWith('loadBalancers');
expect(refreshCacheSpy.calls.count()).toBe(1);
expect(listLoadBalancersSpy.calls.count()).toBe(1);
expect(command.dirty).toBeUndefined();
});

it('attempts to reload firewalls if some are not found on initialization, but does not set dirty flag', function() {
spyOn(AccountService, 'getCredentialsKeyedByAccount').and.returnValue($q.when([]));
const getAllSecurityGroupsSpy = spyOn(securityGroupReader, 'getAllSecurityGroups').and.returnValue($q.when([]));
Expand Down Expand Up @@ -154,44 +119,6 @@ describe('Service: awsServerGroupConfiguration', function() {
expect(getAllSecurityGroupsSpy.calls.count()).toBe(2);
expect(command.dirty).toBeUndefined();
});

it('attempts to reload instance types if already selected on initialization, but does not set dirty flag', function() {
spyOn(AccountService, 'getCredentialsKeyedByAccount').and.returnValue($q.when([]));
spyOn(securityGroupReader, 'getAllSecurityGroups').and.returnValue($q.when([]));
spyOn(loadBalancerReader, 'listLoadBalancers').and.returnValue($q.when([]));
spyOn(SubnetReader, 'listSubnets').and.returnValue($q.when([]));
spyOn(AccountService, 'getPreferredZonesByAccount').and.returnValue($q.when([]));
spyOn(KeyPairsReader, 'listKeyPairs').and.returnValue($q.when([]));
const getAllTypesByRegionSpy = spyOn(awsInstanceTypeService, 'getAllTypesByRegion').and.returnValue(
$q.when({
'us-east-1': [{ name: 'm4.tiny' }],
}),
);
const refreshCacheSpy = spyOn(cacheInitializer, 'refreshCache').and.returnValue($q.when(null));

const command = {
credentials: 'test',
region: 'us-east-1',
securityGroups: [],
instanceType: 'm4.tiny',
vpcId: null,
viewState: {
disableImageSelection: true,
dirty: {},
},
} as any;

service.configureCommand(
applicationModelBuilder.createApplicationForTests('name', { key: 'loadBalancers', lazy: true }),
command,
);
$scope.$digest();

expect(cacheInitializer.refreshCache).toHaveBeenCalledWith('instanceTypes');
expect(refreshCacheSpy.calls.count()).toBe(1);
expect(getAllTypesByRegionSpy.calls.count()).toBe(2);
expect(command.dirty).toBeUndefined();
});
});

describe('configureLoadBalancerOptions', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ export class AwsServerGroupConfigurationService {
terminationPolicies: $q.when(clone(this.terminationPolicies)),
})
.then((backingData: Partial<IAmazonServerGroupCommandBackingData>) => {
let loadBalancerReloader = $q.when();
let securityGroupReloader = $q.when();
let instanceTypeReloader = $q.when();
backingData.accounts = keys(backingData.credentialsKeyedByAccount);
backingData.filtered = {} as IAmazonServerGroupCommandBackingDataFiltered;
backingData.scalingProcesses = AutoScalingProcessService.listProcesses();
Expand All @@ -227,33 +225,14 @@ export class AwsServerGroupConfigurationService {
this.configureInstanceTypes(cmd);
}

if (cmd.loadBalancers && cmd.loadBalancers.length) {
// verify all load balancers are accounted for; otherwise, try refreshing load balancers cache
const loadBalancerNames = this.getLoadBalancerNames(cmd);
if (intersection(loadBalancerNames, cmd.loadBalancers).length < cmd.loadBalancers.length) {
loadBalancerReloader = this.refreshLoadBalancers(cmd, true);
}
}

if (cmd.targetGroups && cmd.targetGroups.length) {
// verify all target groups are accounted for; otherwise, try refreshing load balancers cache
const targetGroupNames = this.getTargetGroupNames(cmd);
if (intersection(targetGroupNames, cmd.targetGroups).length < cmd.targetGroups.length) {
loadBalancerReloader = this.refreshLoadBalancers(cmd, true);
}
}

if (cmd.securityGroups && cmd.securityGroups.length) {
const regionalSecurityGroupIds = map(this.getRegionalSecurityGroups(cmd), 'id');
if (intersection(cmd.securityGroups, regionalSecurityGroupIds).length < cmd.securityGroups.length) {
securityGroupReloader = this.refreshSecurityGroups(cmd, true);
}
}
if (cmd.instanceType) {
instanceTypeReloader = this.refreshInstanceTypes(cmd, true);
}

return $q.all([loadBalancerReloader, securityGroupReloader, instanceTypeReloader]).then(() => {
return securityGroupReloader.then(() => {
this.applyOverrides('afterConfiguration', cmd);
this.attachEventHandlers(cmd);
});
Expand Down Expand Up @@ -438,20 +417,6 @@ export class AwsServerGroupConfigurationService {
});
}

public refreshInstanceTypes(
command: IAmazonServerGroupCommand,
skipCommandReconfiguration?: boolean,
): IPromise<void> {
return this.cacheInitializer.refreshCache('instanceTypes').then(() => {
return this.awsInstanceTypeService.getAllTypesByRegion().then((instanceTypes: string[]) => {
command.backingData.instanceTypes = instanceTypes;
if (!skipCommandReconfiguration) {
this.configureInstanceTypes(command);
}
});
});
}

private getLoadBalancerMap(command: IAmazonServerGroupCommand): IAmazonLoadBalancerSourceData[] {
if (command.backingData.loadBalancers) {
return chain(command.backingData.loadBalancers)
Expand Down Expand Up @@ -540,13 +505,11 @@ export class AwsServerGroupConfigurationService {
}

public refreshLoadBalancers(command: IAmazonServerGroupCommand, skipCommandReconfiguration?: boolean) {
return this.cacheInitializer.refreshCache('loadBalancers').then(() => {
return this.loadBalancerReader.listLoadBalancers('aws').then(loadBalancers => {
command.backingData.loadBalancers = loadBalancers;
if (!skipCommandReconfiguration) {
this.configureLoadBalancerOptions(command);
}
});
return this.loadBalancerReader.listLoadBalancers('aws').then(loadBalancers => {
command.backingData.loadBalancers = loadBalancers;
if (!skipCommandReconfiguration) {
this.configureLoadBalancerOptions(command);
}
});
}

Expand Down
5 changes: 0 additions & 5 deletions app/scripts/modules/appengine/src/appengine.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { module } from 'angular';

import { CloudProviderRegistry, DeploymentStrategyRegistry } from '@spinnaker/core';

import { APPENGINE_CACHE_CONFIGURER } from './cache/cacheConfigurer.service';
import { APPENGINE_COMPONENT_URL_DETAILS } from './common/componentUrlDetails.component';
import { APPENGINE_CONDITIONAL_DESCRIPTION_LIST_ITEM } from './common/conditionalDescriptionListItem.component';
import { APPENGINE_LOAD_BALANCER_CREATE_MESSAGE } from './common/loadBalancerMessage.component';
Expand All @@ -28,7 +27,6 @@ templates.keys().forEach(function(key) {
export const APPENGINE_MODULE = 'spinnaker.appengine';

module(APPENGINE_MODULE, [
APPENGINE_CACHE_CONFIGURER,
APPENGINE_CLONE_SERVER_GROUP_CTRL,
APPENGINE_COMPONENT_URL_DETAILS,
APPENGINE_CONDITIONAL_DESCRIPTION_LIST_ITEM,
Expand All @@ -44,9 +42,6 @@ module(APPENGINE_MODULE, [
]).config(() => {
CloudProviderRegistry.registerProvider('appengine', {
name: 'App Engine',
cache: {
configurer: 'appengineCacheConfigurer',
},
instance: {
detailsTemplateUrl: require('./instance/details/details.html'),
detailsController: 'appengineInstanceDetailsCtrl',
Expand Down
27 changes: 0 additions & 27 deletions app/scripts/modules/appengine/src/cache/cacheConfigurer.service.ts

This file was deleted.

4 changes: 0 additions & 4 deletions app/scripts/modules/azure/azure.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = angular
require('./securityGroup/securityGroup.transformer').name,
require('./securityGroup/securityGroup.reader').name,
require('./image/image.reader').name,
require('./cache/cacheConfigurer.service').name,
require('./validation/applicationName.validator').name,
])
.config(function() {
Expand All @@ -42,9 +41,6 @@ module.exports = angular
logo: {
path: require('./logo_azure.png'),
},
cache: {
configurer: 'azureCacheConfigurer',
},
image: {
reader: 'azureImageReader',
},
Expand Down
35 changes: 0 additions & 35 deletions app/scripts/modules/azure/cache/cacheConfigurer.service.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
const angular = require('angular');
import _ from 'lodash';

import { InfrastructureCaches } from '@spinnaker/core';

module.exports = angular.module('spinnaker.azure.instanceType.service', []).factory('azureInstanceTypeService', [
'$http',
'$q',
Expand Down Expand Up @@ -814,10 +812,6 @@ module.exports = angular.module('spinnaker.azure.instanceType.service', []).fact
}

var getAllTypesByRegion = function getAllTypesByRegion() {
var cached = InfrastructureCaches.get('instanceTypes').get('azure');
if (cached) {
return $q.when(cached);
}
return getCategories();
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { API, InfrastructureCaches } from '@spinnaker/core';

describe('Service: InstanceType', function() {
beforeEach(function() {
window.module(require('./azureInstanceType.service').name);
Expand Down
Loading

0 comments on commit e2b4d8e

Please sign in to comment.