Hello community out there,
A newbie to streamsets world.
I am looking for automatic solution means via python script with pipeline, which exports all jobs, all pipelines by calling StreamSets Control hub.
so I am in very initial stage of my script just for testing, to connect with Control hub and list of jobs.
script: streamsets_connection.py
import os
import sys
from streamsets.sdk import ControlHub
# Get environment variables
server_url = os.getenv('SDC_SERVER_URL')
credential_id = os.getenv('SDC_CREDENTIAL_ID')
token = os.getenv('SDC_TOKEN_ID')
# Validate environment variables
if not server_url or not credential_id or not token:
print("One or more environment variables are not set.")
exit(1)
# Connect to ControlHub
try:
control_hub = ControlHub(server_url=server_url, credential_id=credential_id, token=token)
print("ControlHub client initialized successfully.")
except Exception as e:
print(f"Failed to initialize ControlHub client: {e}")
exit(1)
def list_jobs():
try:
# Fetch all jobs
jobs = control_hub.jobs.get_all()
print("List of jobs:")
if not jobs:
print("No jobs found.")
else:
for job in jobs:
print(f"Job ID: {job.job_id}, Name: {job.job_name}")
except Exception as e:
print(f"An error occurred while listing jobs: {e}")
if __name__ == '__main__':
print("Starting job listing script...")
list_jobs()
print("Finished job listing script.")
output:
streamsets_connection.py
ControlHub client initialized successfully.
I am unable to list of jobs, any one guide me here why its not listing the jobs.
final goal is to have a script which can export all pipelines and all jobs.
Thanks in advance.