1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from lcm.jobs.const import JOB_INSTANCE_URI
18 from lcm.workflows.graphflow.task.async_rest_task import ASyncRestTask
19 from lcm.pub.utils import restcall
21 logger = logging.getLogger(__name__)
24 class LcmASyncRestTask(ASyncRestTask):
26 METHOD_GET_JOB_STATUS = "status"
28 def __init__(self, *args):
29 super(LcmASyncRestTask, self).__init__(*args)
30 # self.job_url = JOB_INSTANCE_URI
32 def call_rest(self, url, method, content=None):
33 ret = restcall.req_by_msb(url, method, content)
34 return ret[2], json.JSONDecoder().decode(ret[1])
36 def get_ext_status(self):
37 job_id = self.parse_job_id()
38 logger.debug("get_ext_status %s", self.key)
41 url = JOB_INSTANCE_URI % job_id
42 status, job_result = self.call_rest(url, self.GET)
43 if status in self.STATUS_OK:
44 progress = job_result["responseDescriptor"]["progress"]
46 job_status = self.FINISHED
48 job_status = self.ERROR
50 job_status = self.PROCESSING
53 def parse_job_id(self):
55 return self.output["jobId"] if "jobId" in self.output else None