Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add explanation for service binding options #35

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 73 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,55 @@ DeploymentApi api = new DeploymentApi(client);

For more customization, creating a [HeaderProvider](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations#about-headerproviders) is also possible.

## Requirements and Setup
## Requirements and Setup for AI Core

### Set AI Core credentials as environment variable
For any AI Core service interaction, the SAP AI SDK requires credentials to be available at application runtime.
By default, the credentials are extracted automatically from a service instance of type "aicore" bound to the application.
Running the application locally without this service binding will throw an exception:

- Running the application locally without a service binding will throw:
```
Could not find any matching service bindings for service identifier 'aicore'
```

There are multiple options to register the service binding:
* Regular service binding in SAP BTP Cloud Foundry (resulting in `VCAP_SERVICES` env var entry).
* Set an environment variable explicitly: `AICORE_SERVICE_KEY`
newtork marked this conversation as resolved.
Show resolved Hide resolved
* Define and use a _Destination_ in _BTP Destination Service_.
* (For CAP applications) use the [hybrid testing](https://cap.cloud.sap/docs/advanced/hybrid-testing#services-on-cloud-foundry) approach _(not recommended for production)_.
* For example: `cds bind --to aicore --exec mvn spring-boot:run`
* Leveraging `"user-provided"` service binding _(not recommended for production)_.
* Define and use a custom `ServiceBinding` or `ServiceBindingAccessor` declaration in application _(not recommended for production)_.

### Regular service binding in SAP BTP Cloud Foundry
newtork marked this conversation as resolved.
Show resolved Hide resolved

* Bind an existing service instance of type `aicore` to your application.
[With SAP BTP multiple options are available](https://help.sap.com/docs/btp/sap-business-technology-platform/binding-service-instances-to-applications): using the web interface, the CLI, MTA or manifest.

<details><summary>After application restart, there should be an "aicore" entry in environment variable <code>VCAP_SERVICES</code>.</summary>

```json
{
"aicore": [
{
"clientid": "...",
"clientsecret": "...",
"url": "...",
"identityzone": "...",
"identityzoneid": "...",
"appname": "...",
"serviceurls": {
"AI_API_URL": "..."
}
}
]
}
```

</details>

### Set credentials as dedicated environment variable
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention that this is recommended if you need to access an external AI Core service instance or for local use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the README is already almost unreadable with all the details and sample code. I don't want to explain and motivate reasons for the options to resolve a service binding.
Not only because of complexity and readability, but also any documented "reasoning" is subject to change over time. I'm certain we will see changes to best-practices, once the project gains traction.


`Could not find any matching service bindings for service identifier 'aicore'`
- Go into the BTP Cockpit
- Go into the SAP BTP Cockpit
- Instances and Subscriptions -> Instances -> AI Core -> View Credentials -> Copy JSON
- Set it as an environment variable `AICORE_SERVICE_KEY` in your IDE

Expand All @@ -428,7 +469,33 @@ For more customization, creating a [HeaderProvider](https://sap.github.io/cloud-
export AICORE_SERVICE_KEY='{ "serviceurls": { "AI_API_URL": ...'
```

### Run the Spring Boot application
### Define and use a Destination

* Lookup service-key credentials as explained in the previous step for `AICORE_SERVICE_KEY`.

* <details><summary>Define a new destination in the SAP BTP Destination Service using the service-key credentials</summary>

* (Destinations can be added on subaccount level and on service instance level.)
* (The URL field requires an additional path segment: `/v2`)
* **Name**: _my-aicore_
* **Type**: HTTP
* **URL**: _[serviceurls.AI_API_URL]/v2_
* **Proxy-Type**: Internet
* **Authentication**: _Oauth2ClientCredentials_
* **Client ID**: _[clientid]_
* **Client Secret**: _[clientsecret]_
* **Token Service URL Type**: Dedicated
* **Token Service URL**: _[url]_

</details>

* At application runtime the following can be executed:
```java
Destination destination = DestinationAccessor.getDestination("my-aicore");
newtork marked this conversation as resolved.
Show resolved Hide resolved
ApiClient client = Core.getClient(destination);
```

### Run the Spring Boot test application

```shell
cd e2e-test-app
Expand Down