1 # Copyright 2017 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.
19 from rest_framework import status
20 from rest_framework.decorators import api_view
21 from rest_framework.response import Response
23 from lcm.pub.database.models import WFPlanModel
24 from lcm.pub.utils.syscomm import fun_name
25 from lcm.pub.utils.values import ignore_case_get
26 from lcm.pub.msapi import activiti
29 logger = logging.getLogger(__name__)
32 @api_view(http_method_names=['POST'])
33 def deploy_workflow(request, *args, **kwargs):
34 logger.debug("Enter %s", fun_name())
36 file_path = ignore_case_get(request.data, "filePath")
37 force_deploy = ignore_case_get(request.data, "forceDeploy")
38 logger.debug("file_path is %s, force_deploy is %s", file_path, force_deploy)
39 if force_deploy.upper() == "TRUE":
40 plans = WFPlanModel.objects.filter()
42 activiti.undeploy_workflow(plans[0].deployed_id)
45 if WFPlanModel.objects.filter():
46 logger.warn("Already deployed.")
47 return Response(data={'msg': 'Already deployed.'}, status=status.HTTP_202_ACCEPTED)
48 deploy_info = activiti.deploy_workflow(file_path)
50 deployed_id=deploy_info["deployedId"],
51 process_id=deploy_info["processId"],
52 status=deploy_info["status"],
53 message=deploy_info["message"],
54 plan_name="ns_instantiate").save()
56 logger.error(traceback.format_exc())
57 return Response(data={'error': str(sys.exc_info())}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
58 logger.debug("Leave %s", fun_name())
59 return Response(data={'msg': 'OK'}, status=status.HTTP_202_ACCEPTED)