cloudfoundry / cf-java-client

Java Client Library for Cloud Foundry
Apache License 2.0
328 stars 318 forks source link

Create a new service instance with a named broker #1115

Open vpdhayanithi opened 3 years ago

vpdhayanithi commented 3 years ago

Hello,

As per the CLI documentation, I could create a service instance using a specific broker by passing broker name as argument ("-b") like the way it is explained in the CF documentation (https://docs.cloudfoundry.org/devguide/services/managing-services.html). However, I don't see such an option available via the cf java client. Could you please advise here.

Thanks, Vishnu Prasath

dmikusa commented 3 years ago

To be clear, this is what you're referring to?

Note: When multiple brokers provide two or more services with the same name, you must specify the broker by including the -b BROKER flag in the cf create-service command.

If that's the case, there is not a similar option.

The createInstance method takes a CreateServiceInstanceRequest which has a service name attribute but if you have two services with the same name, there is no way to differentiate (like this -b flag with the cf cli).

You could do this directly with the client though. The client is driven by guids, so you'd just need to feed in the guids to identify the plan. You can see an example of this here. That is what operations is doing after it has looked up the space/service/plan guids.

I can leave this open as an enhancement request in the backlog, but I cannot guarantee when we can add this functionality to the client. If you or someone is interested in submitting a PR, I can provide guidance and help to get that merged. Just let me know.

vpdhayanithi commented 3 years ago

Hi @dmikusa-pivotal,

Thanks for your response and I would be interested to provide a fix for this. Could you please help me here.

Regards, Vishnu Prasath

dmikusa commented 3 years ago

Sure thing. To get started:

  1. Fork and git clone your repo
  2. Follow these instructions to get the project set up & run the unit tests tests: https://github.com/cloudfoundry/cf-java-client#development
  3. Make a branch & commit your changes there.
  4. Send a PR and I will review.

In terms of what needs to be done:

[ ] - Modify CreateServiceInstanceRequest to allow passing in the broker name [ ] - Modify createInstance to also filter on the broker name. The ListSpaceServicesResponse should have a list of services which contain the broker name. If no broker name is selected, it should pick the first match that it finds. [ ] - Add a unit test test to confirm functionality. Make sure the existing tests & new test all pass. [ ] - Validate that your change fixes the issue in your actual use case (I think it should but please confirm).

Let me know if you have any questions or hit any snags. Thanks in advance!

vpdhayanithi commented 3 years ago

Thanks @dmikusa-pivotal . I shall get back to you once I am done with the change.