You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by oe...@apache.org on 2026/07/29 14:21:45 UTC
(streampipes) 02/03: Implement adapter and pipeline endpoints
This is an automated email from the ASF dual-hosted git repository.
SvenO3 pushed a commit to branch 4791-add-adapter-and-pipeline-support-to-python-client
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit cc7ca016ca1c1f255c85ec687e976645df495ddf
Author: Sven Oehler <oe...@web.de>
AuthorDate: Wed Jul 29 16:20:50 2026 +0200
Implement adapter and pipeline endpoints
---
.../streampipes/client/client.py | 8 ++
.../streampipes/endpoint/api/__init__.py | 4 +
.../streampipes/endpoint/api/adapter.py | 99 ++++++++++++++++++++++
.../streampipes/endpoint/api/pipeline.py | 99 ++++++++++++++++++++++
.../streampipes/endpoint/endpoint.py | 7 +-
5 files changed, 215 insertions(+), 2 deletions(-)
diff --git a/streampipes-client-python/streampipes/client/client.py b/streampipes-client-python/streampipes/client/client.py
index 2b8faff3a6..187543d993 100644
--- a/streampipes-client-python/streampipes/client/client.py
+++ b/streampipes-client-python/streampipes/client/client.py
@@ -31,8 +31,10 @@ from requests import Session
from streampipes.client.config import StreamPipesClientConfig
from streampipes.endpoint import APIEndpoint
from streampipes.endpoint.api import (
+ AdapterEndpoint,
DataLakeMeasureEndpoint,
DataStreamEndpoint,
+ PipelineEndpoint,
VersionEndpoint,
)
@@ -63,6 +65,10 @@ class StreamPipesClient:
Instance of the data lake measure endpoint
dataStreamApi: DataStreamEndpoint
Instance of the data stream endpoint
+ adapterApi: AdapterEndpoint
+ Instance of the adapter endpoint
+ pipelineApi: PipelineEndpoint
+ Instance of the pipeline endpoint
Raises
------
@@ -142,8 +148,10 @@ class StreamPipesClient:
# provide all available endpoints here
# name of the endpoint needs to be consistent with the Java client
+ self.adapterApi = AdapterEndpoint(parent_client=self)
self.dataLakeMeasureApi = DataLakeMeasureEndpoint(parent_client=self)
self.dataStreamApi = DataStreamEndpoint(parent_client=self)
+ self.pipelineApi = PipelineEndpoint(parent_client=self)
self.versionApi = VersionEndpoint(parent_client=self)
self.server_version = self._get_server_version()
diff --git a/streampipes-client-python/streampipes/endpoint/api/__init__.py b/streampipes-client-python/streampipes/endpoint/api/__init__.py
index 28bcf688ae..4121af2dd3 100644
--- a/streampipes-client-python/streampipes/endpoint/api/__init__.py
+++ b/streampipes-client-python/streampipes/endpoint/api/__init__.py
@@ -15,12 +15,16 @@
# limitations under the License.
#
+from .adapter import AdapterEndpoint
from .data_lake_measure import DataLakeMeasureEndpoint
from .data_stream import DataStreamEndpoint
+from .pipeline import PipelineEndpoint
from .version import VersionEndpoint
__all__ = [
+ "AdapterEndpoint",
"DataLakeMeasureEndpoint",
"DataStreamEndpoint",
+ "PipelineEndpoint",
"VersionEndpoint",
]
diff --git a/streampipes-client-python/streampipes/endpoint/api/adapter.py b/streampipes-client-python/streampipes/endpoint/api/adapter.py
new file mode 100644
index 0000000000..f1541ca569
--- /dev/null
+++ b/streampipes-client-python/streampipes/endpoint/api/adapter.py
@@ -0,0 +1,99 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Adapter API endpoint."""
+
+import json
+
+from streampipes.endpoint.endpoint import APIEndpoint
+from streampipes.model.compact import CompactAdapter
+from streampipes.model.container import Adapters
+from streampipes.model.container.resource_container import ResourceContainer
+from streampipes.model.resource import AdapterSummary
+
+__all__ = ["AdapterEndpoint"]
+
+
+class AdapterEndpoint(APIEndpoint):
+ """Read adapter summaries and create compact adapters."""
+
+ @property
+ def _container_cls(self) -> type[ResourceContainer]:
+ """Return the adapter summary container type."""
+ return Adapters
+
+ @property
+ def _relative_api_path(self) -> tuple[str, ...]:
+ """Return the adapter endpoint's relative REST path."""
+ return "api", "v2", "connect", "master", "adapters"
+
+ @property
+ def _compact_url(self) -> str:
+ """Return the compact adapter creation URL."""
+ return f"{self._parent_client.base_api_path}api/v2/connect/compact-adapters"
+
+ def all(self) -> Adapters:
+ """Return all accessible adapter summaries."""
+ response = self._make_request(
+ request_method=self._parent_client.request_session.get,
+ url=f"{self.build_url()}/summary",
+ )
+ return Adapters.from_json(json_string=response.text)
+
+ def get(self, identifier: str, **kwargs) -> AdapterSummary:
+ """Return one adapter summary by identifier."""
+ for adapter in self.all():
+ if adapter.element_id == identifier:
+ return adapter
+ raise KeyError(f"No adapter summary found for identifier '{identifier}'.")
+
+ def post(self, resource: object) -> None:
+ """Create an adapter from its compact representation."""
+ if not isinstance(resource, CompactAdapter):
+ raise TypeError("Adapter creation requires a CompactAdapter.")
+
+ self._make_request(
+ request_method=self._parent_client.request_session.post,
+ url=self._compact_url,
+ data=json.dumps(resource.to_dict(use_source_names=True)),
+ headers={"Content-type": "application/json"},
+ )
+
+ def put(self, resource: object, identifier: str | None = None) -> None:
+ """Reject adapter updates, which are intentionally unsupported."""
+ raise NotImplementedError("Updating adapters is not supported by the Python client.")
+
+ def delete(self, identifier: str) -> None:
+ """Delete an adapter."""
+ self._make_request(
+ request_method=self._parent_client.request_session.delete,
+ url=f"{self.build_url()}/{identifier}",
+ )
+
+ def start(self, identifier: str) -> None:
+ """Start an adapter by identifier."""
+ self._make_request(
+ request_method=self._parent_client.request_session.post,
+ url=f"{self.build_url()}/{identifier}/start",
+ )
+
+ def stop(self, identifier: str) -> None:
+ """Stop an adapter by identifier."""
+ self._make_request(
+ request_method=self._parent_client.request_session.post,
+ url=f"{self.build_url()}/{identifier}/stop",
+ )
diff --git a/streampipes-client-python/streampipes/endpoint/api/pipeline.py b/streampipes-client-python/streampipes/endpoint/api/pipeline.py
new file mode 100644
index 0000000000..4bbb32657e
--- /dev/null
+++ b/streampipes-client-python/streampipes/endpoint/api/pipeline.py
@@ -0,0 +1,99 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Pipeline API endpoint."""
+
+import json
+
+from streampipes.endpoint.endpoint import APIEndpoint
+from streampipes.model.compact import CompactPipeline
+from streampipes.model.container import Pipelines
+from streampipes.model.container.resource_container import ResourceContainer
+from streampipes.model.resource import PipelineSummary
+
+__all__ = ["PipelineEndpoint"]
+
+
+class PipelineEndpoint(APIEndpoint):
+ """Read pipeline summaries and create compact pipelines."""
+
+ @property
+ def _container_cls(self) -> type[ResourceContainer]:
+ """Return the pipeline summary container type."""
+ return Pipelines
+
+ @property
+ def _relative_api_path(self) -> tuple[str, ...]:
+ """Return the pipeline endpoint's relative REST path."""
+ return "api", "v2", "pipelines"
+
+ @property
+ def _compact_url(self) -> str:
+ """Return the compact pipeline creation URL."""
+ return f"{self._parent_client.base_api_path}api/v2/compact-pipelines"
+
+ def all(self) -> Pipelines:
+ """Return all accessible pipeline summaries."""
+ response = self._make_request(
+ request_method=self._parent_client.request_session.get,
+ url=f"{self.build_url()}/summary",
+ )
+ return Pipelines.from_json(json_string=response.text)
+
+ def get(self, identifier: str, **kwargs) -> PipelineSummary:
+ """Return one pipeline summary by identifier."""
+ for pipeline in self.all():
+ if pipeline.element_id == identifier:
+ return pipeline
+ raise KeyError(f"No pipeline summary found for identifier '{identifier}'.")
+
+ def post(self, resource: object) -> None:
+ """Create a pipeline from its compact representation."""
+ if not isinstance(resource, CompactPipeline):
+ raise TypeError("Pipeline creation requires a CompactPipeline.")
+
+ self._make_request(
+ request_method=self._parent_client.request_session.post,
+ url=self._compact_url,
+ data=json.dumps(resource.to_dict(use_source_names=True)),
+ headers={"Content-type": "application/json"},
+ )
+
+ def put(self, resource: object, identifier: str | None = None) -> None:
+ """Reject pipeline updates, which are intentionally unsupported."""
+ raise NotImplementedError("Updating pipelines is not supported by the Python client.")
+
+ def delete(self, identifier: str) -> None:
+ """Delete a pipeline."""
+ self._make_request(
+ request_method=self._parent_client.request_session.delete,
+ url=f"{self.build_url()}/{identifier}",
+ )
+
+ def start(self, identifier: str) -> None:
+ """Start a pipeline by identifier."""
+ self._make_request(
+ request_method=self._parent_client.request_session.get,
+ url=f"{self.build_url()}/{identifier}/start",
+ )
+
+ def stop(self, identifier: str) -> None:
+ """Stop a pipeline by identifier."""
+ self._make_request(
+ request_method=self._parent_client.request_session.get,
+ url=f"{self.build_url()}/{identifier}/stop",
+ )
diff --git a/streampipes-client-python/streampipes/endpoint/endpoint.py b/streampipes-client-python/streampipes/endpoint/endpoint.py
index a29a04a63c..6cc8840d67 100644
--- a/streampipes-client-python/streampipes/endpoint/endpoint.py
+++ b/streampipes-client-python/streampipes/endpoint/endpoint.py
@@ -148,13 +148,16 @@ class APIEndpoint(Endpoint):
status_code = err.response.status_code
# get custom error message based on the returned status code
- error_message = _error_code_to_message[status_code]
+ error_message = _error_code_to_message.get(
+ status_code,
+ "\nThe StreamPipes Backend returned an unexpected HTTP error.\n",
+ )
if status_code in [
HTTPStatus.BAD_REQUEST.numerator,
HTTPStatus.METHOD_NOT_ALLOWED.numerator,
HTTPStatus.NOT_FOUND.numerator,
- ]:
+ ] or status_code not in _error_code_to_message:
error_message += f"url: {err.response.url}\nstatus code: {status_code}"
logger.debug(f"HTTP error response: {err.response.text}")