-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into k8s_anns_labels_secrets
- Loading branch information
Showing
119 changed files
with
2,084 additions
and
1,686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { AMAZON_MODULE } from './aws.module'; | ||
export * from './aws.settings'; | ||
|
||
export * from './domain'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
IDeferred, IHttpInterceptor, IHttpPromiseCallbackArg, IHttpProvider, IPromise, IQService, IRequestConfig, | ||
ITimeoutService, IWindowService, module | ||
} from 'angular'; | ||
import { Dictionary } from 'lodash'; | ||
import { BindAll } from 'lodash-decorators'; | ||
|
||
/** | ||
* Handles two scenarios: | ||
* 1. computer loses network connection (retries connections when network returns) | ||
* 2. requests are aborted due to a network change (retries immediately) | ||
*/ | ||
|
||
@BindAll() | ||
export class NetworkInterceptor implements IHttpInterceptor { | ||
|
||
private networkAvailable: IDeferred<void>; | ||
private retryQueue: Dictionary<number> = {}; | ||
private MAX_RETRIES = 4; | ||
|
||
constructor(private $q: IQService, | ||
private $window: IWindowService, | ||
private $timeout: ITimeoutService, | ||
private $injector: any) { | ||
'ngInject'; | ||
this.$window.addEventListener('offline', this.handleOffline); | ||
this.$window.addEventListener('online', this.handleOnline); | ||
this.resetNetworkAvailable(); | ||
} | ||
|
||
private handleOffline(): void { | ||
this.networkAvailable = this.$q.defer(); | ||
} | ||
|
||
private handleOnline(): void { | ||
this.networkAvailable.resolve(); | ||
this.resetNetworkAvailable(); | ||
} | ||
|
||
private resetNetworkAvailable(): void { | ||
this.networkAvailable = this.$q.defer(); | ||
this.networkAvailable.resolve(); | ||
} | ||
|
||
private removeFromQueue(config: IRequestConfig): void { | ||
delete this.retryQueue[config.url]; | ||
} | ||
|
||
// see http://www.couchcoder.com/angular-1-interceptors-using-typescript for more details on why we need to do this | ||
// in essence, we need to do this because "the ng1 implementation of interceptors only keeps references to the handler | ||
// functions themselves and invokes them directly without any context (stateless) which means we lose `this` inside | ||
// the handlers" | ||
public responseError = <T>(response: IHttpPromiseCallbackArg<T>): IPromise<T> => { | ||
const { config, status } = response; | ||
// status of -1 indicates the request was aborted, retry if we haven't already, with incremental backoff + jitter | ||
const retryCount = this.retryQueue[config.url] || 0; | ||
if (status === -1 && retryCount < this.MAX_RETRIES) { | ||
this.retryQueue[config.url] = retryCount + 1; | ||
return this.networkAvailable.promise.then(() => { | ||
return this.$timeout(() => { | ||
return this.$q.resolve(this.$injector.get('$http')(config)) | ||
.then((result: any) => { | ||
this.removeFromQueue(config); | ||
return result; | ||
}); | ||
}, (retryCount + 1 + Math.random()) * 1000); | ||
}); | ||
} | ||
return this.$q.reject(response).finally(() => this.removeFromQueue(config)); | ||
} | ||
} | ||
|
||
export const NETWORK_INTERCEPTOR = 'spinnaker.core.network.interceptor'; | ||
module(NETWORK_INTERCEPTOR, []) | ||
.service('networkInterceptor', NetworkInterceptor) | ||
.config(($httpProvider: IHttpProvider) => { | ||
$httpProvider.interceptors.push('networkInterceptor'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.