1
1
package software .amazon .rds .dbinstance ;
2
2
3
- import java .time .Instant ;
4
- import java .util .Collection ;
5
- import java .util .Collections ;
6
-
7
- import org .apache .commons .lang3 .BooleanUtils ;
8
-
9
3
import com .amazonaws .util .StringUtils ;
4
+ import org .apache .commons .lang3 .BooleanUtils ;
10
5
import software .amazon .awssdk .services .ec2 .Ec2Client ;
11
6
import software .amazon .awssdk .services .rds .RdsClient ;
12
7
import software .amazon .awssdk .services .rds .model .DBInstance ;
13
- import software .amazon .awssdk .services .rds .model .DBSnapshot ;
14
8
import software .amazon .awssdk .services .rds .model .SourceType ;
15
9
import software .amazon .awssdk .utils .ImmutableMap ;
16
10
import software .amazon .cloudformation .exceptions .CfnInvalidRequestException ;
17
11
import software .amazon .cloudformation .proxy .AmazonWebServicesClientProxy ;
18
12
import software .amazon .cloudformation .proxy .ProgressEvent ;
19
13
import software .amazon .cloudformation .proxy .ProxyClient ;
20
14
import software .amazon .cloudformation .proxy .ResourceHandlerRequest ;
21
- import software .amazon .rds .common .handler .Commons ;
22
- import software .amazon .rds .common .handler .Events ;
23
- import software .amazon .rds .common .handler .HandlerConfig ;
24
- import software .amazon .rds .common .handler .HandlerMethod ;
25
- import software .amazon .rds .common .handler .Tagging ;
15
+ import software .amazon .rds .common .handler .*;
26
16
import software .amazon .rds .common .logging .LoggingProxyClient ;
27
17
import software .amazon .rds .common .request .RequestValidationException ;
28
18
import software .amazon .rds .common .request .ValidatedRequest ;
36
26
import software .amazon .rds .dbinstance .util .ResourceModelHelper ;
37
27
import software .amazon .rds .dbinstance .validators .OracleCustomSystemId ;
38
28
29
+ import java .time .Instant ;
30
+ import java .util .Collection ;
31
+ import java .util .Collections ;
32
+
39
33
public class CreateHandler extends BaseHandlerStd {
40
34
41
35
private static final IdentifierFactory instanceIdentifierFactory = new IdentifierFactory (
@@ -98,6 +92,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
98
92
proxy , rdsProxyClient , allTags , requestLogger , config , getApiVersionDispatcher ()
99
93
);
100
94
95
+ final DBInstanceFactory dbInstanceFactory = factoryFactory .createFactory (model );
101
96
return ProgressEvent .progress (model , callbackContext )
102
97
.then (progress -> {
103
98
if (StringUtils .isNullOrEmpty (progress .getResourceModel ().getEngine ())) {
@@ -109,21 +104,12 @@ proxy, rdsProxyClient, allTags, requestLogger, config, getApiVersionDispatcher()
109
104
}
110
105
return progress ;
111
106
})
112
- .then (progress -> Commons .execOnce (progress , () -> {
113
- final DBInstanceFactory dbInstanceFactory = factoryFactory .createFactory (progress );
114
-
115
- if (ResourceModelHelper .isRestoreToPointInTime (progress .getResourceModel ())) {
116
- // restoreDBInstanceToPointInTime is not a versioned call.
117
- return safeAddTags (this ::restoreDbInstanceToPointInTimeRequest )
118
- .invoke (proxy , rdsProxyClient .defaultClient (), progress , allTags );
119
- } else if (ResourceModelHelper .isReadReplica (progress .getResourceModel ())) {
120
- // createDBInstanceReadReplica is not a versioned call.
121
- return safeAddTags (this ::createDbInstanceReadReplica )
122
- .invoke (proxy , rdsProxyClient .defaultClient (), progress , allTags );
123
- }
124
- // FIXME Currently only handling the fresh instance & snapshot. TODO Handle above cases in factory.
125
- return dbInstanceFactory .create (progress );
126
- }, CallbackContext ::isCreated , CallbackContext ::setCreated ))
107
+ .then (progress -> Commons .execOnce (
108
+ progress ,
109
+ () -> dbInstanceFactory .create (progress ),
110
+ CallbackContext ::isCreated ,
111
+ CallbackContext ::setCreated
112
+ ))
127
113
.then (progress -> Commons .execOnce (progress , () -> {
128
114
final Tagging .TagSet extraTags = Tagging .TagSet .builder ()
129
115
.stackTags (allTags .getStackTags ())
@@ -260,63 +246,6 @@ private String fetchEngine(final ProxyClient<RdsClient> client,
260
246
throw new CfnInvalidRequestException ("Cannot fetch the engine based on current template. Please add the Engine parameter to the template and try again." );
261
247
}
262
248
263
- private ProgressEvent <ResourceModel , CallbackContext > restoreDbInstanceToPointInTimeRequest (
264
- final AmazonWebServicesClientProxy proxy ,
265
- final ProxyClient <RdsClient > rdsProxyClient ,
266
- final ProgressEvent <ResourceModel , CallbackContext > progress ,
267
- final Tagging .TagSet tagSet
268
- ) {
269
- return proxy .initiate (
270
- "rds::restore-db-instance-to-point-in-time" ,
271
- rdsProxyClient ,
272
- progress .getResourceModel (),
273
- progress .getCallbackContext ()
274
- ).translateToServiceRequest (model -> Translator .restoreDbInstanceToPointInTimeRequest (model , tagSet ))
275
- .backoffDelay (config .getBackoff ())
276
- .makeServiceCall ((restoreRequest , proxyInvocation ) -> proxyInvocation .injectCredentialsAndInvokeV2 (
277
- restoreRequest ,
278
- proxyInvocation .client ()::restoreDBInstanceToPointInTime
279
- ))
280
- .stabilize ((request , response , proxyInvocation , model , context ) ->
281
- isDBInstanceStabilizedAfterMutate (proxyInvocation , model , context ))
282
- .handleError ((request , exception , client , model , context ) -> Commons .handleException (
283
- ProgressEvent .progress (model , context ),
284
- exception ,
285
- ErrorRuleSets .RESTORE_DB_INSTANCE ,
286
- requestLogger
287
- ))
288
- .progress ();
289
- }
290
-
291
- private ProgressEvent <ResourceModel , CallbackContext > createDbInstanceReadReplica (
292
- final AmazonWebServicesClientProxy proxy ,
293
- final ProxyClient <RdsClient > rdsProxyClient ,
294
- final ProgressEvent <ResourceModel , CallbackContext > progress ,
295
- final Tagging .TagSet tagSet
296
- ) {
297
- final String currentRegion = progress .getCallbackContext ().getCurrentRegion ();
298
- return proxy .initiate (
299
- "rds::create-db-instance-read-replica" ,
300
- rdsProxyClient ,
301
- progress .getResourceModel (),
302
- progress .getCallbackContext ()
303
- ).translateToServiceRequest (model -> Translator .createDbInstanceReadReplicaRequest (model , tagSet , currentRegion ))
304
- .backoffDelay (config .getBackoff ())
305
- .makeServiceCall ((createRequest , proxyInvocation ) -> proxyInvocation .injectCredentialsAndInvokeV2 (
306
- createRequest ,
307
- proxyInvocation .client ()::createDBInstanceReadReplica
308
- ))
309
- .stabilize ((request , response , proxyInvocation , model , context ) ->
310
- isDBInstanceStabilizedAfterMutate (proxyInvocation , model , context ))
311
- .handleError ((request , exception , client , model , context ) -> Commons .handleException (
312
- ProgressEvent .progress (model , context ),
313
- exception ,
314
- ErrorRuleSets .CREATE_DB_INSTANCE_READ_REPLICA ,
315
- requestLogger
316
- ))
317
- .progress ();
318
- }
319
-
320
249
protected ProgressEvent <ResourceModel , CallbackContext > updateDbInstanceAfterCreateV12 (
321
250
final AmazonWebServicesClientProxy proxy ,
322
251
final ResourceHandlerRequest <ResourceModel > request ,
0 commit comments