Skip to content

Handle multiple bindings between app and service#1820

Open
theghost5800 wants to merge 2 commits intomasterfrom
handleMultipleBindings
Open

Handle multiple bindings between app and service#1820
theghost5800 wants to merge 2 commits intomasterfrom
handleMultipleBindings

Conversation

@theghost5800
Copy link
Copy Markdown
Contributor

JIRA:LMCROSSITXSADEPLOY-3409

@theghost5800 theghost5800 force-pushed the handleMultipleBindings branch from 2ccc380 to f5ed5cc Compare April 24, 2026 08:41
Optional.ofNullable(deleteSingleServiceBinding(guid))
.ifPresent(jobIds::add);
} catch (RuntimeException e) {
errors.add(e);
Copy link
Copy Markdown
Contributor

@IvanBorislavovDimitrov IvanBorislavovDimitrov Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not fast-failing immediately, but collecting the errors? If there is some regression with a service broker, won't this produce too much noise?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this change is due to common from claude review that if we use this codeblock

return Flux.fromIterable(guids)
             .map(UUID::toString)
             .flatMap(guid -> delegate.serviceBindingsV3().delete(...))
             .collectList()
             .block();

it will try to run all deletion requests concurrently and it's possible to lose track of other delete request responses. It's interesting which approach is better.

try {
Optional.ofNullable(deleteSingleServiceBinding(guid))
.ifPresent(jobIds::add);
} catch (RuntimeException e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why catching so generic exception here? Can't we use AbstractCloudFoundryException?

Comment on lines +2051 to +2052
List<String> jobIds = new ArrayList<>();
List<RuntimeException> errors = new ArrayList<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two parameters are in-parameters which is not a best practice. Can you split the method to just return a List of some results instead?

protected AsyncExecutionState checkServiceBindingOperationState(CloudServiceBinding serviceBinding, ProcessContext context) {
ServiceCredentialBindingOperation lastOperation = serviceBinding.getServiceBindingOperation();
protected AsyncExecutionState checkServiceBindingOperationState(List<CloudServiceBinding> serviceBindings, ProcessContext context) {
CloudServiceBinding failedServiceBinding = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only the last failed binding is tracked and not all? Is it always the latest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename these type of classes so they reflect the class is used to monitor multiple bindings between app and service

public AsyncExecutionState execute(ProcessContext context) {
List<String> jobIds = context.getVariable(Variables.SERVICE_UNBINDING_JOB_IDS);
if (jobIds.isEmpty()) {
return super.execute(context);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this produce a null pointer exception because
context.setVariable(Variables.SERVICE_UNBINDING_JOB_ID, jobId);
is not set if it is a first execution of this step?

.getState() == ServiceCredentialBindingOperation.State.SUCCEEDED)
.max(Comparator.comparing(binding -> binding.getMetadata()
.getCreatedAt()))
.orElseGet(() -> bindings.isEmpty() ? null : bindings.get(0));
Copy link
Copy Markdown
Contributor

@IvanBorislavovDimitrov IvanBorislavovDimitrov Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we will never get here, but isn't it more correctly at least to return the latest created binding instead of bindings.get(0)? Or just throw an exception?

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
68.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants