def post(self, request, *args, **kwargs): result = {} try: service_id = request.POST.get("service_id", "") dependency = request.POST.get("condition", "") logger.debug(service_id + "=" + dependency) if service_id is not None and service_id != "" and dependency != "": dps = json.loads(dependency) language = dps["language"] if language is not None and language != "" and language != "no": try: tse = TenantServiceEnv.objects.get( service_id=service_id) tse.language = language tse.check_dependency = dependency tse.save() except Exception: tse = TenantServiceEnv(service_id=service_id, language=language, check_dependency=dependency) tse.save() service = TenantServiceInfo.objects.get( service_id=service_id) if language != "false": if language.find( "Java") > -1 and service.min_memory < 512: service.min_memory = 512 service.language = language service.save() result["status"] = "success" except Exception as e: logger.exception(e) result["status"] = "failure" return HttpResponse(json.dumps(result))
def post(self, request, format=None): """ 代码检测 --- parameters: - name: service_id description: 租户ID required: false type: string paramType: form - name: condition description: 检测条件 required: false type: string paramType: form """ data = {} try: service_id = request.data.get('service_id', "") dependency = request.data.get("condition", "") check_type = request.data.get('check_type', 'first_check') logger.debug(service_id + "=" + dependency) if service_id != "" and dependency != "": if check_type == 'first_check': dps = json.loads(dependency) language = dps["language"] if language is not None and language != "" and language != "no": try: tse = TenantServiceEnv.objects.get( service_id=service_id) tse.language = language tse.check_dependency = dependency tse.save() except Exception: tse = TenantServiceEnv(service_id=service_id, language=language, check_dependency=dependency) tse.save() service = TenantServiceInfo.objects.get( service_id=service_id) if language != "false": if language.find( "Java") > -1 and service.min_memory < 512: service.min_memory = 512 service.language = language service.save() elif check_type == 'git_change': code_version = request.data.get("code_version", "master") git_project_id = request.data.get("git_project_id", "0") code_from = request.data.get("code_from", "gitlab_manual") url_repos = request.data.get("url_repos") dps = json.loads(dependency) language = dps["language"] if language is not None and language != "" and language != "no" and language != "false": tenantService = TenantServiceInfo.objects.get( service_id=service_id) try: if tenantService.language != language: tenantService.language = language tenantService.code_version = code_version tenantService.git_project_id = git_project_id tenantService.code_from = code_from tenantService.git_url = url_repos tenantService.save() tse = TenantServiceEnv.objects.get( service_id=service_id) tse.language = language tse.check_dependency = dependency checkJson = self.get_language_env(language) tse.user_dependency = json.dumps(checkJson) tse.save() if language.find( "Java" ) > -1 and tenantService.min_memory < 512: tenantService.min_memory = 512 data = {} data["language"] = "java" tenant = Tenants.objects.get( tenant_id=tenantService.tenant_id) event_id = self.create_service_event( tenant, tenantService) data["event_id"] = event_id data[ "enterprise_id"] = tenant.enterprise_id region_api.change_memory( tenantService.service_region, tenant.tenant_name, tenantService.service_alias, data) tenantService.language = language tenantService.save() else: tenantService.code_version = code_version tenantService.git_project_id = git_project_id tenantService.code_from = code_from tenantService.git_url = url_repos tenantService.save() except TenantServiceEnv.DoesNotExist: tse = TenantServiceEnv(service_id=service_id, language=language, check_dependency=dependency) tse.save() data["status"] = "success" except Exception as e: logger.exception(e) data["status"] = "failure" return Response(data, status=200)