1
- import CapacityCalculator from './CapacityCalculator' ;
2
1
import Global from './global' ;
3
2
const {
4
3
stats,
@@ -9,34 +8,22 @@ class ConfigurableProvisioner {
9
8
10
9
constructor ( config ) {
11
10
this . config = config ;
12
- this . capacityCalculator = new CapacityCalculator ( ) ;
13
11
}
14
12
15
13
getTableUpdate ( tableDescription , tableConsumedCapacityDescription ) {
16
14
try {
17
15
logger . debug ( 'ConfigurableProvisioner.getTableUpdate (start)' ) ;
18
16
19
- let provisionedThroughput = this . getProvisionedThroughput (
20
- tableDescription . Table . ProvisionedThroughput ,
21
- tableConsumedCapacityDescription . Table . ConsumedThroughput ,
22
- tableDescription . Table . TableName ) ;
17
+ let tableData = {
18
+ TableName : tableDescription . Table . TableName ,
19
+ ProvisionedThroughput : tableDescription . Table . ProvisionedThroughput ,
20
+ ConsumedThroughput : tableConsumedCapacityDescription . Table . ConsumedThroughput
21
+ } ;
23
22
23
+ let provisionedThroughput = this . getUpdatedProvisionedThroughput ( tableData ) ;
24
24
let gsis = tableDescription . Table . GlobalSecondaryIndexes || [ ] ;
25
25
let globalSecondaryIndexUpdates = gsis
26
- . map ( gsi => {
27
- let gsicc = tableConsumedCapacityDescription . Table . GlobalSecondaryIndexes . find ( i => i . IndexName === gsi . IndexName ) ;
28
- let provisionedThroughput = this . getProvisionedThroughput ( gsi . ProvisionedThroughput , gsicc . ConsumedThroughput , tableDescription . Table . TableName , gsicc . IndexName ) ;
29
- if ( provisionedThroughput == null ) {
30
- return null ;
31
- }
32
-
33
- return {
34
- Update : {
35
- IndexName : gsi . IndexName ,
36
- ProvisionedThroughput : provisionedThroughput
37
- }
38
- } ;
39
- } )
26
+ . map ( gsi => this . getGlobalSecondaryIndexUpdate ( tableDescription , tableConsumedCapacityDescription , gsi ) )
40
27
. filter ( i => i != null ) ;
41
28
42
29
if ( ! provisionedThroughput && ( globalSecondaryIndexUpdates == null || globalSecondaryIndexUpdates . length === 0 ) ) {
@@ -64,71 +51,53 @@ class ConfigurableProvisioner {
64
51
}
65
52
}
66
53
67
- parseDate ( value ) {
68
- if ( typeof value === 'undefined' || value == null ) {
69
- return new Date ( - 8640000000000000 ) ;
70
- }
71
-
72
- return Date . parse ( value ) ;
73
- }
54
+ getGlobalSecondaryIndexUpdate ( tableDescription , tableConsumedCapacityDescription , gsi ) {
55
+ let gsicc = tableConsumedCapacityDescription . Table . GlobalSecondaryIndexes . find ( i => i . IndexName === gsi . IndexName ) ;
56
+ let provisionedThroughput = this . getUpdatedProvisionedThroughput ( {
57
+ TableName : tableDescription . Table . TableName ,
58
+ IndexName : gsicc . IndexName ,
59
+ ProvisionedThroughput : gsi . ProvisionedThroughput ,
60
+ ConsumedThroughput : gsicc . ConsumedThroughput
61
+ } ) ;
74
62
75
- getMax ( value ) {
76
- if ( typeof value === 'undefined' ) {
77
- return 40000 ;
63
+ if ( provisionedThroughput == null ) {
64
+ return null ;
78
65
}
79
66
80
- return value ;
67
+ return {
68
+ Update : {
69
+ IndexName : gsi . IndexName ,
70
+ ProvisionedThroughput : provisionedThroughput
71
+ }
72
+ } ;
81
73
}
82
74
83
- getMin ( value ) {
84
- if ( typeof value === 'undefined' ) {
85
- return 1 ;
75
+ getUpdatedProvisionedThroughput ( params ) {
76
+ debugger ;
77
+ let newProvisionedThroughput = {
78
+ ReadCapacityUnits : params . ProvisionedThroughput . ReadCapacityUnits ,
79
+ WriteCapacityUnits : params . ProvisionedThroughput . WriteCapacityUnits
80
+ } ;
81
+
82
+ // Adjust read capacity
83
+ if ( this . config . readCapacity . increment . isAdjustmentRequired ( params ) ) {
84
+ newProvisionedThroughput . ReadCapacityUnits = this . config . readCapacity . increment . calculateValue ( params ) ;
85
+ } else if ( this . config . readCapacity . decrement . isAdjustmentRequired ( params ) ) {
86
+ newProvisionedThroughput . ReadCapacityUnits = this . config . readCapacity . decrement . calculateValue ( params ) ;
86
87
}
87
88
88
- return value ;
89
- }
89
+ // Adjust write capacity
90
+ if ( this . config . writeCapacity . increment . isAdjustmentRequired ( params ) ) {
91
+ newProvisionedThroughput . WriteCapacityUnits = this . config . writeCapacity . increment . calculateValue ( params ) ;
92
+ } else if ( this . config . writeCapacity . decrement . isAdjustmentRequired ( params ) ) {
93
+ newProvisionedThroughput . WriteCapacityUnits = this . config . writeCapacity . decrement . calculateValue ( params ) ;
94
+ }
90
95
91
- getProvisionedThroughput ( provisionedThroughput , consumedThroughput , tableName , indexName ) {
92
- // logger.debug(JSON.stringify({tableName, indexName, provisionedThroughput, consumedThroughput}, null, 2));
93
-
94
- let ReadCapacityUnits = this . capacityCalculator . getNewCapacity (
95
- provisionedThroughput . ReadCapacityUnits ,
96
- consumedThroughput . ReadCapacityUnits ,
97
- this . config . readCapacity . increment . threshold . percent ,
98
- this . config . readCapacity . decrement . threshold . percent ,
99
- this . config . readCapacity . increment . adjustment . percent ,
100
- this . config . readCapacity . decrement . adjustment . percent ,
101
- this . getMin ( this . config . readCapacity . min ) ,
102
- this . getMax ( this . config . readCapacity . max ) ,
103
- provisionedThroughput . NumberOfDecreasesToday ,
104
- this . parseDate ( provisionedThroughput . LastIncreaseDateTime ) ,
105
- this . parseDate ( provisionedThroughput . LastDecreaseDateTime )
106
- ) ;
107
-
108
- let WriteCapacityUnits = this . capacityCalculator . getNewCapacity (
109
- provisionedThroughput . WriteCapacityUnits ,
110
- consumedThroughput . WriteCapacityUnits ,
111
- this . config . writeCapacity . increment . threshold . percent ,
112
- this . config . writeCapacity . decrement . threshold . percent ,
113
- this . config . writeCapacity . increment . adjustment . percent ,
114
- this . config . writeCapacity . decrement . adjustment . percent ,
115
- this . getMin ( this . config . writeCapacity . min ) ,
116
- this . getMax ( this . config . writeCapacity . max ) ,
117
- provisionedThroughput . NumberOfDecreasesToday ,
118
- this . parseDate ( provisionedThroughput . LastIncreaseDateTime ) ,
119
- this . parseDate ( provisionedThroughput . LastDecreaseDateTime )
120
- ) ;
121
-
122
- if ( ReadCapacityUnits === provisionedThroughput . ReadCapacityUnits
123
- && WriteCapacityUnits === provisionedThroughput . WriteCapacityUnits ) {
96
+ if ( newProvisionedThroughput . ReadCapacityUnits === params . ProvisionedThroughput . ReadCapacityUnits
97
+ && newProvisionedThroughput . WriteCapacityUnits === params . ProvisionedThroughput . WriteCapacityUnits ) {
124
98
return null ;
125
99
}
126
100
127
- let newProvisionedThroughput = {
128
- ReadCapacityUnits,
129
- WriteCapacityUnits
130
- } ;
131
-
132
101
return newProvisionedThroughput ;
133
102
}
134
103
}
0 commit comments