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

feat: adaptation to the new version of middleware #66

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 20 additions & 22 deletions era_5g_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from era_5g_client.client_base import NetAppClientBase
from era_5g_client.dataclasses import MiddlewareInfo
from era_5g_client.exceptions import FailedToConnect, FailedToDeleteResource, FailedToObtainPlan, NetAppNotReady
from era_5g_client.exceptions import FailedToConnect, FailedToDeleteResource, NetAppNotReady
from era_5g_client.middleware_resource_checker import MiddlewareResourceChecker
from era_5g_interface.channels import CallbackInfoClient

Expand Down Expand Up @@ -118,7 +118,6 @@ def run_task(
is True. Defaults to None.

Raises:
FailedToObtainPlan: Raised when could not get the plan.
FailedToConnect: Raised when running the task failed.
"""

Expand All @@ -128,7 +127,7 @@ def run_task(
task_id, resource_lock, robot_id
) # Get the plan_id by sending the token and task_id.
if not self.action_plan_id:
raise FailedToObtainPlan("Failed to obtain action plan id...")
raise FailedToConnect("Failed to obtain action plan id...")

self.resource_checker = MiddlewareResourceChecker(
str(self.token),
Expand Down Expand Up @@ -267,29 +266,28 @@ def gateway_get_plan(self, taskid: str, resource_lock: bool, robot_id: str) -> s

assert self.middleware_info
# Request plan.
try:
self.logger.debug("Goal task is: " + str(taskid))
hed = {"Authorization": f"Bearer {str(self.token)}"}
data = {
"TaskId": str(taskid),
"LockResourceReUse": resource_lock,
"RobotId": robot_id,
}
r = requests.post(self.middleware_info.build_api_endpoint("Task/Plan"), json=data, headers=hed)
response = r.json()
self.logger.debug("Goal task is: " + str(taskid))
hed = {"Authorization": f"Bearer {str(self.token)}"}
data = {
"TaskId": str(taskid),
"DisableResourceReuse": resource_lock,
"RobotId": robot_id,
}
r = requests.post(self.middleware_info.build_api_endpoint("Task/Plan"), json=data, headers=hed)
response = r.json()

if not isinstance(response, dict):
raise FailedToConnect("Invalid response.")

if "statusCode" in response and (response["statusCode"] == 500 or response["statusCode"] == 400):
raise FailedToConnect(f"response {response['statusCode']}: {response['message']}")

if not isinstance(response, Dict):
raise FailedToConnect("Invalid response.")

if "statusCode" in response and (response["statusCode"] == 500 or response["statusCode"] == 400):
raise FailedToConnect(f"response {response['statusCode']}: {response['message']}")
# TODO: if "errors" in response:
# raise FailedToConnect(str(response["errors"]))
action_plan_id = str(response["ActionPlanId"])
try:
action_plan_id = str(response["task"]["ActionPlanId"])
self.logger.debug("ActionPlanId ** is: " + str(action_plan_id))
return action_plan_id
except KeyError as e:
raise FailedToObtainPlan(f"Could not get the plan: {e}")
raise FailedToConnect(f"Could not get the plan: {e}")

def delete_all_resources(self) -> None:
"""Delete all resources.
Expand Down
6 changes: 0 additions & 6 deletions era_5g_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ class FailedToInitialize(Era5gClientException):
pass


class FailedToObtainPlan(Era5gClientException):
"""Exception which is raised when the client could not get the plan from the Middleware."""

pass


class FailedToDeleteResource(Era5gClientException):
"""Exception which is raised when the client could not when could not delete Middleware resource."""

Expand Down
Loading