23
23
import com .google .common .base .MoreObjects ;
24
24
import com .google .common .collect .ImmutableMap ;
25
25
import com .google .protobuf .FieldMask ;
26
+ import com .google .spanner .admin .instance .v1 .AutoscalingConfig ;
26
27
import java .util .HashMap ;
27
28
import java .util .Map ;
28
29
import java .util .Objects ;
@@ -35,13 +36,16 @@ public enum InstanceField implements FieldSelector {
35
36
DISPLAY_NAME ("display_name" ),
36
37
NODE_COUNT ("node_count" ),
37
38
PROCESSING_UNITS ("processing_units" ),
39
+ AUTOSCALING_CONFIG ("autoscaling_config" ),
38
40
LABELS ("labels" );
39
41
40
42
static InstanceField [] defaultFieldsToUpdate (InstanceInfo info ) {
41
- if (info .getNodeCount () > 0 ) {
42
- return new InstanceField [] {DISPLAY_NAME , NODE_COUNT , LABELS };
43
+ if (info .getAutoscalingConfig () != null ) {
44
+ return new InstanceField [] {DISPLAY_NAME , AUTOSCALING_CONFIG , LABELS };
45
+ } else if (info .getNodeCount () > 0 ) {
46
+ return new InstanceField [] {DISPLAY_NAME , AUTOSCALING_CONFIG , NODE_COUNT , LABELS };
43
47
} else {
44
- return new InstanceField [] {DISPLAY_NAME , PROCESSING_UNITS , LABELS };
48
+ return new InstanceField [] {DISPLAY_NAME , AUTOSCALING_CONFIG , PROCESSING_UNITS , LABELS };
45
49
}
46
50
}
47
51
@@ -87,21 +91,31 @@ Builder setCreateTime(Timestamp createTime) {
87
91
}
88
92
89
93
/**
90
- * Sets the number of nodes for the instance. Exactly one of processing units or node count must
91
- * be set when creating a new instance.
94
+ * Sets the number of nodes for the instance. Exactly one of processing units, node count or
95
+ * autoscaling config must be set when creating a new instance.
92
96
*/
93
97
public abstract Builder setNodeCount (int nodeCount );
94
98
95
99
/**
96
- * Sets the number of processing units for the instance. Exactly one of processing units or node
97
- * count must be set when creating a new instance. Processing units must be between 1 and 999
98
- * (inclusive) when creating a new instance with node count = 0. Processing units from 1000 and
99
- * up must always be a multiple of 1000 (that is equal to an integer number of nodes).
100
+ * Sets the number of processing units for the instance. Exactly one of processing units, node
101
+ * count, or autoscaling config must be set when creating a new instance. Processing units must
102
+ * be between 1 and 999 (inclusive) when creating a new instance with node count = 0. Processing
103
+ * units from 1000 and up must always be a multiple of 1000 (that is equal to an integer number
104
+ * of nodes).
100
105
*/
101
106
public Builder setProcessingUnits (int processingUnits ) {
102
107
throw new UnsupportedOperationException ("Unimplemented" );
103
108
}
104
109
110
+ /**
111
+ * Sets the autoscaling config for the instance, which will enable the autoscaling for this
112
+ * instance. Exactly one of processing units, node count, or autoscaling config must be set when
113
+ * creating a new instance.
114
+ */
115
+ public Builder setAutoscalingConfig (AutoscalingConfig autoscalingConfig ) {
116
+ throw new UnsupportedOperationException ("Unimplemented" );
117
+ }
118
+
105
119
public abstract Builder setState (State state );
106
120
107
121
public abstract Builder addLabel (String key , String value );
@@ -117,6 +131,7 @@ static class BuilderImpl extends Builder {
117
131
private String displayName ;
118
132
private int nodeCount ;
119
133
private int processingUnits ;
134
+ private AutoscalingConfig autoscalingConfig ;
120
135
private State state ;
121
136
private Map <String , String > labels ;
122
137
private Timestamp updateTime ;
@@ -133,6 +148,7 @@ static class BuilderImpl extends Builder {
133
148
this .displayName = instance .displayName ;
134
149
this .nodeCount = instance .nodeCount ;
135
150
this .processingUnits = instance .processingUnits ;
151
+ this .autoscalingConfig = instance .autoscalingConfig ;
136
152
this .state = instance .state ;
137
153
this .labels = new HashMap <>(instance .labels );
138
154
this .updateTime = instance .updateTime ;
@@ -175,6 +191,12 @@ public BuilderImpl setProcessingUnits(int processingUnits) {
175
191
return this ;
176
192
}
177
193
194
+ @ Override
195
+ public BuilderImpl setAutoscalingConfig (AutoscalingConfig autoscalingConfig ) {
196
+ this .autoscalingConfig = autoscalingConfig ;
197
+ return this ;
198
+ }
199
+
178
200
@ Override
179
201
public BuilderImpl setState (State state ) {
180
202
this .state = state ;
@@ -204,6 +226,7 @@ public InstanceInfo build() {
204
226
private final String displayName ;
205
227
private final int nodeCount ;
206
228
private final int processingUnits ;
229
+ private final AutoscalingConfig autoscalingConfig ;
207
230
private final State state ;
208
231
private final ImmutableMap <String , String > labels ;
209
232
private final Timestamp updateTime ;
@@ -215,6 +238,7 @@ public InstanceInfo build() {
215
238
this .displayName = builder .displayName ;
216
239
this .nodeCount = builder .nodeCount ;
217
240
this .processingUnits = builder .processingUnits ;
241
+ this .autoscalingConfig = builder .autoscalingConfig ;
218
242
this .state = builder .state ;
219
243
this .labels = ImmutableMap .copyOf (builder .labels );
220
244
this .updateTime = builder .updateTime ;
@@ -254,6 +278,11 @@ public int getProcessingUnits() {
254
278
return processingUnits ;
255
279
}
256
280
281
+ /** Returns the autoscaling config of the instance. */
282
+ public AutoscalingConfig getAutoscalingConfig () {
283
+ return autoscalingConfig ;
284
+ }
285
+
257
286
/** Returns the current state of the instance. */
258
287
public State getState () {
259
288
return state ;
@@ -276,6 +305,7 @@ public String toString() {
276
305
.add ("displayName" , displayName )
277
306
.add ("nodeCount" , nodeCount )
278
307
.add ("processingUnits" , processingUnits )
308
+ .add ("autoscaling_config" , autoscalingConfig )
279
309
.add ("state" , state )
280
310
.add ("labels" , labels )
281
311
.add ("createTime" , createTime )
@@ -297,6 +327,7 @@ public boolean equals(Object o) {
297
327
&& Objects .equals (displayName , that .displayName )
298
328
&& nodeCount == that .nodeCount
299
329
&& processingUnits == that .processingUnits
330
+ && Objects .equals (autoscalingConfig , that .autoscalingConfig )
300
331
&& state == that .state
301
332
&& Objects .equals (labels , that .labels )
302
333
&& Objects .equals (updateTime , that .updateTime )
@@ -311,6 +342,7 @@ public int hashCode() {
311
342
displayName ,
312
343
nodeCount ,
313
344
processingUnits ,
345
+ autoscalingConfig ,
314
346
state ,
315
347
labels ,
316
348
updateTime ,
@@ -330,6 +362,9 @@ com.google.spanner.admin.instance.v1.Instance toProto() {
330
362
if (getInstanceConfigId () != null ) {
331
363
builder .setConfig (getInstanceConfigId ().getName ());
332
364
}
365
+ if (getAutoscalingConfig () != null ) {
366
+ builder .setAutoscalingConfig (getAutoscalingConfig ());
367
+ }
333
368
return builder .build ();
334
369
}
335
370
0 commit comments