Optimize the ptp status pull request handler
return 404 in case that nodeinfo is not available Story: 2008529 Task: 41873 Signed-off-by: Bin Yang <bin.yang@windriver.com> Change-Id: Id608a37fd6d93052df338aac663892f20d5ca5b1
This commit is contained in:
parent
1e3fa666e9
commit
4481a7f00c
@ -1,5 +1,6 @@
|
||||
import oslo_messaging
|
||||
import logging
|
||||
import json
|
||||
|
||||
from notificationclientsdk.repository.node_repo import NodeRepo
|
||||
from notificationclientsdk.repository.subscription_repo import SubscriptionRepo
|
||||
@ -30,6 +31,20 @@ class PtpService(object):
|
||||
return
|
||||
|
||||
def query(self, broker_node_name):
|
||||
default_node_name = NodeInfoHelper.default_node_name(broker_node_name)
|
||||
nodeinfo_repo = NodeRepo(autocommit=False)
|
||||
nodeinfo = nodeinfo_repo.get_one(Status=1, NodeName=default_node_name)
|
||||
# check node availability from DB
|
||||
if not nodeinfo:
|
||||
raise client_exception.NodeNotAvailable(broker_node_name)
|
||||
else:
|
||||
supported_resource_types = json.loads(nodeinfo.ResourceTypes or '[]')
|
||||
if ResourceType.TypePTP in supported_resource_types:
|
||||
return self._query(default_node_name)
|
||||
else:
|
||||
raise client_exception.ResourceNotAvailable(default_node_name, ResourceType.TypePTP)
|
||||
|
||||
def _query(self, broker_node_name):
|
||||
broker_host = "notificationservice-{0}".format(broker_node_name)
|
||||
broker_transport_endpoint = "rabbit://{0}:{1}@{2}:{3}".format(
|
||||
self.daemon_control.daemon_context['NOTIFICATION_BROKER_USER'],
|
||||
@ -63,7 +78,7 @@ class PtpService(object):
|
||||
if default_node_name:
|
||||
ptpstatus = None
|
||||
try:
|
||||
ptpstatus = self.query(default_node_name)
|
||||
ptpstatus = self._query(default_node_name)
|
||||
LOG.info("initial ptpstatus:{0}".format(ptpstatus))
|
||||
except oslo_messaging.exceptions.MessagingTimeout as ex:
|
||||
LOG.warning("ptp status is not available @node {0} due to {1}".format(
|
||||
|
@ -8,8 +8,10 @@ from wsmeext.pecan import wsexpose
|
||||
|
||||
import os
|
||||
import logging
|
||||
import oslo_messaging
|
||||
|
||||
from notificationclientsdk.services.ptp import PtpService
|
||||
from notificationclientsdk.exception import client_exception
|
||||
|
||||
from sidecar.repository.notification_control import notification_control
|
||||
|
||||
@ -31,6 +33,15 @@ class CurrentStateController(rest.RestController):
|
||||
ptpstatus = ptpservice.query(THIS_NODE_NAME)
|
||||
# response.status = 200
|
||||
return ptpstatus
|
||||
except client_exception.NodeNotAvailable as ex:
|
||||
LOG.warning("Node is not available:{0}".format(str(ex)))
|
||||
abort(404)
|
||||
except client_exception.ResourceNotAvailable as ex:
|
||||
LOG.warning("Resource is not available:{0}".format(str(ex)))
|
||||
abort(404)
|
||||
except oslo_messaging.exceptions.MessagingTimeout as ex:
|
||||
LOG.warning("Resource is not reachable:{0}".format(str(ex)))
|
||||
abort(404)
|
||||
except HTTPException as ex:
|
||||
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
|
||||
# raise ex
|
||||
|
Loading…
x
Reference in New Issue
Block a user