summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-26 13:09:59 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-01-26 13:09:59 +0800
commit4b0405b68e89e357120c28faf5f9b311a7cc7206 (patch)
tree54cd4419daa0cd77c9146253543c6fafe4c70727 /lcm
parentc8885020c54db7deb9bf2d490d4a9eee6601cfca (diff)
Add vfc-vnflcm get_jobs auto-swagger
Change-Id: I09c70b7be25b51848ba27ca1441c77353e948ce0 Issue-ID: VFC-682 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/jobs/serializers.py11
-rw-r--r--lcm/lcm/jobs/views.py28
2 files changed, 24 insertions, 15 deletions
diff --git a/lcm/lcm/jobs/serializers.py b/lcm/lcm/jobs/serializers.py
index 61fa2dda..afaa40e8 100644
--- a/lcm/lcm/jobs/serializers.py
+++ b/lcm/lcm/jobs/serializers.py
@@ -35,14 +35,3 @@ class JobDescriptorSerializer(serializers.Serializer):
class JobQueryRespSerializer(serializers.Serializer):
jobId = serializers.CharField(help_text="UUID of job", required=True)
responseDescriptor = JobDescriptorSerializer(help_text="Descriptor of job", required=False)
-
-
-class JobUpdReqSerializer(serializers.Serializer):
- progress = serializers.CharField(help_text="Progress of job", required=True)
- desc = serializers.CharField(help_text="Desc of job", required=False)
- errcode = serializers.CharField(help_text="Error code of job", required=False)
-
-
-class JobUpdRespSerializer(serializers.Serializer):
- result = serializers.CharField(help_text="Result of job update", required=True)
- msg = serializers.CharField(help_text="Detail of job update", required=False)
diff --git a/lcm/lcm/jobs/views.py b/lcm/lcm/jobs/views.py
index 57a999b4..37318639 100644
--- a/lcm/lcm/jobs/views.py
+++ b/lcm/lcm/jobs/views.py
@@ -13,17 +13,37 @@
# limitations under the License.
import logging
+import traceback
+from drf_yasg.utils import swagger_auto_schema
+from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
-from lcm.pub.utils.values import ignore_case_get
+
from lcm.jobs.job_get import GetJobInfoService
+from lcm.jobs.serializers import JobQueryRespSerializer
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
class JobView(APIView):
+ @swagger_auto_schema(
+ request_body=None,
+ responses={
+ status.HTTP_200_OK: JobQueryRespSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
def get(self, request, job_id):
- response_id = ignore_case_get(request.META, 'responseId')
- ret = GetJobInfoService(job_id, response_id).do_biz()
- return Response(data=ret)
+ try:
+ response_id = ignore_case_get(request.META, 'responseId')
+ ret = GetJobInfoService(job_id, response_id).do_biz()
+ resp_serializer = JobQueryRespSerializer(data=ret)
+ if not resp_serializer.is_valid():
+ raise NFLCMException(resp_serializer.errors)
+ return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
+ except Exception as e:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)