Skip to content

Commit

Permalink
Release 1.1.0 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jridfe authored Jun 27, 2024
1 parent 3bdbccf commit 411fa6e
Show file tree
Hide file tree
Showing 10 changed files with 2,718 additions and 2,013 deletions.
28 changes: 28 additions & 0 deletions MIGRATION-V1.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Upgrading to ABAP SDK version 1.1.0

<details>
<summary>Table of Contents</summary>

- [Breaking changes](#breaking-changes)
- [Breaking changes by service](#breaking-changes-by-service)
- [watsonx.ai V1](#watsonxai-v1)
- [New features by service](#new-features-by-service)
- [watsonx.ai V1](#watsonxai-v1-1)

</details>

## Breaking changes

### Breaking changes by service

#### watsonx.ai V1

- Method `Deployments_Text_Generation`

- Parameter `i_DeploymentTextGenRequest` of type `t_Deployment_Text_Gen_Request` was replaced with parameter `i_Body` of type `t_Deployment_Text_Gen`.

### New features by service

#### watsonx.ai V1

- New method `Text_Embeddings`
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ information in [Support and Feedback](#support-and-feedback).
| [abap-sdk-nwas-x](https://github.com/IBM/abap-sdk-nwas-x) | **abap-sdk-btp-x** |
|---|---|
| for SAP NetWeaver<sup>®</sup> AS ABAP 7.50+ | for SAP BTP ABAP Environment |
| tested on SAP Business Suite and SAP S/4HANA on-premises edition | tested with SAP BTP ABAP Environment 2402 |
| tested on SAP Business Suite and SAP S/4HANA on-premises edition | tested with SAP BTP ABAP Environment 2405 |
| | `this repository` |

---
Expand All @@ -45,7 +45,7 @@ information in [Support and Feedback](#support-and-feedback).
<summary>Table of Contents</summary>

- [Announcements](#announcements)
- [Major version 1.0.0 released](#major-version-100-released)
- [Version 1.1.0 released](#version-110-released)
- [Before you begin](#before-you-begin)
- [Installation](#installation)
- [SSL Certificates](#ssl-certificates)
Expand All @@ -62,9 +62,10 @@ information in [Support and Feedback](#support-and-feedback).

## Announcements

### Major version 1.0.0 released
### Version 1.1.0 released

Version v1.0.0 of the SDK has been released.
Version v1.1.0 of the SDK has been released - see what's changed in
the [migration guide](MIGRATION-V1.1.0.md).

## Before you begin

Expand Down Expand Up @@ -160,7 +161,7 @@ called again with a new (refreshed) bearer-token as parameter.
## Usage

The client library is delivered as package *ZIBMX*. Once the Git
Repository has been cloned to the SAP system, a watsonx service
repository has been cloned to the SAP system, a watsonx service
instance is wrapped by an ABAP class instance.<br> The following
watsonx services are currently supported:

Expand Down
28 changes: 19 additions & 9 deletions src/zcl_ibmx_service.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ CLASS ZCL_IBMX_SERVICE IMPLEMENTATION.
lv_url type string.

if not i_url-host cp 'http*'.
if i_url-protocol is initial.
if i_url-protocol is initial and not i_url-host is initial.
lv_url = 'http://'.
else.
lv_url = i_url-protocol && `://`.
Expand Down Expand Up @@ -1165,19 +1165,29 @@ CLASS ZCL_IBMX_SERVICE IMPLEMENTATION.
c_request_prop = ls_request_prop ).

" create http client instance
lv_url = ls_request_prop-url-protocol && `://` && ls_request_prop-url-host.
create_client_by_url(
exporting
i_url = lv_url
i_request_prop = ls_request_prop
importing
e_client = e_client ).
if not ls_request_prop-destination is initial.
create_client_by_destination(
exporting
i_request_prop = ls_request_prop
importing
e_client = e_client ).
else.
lv_url = ls_request_prop-url-protocol && `://` && ls_request_prop-url-host.
create_client_by_url(
exporting
i_url = lv_url
i_request_prop = ls_request_prop
importing
e_client = e_client ).
endif.

" set URI and authorization
lv_url = set_uri_and_authorization( i_client = e_client i_request_prop = ls_request_prop ).

" set request uri
set_request_uri( i_client = e_client i_uri = lv_url ).
if ls_request_prop-destination is initial.
set_request_uri( i_client = e_client i_uri = lv_url ).
endif.

" set 'Content-Type' header
if not i_request_prop-header_content_type is initial.
Expand Down
40 changes: 39 additions & 1 deletion src/zcl_ibmx_service_arch.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ CLASS ZCL_IBMX_SERVICE_ARCH DEFINITION
!e_client TYPE ts_client
RAISING
ZCX_IBMX_SERVICE_EXCEPTION .
"! <p class="shorttext synchronized" lang="en">Returns a HTTP/REST client based on an DESTINATION.</p>
"!
"! @parameter I_REQUEST_PROP | Request parameters
"! @parameter E_CLIENT | HTTP/REST client
"! @raising ZCX_IBMX_SERVICE_EXCEPTION | Exception being raised in case of an error.
"!
CLASS-METHODS create_client_by_destination
IMPORTING
!i_request_prop TYPE ts_request_prop
EXPORTING
!e_client TYPE ts_client
RAISING
ZCX_IBMX_service_exception .
"! <p class="shorttext synchronized" lang="en">Returns the default proxy host and port.</p>
"!
"! @parameter I_URL | target URL
Expand Down Expand Up @@ -298,7 +311,32 @@ CLASS ZCL_IBMX_SERVICE_ARCH IMPLEMENTATION.
TRY.
"create http destination by url
DATA(lo_http_destination) =
cl_http_destination_provider=>create_by_url( i_url ).
cl_http_destination_provider=>create_by_url( i_url ).
CATCH cx_http_dest_provider_error.
ENDTRY.

"create HTTP client by destination
TRY.
e_client-http = cl_web_http_client_manager=>create_by_http_destination( lo_http_destination ) .
CATCH cx_web_http_client_error.
lv_text = `HTTP client cannot be created: ` && lv_text ##NO_TEXT.
ZCL_IBMX_SERVICE=>raise_exception( i_text = lv_text ).
ENDTRY.

e_client-request = e_client-http->get_http_request( ).

ENDMETHOD.


METHOD create_client_by_destination.

DATA:
lv_text TYPE string.

TRY.
"get http destination
DATA(lo_http_destination) =
cl_http_destination_provider=>create_by_destination( i_request_prop-destination ).
CATCH cx_http_dest_provider_error.
ENDTRY.

Expand Down
6 changes: 6 additions & 0 deletions src/zcl_ibmx_service_arch.clas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<LANGU>E</LANGU>
<DESCRIPT>Returns a HTTP/REST client based on an URL.</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CLSNAME>ZCL_IBMX_SERVICE_ARCH</CLSNAME>
<CMPNAME>CREATE_CLIENT_BY_DESTINATION</CMPNAME>
<LANGU>E</LANGU>
<DESCRIPT>Returns a HTTP/REST client based on an DESTINATION.</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CLSNAME>ZCL_IBMX_SERVICE_ARCH</CLSNAME>
<CMPNAME>EXECUTE</CMPNAME>
Expand Down
41 changes: 31 additions & 10 deletions src/zcl_ibmx_service_ext.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public section.
types TY_IMAGE_CLASS type STRING .
types:
begin of ts_oauth_prop,
url type ts_url,
username type string,
password type string,
apikey type string,
url type ts_url,
destination type Zif_IBMX_service_arch=>ty_http_destination,
username type string,
password type string,
apikey type string,
end of ts_oauth_prop .

constants C_FIELD_NONE type FIELDNAME value '###' ##NO_TEXT.
Expand Down Expand Up @@ -165,6 +166,7 @@ private section.
importing
!I_SERVICENAME type TY_SERVICENAME
!I_INSTANCE_ID type TY_INSTANCE_ID optional
!I_PREFIX type STRING optional
changing
!C_REQUEST_PROP type ANY .
"! <p class="shorttext synchronized" lang="en">Method for internal use.</p>
Expand Down Expand Up @@ -206,6 +208,7 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_SERVICENAME TYPE TY_SERVICENAME
* | [--->] I_INSTANCE_ID TYPE TY_INSTANCE_ID(optional)
* | [--->] I_PREFIX TYPE STRING(optional)
* | [<-->] C_REQUEST_PROP TYPE ANY
* +--------------------------------------------------------------------------------------</SIGNATURE>
method add_config_prop.
Expand All @@ -215,6 +218,7 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.
lv_type type char,
ls_config type ZIBMX_config,
lt_config type standard table of ZIBMX_config,
lv_param type ZIBMX_config-param,
lt_ref type standard table of ref to data,
lr_data type ref to data,
lv_index type i value 0,
Expand Down Expand Up @@ -281,7 +285,12 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.
append lr_data to lt_ref.
else.
if <lv_comp_val> is initial.
read table lt_config into ls_config with key param = <lv_compname> ##WARN_OK.
if i_prefix is supplied.
lv_param = i_prefix && `-` && <lv_compname>.
else.
lv_param = <lv_compname>.
endif.
read table lt_config into ls_config with key param = lv_param ##WARN_OK.
if sy-subrc = 0.
condense ls_config-value.
<lv_comp_val> = ls_config-value.
Expand Down Expand Up @@ -393,14 +402,15 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.
ls_token_request_prop type ts_request_prop.

ls_token_request_prop-url = p_oauth_prop-url.
ls_token_request_prop-destination = p_oauth_prop-destination.
" set to tribool_false to distinguish between false and inital
ls_token_request_prop-auth_basic = c_tribool_false.
ls_token_request_prop-auth_oauth = c_tribool_false.
ls_token_request_prop-auth_apikey = c_tribool_false.
ls_token_request_prop-header_accept = ZCL_IBMX_service=>ZIF_IBMX_service_arch~c_mediatype-appl_json.


if i_request_prop-auth_name eq 'IAM' or i_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
if i_request_prop-auth_name eq 'IAM' or i_request_prop-auth_name eq 'Bearer' or i_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.

" write urlencoded parameters
if not ls_token-refresh_token is initial.
Expand All @@ -416,6 +426,10 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.
lv_grand_urlencoded = escape( val = 'urn:ibm:params:oauth:grant-type:password' format = cl_abap_format=>e_uri_full ) ##NO_TEXT.
lv_key_urlencoded = escape( val = p_oauth_prop-password format = cl_abap_format=>e_uri_full ).
ls_token_request_prop-body = `grant_type=` && lv_grand_urlencoded && `&username=` && p_oauth_prop-username && `&password=` && p_oauth_prop-password ##NO_TEXT.
elseif not p_oauth_prop-destination is initial.
data(lv_full_url) = get_full_url( ls_token_request_prop-url ).
data(lv_token_endpoint_urlencoded) = escape( val = lv_full_url format = cl_abap_format=>e_uri_full ) ##NO_TEXT.
ls_token_request_prop-body = `token_endpoint=` && lv_token_endpoint_urlencoded ##NO_TEXT.
else.
ls_token_request_prop-username = p_oauth_prop-username.
ls_token_request_prop-password = p_oauth_prop-password.
Expand Down Expand Up @@ -885,21 +899,28 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.

" Set OAuth properties
lo_instance->p_oauth_prop = i_oauth_prop.
add_config_prop(
exporting
i_servicename = lo_instance->p_servicename
i_instance_id = lo_instance->p_instance_id
i_prefix = 'OAUTH'
changing
c_request_prop = lo_instance->p_oauth_prop ).
normalize_url(
changing
c_url = lo_instance->p_oauth_prop-url ).
if ls_request_prop-auth_name eq 'IAM' or ls_request_prop-auth_name eq 'ICP4D' or ls_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
if ls_request_prop-auth_name eq 'IAM' or ls_request_prop-auth_name eq 'ICP4D' or ls_request_prop-auth_name eq 'Bearer' or ls_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
if lo_instance->p_oauth_prop-url-host is initial.
lo_instance->p_oauth_prop-url-protocol = 'https' ##NO_TEXT.
if ls_request_prop-auth_name eq 'IAM' or ls_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
if ls_request_prop-auth_name eq 'IAM' or ls_request_prop-auth_name eq 'Bearer' or ls_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
lo_instance->p_oauth_prop-url-host = c_iam_token_host.
else.
lo_instance->p_oauth_prop-url-host = lo_instance->p_request_prop_default-url-host.
endif.
endif.
if lo_instance->p_oauth_prop-url-path_base is initial and lo_instance->p_oauth_prop-url-path is initial.
" Set path_base (not path), otherwise the default service path_base would be added, which is not correct
if ls_request_prop-auth_name eq 'IAM' or ls_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
if ls_request_prop-auth_name eq 'IAM' or ls_request_prop-auth_name eq 'Bearer' or ls_request_prop-auth_name eq 'BearerToken' ##NO_TEXT.
lo_instance->p_oauth_prop-url-path_base = c_iam_token_path.
elseif ls_request_prop-auth_name eq 'WATSONX'.
lo_instance->p_oauth_prop-url-path_base = c_watsonx_token_path.
Expand Down Expand Up @@ -971,7 +992,7 @@ CLASS ZCL_IBMX_SERVICE_EXT IMPLEMENTATION.
* +--------------------------------------------------------------------------------------</SIGNATURE>
method get_sdk_version_date.

e_sdk_version_date = '20240325'.
e_sdk_version_date = '20240625'.

endmethod.

Expand Down
Loading

0 comments on commit 411fa6e

Please sign in to comment.