1
1
package org .cloudfoundry .multiapps .controller .process .steps ;
2
2
3
- import com .sap .cloudfoundry .client .facade .CloudControllerClient ;
4
- import com .sap .cloudfoundry .client .facade .CloudOperationException ;
5
- import com .sap .cloudfoundry .client .facade .domain .CloudServiceInstance ;
6
- import com .sap .cloudfoundry .client .facade .domain .CloudServiceKey ;
7
- import com .sap .cloudfoundry .client .facade .domain .ServiceOperation ;
8
- import jakarta .inject .Inject ;
9
- import jakarta .inject .Named ;
3
+ import java .io .ByteArrayInputStream ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStream ;
6
+ import java .text .MessageFormat ;
7
+ import java .util .ArrayList ;
8
+ import java .util .Arrays ;
9
+ import java .util .Collections ;
10
+ import java .util .List ;
11
+ import java .util .Map ;
12
+ import java .util .Objects ;
13
+
10
14
import org .apache .commons .collections4 .CollectionUtils ;
11
15
import org .apache .commons .collections4 .MapUtils ;
12
16
import org .apache .commons .lang3 .ObjectUtils ;
18
22
import org .cloudfoundry .multiapps .controller .core .cf .v2 .ResourceType ;
19
23
import org .cloudfoundry .multiapps .controller .core .helpers .MtaArchiveElements ;
20
24
import org .cloudfoundry .multiapps .controller .core .security .serialization .SecureSerialization ;
21
- import org .cloudfoundry .multiapps .controller .persistence .services .FileStorageException ;
22
25
import org .cloudfoundry .multiapps .controller .process .Constants ;
23
26
import org .cloudfoundry .multiapps .controller .process .Messages ;
24
27
import org .cloudfoundry .multiapps .controller .process .util .ArchiveEntryExtractor ;
28
31
import org .cloudfoundry .multiapps .controller .process .util .ImmutableFileEntryProperties ;
29
32
import org .cloudfoundry .multiapps .controller .process .util .ServiceAction ;
30
33
import org .cloudfoundry .multiapps .controller .process .variables .Variables ;
31
- import org .cloudfoundry .multiapps .mta .handlers .ArchiveHandler ;
32
34
import org .cloudfoundry .multiapps .mta .util .PropertiesUtil ;
33
35
import org .springframework .beans .factory .config .BeanDefinition ;
34
36
import org .springframework .context .annotation .Scope ;
35
37
36
- import java .io .ByteArrayInputStream ;
37
- import java .io .IOException ;
38
- import java .io .InputStream ;
39
- import java .text .MessageFormat ;
40
- import java .util .ArrayList ;
41
- import java .util .Arrays ;
42
- import java .util .Collections ;
43
- import java .util .List ;
44
- import java .util .Map ;
45
- import java .util .Objects ;
38
+ import com .sap .cloudfoundry .client .facade .CloudControllerClient ;
39
+ import com .sap .cloudfoundry .client .facade .CloudOperationException ;
40
+ import com .sap .cloudfoundry .client .facade .domain .CloudServiceInstance ;
41
+ import com .sap .cloudfoundry .client .facade .domain .CloudServiceKey ;
42
+ import com .sap .cloudfoundry .client .facade .domain .ServiceOperation ;
43
+
44
+ import jakarta .inject .Inject ;
45
+ import jakarta .inject .Named ;
46
46
47
47
@ Named ("determineServiceCreateUpdateActionsStep" )
48
48
@ Scope (BeanDefinition .SCOPE_PROTOTYPE )
@@ -76,17 +76,18 @@ protected StepPhase executeStep(ProcessContext context) throws Exception {
76
76
77
77
@ Override
78
78
protected String getStepErrorMessage (ProcessContext context ) {
79
- return MessageFormat .format (Messages .ERROR_DETERMINING_ACTIONS_TO_EXECUTE_ON_SERVICE , context .getVariable (Variables .SERVICE_TO_PROCESS )
80
- .getName ());
79
+ return MessageFormat .format (Messages .ERROR_DETERMINING_ACTIONS_TO_EXECUTE_ON_SERVICE ,
80
+ context .getVariable (Variables .SERVICE_TO_PROCESS )
81
+ .getName ());
81
82
}
82
83
83
84
private List <ServiceAction > determineActionsAndHandleExceptions (ProcessContext context , CloudServiceInstance existingService ) {
84
85
CloudServiceInstanceExtended service = context .getVariable (Variables .SERVICE_TO_PROCESS );
85
86
try {
86
87
return determineActions (context , service , existingService );
87
88
} catch (CloudOperationException e ) {
88
- String determineServiceActionsFailedMessage = MessageFormat .format (Messages .ERROR_DETERMINING_ACTIONS_TO_EXECUTE_ON_SERVICE , service . getName (),
89
- e .getStatusText ());
89
+ String determineServiceActionsFailedMessage = MessageFormat .format (Messages .ERROR_DETERMINING_ACTIONS_TO_EXECUTE_ON_SERVICE ,
90
+ service . getName (), e .getStatusText ());
90
91
throw new CloudOperationException (e .getStatusCode (), determineServiceActionsFailedMessage , e .getDescription (), e );
91
92
}
92
93
}
@@ -102,7 +103,8 @@ private boolean shouldResolveFileParameters(ProcessContext context) {
102
103
return !context .getVariable (Variables .SHOULD_BACKUP_PREVIOUS_VERSION );
103
104
}
104
105
105
- private List <ServiceAction > determineActions (ProcessContext context , CloudServiceInstanceExtended service , CloudServiceInstance existingService ) {
106
+ private List <ServiceAction > determineActions (ProcessContext context , CloudServiceInstanceExtended service ,
107
+ CloudServiceInstance existingService ) {
106
108
List <ServiceAction > actions = new ArrayList <>();
107
109
if (shouldUpdateKeys (service , existingService , context )) {
108
110
getStepLogger ().debug (Messages .SHOULD_UPDATE_SERVICE_KEY );
@@ -150,9 +152,11 @@ private List<ServiceAction> determineActions(ProcessContext context, CloudServic
150
152
}
151
153
152
154
if (service .shouldSkipParametersUpdate ()) {
153
- getStepLogger ().warnWithoutProgressMessage (Messages .WILL_NOT_UPDATE_SERVICE_PARAMS_BECAUSE_PARAMETER_SKIP_SERVICE_UPDATES , service .getName ());
155
+ getStepLogger ().warnWithoutProgressMessage (Messages .WILL_NOT_UPDATE_SERVICE_PARAMS_BECAUSE_PARAMETER_SKIP_SERVICE_UPDATES ,
156
+ service .getName ());
154
157
} else if (MapUtils .isEmpty (service .getCredentials ())) {
155
- getStepLogger ().warnWithoutProgressMessage (Messages .WILL_NOT_UPDATE_SERVICE_PARAMS_BECAUSE_UNDEFINED_OR_EMPTY , service .getName ());
158
+ getStepLogger ().warnWithoutProgressMessage (Messages .WILL_NOT_UPDATE_SERVICE_PARAMS_BECAUSE_UNDEFINED_OR_EMPTY ,
159
+ service .getName ());
156
160
} else {
157
161
getStepLogger ().debug (Messages .WILL_UPDATE_SERVICE_PARAMETERS );
158
162
getStepLogger ().debug (Messages .NEW_SERVICE_PARAMETERS , SecureSerialization .toJson (service .getCredentials ()));
@@ -185,8 +189,11 @@ private List<ServiceAction> determineActions(ProcessContext context, CloudServic
185
189
}
186
190
187
191
private SLException getServiceRecreationNeededException (CloudServiceInstanceExtended service , CloudServiceInstance existingService ) {
188
- return new SLException (Messages .ERROR_SERVICE_NEEDS_TO_BE_RECREATED_BUT_FLAG_NOT_SET , service .getResourceName (), buildServiceType (service ),
189
- existingService .getName (), buildServiceType (existingService ));
192
+ return new SLException (Messages .ERROR_SERVICE_NEEDS_TO_BE_RECREATED_BUT_FLAG_NOT_SET ,
193
+ service .getResourceName (),
194
+ buildServiceType (service ),
195
+ existingService .getName (),
196
+ buildServiceType (existingService ));
190
197
}
191
198
192
199
private String buildServiceType (CloudServiceInstance service ) {
@@ -218,32 +225,19 @@ private CloudServiceInstanceExtended prepareServiceParameters(ProcessContext con
218
225
return service ;
219
226
}
220
227
221
- private CloudServiceInstanceExtended setServiceParameters (ProcessContext context , CloudServiceInstanceExtended service , String fileName ) {
228
+ private CloudServiceInstanceExtended setServiceParameters (ProcessContext context , CloudServiceInstanceExtended service ,
229
+ String fileName ) {
222
230
String appArchiveId = context .getRequiredVariable (Variables .APP_ARCHIVE_ID );
223
231
String spaceGuid = context .getVariable (Variables .SPACE_GUID );
224
- // TODO: backwards compatibility for one tact
225
- List <ArchiveEntryWithStreamPositions > archiveEntriesWithStreamPositions = context .getVariable (Variables .ARCHIVE_ENTRIES_POSITIONS );
226
- if (archiveEntriesWithStreamPositions == null ) {
227
- try {
228
- return fileService .processFileContent (spaceGuid , appArchiveId , appArchiveStream -> {
229
- InputStream fileStream = ArchiveHandler .getInputStream (appArchiveStream , fileName , configuration .getMaxManifestSize ());
230
- return mergeCredentials (service , fileStream );
231
- });
232
- } catch (FileStorageException e ) {
233
- throw new SLException (e , e .getMessage ());
234
- }
235
- }
236
- // TODO: backwards compatibility for one tact
237
- ArchiveEntryWithStreamPositions serviceBindingParametersEntry = ArchiveEntryExtractorUtil .findEntry (fileName , context .getVariable (
238
- Variables .ARCHIVE_ENTRIES_POSITIONS ));
232
+ ArchiveEntryWithStreamPositions serviceBindingParametersEntry = ArchiveEntryExtractorUtil .findEntry (fileName ,
233
+ context .getVariable (Variables .ARCHIVE_ENTRIES_POSITIONS ));
239
234
byte [] serviceBindingsParametersContent = archiveEntryExtractor .extractEntryBytes (ImmutableFileEntryProperties .builder ()
240
235
.guid (appArchiveId )
241
- .name (
242
- serviceBindingParametersEntry .getName ())
236
+ .name (serviceBindingParametersEntry .getName ())
243
237
.spaceGuid (spaceGuid )
244
- .maxFileSizeInBytes (
245
- configuration . getMaxManifestSize ())
246
- . build (), serviceBindingParametersEntry );
238
+ .maxFileSizeInBytes (configuration . getMaxManifestSize ())
239
+ . build (),
240
+ serviceBindingParametersEntry );
247
241
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream (serviceBindingsParametersContent )) {
248
242
return mergeCredentials (service , byteArrayInputStream );
249
243
} catch (IOException e ) {
@@ -321,7 +315,8 @@ private boolean shouldUpdateSyslogUrl(CloudServiceInstance service, String exist
321
315
return !Objects .equals (syslogDrainUrl , existingSyslogUrl );
322
316
}
323
317
324
- private void setServiceGuidIfPresent (ProcessContext context , List <ServiceAction > actions , CloudServiceInstance existingService , CloudServiceInstanceExtended serviceToProcess ) {
318
+ private void setServiceGuidIfPresent (ProcessContext context , List <ServiceAction > actions , CloudServiceInstance existingService ,
319
+ CloudServiceInstanceExtended serviceToProcess ) {
325
320
if (existingService != null && !actions .contains (ServiceAction .RECREATE )) {
326
321
new DynamicResolvableParametersContextUpdater (context ).updateServiceGuid (serviceToProcess , existingService );
327
322
}
0 commit comments