diff --git a/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/HttpUtils.java b/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/HttpUtils.java index 299e145615..a4cd9f4698 100644 --- a/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/HttpUtils.java +++ b/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/HttpUtils.java @@ -59,8 +59,7 @@ public static Response httpClientHandleBase(String actionUrl, RequestBody reques public static String httpClientHandle(String actionUrl, RequestBody requestBody, Map urlMap) throws Exception{ String returnData = ""; - try { - Response response = httpClientHandleBase(actionUrl, requestBody, urlMap); + try (Response response = httpClientHandleBase(actionUrl, requestBody, urlMap)) { returnData = response.body().string(); logger.info("mask interface return message:" + returnData); } catch (IOException e) { @@ -80,8 +79,7 @@ public static String httpClientHandle(String actionUrl) throws Exception{ .build(); Call call = okHttpClient.newCall(request); String returnData = ""; - try { - Response response = call.execute(); + try (Response response = call.execute()) { returnData = response.body().string(); logger.info("interface return message:" + returnData); } catch (IOException e) { diff --git a/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/QualitisUtil.java b/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/QualitisUtil.java index 8d371efebc..ff7fb18340 100644 --- a/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/QualitisUtil.java +++ b/dss-appconn/appconns/dss-datachecker-appconn/src/main/java/com/webank/wedatasphere/dss/appconn/datachecker/utils/QualitisUtil.java @@ -94,22 +94,24 @@ public String submitTask(long groupId, String createUser, String executionUser) .build(); Call call = okHttpClient.newCall(request); - Response response = call.execute(); - String resultJson = response.body().string(); - logger.info("Response Json: " + resultJson); - if (StringUtils.isNotEmpty(resultJson)) { - Map resultMap = DSSCommonUtils.COMMON_GSON.fromJson(resultJson,Map.class); - logger.info(String.valueOf(resultMap)); - String code = (String) resultMap.get("code"); - if ("200".equals(code)) { - applicationId = (String) ((Map) resultMap.get("data")).get( - "application_id"); - logger.info(resultMap.get("message").toString()); - } else { - throw new RuntimeException(resultMap.get("message").toString()); + try (Response response = call.execute()) { + String resultJson = response.body().string(); + logger.info("Response Json: " + resultJson); + if (StringUtils.isNotEmpty(resultJson)) { + Map resultMap = DSSCommonUtils.COMMON_GSON.fromJson(resultJson, Map.class); + logger.info(String.valueOf(resultMap)); + String code = (String) resultMap.get("code"); + if ("200".equals(code)) { + applicationId = (String) ((Map) resultMap.get("data")).get( + "application_id"); + logger.info(resultMap.get("message").toString()); + return applicationId; + } else { + throw new RuntimeException(resultMap.get("message").toString()); + } } } - return applicationId; + return null; } public String createAndSubmitRule(CheckDataObject dataObject,String projectName,String ruleName,String user) throws IOException { @@ -161,24 +163,26 @@ public String createAndSubmitRule(CheckDataObject dataObject,String projectName, .build(); Call call = okHttpClient.newCall(request); - Response response = call.execute(); - String resultJson = response.body().string(); - logger.info("call qualitis end,Response Json:{} " , resultJson); - if (StringUtils.isNotEmpty(resultJson)) { - Map resultMap = DSSCommonUtils.COMMON_GSON.fromJson(resultJson,Map.class); - String code = (String) resultMap.get("code"); - if ("200".equals(code)) { - Map applicationDetail = (Map) ((Map) (resultMap.get( - "data"))).get("application_detail"); - Map project_application = ((List>) (applicationDetail.get( - "project_applications"))).get(0); - applicationId = (String) project_application.get("application_id"); - logger.info(resultMap.get("message").toString()); - } else { - throw new RuntimeException(resultMap.get("message").toString()); + try (Response response = call.execute()) { + String resultJson = response.body().string(); + logger.info("call qualitis end,Response Json:{} ", resultJson); + if (StringUtils.isNotEmpty(resultJson)) { + Map resultMap = DSSCommonUtils.COMMON_GSON.fromJson(resultJson, Map.class); + String code = (String) resultMap.get("code"); + if ("200".equals(code)) { + Map applicationDetail = (Map) ((Map) (resultMap.get( + "data"))).get("application_detail"); + Map project_application = ((List>) (applicationDetail.get( + "project_applications"))).get(0); + applicationId = (String) project_application.get("application_id"); + logger.info(resultMap.get("message").toString()); + return applicationId; + } else { + throw new RuntimeException(resultMap.get("message").toString()); + } } } - return applicationId; + return null; } /** @@ -215,11 +219,9 @@ public String getTaskStatus(String applicationId){ .build(); Call call = okHttpClient.newCall(request); - Response response = null; String resultJson = ""; String status = ""; - try { - response = call.execute(); + try (Response response = call.execute()) { resultJson = response.body().string(); logger.info("Response Json: " + resultJson); if (StringUtils.isNotEmpty(resultJson)) { diff --git a/dss-orchestrator/orchestrators/dss-workflow/dss-workflow-server/src/main/java/com/webank/wedatasphere/dss/workflow/io/input/impl/NodeInputServiceImpl.java b/dss-orchestrator/orchestrators/dss-workflow/dss-workflow-server/src/main/java/com/webank/wedatasphere/dss/workflow/io/input/impl/NodeInputServiceImpl.java index da185f234e..2ddc20374e 100644 --- a/dss-orchestrator/orchestrators/dss-workflow/dss-workflow-server/src/main/java/com/webank/wedatasphere/dss/workflow/io/input/impl/NodeInputServiceImpl.java +++ b/dss-orchestrator/orchestrators/dss-workflow/dss-workflow-server/src/main/java/com/webank/wedatasphere/dss/workflow/io/input/impl/NodeInputServiceImpl.java @@ -144,34 +144,36 @@ public String uploadAppConnResourceNew(String userName, String projectName, DSSF logger.info("nodeResourcePath:{}", nodeResourcePath); File file = new File(nodeResourcePath); if (file.exists()) { - InputStream resourceInputStream = bmlService.readLocalResourceFile(userName, nodeResourcePath); - Supplier> bmlResourceMap = () -> { - BmlResource resource = bmlService.upload(userName, resourceInputStream, UUID.randomUUID().toString() + ".json", - projectName); - return ImmutableMap.of( - "resourceId", resource.getResourceId(), - "version", resource.getVersion() - ); - }; - Supplier> streamResourceMap = () -> MapUtils.newCommonMap(ImportRequestRef.INPUT_STREAM_KEY, resourceInputStream); - try { - nodeExportContent = nodeService.importNode(userName, appConnNode, bmlResourceMap, streamResourceMap, orcVersion); - } catch (ExternalOperationFailedException e) { - logger.error("failed to import node.", e); - throw new DSSRuntimeException(e.getErrCode(), e.getMessage()); - } catch (Exception e) { - logger.error("failed to import node.", e); - throw new DSSRuntimeException(90011, e.getMessage()); - } - if (nodeExportContent != null) { - if (nodeExportContent.get("project_id") != null) { - Long newProjectId = Long.parseLong(nodeExportContent.get("project_id").toString()); - logger.warn(String.format("new appConn node add into dss,dssProjectId: %s,newProjectId: %s", appConnNode.getProjectId(), newProjectId)); - nodeExportContent.remove("project_id"); + try (InputStream resourceInputStream = bmlService.readLocalResourceFile(userName, nodeResourcePath)) { + Supplier> bmlResourceMap = () -> { + BmlResource resource = bmlService.upload(userName, resourceInputStream, UUID.randomUUID().toString() + ".json", + projectName); + return ImmutableMap.of( + "resourceId", resource.getResourceId(), + "version", resource.getVersion() + ); + }; + + Supplier> streamResourceMap = () -> MapUtils.newCommonMap(ImportRequestRef.INPUT_STREAM_KEY, resourceInputStream); + try { + nodeExportContent = nodeService.importNode(userName, appConnNode, bmlResourceMap, streamResourceMap, orcVersion); + } catch (ExternalOperationFailedException e) { + logger.error("failed to import node.", e); + throw new DSSRuntimeException(e.getErrCode(), e.getMessage()); + } catch (Exception e) { + logger.error("failed to import node.", e); + throw new DSSRuntimeException(90011, e.getMessage()); + } + if (nodeExportContent != null) { + if (nodeExportContent.get("project_id") != null) { + Long newProjectId = Long.parseLong(nodeExportContent.get("project_id").toString()); + logger.warn(String.format("new appConn node add into dss,dssProjectId: %s,newProjectId: %s", appConnNode.getProjectId(), newProjectId)); + nodeExportContent.remove("project_id"); + } + nodeJsonMap.replace("jobContent", nodeExportContent); + appConnNode.setJobContent(nodeExportContent); + return BDPJettyServerHelper.jacksonJson().writeValueAsString(nodeJsonMap); } - nodeJsonMap.replace("jobContent", nodeExportContent); - appConnNode.setJobContent(nodeExportContent); - return BDPJettyServerHelper.jacksonJson().writeValueAsString(nodeJsonMap); } } else { logger.warn("appConn node resource file does not exists. nodeId: {}" + nodeId); @@ -209,34 +211,35 @@ public String uploadAppConnResource(String userName, String projectName, DSSFlow logger.info("nodeResourcePath:{}", nodeResourcePath); File file = new File(nodeResourcePath); if (file.exists()) { - InputStream resourceInputStream = bmlService.readLocalResourceFile(userName, nodeResourcePath); - Supplier> bmlResourceMap = () -> { - BmlResource resource = bmlService.upload(userName, resourceInputStream, UUID.randomUUID().toString() + ".json", - projectName); - return ImmutableMap.of( - "resourceId", resource.getResourceId(), - "version", resource.getVersion() - ); - }; - Supplier> streamResourceMap = () -> MapUtils.newCommonMap(ImportRequestRef.INPUT_STREAM_KEY, resourceInputStream); - try { - nodeExportContent = nodeService.importNode(userName, appConnNode, bmlResourceMap, streamResourceMap, orcVersion); - } catch (ExternalOperationFailedException e) { - logger.error("failed to import node.", e); - throw new DSSRuntimeException(e.getErrCode(), e.getMessage()); - } catch (Exception e) { - logger.error("failed to import node.", e); - throw new DSSRuntimeException(90011, e.getMessage()); - } - if (nodeExportContent != null) { - if (nodeExportContent.get("project_id") != null) { - Long newProjectId = Long.parseLong(nodeExportContent.get("project_id").toString()); - logger.warn(String.format("new appConn node add into dss,dssProjectId: %s,newProjectId: %s", appConnNode.getProjectId(), newProjectId)); - nodeExportContent.remove("project_id"); + try (InputStream resourceInputStream = bmlService.readLocalResourceFile(userName, nodeResourcePath)) { + Supplier> bmlResourceMap = () -> { + BmlResource resource = bmlService.upload(userName, resourceInputStream, UUID.randomUUID().toString() + ".json", + projectName); + return ImmutableMap.of( + "resourceId", resource.getResourceId(), + "version", resource.getVersion() + ); + }; + Supplier> streamResourceMap = () -> MapUtils.newCommonMap(ImportRequestRef.INPUT_STREAM_KEY, resourceInputStream); + try { + nodeExportContent = nodeService.importNode(userName, appConnNode, bmlResourceMap, streamResourceMap, orcVersion); + } catch (ExternalOperationFailedException e) { + logger.error("failed to import node.", e); + throw new DSSRuntimeException(e.getErrCode(), e.getMessage()); + } catch (Exception e) { + logger.error("failed to import node.", e); + throw new DSSRuntimeException(90011, e.getMessage()); + } + if (nodeExportContent != null) { + if (nodeExportContent.get("project_id") != null) { + Long newProjectId = Long.parseLong(nodeExportContent.get("project_id").toString()); + logger.warn(String.format("new appConn node add into dss,dssProjectId: %s,newProjectId: %s", appConnNode.getProjectId(), newProjectId)); + nodeExportContent.remove("project_id"); + } + nodeJsonMap.replace("jobContent", nodeExportContent); + appConnNode.setJobContent(nodeExportContent); + return BDPJettyServerHelper.jacksonJson().writeValueAsString(nodeJsonMap); } - nodeJsonMap.replace("jobContent", nodeExportContent); - appConnNode.setJobContent(nodeExportContent); - return BDPJettyServerHelper.jacksonJson().writeValueAsString(nodeJsonMap); } } else { logger.warn("appConn node resource file does not exists. nodeId: {}" + nodeId);