From 5fbd2178f7422d21cf6d7aad6dcdda10346ca853 Mon Sep 17 00:00:00 2001 From: FishJoy Date: Thu, 19 Jun 2025 12:45:22 +0800 Subject: [PATCH 1/2] fix(reasoner): remove useless code --- .../reasoner/progress/DecryptUtils.java | 57 --------- .../reasoner/sink/KgReasonerSinkUtils.java | 112 ------------------ 2 files changed, 169 deletions(-) delete mode 100644 reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/progress/DecryptUtils.java delete mode 100644 reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/sink/KgReasonerSinkUtils.java diff --git a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/progress/DecryptUtils.java b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/progress/DecryptUtils.java deleted file mode 100644 index 644b01043..000000000 --- a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/progress/DecryptUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2023 OpenSPG Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. - */ - -package com.antgroup.openspg.reasoner.progress; - -import java.io.Serializable; -import java.security.Key; -import java.util.Base64; -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DecryptUtils implements Serializable { - private static final Logger log = LoggerFactory.getLogger(DecryptUtils.class); - - private static final String key = "triedthisfunctio"; - - public static String encryptAccessInfo(String info) { - try { - Key aesKey = new SecretKeySpec(key.getBytes(), "AES"); - Cipher cipher = Cipher.getInstance("AES"); - // encrypt the text - cipher.init(Cipher.ENCRYPT_MODE, aesKey); - byte[] encrypted = cipher.doFinal(info.getBytes()); - return Base64.getEncoder().encodeToString(encrypted); - } catch (Exception e) { - log.error("encrypt error", e); - } - return null; - } - - public static String decryptAccessInfo(String code) { - // Create key and cipher - try { - byte[] codeBytes = Base64.getDecoder().decode(code); - Key aesKey = new SecretKeySpec(key.getBytes(), "AES"); - Cipher cipher = Cipher.getInstance("AES"); - // decrypt the text - cipher.init(Cipher.DECRYPT_MODE, aesKey); - return new String(cipher.doFinal(codeBytes)); - } catch (Exception e) { - log.error("decrypt error", e); - } - return null; - } -} diff --git a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/sink/KgReasonerSinkUtils.java b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/sink/KgReasonerSinkUtils.java deleted file mode 100644 index 19805b3a8..000000000 --- a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/sink/KgReasonerSinkUtils.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2023 OpenSPG Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. - */ - -package com.antgroup.openspg.reasoner.sink; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.antgroup.openspg.reasoner.io.model.AbstractTableInfo; -import com.antgroup.openspg.reasoner.io.model.CanvasTableInfo; -import com.antgroup.openspg.reasoner.io.model.HiveTableInfo; -import com.antgroup.openspg.reasoner.io.model.OdpsTableInfo; -import com.antgroup.openspg.reasoner.io.model.SLSTableInfo; -import com.antgroup.openspg.reasoner.progress.DecryptUtils; -import com.antgroup.openspg.reasoner.runner.ConfigKey; -import java.util.HashMap; -import java.util.Map; - -public class KgReasonerSinkUtils { - - /** get sink type from config params */ - public static KgReasonerSinkType getKgReasonerSinkType(Map params) { - JSONObject outputTableConfig = getOutputTableConfig(params); - if (null == outputTableConfig) { - return KgReasonerSinkType.LOG; - } - String outputType = outputTableConfig.getString("type"); - return KgReasonerSinkType.valueOf(outputType.toUpperCase()); - } - - /** get sink table info from config */ - public static AbstractTableInfo getSinkTableInfo(Map params) { - KgReasonerSinkType sinkType = getKgReasonerSinkType(params); - if (KgReasonerSinkType.ODPS.equals(sinkType)) { - JSONObject outputTableConfig = getOutputTableConfig(params); - assert outputTableConfig != null; - // odps config - JSONObject odpsConfig = - outputTableConfig.getJSONArray(KgReasonerSinkType.ODPS.name()).getJSONObject(0); - OdpsTableInfo odpsTableInfo = new OdpsTableInfo(); - odpsTableInfo.setProject(odpsConfig.getString("project")); - odpsTableInfo.setTable(odpsConfig.getString("table")); - odpsTableInfo.setAccessID(odpsConfig.getString("accessId")); - odpsTableInfo.setAccessKey(DecryptUtils.decryptAccessInfo(odpsConfig.getString("accessKey"))); - odpsTableInfo.setEndPoint(odpsConfig.getString("endPoint")); - odpsTableInfo.setTunnelEndPoint(odpsConfig.getString("tunnelEndpoint")); - // partition table - JSONObject partitionJsonObj = outputTableConfig.getJSONObject("partition"); - if (null != partitionJsonObj) { - Map partitionMap = new HashMap<>(); - partitionJsonObj.forEach((key, value) -> partitionMap.put(key, String.valueOf(value))); - odpsTableInfo.setPartition(partitionMap); - } - return odpsTableInfo; - } else if (KgReasonerSinkType.HIVE.equals(sinkType)) { - String tableInfoStr = String.valueOf(params.get(ConfigKey.KG_REASONER_SINK_TABLE_INFO)); - return JSON.parseObject(tableInfoStr, HiveTableInfo.class); - } else if (KgReasonerSinkType.CANVAS.equals(sinkType)) { - JSONObject outputTableConfig = getOutputTableConfig(params); - assert outputTableConfig != null; - CanvasTableInfo canvasTableInfo = new CanvasTableInfo(); - canvasTableInfo.setQueryId(outputTableConfig.getString("queryId")); - canvasTableInfo.setApiPath(outputTableConfig.getString("canvasUrl")); - return canvasTableInfo; - } else if (KgReasonerSinkType.REALTIME.equals(sinkType)) { - JSONObject outputTableConfig = getOutputTableConfig(params); - assert outputTableConfig != null; - String slsConfigStr = outputTableConfig.getString("SLS"); - assert slsConfigStr != null; - JSONObject slsConfigs = JSON.parseObject(slsConfigStr); - Object devId = params.get(ConfigKey.DEV_ID); - assert devId != null; - SLSTableInfo slsTableInfo = new SLSTableInfo(); - slsTableInfo.setProject(slsConfigs.getString("project")); - slsTableInfo.setEndpoint(slsConfigs.getString("endpoint")); - slsTableInfo.setLogStore(slsConfigs.getString("logStore")); - slsTableInfo.setAccessId(slsConfigs.getString("accessId")); - slsTableInfo.setAccessKey(DecryptUtils.decryptAccessInfo(slsConfigs.getString("accessKey"))); - slsTableInfo.setTaskId(String.valueOf(devId)); - return slsTableInfo; - } - return null; - } - - /** get write file */ - public static String getKgReasonerSinkFile(Map params) { - return String.valueOf(params.get(ConfigKey.KG_REASONER_SINK_FILE)); - } - - private static JSONObject getOutputTableConfig(Map params) { - JSONObject outputTableConfig; - Object outputTableConfigObj = params.get(ConfigKey.KG_REASONER_OUTPUT_TABLE_CONFIG); - if (null == outputTableConfigObj) { - return null; - } - if (outputTableConfigObj instanceof String) { - outputTableConfig = JSON.parseObject(String.valueOf(outputTableConfigObj)); - } else { - outputTableConfig = (JSONObject) outputTableConfigObj; - } - return outputTableConfig; - } -} From c18b6ea3d12a0b1bc845b8794c8c602cb7f8f31a Mon Sep 17 00:00:00 2001 From: FishJoy Date: Thu, 19 Jun 2025 14:04:45 +0800 Subject: [PATCH 2/2] fix(reasoner): remove useless code --- .../account/impl/AccountServiceDefaultImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/common/service/src/main/java/com/antgroup/openspg/server/common/service/account/impl/AccountServiceDefaultImpl.java b/server/common/service/src/main/java/com/antgroup/openspg/server/common/service/account/impl/AccountServiceDefaultImpl.java index 931031c6c..3a323832c 100644 --- a/server/common/service/src/main/java/com/antgroup/openspg/server/common/service/account/impl/AccountServiceDefaultImpl.java +++ b/server/common/service/src/main/java/com/antgroup/openspg/server/common/service/account/impl/AccountServiceDefaultImpl.java @@ -1,3 +1,16 @@ +/* + * Copyright 2023 OpenSPG Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. + */ + package com.antgroup.openspg.server.common.service.account.impl; import com.antgroup.openspg.server.api.facade.Paged;