Creating a library set for your instance
A library set is a collection of libraries that you can create and reference in Spark applications. The library set is stored in the instance home storage associated with the instance.
Creating a library set for Python package install
Spark engine bundles a Spark application called customize_instance_app.py
that you run to create a library set with your custom packages.
Prerequisites: You must have the permissions to submit a Spark application. See Managing roles and privileges.
- Prepare a JSON file with the following content:
{ "library_set": { "action": "add", "name": "my_library_set", "libraries": { "conda": { "python": { "packages": ["numpy"] } } } } }JSON attribute descriptions:
"action": Specifies the action ("add"is the only option supported)."name": Specifies the name of the library set. Use unique names for each set to avoid overwriting."libraries": Defines a set of libraries. Only"conda"and"pip"package managers are supported."packages": List of packages to install. For a specific version:package_name==version.
- Get the IAM token.
- Pass the JSON file as
"arguments"in the following REST API call:curl --request POST \ --url https://<region>.lakehouse.cloud.ibm.com/lakehouse/api/<api_version>/spark_engines/<spark_engine_id>/applications \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --header 'AuthInstanceID: <crn_instance>' \ -d @createLibraryset.jsonParameters:
<region>– Spark instance region;<spark_engine_id>– Native Spark engine ID;<crn_instance>– CRN of the watsonx.data instance;<api_version>–v2orv3. - Track the status of the application by invoking the application status REST API.
Creating a library set for other packages or file download (Script based)
With script based customization, create a Python script using the module naming convention
expected by watsonx.data. Implement a Python
function that downloads libraries to the predesignated directory:
/home/spark/shared/user-libs/<libraryset_name>/custom/<subdir_if_applicable>.
- Create a Python file named
customization_script.py. - Implement a function called
customize(<install_path>, <params>)in your script. - Store the
customization_script.pyfile in IBM Cloud Object Storage or in GitHub. - Pass the location of the file to the customization Spark application through
"application_details" > "conf" > "spark.submit.pyFiles". - Submit the application:
curl --request POST \ --url https://<region>.lakehouse.cloud.ibm.com/lakehouse/api/<api_version>/spark_engines/<spark_engine_id>/applications \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --header 'AuthInstanceID: <crn_instance>' \ -d @createLibraryset.json