You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ja...@apache.org on 2023/03/07 10:19:09 UTC
[linkis] branch dev-1.3.2 updated: Fix CS creates ContextID concurrency bug (#4318)
This is an automated email from the ASF dual-hosted git repository.
jackxu2011 pushed a commit to branch dev-1.3.2
in repository https://gitbox.apache.org/repos/asf/linkis.git
The following commit(s) were added to refs/heads/dev-1.3.2 by this push:
new 59d0c97aa Fix CS creates ContextID concurrency bug (#4318)
59d0c97aa is described below
commit 59d0c97aa20d985ab6bea869d7a72af3075e1c46
Author: peacewong <wp...@gmail.com>
AuthorDate: Tue Mar 7 18:18:59 2023 +0800
Fix CS creates ContextID concurrency bug (#4318)
* Optimize the restful call of CS as a synchronous call
* Solve the concurrency problem of CS context during conversion
* Fix compile error
* Fix unit test
* delete cs restful test class
* Fix contextID error
---
.../entity/source/CombinedNodeIDContextID.java | 16 ++
.../cs/common/entity/source/CommonHAContextID.java | 9 +
.../cs/common/entity/source/HAContextID.java | 2 +
.../entity/source/LinkisHAWorkFlowContextID.java | 15 ++
.../contextcache/DefaultContextCacheService.java | 67 +++----
.../cs/contextcache/cache/DefaultContextCache.java | 13 +-
.../cache/csid/impl/ContextIDValueImpl.java | 43 +----
.../cs/contextcache/metric/ContextIDMetric.java | 1 +
.../errorcode/LinkisCsServerErrorCodeSummary.java | 6 +-
.../cs/highavailable/DefaultContextHAManager.java | 6 +-
.../highavailable/proxy/MethodInterceptorImpl.java | 170 ++++++-----------
.../persistence/entity/PersistenceContextID.java | 18 ++
.../server/restful/ContextHistoryRestfulApi.java | 98 ++++++----
.../cs/server/restful/ContextIDRestfulApi.java | 96 +++++-----
.../server/restful/ContextListenerRestfulApi.java | 42 ++---
.../cs/server/restful/ContextRestfulApi.java | 160 ++++++++--------
.../linkis/cs/server/restful/CsRestfulParent.java | 55 +++---
.../server/service/impl/ContextIDServiceImpl.java | 6 +-
.../cs/server/service/impl/ContextServiceImpl.java | 110 +++++------
.../LinkisCsServerErrorCodeSummaryTest.java | 4 -
.../cs/highavailable/test/haid/TestHAID.java | 5 +
.../apache/linkis/cs/persistence/AContextID.java | 5 +
.../linkis/cs/server/ContextHistoryRestfulApi.java | 136 --------------
.../linkis/cs/server/ContextIDRestfulApi.java | 124 ------------
.../cs/server/ContextListenerRestfulApi.java | 78 --------
.../apache/linkis/cs/server/ContextRestfulApi.java | 208 ---------------------
26 files changed, 455 insertions(+), 1038 deletions(-)
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CombinedNodeIDContextID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CombinedNodeIDContextID.java
index 1b0ffcfd9..2c4da140c 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CombinedNodeIDContextID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CombinedNodeIDContextID.java
@@ -61,4 +61,20 @@ public class CombinedNodeIDContextID extends LinkisHAWorkFlowContextID {
linkisHAWorkFlowContextID.setContextId(getContextId());
return linkisHAWorkFlowContextID;
}
+
+ @Override
+ public HAContextID copy() {
+ CombinedNodeIDContextID contextID = new CombinedNodeIDContextID();
+ contextID.setBackupInstance(getBackupInstance());
+ contextID.setInstance(getInstance());
+ contextID.setEnv(getEnv());
+ contextID.setFlow(getFlow());
+ contextID.setProject(getProject());
+ contextID.setVersion(getVersion());
+ contextID.setWorkSpace(getWorkSpace());
+ contextID.setUser(getUser());
+ contextID.setContextId(getContextId());
+ contextID.setNodeID(nodeID);
+ return contextID;
+ }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CommonHAContextID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CommonHAContextID.java
index 0cd418361..8f8bbf1c1 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CommonHAContextID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/CommonHAContextID.java
@@ -51,6 +51,15 @@ public class CommonHAContextID implements HAContextID {
this.backupInstance = backupInstance;
}
+ @Override
+ public HAContextID copy() {
+ CommonHAContextID commonHAContextID = new CommonHAContextID();
+ commonHAContextID.setContextId(contextID);
+ commonHAContextID.setInstance(mainInstance);
+ commonHAContextID.setBackupInstance(this.backupInstance);
+ return commonHAContextID;
+ }
+
@Override
public String getContextId() {
return contextID;
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/HAContextID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/HAContextID.java
index d4fe0b5cf..7d50bc43e 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/HAContextID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/HAContextID.java
@@ -27,4 +27,6 @@ public interface HAContextID extends ContextID {
String getBackupInstance();
void setBackupInstance(String backupInstance);
+
+ HAContextID copy();
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/LinkisHAWorkFlowContextID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/LinkisHAWorkFlowContextID.java
index c2821e37e..7c17485fd 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/LinkisHAWorkFlowContextID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-common/src/main/java/org/apache/linkis/cs/common/entity/source/LinkisHAWorkFlowContextID.java
@@ -46,6 +46,21 @@ public class LinkisHAWorkFlowContextID extends LinkisWorkflowContextID
this.backupInstance = backupInstance;
}
+ @Override
+ public HAContextID copy() {
+ LinkisHAWorkFlowContextID linkisHAWorkFlowContextID = new LinkisHAWorkFlowContextID();
+ linkisHAWorkFlowContextID.setBackupInstance(getBackupInstance());
+ linkisHAWorkFlowContextID.setInstance(getInstance());
+ linkisHAWorkFlowContextID.setEnv(getEnv());
+ linkisHAWorkFlowContextID.setFlow(getFlow());
+ linkisHAWorkFlowContextID.setProject(getProject());
+ linkisHAWorkFlowContextID.setVersion(getVersion());
+ linkisHAWorkFlowContextID.setWorkSpace(getWorkSpace());
+ linkisHAWorkFlowContextID.setUser(getUser());
+ linkisHAWorkFlowContextID.setContextId(getContextId());
+ return linkisHAWorkFlowContextID;
+ }
+
@Override
public void setUser(String user) {
this.user = user;
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/DefaultContextCacheService.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/DefaultContextCacheService.java
index f9227aef8..1c7ed0cfd 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/DefaultContextCacheService.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/DefaultContextCacheService.java
@@ -77,10 +77,7 @@ public class DefaultContextCacheService implements ContextCacheService {
return contextIDValue.getContextKeyValueContext().remove(csKey);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to rest contextID(%s) of csKey(%s)",
- contextID.getContextId(), csKey.getKey()),
- e);
+ "Failed to rest contextID({}) of csKey({})", contextID.getContextId(), csKey.getKey(), e);
}
return null;
}
@@ -97,9 +94,7 @@ public class DefaultContextCacheService implements ContextCacheService {
.getContextKeyValue(csKey, csKey.getContextType());
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to get contextID(%s) of csKey(%s)", contextID.getContextId(), csKey.getKey()),
- e);
+ "Failed to get contextID({}) of csKey({})", contextID.getContextId(), csKey.getKey(), e);
}
return null;
}
@@ -114,9 +109,9 @@ public class DefaultContextCacheService implements ContextCacheService {
return contextIDValue.getContextKeyValueContext().getValues(keyword, csType);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to getValues contextID(%s) of keyword(%s)",
- contextID.getContextId(), keyword),
+ "Failed to get values contextID({}) of keyword({})",
+ contextID.getContextId(),
+ keyword,
e);
}
return null;
@@ -132,9 +127,7 @@ public class DefaultContextCacheService implements ContextCacheService {
return contextIDValue.getContextKeyValueContext().getAllLikes(regex, csType);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to getAllLikes contextID(%s) of regex(%s)", contextID.getContextId(), regex),
- e);
+ "Failed to getAllLikes contextID({}) of regex({})", contextID.getContextId(), regex, e);
}
return null;
}
@@ -149,8 +142,7 @@ public class DefaultContextCacheService implements ContextCacheService {
ContextIDValue contextIDValue = contextCache.getContextIDValue(contextID);
return contextIDValue.getContextKeyValueContext().getAll();
} catch (Exception e) {
- logger.error(
- String.format("Failed to getAllByType contextID(%s)", contextID.getContextId()), e);
+ logger.error("Failed to getAllByType contextID({})", contextID.getContextId(), e);
}
return null;
}
@@ -173,9 +165,10 @@ public class DefaultContextCacheService implements ContextCacheService {
}
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to getAllByScope contextID(%s) of ContextScope(%s) of csType(%s)",
- contextID.getContextId(), scope, csType),
+ "Failed to getAllByScope contextID({}) of ContextScope({}) of csType({})",
+ contextID.getContextId(),
+ scope,
+ csType,
e);
}
return null;
@@ -193,9 +186,9 @@ public class DefaultContextCacheService implements ContextCacheService {
return allValues;
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to getAllByType contextID(%s) of csType(%s)",
- contextID.getContextId(), csType),
+ "Failed to getAllByType contextID({}) of csType({})",
+ contextID.getContextId(),
+ csType,
e);
}
return null;
@@ -211,9 +204,9 @@ public class DefaultContextCacheService implements ContextCacheService {
return contextIDValue.getContextKeyValueContext().remove(csKey);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to remove contextID(%s) of csKey(%s)",
- contextID.getContextId(), csKey.getKey()),
+ "Failed to remove contextID({}) of csKey({})",
+ contextID.getContextId(),
+ csKey.getKey(),
e);
}
return null;
@@ -227,7 +220,7 @@ public class DefaultContextCacheService implements ContextCacheService {
try {
contextCache.remove(contextID);
} catch (Exception e) {
- logger.error(String.format("Failed to removeAll contextID(%s)", contextID.getContextId()), e);
+ logger.error("Failed to removeAll contextID({})", contextID.getContextId(), e);
}
}
@@ -251,9 +244,7 @@ public class DefaultContextCacheService implements ContextCacheService {
contextIDValue.getContextKeyValueContext().removeAll(csType);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to removeAll contextID(%s) of csType(%s)", contextID.getContextId(), csType),
- e);
+ "Failed to removeAll contextID({}) of csType({})", contextID.getContextId(), csType, e);
}
}
@@ -267,9 +258,9 @@ public class DefaultContextCacheService implements ContextCacheService {
contextIDValue.getContextKeyValueContext().removeByKeyPrefix(preFix);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to removeByKeyPrefix contextID(%s) of key preFix(%s)",
- contextID.getContextId(), preFix),
+ "Failed to removeByKeyPrefix contextID({}) of key preFix({})",
+ contextID.getContextId(),
+ preFix,
e);
}
}
@@ -284,9 +275,10 @@ public class DefaultContextCacheService implements ContextCacheService {
contextIDValue.getContextKeyValueContext().removeByKeyPrefix(preFix, csType);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to removeByKeyPrefix contextID(%s) of key preFix(%s) and csyTye(%s)",
- contextID.getContextId(), preFix, csType.name()),
+ "Failed to removeByKeyPrefix contextID({}) of key preFix({}) and csyTye({})",
+ contextID.getContextId(),
+ preFix,
+ csType.name(),
e);
}
}
@@ -301,9 +293,10 @@ public class DefaultContextCacheService implements ContextCacheService {
contextIDValue.getContextKeyValueContext().removeByKey(keyStr, csType);
} catch (Exception e) {
logger.error(
- String.format(
- "Failed to removeByKey contextID(%s) of key keyStr(%s) and csyTye(%s)",
- contextID.getContextId(), keyStr, csType.name()),
+ "Failed to removeByKey contextID({}) of key keyStr({}) and csyTye({})",
+ contextID.getContextId(),
+ keyStr,
+ csType.name(),
e);
}
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/DefaultContextCache.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/DefaultContextCache.java
index d9d5479c0..fcff0ac5f 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/DefaultContextCache.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/DefaultContextCache.java
@@ -24,7 +24,6 @@ import org.apache.linkis.cs.contextcache.cache.csid.ContextIDValue;
import org.apache.linkis.cs.contextcache.cache.csid.ContextIDValueGenerator;
import org.apache.linkis.cs.contextcache.conf.ContextCacheConf;
import org.apache.linkis.cs.contextcache.metric.ContextCacheMetric;
-import org.apache.linkis.cs.contextcache.metric.ContextIDMetric;
import org.apache.linkis.cs.contextcache.metric.DefaultContextCacheMetric;
import org.apache.linkis.cs.listener.CSIDListener;
import org.apache.linkis.cs.listener.ListenerBus.ContextAsyncListenerBus;
@@ -165,17 +164,7 @@ public class DefaultContextCache implements ContextCache, CSIDListener {
@Override
public void onCSIDAccess(ContextIDEvent contextIDEvent) {
- ContextID contextID = contextIDEvent.getContextID();
- try {
- ContextIDValue contextIDValue = getContextIDValue(contextID);
- ContextIDMetric contextIDMetric = contextIDValue.getContextIDMetric();
-
- contextIDMetric.setLastAccessTime(System.currentTimeMillis());
- contextIDMetric.addCount();
- getContextCacheMetric().addCount();
- } catch (CSErrorException e) {
- logger.error("Failed to deal CSIDAccess event csid is {}", contextID.getContextId());
- }
+ getContextCacheMetric().addCount();
}
@Override
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/csid/impl/ContextIDValueImpl.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/csid/impl/ContextIDValueImpl.java
index b5000343d..469fa60f3 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/csid/impl/ContextIDValueImpl.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/cache/csid/impl/ContextIDValueImpl.java
@@ -22,10 +22,8 @@ import org.apache.linkis.cs.contextcache.cache.csid.ContextIDValue;
import org.apache.linkis.cs.contextcache.cache.cskey.ContextKeyValueContext;
import org.apache.linkis.cs.contextcache.metric.ContextIDMetric;
import org.apache.linkis.cs.contextcache.metric.DefaultContextIDMetric;
-import org.apache.linkis.cs.contextcache.metric.SizeEstimator;
import org.apache.linkis.cs.listener.CSKeyListener;
import org.apache.linkis.cs.listener.event.ContextKeyEvent;
-import org.apache.linkis.cs.listener.event.impl.DefaultContextKeyEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,47 +68,10 @@ public class ContextIDValueImpl implements ContextIDValue, CSKeyListener {
}
@Override
- public void onEvent(Event event) {
- DefaultContextKeyEvent defaultContextKeyEvent = null;
- if (event != null && event instanceof DefaultContextKeyEvent) {
- defaultContextKeyEvent = (DefaultContextKeyEvent) event;
- }
- if (null == defaultContextKeyEvent) {
- return;
- }
- if (ACCESS.equals(defaultContextKeyEvent.getOperateType())) {
- onCSKeyAccess(defaultContextKeyEvent);
- } else {
- onCSKeyUpdate(defaultContextKeyEvent);
- }
- }
+ public void onEvent(Event event) {}
@Override
- public void onCSKeyUpdate(ContextKeyEvent contextKeyEvent) {
-
- DefaultContextKeyEvent defaultContextKeyEvent = (DefaultContextKeyEvent) contextKeyEvent;
- logger.debug("Start to deal csKeyEvent of csID({})", this.contextID);
- if (ADD == defaultContextKeyEvent.getOperateType()) {
- Long size = SizeEstimator.estimate(defaultContextKeyEvent.getContextKeyValue());
- this.contextIDMetric.setMemory(getContextIDMetric().getMemory() + size);
- } else if (DELETE == defaultContextKeyEvent.getOperateType()) {
- Long size = SizeEstimator.estimate(defaultContextKeyEvent.getContextKeyValue());
- this.contextIDMetric.setMemory(getContextIDMetric().getMemory() - size);
- } else if (REMOVEALL == defaultContextKeyEvent.getOperateType()) {
- Long size = SizeEstimator.estimate(getContextKeyValueContext());
- this.contextIDMetric.setMemory(size);
- } else {
- long size =
- SizeEstimator.estimate(defaultContextKeyEvent.getContextKeyValue())
- - SizeEstimator.estimate(defaultContextKeyEvent.getOldValue());
- this.contextIDMetric.setMemory(getContextIDMetric().getMemory() - size);
- }
- logger.info(
- "Now, The Memory of ContextID({}) are {}", contextID, getContextIDMetric().getMemory());
- if (logger.isDebugEnabled()) {
- logger.debug("Finished to deal csKeyEvent of csID({})", this.contextID);
- }
- }
+ public void onCSKeyUpdate(ContextKeyEvent contextKeyEvent) {}
@Override
public void onCSKeyAccess(ContextKeyEvent contextKeyEvent) {
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/metric/ContextIDMetric.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/metric/ContextIDMetric.java
index 63a7bbc0f..ef53271ea 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/metric/ContextIDMetric.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/contextcache/metric/ContextIDMetric.java
@@ -17,6 +17,7 @@
package org.apache.linkis.cs.contextcache.metric;
+@Deprecated
public interface ContextIDMetric extends Metrtic {
int getUsedCount();
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummary.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummary.java
index 1f45f0ff7..07a1c8328 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummary.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummary.java
@@ -17,10 +17,13 @@
package org.apache.linkis.cs.errorcode;
+import org.apache.linkis.common.errorcode.ErrorCodeUtils;
import org.apache.linkis.common.errorcode.LinkisErrorCode;
public enum LinkisCsServerErrorCodeSummary implements LinkisErrorCode {
- UNKNOWN_CONDITION_TYPE(1200001, "Unknown Condition Type(未知条件类型)");
+ UNKNOWN_CONDITION_TYPE(20031, "Unknown Condition Type(未知条件类型)"),
+ PARAMS_CANNOT_EMPTY(20032, "Params [{0}] cannot be empty"),
+ NO_PERMISSION(20033, "Only station admins are allowed.");
/** (errorCode)错误码 */
private final int errorCode;
@@ -28,6 +31,7 @@ public enum LinkisCsServerErrorCodeSummary implements LinkisErrorCode {
private final String errorDesc;
LinkisCsServerErrorCodeSummary(int errorCode, String errorDesc) {
+ ErrorCodeUtils.validateErrorCode(errorCode, 20031, 20040);
this.errorCode = errorCode;
this.errorDesc = errorDesc;
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/DefaultContextHAManager.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/DefaultContextHAManager.java
index 1843286bd..2bf27e20c 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/DefaultContextHAManager.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/DefaultContextHAManager.java
@@ -60,12 +60,12 @@ public class DefaultContextHAManager extends AbstractContextHAManager {
}
@Override
- public HAContextID convertProxyHAID(HAContextID haContextID) throws CSErrorException {
-
- if (null == haContextID) {
+ public HAContextID convertProxyHAID(HAContextID oriHaContextID) throws CSErrorException {
+ if (null == oriHaContextID) {
logger.error("HaContextID cannot be null.");
throw new CSErrorException(CSErrorCode.INVALID_HAID, "HaContextID cannot be null.");
}
+ HAContextID haContextID = oriHaContextID.copy();
if (StringUtils.isBlank(haContextID.getContextId())) {
// generate new haid
HAContextID tmpHAID = contextHAIDGenerator.generateHAContextID(null);
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/proxy/MethodInterceptorImpl.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/proxy/MethodInterceptorImpl.java
index aa0192b14..7e61d69ea 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/proxy/MethodInterceptorImpl.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/highavailable/proxy/MethodInterceptorImpl.java
@@ -29,26 +29,24 @@ import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * 基于CGLib库实现的动态代理拦截器,拦截被代理方法的参数,在被代理方法之前和之后进行增强
- * 被代理方法调用前增强场景较多,一般对参数为HAContextID实例、参数名包含contextid的方法参数进行转换
- * 被代理方法调用后,目前只用于将HAContextID的数字型contextID转换为HAIDKey
+ * Based on the dynamic proxy interceptor implemented by the CGLib library, it intercepts the
+ * parameters of the proxy method and enhances it before and after the proxy method There are many
+ * enhanced scenarios before being called by the proxy method. Generally, the method parameters
+ * whose parameters are HAContextID instances and whose parameter names include contextid are
+ * converted After being called by the proxy method, it is currently only used to convert the
+ * numeric contextID of HAContextID to HAIDKey
*/
public class MethodInterceptorImpl implements MethodInterceptor {
private static final Logger logger = LoggerFactory.getLogger(MethodInterceptorImpl.class);
- private static final Gson gson = new Gson();
private AbstractContextHAManager contextHAManager;
private Object object;
- private final Map<Integer, String> contextIDCacheMap = new HashMap<Integer, String>();
private static final String CONTEXTID = "contextid";
private static final String GETCONTEXTID = "getcontextid";
@@ -58,39 +56,45 @@ public class MethodInterceptorImpl implements MethodInterceptor {
this.object = object;
}
+ /**
+ * 1. Judging the input parameter, if it is ContextID, convert it to a normal ID 2. Convert the
+ * method whose name contains ContextID, and only judge the first parameter of String type 3.
+ * Encapsulate the returned result as HA ID
+ *
+ * @param interceptObject
+ * @param method
+ * @param args
+ * @param methodProxy
+ * @return
+ * @throws Throwable
+ */
@Override
- public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy)
+ public Object intercept(
+ Object interceptObject, Method method, Object[] args, MethodProxy methodProxy)
throws Throwable {
-
- this.contextIDCacheMap.clear();
- // 1,执行方法前转换
for (int i = 0; i < args.length; i++) {
-
- // ①参数含有ContextID实例
- if (ContextID.class.isInstance(args[i])) {
+ if (args[i] instanceof ContextID) {
ContextID contextID = (ContextID) args[i];
- convertContextIDBeforeInvoke(contextID, i);
+ args[i] = convertContextIDBeforeInvoke(contextID);
}
-
- // ②参数含有getContextID方法的
- convertGetContextIDBeforeInvoke(args[i]);
}
-
- // ③方法名含有ContextID,并且有String类型参数,取第一个转换
if (method.getName().toLowerCase().contains(CONTEXTID)) {
for (int j = 0; j < args.length; j++) {
- if (String.class.isInstance(args[j])) {
- String pStr = (String) args[j];
- if (StringUtils.isNotBlank(pStr) && !StringUtils.isNumeric(pStr)) {
- if (this.contextHAManager.getContextHAChecker().isHAIDValid(pStr)) {
+ if (args[j] instanceof String) {
+ String contextIdStr = (String) args[j];
+ if (StringUtils.isNotBlank(contextIdStr) && !StringUtils.isNumeric(contextIdStr)) {
+ if (this.contextHAManager.getContextHAChecker().isHAIDValid(contextIdStr)) {
String contextID =
- this.contextHAManager.getContextHAChecker().parseHAIDFromKey(pStr).getContextId();
+ this.contextHAManager
+ .getContextHAChecker()
+ .parseHAIDFromKey(contextIdStr)
+ .getContextId();
args[j] = contextID;
} else {
- logger.error("Invalid HAID : " + pStr + " in method : " + method.getName());
+ logger.error("Invalid HAID : " + contextIdStr + " in method : " + method.getName());
throw new CSErrorException(
CSErrorCode.INVALID_HAID,
- "Invalid HAID : " + pStr + " in method : " + method.getName());
+ "Invalid HAID : " + contextIdStr + " in method : " + method.getName());
}
}
break;
@@ -98,123 +102,63 @@ public class MethodInterceptorImpl implements MethodInterceptor {
}
}
- // 2,执行原方法
Object oriResult = method.invoke(this.object, args);
- // 3,执行方法后处理
- // (1)返回值处理
if (null != oriResult) {
- // ①判断集合中元素是否有getContextID方法
- if (List.class.isInstance(oriResult)) {
+ if (oriResult instanceof List) {
List objList = (List) oriResult;
for (Object oneParameter : objList) {
- convertGetContextIDAfterInvoke(oneParameter);
+ if (null != objList && oneParameter instanceof HAContextID) {
+ HAContextID haContextID = (HAContextID) oneParameter;
+ if (StringUtils.isNumeric(haContextID.getContextId())) {
+ String haId =
+ this.contextHAManager.getContextHAChecker().convertHAIDToHAKey(haContextID);
+ haContextID.setContextId(haId);
+ }
+ }
}
- // ②判断ContextID
- } else if (HAContextID.class.isInstance(oriResult)) {
+ } else if (oriResult instanceof HAContextID) {
HAContextID haContextID = (HAContextID) oriResult;
if (StringUtils.isNumeric(haContextID.getContextId())) {
String haId = this.contextHAManager.getContextHAChecker().convertHAIDToHAKey(haContextID);
haContextID.setContextId(haId);
}
- } else {
- // ③ 返回值方法含有getContextID
- convertGetContextIDAfterInvoke(oriResult);
- }
- }
-
- // (2)请求参数还原
- // ①参数有ContextID实例
- for (int k = 0; k < args.length; k++) {
- if (ContextID.class.isInstance(args[k])) {
- if (this.contextIDCacheMap.containsKey(k)) {
- ContextID contextID = (ContextID) args[k];
- contextID.setContextId(this.contextIDCacheMap.get(k));
- } else {
- if (HAContextID.class.isInstance(args[k])) {
- HAContextID haContextID = (HAContextID) args[k];
- if (StringUtils.isNumeric(haContextID.getContextId())) {
- if (StringUtils.isNotBlank(haContextID.getInstance())
- && StringUtils.isNotBlank(haContextID.getBackupInstance())) {
- String haId =
- this.contextHAManager.getContextHAChecker().convertHAIDToHAKey(haContextID);
- haContextID.setContextId(haId);
- } else {
- logger.error("Invalid HAContextID : " + gson.toJson(haContextID));
- throw new CSErrorException(
- CSErrorCode.INVAID_HA_CONTEXTID,
- "Invalid HAContextID : " + gson.toJson(haContextID));
- }
- }
- }
- }
- } else {
- // ②参数含有getContextID方法
- convertGetContextIDAfterInvoke(args[k]);
}
}
- // ③方法名含有ContextID,并且有String类型参数 引用不需要作处理
-
return oriResult;
}
- private void convertContextIDBeforeInvoke(ContextID contextID, int index)
- throws CSErrorException {
+ private ContextID convertContextIDBeforeInvoke(ContextID contextID) throws CSErrorException {
if (null == contextID) {
- return;
+ return null;
}
if (StringUtils.isNumeric(contextID.getContextId())) {
- if (HAContextID.class.isInstance(contextID)) {
+ if (contextID instanceof HAContextID) {
logger.error(
- "ContextId of HAContextID instance cannot be numberic. contextId : "
- + gson.toJson(contextID));
+ "ContextId of HAContextID instance cannot be numberic. contextId : {} ",
+ contextID.getContextId());
throw new CSErrorException(
CSErrorCode.INVALID_CONTEXTID,
"ContextId of HAContextID instance cannot be numberic. contextId : "
- + gson.toJson(contextID));
+ + contextID.getContextId());
}
} else {
- if (HAContextID.class.isInstance(contextID)) {
+ if (contextID instanceof HAContextID) {
if (null == contextID.getContextId()) {
- this.contextHAManager.convertProxyHAID((HAContextID) contextID);
+ return this.contextHAManager.convertProxyHAID((HAContextID) contextID);
} else if (this.contextHAManager
.getContextHAChecker()
.isHAIDValid(contextID.getContextId())) {
- if (index > 0) {
- this.contextIDCacheMap.put(index, contextID.getContextId());
- }
- this.contextHAManager.convertProxyHAID((HAContextID) contextID);
+ return this.contextHAManager.convertProxyHAID((HAContextID) contextID);
} else {
- logger.error("Invalid haContextId. contextId : " + gson.toJson(contextID));
+ logger.error("Invalid haContextId. contextId : {} ", contextID.getContextId());
throw new CSErrorException(
CSErrorCode.INVALID_HAID,
- "Invalid haContextId. contextId : " + gson.toJson(contextID));
- }
- }
- }
- }
-
- private void convertGetContextIDBeforeInvoke(Object object) throws CSErrorException {
- if (null == object) {
- return;
- }
- for (Method innerMethod : object.getClass().getMethods()) {
- if (innerMethod.getName().toLowerCase().contains(GETCONTEXTID)) {
- try {
- Object result = innerMethod.invoke(object);
- if (null != object && ContextID.class.isInstance(result)) {
- convertContextIDBeforeInvoke((ContextID) result, -1);
- } else {
- logger.warn(
- "Method {} returns non-contextid object : {}",
- innerMethod.getName(),
- gson.toJson(object));
- }
- } catch (Exception e) {
- logger.error("call method : {} error, ", innerMethod.getName(), e);
+ "Invalid haContextId. contextId : " + contextID.getContextId());
}
}
}
+ return contextID;
}
private void convertGetContextIDAfterInvoke(Object object) throws CSErrorException {
@@ -235,7 +179,7 @@ public class MethodInterceptorImpl implements MethodInterceptor {
} catch (Exception e) {
logger.warn("Invoke method : {} error. ", method.getName(), e);
}
- if (null != result && HAContextID.class.isInstance(result)) {
+ if (HAContextID.class.isInstance(result)) {
HAContextID haContextID = (HAContextID) result;
if (StringUtils.isNumeric(haContextID.getContextId())
&& StringUtils.isNotBlank(haContextID.getInstance())
@@ -247,13 +191,13 @@ public class MethodInterceptorImpl implements MethodInterceptor {
"GetContextID method : "
+ method.getName()
+ " returns invalid haContextID : "
- + gson.toJson(result));
+ + result);
throw new CSErrorException(
CSErrorCode.INVALID_HAID,
"GetContextID method : "
+ method.getName()
+ " returns invalid haContextID : "
- + gson.toJson(result));
+ + result);
}
}
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/persistence/entity/PersistenceContextID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/persistence/entity/PersistenceContextID.java
index e3ff8deeb..a68947ffd 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/persistence/entity/PersistenceContextID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/persistence/entity/PersistenceContextID.java
@@ -97,6 +97,24 @@ public class PersistenceContextID implements UserContextID, HAContextID {
this.backupInstance = backupInstance;
}
+ @Override
+ public HAContextID copy() {
+ PersistenceContextID persistenceContextID = new PersistenceContextID();
+ persistenceContextID.setContextId(contextId);
+ persistenceContextID.setAccessTime(accessTime);
+ persistenceContextID.setApplication(application);
+ persistenceContextID.setCreateTime(createTime);
+ persistenceContextID.setUpdateTime(updateTime);
+ persistenceContextID.setBackupInstance(backupInstance);
+ persistenceContextID.setExpireTime(expireTime);
+ persistenceContextID.setExpireType(expireType);
+ persistenceContextID.setInstance(instance);
+ persistenceContextID.setSource(source);
+ persistenceContextID.setUser(user);
+ persistenceContextID.setContextIDType(getContextIDType());
+ return persistenceContextID;
+ }
+
public String getApplication() {
return application;
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextHistoryRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextHistoryRestfulApi.java
index 9efc4ed3e..79d9d49af 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextHistoryRestfulApi.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextHistoryRestfulApi.java
@@ -20,15 +20,14 @@ package org.apache.linkis.cs.server.restful;
import org.apache.linkis.cs.common.entity.history.ContextHistory;
import org.apache.linkis.cs.common.entity.source.ContextID;
import org.apache.linkis.cs.common.exception.CSErrorException;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
+import org.apache.linkis.cs.server.service.ContextHistoryService;
import org.apache.linkis.server.Message;
import org.apache.linkis.server.utils.ModuleUserUtils;
+import org.apache.commons.lang3.StringUtils;
+
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -37,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
+import java.text.MessageFormat;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -45,13 +45,19 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary.PARAMS_CANNOT_EMPTY;
@Api(tags = "cs(contextservice) history operation")
@RestController
@RequestMapping(path = "/contextservice")
public class ContextHistoryRestfulApi implements CsRestfulParent {
- @Autowired private CsScheduler csScheduler;
+ private static final Logger logger = LoggerFactory.getLogger(ContextIDRestfulApi.class);
+
+ @Autowired private ContextHistoryService contextHistoryService;
private ObjectMapper objectMapper = new ObjectMapper();
@@ -64,18 +70,24 @@ public class ContextHistoryRestfulApi implements CsRestfulParent {
@RequestMapping(path = "createHistory", method = RequestMethod.POST)
public Message createHistory(HttpServletRequest req, @RequestBody JsonNode jsonNode)
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+
ContextHistory history = getContextHistoryFromJsonNode(jsonNode);
+
ContextID contextID = getContextIDFromJsonNode(jsonNode);
// source and contextid cannot be empty
- if (StringUtils.isEmpty(history.getSource())) {
- throw new CSErrorException(97000, "history source cannot be empty");
+ if (StringUtils.isBlank(history.getSource())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "history source"));
}
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(contextID.getContextId())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "createHistory,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.CREATE, contextID, history);
- return generateResponse(answerJob, "");
+ contextHistoryService.createHistroy(contextID, history);
+ return generateMessage(null, "");
}
@ApiOperation(value = "removeHistory", notes = "remove context history", response = Message.class)
@@ -90,15 +102,19 @@ public class ContextHistoryRestfulApi implements CsRestfulParent {
ContextHistory history = getContextHistoryFromJsonNode(jsonNode);
ContextID contextID = getContextIDFromJsonNode(jsonNode);
// source and contextid cannot be empty
- if (StringUtils.isEmpty(history.getSource())) {
- throw new CSErrorException(97000, "history source cannot be empty");
+ if (StringUtils.isBlank(history.getSource())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "history source"));
}
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(contextID.getContextId())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "removeHistory,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVE, contextID, history);
- return generateResponse(answerJob, "");
+ contextHistoryService.removeHistory(contextID, history);
+ return generateMessage(null, "");
}
@ApiOperation(
@@ -109,15 +125,16 @@ public class ContextHistoryRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "getHistories", method = RequestMethod.POST)
public Message getHistories(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(contextID.getContextId())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
- ModuleUserUtils.getOperationUser(req, "getHistories,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, contextID);
- Message message = generateResponse(answerJob, "contextHistory");
- return message;
+ ModuleUserUtils.getOperationUser(req, "getHistory,contextID:" + contextID.getContextId());
+ Object history = contextHistoryService.getHistories(contextID);
+ return generateMessage(history, "contextHistory");
}
@ApiOperation(value = "GetHistory", notes = "get context history", response = Message.class)
@@ -133,16 +150,19 @@ public class ContextHistoryRestfulApi implements CsRestfulParent {
String source = jsonNode.get("source").textValue();
ContextID contextID = getContextIDFromJsonNode(jsonNode);
// source and contextid cannot be empty
- if (StringUtils.isEmpty(source)) {
- throw new CSErrorException(97000, "history source cannot be empty");
+ if (StringUtils.isBlank(source)) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "history source"));
}
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(contextID.getContextId())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "getHistory,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, contextID, source);
- Message message = generateResponse(answerJob, "contextHistory");
- return message;
+ Object history = contextHistoryService.getHistory(contextID, source);
+ return generateMessage(history, "contextHistory");
}
@ApiOperation(value = "searchHistory", notes = "search history", response = Message.class)
@@ -157,22 +177,18 @@ public class ContextHistoryRestfulApi implements CsRestfulParent {
// ContextID contextID, String[] keywords
ContextID contextID = getContextIDFromJsonNode(jsonNode);
String[] keywords = objectMapper.treeToValue(jsonNode.get("keywords"), String[].class);
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(contextID.getContextId())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "searchHistory,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SEARCH, contextID, keywords);
- Message message = generateResponse(answerJob, "contextHistory");
- return message;
+ Object history = contextHistoryService.searchHistory(contextID, keywords);
+ return generateMessage(history, "contextHistory");
}
@Override
public ServiceType getServiceType() {
return ServiceType.CONTEXT_HISTORY;
}
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextIDRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextIDRestfulApi.java
index 6245c05d2..43f267c47 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextIDRestfulApi.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextIDRestfulApi.java
@@ -22,25 +22,20 @@ import org.apache.linkis.cs.common.entity.source.ContextID;
import org.apache.linkis.cs.common.exception.CSErrorException;
import org.apache.linkis.cs.common.protocol.ContextHTTPConstant;
import org.apache.linkis.cs.common.utils.CSCommonUtils;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
+import org.apache.linkis.cs.server.service.ContextIDService;
import org.apache.linkis.server.Message;
import org.apache.linkis.server.utils.ModuleUserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
+import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
@@ -55,6 +50,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.linkis.cs.common.utils.CSCommonUtils.localDatetimeToDate;
+import static org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary.NO_PERMISSION;
+import static org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary.PARAMS_CANNOT_EMPTY;
@Api(tags = "cs(contextservice) recording operation")
@RestController
@@ -63,7 +60,7 @@ public class ContextIDRestfulApi implements CsRestfulParent {
private static final Logger logger = LoggerFactory.getLogger(ContextIDRestfulApi.class);
- @Autowired private CsScheduler csScheduler;
+ @Autowired private ContextIDService contextIDService;
@ApiOperation(value = "createContextID", notes = "create context Id", response = Message.class)
@ApiImplicitParams({@ApiImplicitParam(name = "contextID", dataType = "String")})
@@ -74,9 +71,8 @@ public class ContextIDRestfulApi implements CsRestfulParent {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
ModuleUserUtils.getOperationUser(
req, "createContextID,contextIDType: " + contextID.getContextIDType());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.CREATE, contextID);
-
- return generateResponse(answerJob, "contextId");
+ String res = contextIDService.createContextID(contextID);
+ return generateMessage(res, "contextId");
}
@ApiOperation(value = "GetContextID", notes = "Get_Context_Id", response = Message.class)
@@ -85,13 +81,14 @@ public class ContextIDRestfulApi implements CsRestfulParent {
public Message getContextID(
HttpServletRequest req, @RequestParam(value = "contextId", required = false) String id)
throws InterruptedException, CSErrorException {
- if (StringUtils.isEmpty(id)) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(id)) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "getContextID,contextID:" + id);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, id);
- Message message = generateResponse(answerJob, "contextID");
- return message;
+ Object res = contextIDService.getContextID(id);
+ return generateMessage(res, "contextId");
}
@ApiOperation(value = "updateContextID", notes = "update content id", response = Message.class)
@@ -101,12 +98,14 @@ public class ContextIDRestfulApi implements CsRestfulParent {
public Message updateContextID(HttpServletRequest req, @RequestBody JsonNode jsonNode)
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(contextID.getContextId())) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "updateContextID,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.UPDATE, contextID);
- return generateResponse(answerJob, "");
+ contextIDService.updateContextID(contextID);
+ return generateMessage(null, "contextId");
}
@ApiOperation(value = "resetContextID", notes = "reset context Id", response = Message.class)
@@ -114,17 +113,21 @@ public class ContextIDRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "resetContextID", method = RequestMethod.POST)
public Message resetContextID(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException {
+ throws CSErrorException {
if (!jsonNode.has(ContextHTTPConstant.CONTEXT_ID_STR)) {
- throw new CSErrorException(97000, ContextHTTPConstant.CONTEXT_ID_STR + " cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
String id = jsonNode.get(ContextHTTPConstant.CONTEXT_ID_STR).textValue();
- if (StringUtils.isEmpty(id)) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(id)) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "resetContextID,contextID:" + id);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.RESET, id);
- return generateResponse(answerJob, "");
+ contextIDService.resetContextID(id);
+ return generateMessage(null, "contextId");
}
@ApiOperation(value = "removeContextID", notes = "remove context ID", response = Message.class)
@@ -132,14 +135,16 @@ public class ContextIDRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "removeContextID", method = RequestMethod.POST)
public Message removeContextID(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException {
+ throws CSErrorException {
String id = jsonNode.get(ContextHTTPConstant.CONTEXT_ID_STR).textValue();
- if (StringUtils.isEmpty(id)) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ if (StringUtils.isBlank(id)) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "removeContextID,contextID:" + id);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVE, id);
- return generateResponse(answerJob, "");
+ contextIDService.removeContextID(id);
+ return generateMessage(null, "contextId");
}
@ApiOperation(
@@ -167,10 +172,10 @@ public class ContextIDRestfulApi implements CsRestfulParent {
@RequestParam(value = "accessTimeEnd", required = false) String accessTimeEnd,
@RequestParam(value = "pageNow", required = false) Integer paramPageNow,
@RequestParam(value = "pageSize", required = false) Integer paramPageSize)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException {
String username = ModuleUserUtils.getOperationUser(req, "searchContextIDByTime");
if (Configuration.isNotAdmin(username)) {
- throw new CSErrorException(97018, "Only station admins are allowed.");
+ throw new CSErrorException(NO_PERMISSION.getErrorCode(), NO_PERMISSION.getErrorDesc());
}
logger.info(
"user: {}, searchContextIDByTime : createTimeStart : {}, createTimeEnd : {}, updateTimeStart : {}, updateTimeEnd : {}, accessTimeStart : {}, accessTimeEnd : {}, pageNow : {}, pageSize : {}.",
@@ -191,16 +196,18 @@ public class ContextIDRestfulApi implements CsRestfulParent {
&& null == accessTimeStart
&& null == accessTimeEnd) {
throw new CSErrorException(
- 97000,
- "createTimeStart, createTimeEnd, updateTimeStart, updateTimeEnd, accessTimeStart, accessTimeEnd cannot be all null.");
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(
+ PARAMS_CANNOT_EMPTY.getErrorDesc(),
+ "createTimeStart, createTimeEnd, updateTimeStart, updateTimeEnd, accessTimeStart, accessTimeEnd cannot be all null."));
}
- int pageStart = 0;
+ int pageStart;
if (null == paramPageNow || paramPageNow <= 0) {
pageStart = 1;
} else {
pageStart = paramPageNow;
}
- int pageSize = 0;
+ int pageSize;
if (null == paramPageSize
|| paramPageSize <= 0
|| paramPageSize > CSCommonUtils.CONTEXT_MAX_PAGE_SIZE) {
@@ -228,10 +235,8 @@ public class ContextIDRestfulApi implements CsRestfulParent {
accessTimeStartDate = localDatetimeToDate(LocalDateTime.parse(accessTimeStart, dtf));
if (StringUtils.isNotBlank(accessTimeEnd))
accessTimeEndDate = localDatetimeToDate(LocalDateTime.parse(accessTimeEnd, dtf));
- HttpAnswerJob answerJob =
- submitRestJob(
- req,
- ServiceMethod.SEARCH,
+ Object res =
+ contextIDService.searchCSIDByTime(
createTimeStartDate,
createTimeEndDate,
updateTimeStartDate,
@@ -240,7 +245,7 @@ public class ContextIDRestfulApi implements CsRestfulParent {
accessTimeEndDate,
pageStart,
pageSize);
- Message resp = generateResponse(answerJob, "contextIDs");
+ Message resp = generateMessage(res, "contextIds");
resp.setMethod("/api/contextservice/searchContextIDByTime");
return resp;
}
@@ -249,9 +254,4 @@ public class ContextIDRestfulApi implements CsRestfulParent {
public ServiceType getServiceType() {
return ServiceType.CONTEXT_ID;
}
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextListenerRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextListenerRestfulApi.java
index 5b818cfb2..a8eabb667 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextListenerRestfulApi.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextListenerRestfulApi.java
@@ -23,10 +23,8 @@ import org.apache.linkis.cs.common.entity.listener.ContextIDListenerDomain;
import org.apache.linkis.cs.common.entity.source.ContextID;
import org.apache.linkis.cs.common.entity.source.ContextKey;
import org.apache.linkis.cs.common.exception.CSErrorException;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
+import org.apache.linkis.cs.server.service.ContextListenerService;
import org.apache.linkis.server.Message;
import org.apache.linkis.server.utils.ModuleUserUtils;
@@ -41,21 +39,21 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
+import java.text.MessageFormat;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import static org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary.PARAMS_CANNOT_EMPTY;
+
@Api(tags = "cs(contextservice) listener operation")
@RestController
@RequestMapping(path = "/contextservice")
public class ContextListenerRestfulApi implements CsRestfulParent {
- @Autowired private CsScheduler csScheduler;
-
- private ObjectMapper objectMapper = new ObjectMapper();
+ @Autowired private ContextListenerService contextListenerService;
@ApiOperation(value = "onBindIDListener", notes = "on bind id listener", response = Message.class)
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@@ -65,13 +63,15 @@ public class ContextListenerRestfulApi implements CsRestfulParent {
String source = jsonNode.get("source").textValue();
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "onBindIDListener,contextID:" + contextID.getContextId());
ContextIDListenerDomain listener = new CommonContextIDListenerDomain();
listener.setSource(source);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.BIND, contextID, listener);
- return generateResponse(answerJob, "");
+ contextListenerService.onBind(contextID, listener);
+ return generateMessage(null, "listener");
}
@ApiOperation(
@@ -81,40 +81,36 @@ public class ContextListenerRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "onBindKeyListener", method = RequestMethod.POST)
public Message onBindKeyListener(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException, IOException, ClassNotFoundException {
String source = jsonNode.get("source").textValue();
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(
req, "onBindKeyListener,contextID:" + contextID.getContextId());
ContextKey contextKey = getContextKeyFromJsonNode(jsonNode);
CommonContextKeyListenerDomain listener = new CommonContextKeyListenerDomain();
listener.setSource(source);
- HttpAnswerJob answerJob =
- submitRestJob(req, ServiceMethod.BIND, contextID, contextKey, listener);
- return generateResponse(answerJob, "");
+ contextListenerService.onBind(contextID, contextKey, listener);
+ return generateMessage(null, "listener");
}
@ApiOperation(value = "heartbeat", notes = "heart beat", response = Message.class)
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "heartbeat", method = RequestMethod.POST)
public Message heartbeat(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, IOException, CSErrorException {
+ throws CSErrorException {
ModuleUserUtils.getOperationUser(req, "heartbeat");
String source = jsonNode.get("source").textValue();
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.HEARTBEAT, source);
- return generateResponse(answerJob, "ContextKeyValueBean");
+ Object res = contextListenerService.heartbeat(source);
+ return generateMessage(res, "ContextKeyValueBean");
}
@Override
public ServiceType getServiceType() {
return ServiceType.CONTEXT_LISTENER;
}
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextRestfulApi.java
index 6573596d4..b4938e0ac 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextRestfulApi.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/ContextRestfulApi.java
@@ -26,10 +26,9 @@ import org.apache.linkis.cs.common.entity.source.ContextValue;
import org.apache.linkis.cs.common.exception.CSErrorException;
import org.apache.linkis.cs.common.protocol.ContextHTTPConstant;
import org.apache.linkis.cs.common.utils.CSCommonUtils;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
+import org.apache.linkis.cs.exception.ContextSearchFailedException;
import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
+import org.apache.linkis.cs.server.service.ContextService;
import org.apache.linkis.server.Message;
import org.apache.linkis.server.utils.ModuleUserUtils;
@@ -44,6 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
+import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -64,6 +64,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.linkis.cs.common.utils.CSCommonUtils.localDatetimeToDate;
+import static org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary.NO_PERMISSION;
+import static org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary.PARAMS_CANNOT_EMPTY;
@Api(tags = "cs(contextservice) operation")
@RestController
@@ -72,7 +74,7 @@ public class ContextRestfulApi implements CsRestfulParent {
private static final Logger logger = LoggerFactory.getLogger(ContextRestfulApi.class);
- @Autowired private CsScheduler csScheduler;
+ @Autowired private ContextService contextService;
private ObjectMapper objectMapper = new ObjectMapper();
@@ -87,13 +89,14 @@ public class ContextRestfulApi implements CsRestfulParent {
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "getContextValue,contextID:" + contextID.getContextId());
ContextKey contextKey = getContextKeyFromJsonNode(jsonNode);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, contextID, contextKey);
- Message message = generateResponse(answerJob, "contextValue");
- return message;
+ Object res = contextService.getContextValue(contextID, contextKey);
+ return generateMessage(res, "contextValue");
}
@ApiOperation(
@@ -107,19 +110,20 @@ public class ContextRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "searchContextValue", method = RequestMethod.POST)
public Message searchContextValue(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException, IOException, ClassNotFoundException, ContextSearchFailedException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(
req, "searchContextValue,contextID:" + contextID.getContextId());
JsonNode condition = jsonNode.get("condition");
Map<Object, Object> conditionMap =
objectMapper.convertValue(condition, new TypeReference<Map<Object, Object>>() {});
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SEARCH, contextID, conditionMap);
- Message message = generateResponse(answerJob, "contextKeyValue");
- return message;
+ Object res = contextService.searchContextValue(contextID, conditionMap);
+ return generateMessage(res, "contextKeyValue");
}
@ApiOperation(value = "setValueByKey", notes = "set value by key", response = Message.class)
@@ -133,14 +137,15 @@ public class ContextRestfulApi implements CsRestfulParent {
throws CSErrorException, IOException, ClassNotFoundException, InterruptedException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "setValueByKey,contextID:" + contextID.getContextId());
ContextKey contextKey = getContextKeyFromJsonNode(jsonNode);
ContextValue contextValue = getContextValueFromJsonNode(jsonNode);
- HttpAnswerJob answerJob =
- submitRestJob(req, ServiceMethod.SET, contextID, contextKey, contextValue);
- return generateResponse(answerJob, "");
+ contextService.setValueByKey(contextID, contextKey, contextValue);
+ return generateMessage(null, "");
}
@ApiOperation(value = "setValue", notes = "set value", response = Message.class)
@@ -154,12 +159,14 @@ public class ContextRestfulApi implements CsRestfulParent {
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "setValue,contextID:" + contextID.getContextId());
ContextKeyValue contextKeyValue = getContextKeyValueFromJsonNode(jsonNode);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SET, contextID, contextKeyValue);
- return generateResponse(answerJob, "");
+ contextService.setValue(contextID, contextKeyValue);
+ return generateMessage(null, "");
}
@ApiOperation(value = "resetValue", notes = "reset value", response = Message.class)
@@ -170,15 +177,17 @@ public class ContextRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "resetValue", method = RequestMethod.POST)
public Message resetValue(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "resetValue,contextID:" + contextID.getContextId());
ContextKey contextKey = getContextKeyFromJsonNode(jsonNode);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.RESET, contextID, contextKey);
- return generateResponse(answerJob, "");
+ contextService.resetValue(contextID, contextKey);
+ return generateMessage(null, "");
}
@ApiOperation(value = "removeValue", notes = "remove value", response = Message.class)
@@ -189,15 +198,17 @@ public class ContextRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "removeValue", method = RequestMethod.POST)
public Message removeValue(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "removeValue,contextID:" + contextID.getContextId());
ContextKey contextKey = getContextKeyFromJsonNode(jsonNode);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVE, contextID, contextKey);
- return generateResponse(answerJob, "");
+ contextService.removeValue(contextID, contextKey);
+ return generateMessage(null, "");
}
@ApiOperation(value = "removeAllValue", notes = "remove all value", response = Message.class)
@@ -208,14 +219,16 @@ public class ContextRestfulApi implements CsRestfulParent {
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "removeAllValue", method = RequestMethod.POST)
public Message removeAllValue(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(req, "removeAllValue,contextID:" + contextID.getContextId());
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVEALL, contextID);
- return generateResponse(answerJob, "");
+ contextService.removeAllValue(contextID);
+ return generateMessage(null, "");
}
@ApiOperation(
@@ -233,16 +246,17 @@ public class ContextRestfulApi implements CsRestfulParent {
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(
req, "removeAllValueByKeyPrefixAndContextType,contextID:" + contextID.getContextId());
String contextType = jsonNode.get(ContextHTTPConstant.CONTEXT_KEY_TYPE_STR).textValue();
String keyPrefix = jsonNode.get(ContextHTTPConstant.CONTEXT_KEY_PREFIX_STR).textValue();
- HttpAnswerJob answerJob =
- submitRestJob(
- req, ServiceMethod.REMOVEALL, contextID, ContextType.valueOf(contextType), keyPrefix);
- return generateResponse(answerJob, "");
+ contextService.removeAllValueByKeyPrefixAndContextType(
+ contextID, ContextType.valueOf(contextType), keyPrefix);
+ return generateMessage(null, "");
}
@ApiOperation(
@@ -255,20 +269,15 @@ public class ContextRestfulApi implements CsRestfulParent {
})
@ApiOperationSupport(ignoreParameters = {"jsonNode"})
@RequestMapping(path = "removeAllValueByKeyAndContextType", method = RequestMethod.POST)
- public Message removeAllValueByKeyAndContextType(
+ public Message removeValueByKeyAndContextType(
HttpServletRequest req, @RequestBody JsonNode jsonNode)
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
String contextType = jsonNode.get(ContextHTTPConstant.CONTEXT_KEY_TYPE_STR).textValue();
String keyStr = jsonNode.get(ContextHTTPConstant.CONTEXT_KEY_STR).textValue();
- HttpAnswerJob answerJob =
- submitRestJob(
- req,
- ServiceMethod.REMOVEVALUEBYKEY,
- contextID,
- ContextType.valueOf(contextType),
- keyStr);
- return generateResponse(answerJob, "");
+ contextService.removeValueByKeyAndContextType(
+ contextID, ContextType.valueOf(contextType), keyStr);
+ return generateMessage(null, "");
}
@ApiOperation(
@@ -284,13 +293,15 @@ public class ContextRestfulApi implements CsRestfulParent {
throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
ContextID contextID = getContextIDFromJsonNode(jsonNode);
if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "ContextID"));
}
ModuleUserUtils.getOperationUser(
req, "removeAllValueByKeyPrefix,contextID:" + contextID.getContextId());
String keyPrefix = jsonNode.get(ContextHTTPConstant.CONTEXT_KEY_PREFIX_STR).textValue();
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVEALL, contextID, keyPrefix);
- return generateResponse(answerJob, "");
+ contextService.removeAllValueByKeyPrefix(contextID, keyPrefix);
+ return generateMessage(null, "");
}
@ApiOperation(
@@ -302,12 +313,14 @@ public class ContextRestfulApi implements CsRestfulParent {
})
@RequestMapping(path = "clearAllContextByID", method = RequestMethod.POST)
public Message clearAllContextByID(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws InterruptedException, CSErrorException {
if (null == jsonNode
|| !jsonNode.has("idList")
|| !jsonNode.get("idList").isArray()
- || (jsonNode.get("idList").isArray() && ((ArrayNode) jsonNode.get("idList")).size() == 0)) {
- throw new CSErrorException(97000, "idList cannot be empty.");
+ || (jsonNode.get("idList").isArray() && jsonNode.get("idList").size() == 0)) {
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "idList"));
}
ModuleUserUtils.getOperationUser(req, "clearAllContextByID");
ArrayNode idArray = (ArrayNode) jsonNode.get("idList");
@@ -316,8 +329,7 @@ public class ContextRestfulApi implements CsRestfulParent {
for (int i = 0; i < idArray.size(); i++) {
idList.add(idArray.get(i).asText());
}
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.CLEAR, idList);
- Message resp = generateResponse(answerJob, "num");
+ Message resp = generateMessage(contextService.clearAllContextByID(idList), "num");
resp.setMethod("/api/contextservice/clearAllContextByID");
return resp;
}
@@ -337,13 +349,15 @@ public class ContextRestfulApi implements CsRestfulParent {
@RequestMapping(path = "clearAllContextByTime", method = RequestMethod.POST)
public Message clearAllContextByID(
HttpServletRequest req, @RequestBody Map<String, Object> bodyMap)
- throws InterruptedException, CSErrorException, IOException, ClassNotFoundException {
+ throws InterruptedException, CSErrorException {
String username = ModuleUserUtils.getOperationUser(req, "clearAllContextByTime");
if (Configuration.isNotAdmin(username)) {
- throw new CSErrorException(97018, "Only station admins are allowed.");
+ throw new CSErrorException(NO_PERMISSION.getErrorCode(), NO_PERMISSION.getErrorDesc());
}
if (null == bodyMap || bodyMap.isEmpty()) {
- throw new CSErrorException(97000, "idList cannot be empty.");
+ throw new CSErrorException(
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(PARAMS_CANNOT_EMPTY.getErrorDesc(), "idList"));
}
Date createTimeStart = null;
Date createTimeEnd = null;
@@ -376,8 +390,10 @@ public class ContextRestfulApi implements CsRestfulParent {
&& null == updateTimeStart
&& null == updateTimeEnd) {
throw new CSErrorException(
- 97000,
- "createTimeStart, createTimeEnd, updateTimeStart, updateTimeEnd cannot be all null.");
+ PARAMS_CANNOT_EMPTY.getErrorCode(),
+ MessageFormat.format(
+ PARAMS_CANNOT_EMPTY.getErrorDesc(),
+ "createTimeStart, createTimeEnd, updateTimeStart, updateTimeEnd"));
}
logger.info(
"clearAllContextByTime: user : {}, createTimeStart : {}, createTimeEnd : {}, updateTimeStart : {}, updateTimeEnd : {}, accessTimeStart : {}, accessTimeEnd : {}.",
@@ -388,17 +404,16 @@ public class ContextRestfulApi implements CsRestfulParent {
updateTimeEnd,
accessTimeStart,
accessTimeEnd);
- HttpAnswerJob answerJob =
- submitRestJob(
- req,
- ServiceMethod.CLEAR,
- createTimeStart,
- createTimeEnd,
- updateTimeStart,
- updateTimeEnd,
- accessTimeStart,
- accessTimeEnd);
- Message resp = generateResponse(answerJob, "num");
+ Message resp =
+ generateMessage(
+ contextService.clearAllContextByTime(
+ createTimeStart,
+ createTimeEnd,
+ updateTimeStart,
+ updateTimeEnd,
+ accessTimeStart,
+ accessTimeEnd),
+ "num");
resp.setMethod("/api/contextservice/clearAllContextByTime");
return resp;
}
@@ -407,9 +422,4 @@ public class ContextRestfulApi implements CsRestfulParent {
public ServiceType getServiceType() {
return ServiceType.CONTEXT;
}
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/CsRestfulParent.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/CsRestfulParent.java
index 0faa79ae3..8e7d397ad 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/CsRestfulParent.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/restful/CsRestfulParent.java
@@ -23,21 +23,13 @@ import org.apache.linkis.cs.common.entity.source.ContextKey;
import org.apache.linkis.cs.common.entity.source.ContextKeyValue;
import org.apache.linkis.cs.common.entity.source.ContextValue;
import org.apache.linkis.cs.common.exception.CSErrorException;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.protocol.HttpRequestProtocol;
import org.apache.linkis.cs.server.protocol.HttpResponseProtocol;
import org.apache.linkis.cs.server.protocol.RestResponseProtocol;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
-import org.apache.linkis.cs.server.scheduler.RestJobBuilder;
import org.apache.linkis.cs.server.util.CsUtils;
import org.apache.linkis.server.Message;
-import org.apache.linkis.server.utils.ModuleUserUtils;
-import javax.servlet.http.HttpServletRequest;
-
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -49,18 +41,6 @@ public interface CsRestfulParent {
Logger logger = LoggerFactory.getLogger(CsRestfulParent.class);
- default HttpAnswerJob submitRestJob(
- HttpServletRequest req, ServiceMethod method, Object... objects) throws InterruptedException {
- // TODO: 2020/3/3 单例
- HttpAnswerJob job = (HttpAnswerJob) new RestJobBuilder().build(getServiceType());
- HttpRequestProtocol protocol = job.getRequestProtocol();
- protocol.setUsername(ModuleUserUtils.getOperationUser(req));
- protocol.setServiceMethod(method);
- protocol.setRequestObjects(objects);
- getScheduler().submit(job);
- return job;
- }
-
default Message generateResponse(HttpAnswerJob job, String responseKey) throws CSErrorException {
HttpResponseProtocol responseProtocol = job.getResponseProtocol();
if (responseProtocol instanceof RestResponseProtocol) {
@@ -95,12 +75,28 @@ public interface CsRestfulParent {
return Message.ok();
}
- ServiceType getServiceType();
+ default Message generateMessage(Object data, String responseKey) throws CSErrorException {
+ if (null != data) {
+ if (data instanceof List && ((List) data).isEmpty()) {
+ return Message.ok().data(responseKey, new String[] {});
+ } else if (data instanceof List) {
+ ArrayList<String> strings = new ArrayList<>();
+ for (Object d : (List) data) {
+ strings.add(CsUtils.serialize(d));
+ }
+ return Message.ok().data(responseKey, strings);
+ } else {
+ String dataStr = CsUtils.serialize(data);
+ return Message.ok().data(responseKey, dataStr);
+ }
+ } else {
+ return Message.ok().data(responseKey, null);
+ }
+ }
- CsScheduler getScheduler();
+ ServiceType getServiceType();
- default ContextID getContextIDFromJsonNode(JsonNode jsonNode)
- throws CSErrorException, IOException, ClassNotFoundException {
+ default ContextID getContextIDFromJsonNode(JsonNode jsonNode) throws CSErrorException {
return deserialize(jsonNode, "contextID");
}
@@ -110,23 +106,20 @@ public interface CsRestfulParent {
return (T) CsUtils.SERIALIZE.deserialize(str);
}
- default ContextKey getContextKeyFromJsonNode(JsonNode jsonNode)
- throws CSErrorException, IOException, ClassNotFoundException {
+ default ContextKey getContextKeyFromJsonNode(JsonNode jsonNode) throws CSErrorException {
return deserialize(jsonNode, "contextKey");
}
- default ContextValue getContextValueFromJsonNode(JsonNode jsonNode)
- throws CSErrorException, IOException, ClassNotFoundException {
+ default ContextValue getContextValueFromJsonNode(JsonNode jsonNode) throws CSErrorException {
return deserialize(jsonNode, "contextValue");
}
default ContextKeyValue getContextKeyValueFromJsonNode(JsonNode jsonNode)
- throws CSErrorException, IOException, ClassNotFoundException {
+ throws CSErrorException {
return deserialize(jsonNode, "contextKeyValue");
}
- default ContextHistory getContextHistoryFromJsonNode(JsonNode jsonNode)
- throws CSErrorException, IOException, ClassNotFoundException {
+ default ContextHistory getContextHistoryFromJsonNode(JsonNode jsonNode) throws CSErrorException {
return deserialize(jsonNode, "contextHistory");
}
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextIDServiceImpl.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextIDServiceImpl.java
index 7eccca09b..683523c45 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextIDServiceImpl.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextIDServiceImpl.java
@@ -58,9 +58,9 @@ public class ContextIDServiceImpl extends ContextIDService {
@Override
public String createContextID(ContextID contextID) throws CSErrorException {
- getPersistence().createContextID(contextID);
- logger.info(String.format("createContextID,csId:%s", contextID.getContextId()));
- return contextID.getContextId();
+ ContextID res = getPersistence().createContextID(contextID);
+ logger.info(String.format("createContextID,csId:%s", res.getContextId()));
+ return res.getContextId();
}
@Override
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextServiceImpl.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextServiceImpl.java
index 27b44d2d3..4fc165d92 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextServiceImpl.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/main/java/org/apache/linkis/cs/server/service/impl/ContextServiceImpl.java
@@ -26,6 +26,7 @@ import org.apache.linkis.cs.common.entity.source.ContextKeyValue;
import org.apache.linkis.cs.common.entity.source.ContextValue;
import org.apache.linkis.cs.common.exception.CSErrorException;
import org.apache.linkis.cs.contextcache.ContextCacheService;
+import org.apache.linkis.cs.errorcode.LinkisCsServerErrorCodeSummary;
import org.apache.linkis.cs.exception.ContextSearchFailedException;
import org.apache.linkis.cs.highavailable.ha.ContextHAChecker;
import org.apache.linkis.cs.persistence.ContextPersistenceManager;
@@ -78,7 +79,6 @@ public class ContextServiceImpl extends ContextService {
@Override
public ContextValue getContextValue(ContextID contextID, ContextKey contextKey) {
- // 从缓存取即可,缓存中无会去数据库中拉取
ContextKeyValue keyValue = contextCacheService.get(contextID, contextKey);
if (keyValue == null) {
logger.info(
@@ -88,56 +88,44 @@ public class ContextServiceImpl extends ContextService {
return null;
}
logger.info(
- String.format(
- "getContextValue,csId:%s,key:%s,csType:%s,csScope:%s",
- contextID.getContextId(),
- contextKey.getKey(),
- contextKey.getContextType(),
- contextKey.getContextScope()));
+ "getContextValue,csId:{},key:{},csType:{},csScope:{}",
+ contextID.getContextId(),
+ contextKey.getKey(),
+ contextKey.getContextType(),
+ contextKey.getContextScope());
return keyValue.getContextValue();
}
@Override
public List<ContextKeyValue> searchContextValue(
ContextID contextID, Map<Object, Object> conditionMap) throws ContextSearchFailedException {
- // return List<ContextKeyValue>
- logger.info(String.format("searchContextValue,csId:%s", contextID.getContextId()));
+ logger.info("searchContextValue,csId:{}", contextID.getContextId());
return contextSearch.search(contextCacheService, contextID, conditionMap);
}
- /* @Override
- public List<ContextKeyValue> searchContextValueByCondition(Condition condition) throws ContextSearchFailedException {
- //return List<ContextKeyValue>
- return contextSearch.search(contextCacheService, null, condition);
- }*/
-
@Override
public void setValueByKey(ContextID contextID, ContextKey contextKey, ContextValue contextValue)
- throws CSErrorException, ClassNotFoundException, JsonProcessingException {
- // 1.获取value
+ throws CSErrorException, JsonProcessingException {
Object value = contextValue.getValue();
- // 2.解析keywords,放入contextKey的keys中
Set<String> keys = keywordParser.parse(value);
keys.add(contextKey.getKey());
contextValue.setKeywords(jackson.writeValueAsString(keys));
- // 3.缓存中是否有这个key,没有创建,有就更新
ContextKeyValue keyValue = contextCacheService.get(contextID, contextKey);
if (keyValue == null) {
- // 创建校验scope和tye
if (contextKey.getContextScope() == null || contextKey.getContextType() == null) {
- throw new CSErrorException(97000, "try to create context ,type or scope cannot be empty");
+ throw new CSErrorException(
+ LinkisCsServerErrorCodeSummary.PARAMS_CANNOT_EMPTY.getErrorCode(),
+ "try to create context ,type or scope cannot be empty");
}
- // 这里没有给出contextKeyvalue的具体实现,给个默认的persistence
- logger.warn(
- String.format(
- "setValueByKey, keyValue is not exist, csId:%s,key:%s",
- contextID.getContextId(), contextKey.getKey()));
+ logger.info(
+ "Create cs key value setValueByKey, csId:{}},key:{}",
+ contextID.getContextId(),
+ contextKey.getKey());
keyValue = new PersistenceContextKeyValue();
keyValue.setContextKey(contextKey);
keyValue.setContextValue(contextValue);
getPersistence().create(contextID, keyValue);
} else {
- // update的话,如果scope和type 是空的,要用数据库中的值,因为update缓存要用到
if (contextKey.getContextScope() == null) {
contextKey.setContextScope(keyValue.getContextKey().getContextScope());
}
@@ -148,23 +136,22 @@ public class ContextServiceImpl extends ContextService {
keyValue.setContextValue(contextValue);
getPersistence().update(contextID, keyValue);
}
- // 4.更新缓存
contextCacheService.put(contextID, keyValue);
logger.info(
- String.format(
- "setValueByKey, csId:%s,key:%s,keywords:%s",
- contextID.getContextId(), contextKey.getKey(), contextValue.getKeywords()));
+ "setValueByKey, csId:{},key: {},keywords:{}",
+ contextID.getContextId(),
+ contextKey.getKey(),
+ contextValue.getKeywords());
}
@Override
public void setValue(ContextID contextID, ContextKeyValue contextKeyValue)
throws CSErrorException, ClassNotFoundException, JsonProcessingException {
- // 1.解析keywords
+ // parse keywords
Object value = contextKeyValue.getContextValue().getValue();
Set<String> keys = keywordParser.parse(value);
keys.add(contextKeyValue.getContextKey().getKey());
contextKeyValue.getContextValue().setKeywords(jackson.writeValueAsString(keys));
- // 2.数据库中是否有这个key,没有就创建,有就更新
ContextKeyValue keyValue = contextCacheService.get(contextID, contextKeyValue.getContextKey());
if (keyValue == null) {
logger.warn(
@@ -185,7 +172,8 @@ public class ContextServiceImpl extends ContextService {
}
getPersistence().create(contextID, contextKeyValue);
} else {
- // update的话,如果scope和type 是空的,要用数据库中的值,因为update缓存要用到
+ // For update, if the scope and type are empty, use the value in the database, because the
+ // update cache needs to be used
if (contextKeyValue.getContextKey().getContextScope() == null) {
contextKeyValue.getContextKey().setContextScope(keyValue.getContextKey().getContextScope());
}
@@ -194,22 +182,24 @@ public class ContextServiceImpl extends ContextService {
}
getPersistence().update(contextID, contextKeyValue);
}
- // 3.更新缓存
+ // refresh cache
contextCacheService.put(contextID, contextKeyValue);
logger.info(
- String.format(
- "setValue, csId:%s,key:%s",
- contextID.getContextId(), contextKeyValue.getContextKey().getKey()));
+ "From db and cache to setValue, csId:{},key:{}",
+ contextID.getContextId(),
+ contextKeyValue.getContextKey().getKey());
}
@Override
public void resetValue(ContextID contextID, ContextKey contextKey) throws CSErrorException {
- // 1.reset 数据库
+ // 1.reset db
getPersistence().reset(contextID, contextKey);
- // 2.reset 缓存
+ // 2.reset cache
contextCacheService.rest(contextID, contextKey);
logger.info(
- String.format("resetValue, csId:%s,key:%s", contextID.getContextId(), contextKey.getKey()));
+ "From db and cache resetValue, csId:{},key:{}",
+ contextID.getContextId(),
+ contextKey.getKey());
}
@Override
@@ -218,30 +208,28 @@ public class ContextServiceImpl extends ContextService {
if (contextKeyValue == null) {
return;
}
- // 如果scope和type 不为空,则从原数据中进行赋值
+
if (contextKey.getContextScope() == null) {
contextKey.setContextScope(contextKeyValue.getContextKey().getContextScope());
}
if (contextKey.getContextType() == null) {
contextKey.setContextType(contextKeyValue.getContextKey().getContextType());
}
- // 1.remove 数据库
+ // 1.remove db
getPersistence().remove(contextID, contextKey);
- // 2.remove 缓存
+ // 2.remove cache
contextCacheService.remove(contextID, contextKey);
logger.info(
- String.format(
- "removeValue, csId:%s,key:%s", contextID.getContextId(), contextKey.getKey()));
+ "From db and cache removeValue, csId:{},key:{}",
+ contextID.getContextId(),
+ contextKey.getKey());
}
@Override
public void removeAllValue(ContextID contextID) throws CSErrorException {
- // 移除数据库
getPersistence().removeAll(contextID);
- // 移除缓存
contextCacheService.removeAll(contextID);
-
- logger.info(String.format("removeAllValue, csId:%s", contextID.getContextId()));
+ logger.info("From db and cache removeAllValue, csId:{}", contextID.getContextId());
}
@Override
@@ -250,9 +238,10 @@ public class ContextServiceImpl extends ContextService {
contextCacheService.removeByKeyPrefix(contextID, keyPrefix, contextType);
getPersistence().removeByKeyPrefix(contextID, contextType, keyPrefix);
logger.info(
- String.format(
- "removeAllValueByKeyPrefixAndContextType, csId:%s,csType:%s,keyPrefix:%s",
- contextID.getContextId(), contextType, keyPrefix));
+ "From db and cache removeAllValueByKeyPrefixAndContextType, csId:{},csType:{},keyPrefix:{}",
+ contextID.getContextId(),
+ contextType,
+ keyPrefix);
}
@Override
@@ -261,9 +250,10 @@ public class ContextServiceImpl extends ContextService {
contextCacheService.removeByKey(contextID, keyStr, contextType);
getPersistence().removeByKey(contextID, contextType, keyStr);
logger.info(
- String.format(
- "removeAllValueByKeyAndContextType, csId:%s,csType:%s,keyStr:%s",
- contextID.getContextId(), contextType, keyStr));
+ "From db and cache removeAllValueByKeyAndContextType, csId:{},csType:{},keyStr:{}",
+ contextID.getContextId(),
+ contextType,
+ keyStr);
}
@Override
@@ -272,9 +262,9 @@ public class ContextServiceImpl extends ContextService {
contextCacheService.removeByKeyPrefix(contextID, keyPrefix);
getPersistence().removeByKeyPrefix(contextID, keyPrefix);
logger.info(
- String.format(
- "removeAllValueByKeyPrefix, csId:%s,keyPrefix:%s",
- contextID.getContextId(), keyPrefix));
+ "From db and cache removeAllValueByKeyPrefix, csId:{},keyPrefix:{}",
+ contextID.getContextId(),
+ keyPrefix);
}
@Override
@@ -289,7 +279,7 @@ public class ContextServiceImpl extends ContextService {
getIDPersistence().deleteContextID(csid);
num++;
} catch (Exception e) {
- logger.warn("clear all for haid : {} failed, {}", haid, e.getMessage(), e);
+ logger.warn("clear all for haid : {}", haid, e);
}
}
return num;
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummaryTest.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummaryTest.java
index 459438b18..f6b6dd409 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummaryTest.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/errorcode/LinkisCsServerErrorCodeSummaryTest.java
@@ -26,11 +26,7 @@ public class LinkisCsServerErrorCodeSummaryTest {
@Test
@DisplayName("enumTest")
public void enumTest() {
-
- int errorCode = LinkisCsServerErrorCodeSummary.UNKNOWN_CONDITION_TYPE.getErrorCode();
String errorDesc = LinkisCsServerErrorCodeSummary.UNKNOWN_CONDITION_TYPE.getErrorDesc();
-
- Assertions.assertTrue(errorCode == 1200001);
Assertions.assertNotNull(errorDesc);
}
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/highavailable/test/haid/TestHAID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/highavailable/test/haid/TestHAID.java
index 75bcba410..0c34e2c84 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/highavailable/test/haid/TestHAID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/highavailable/test/haid/TestHAID.java
@@ -54,4 +54,9 @@ public class TestHAID implements HAContextID {
public void setBackupInstance(String backupInstance) {
this.backupInstance = backupInstance;
}
+
+ @Override
+ public HAContextID copy() {
+ return null;
+ }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/persistence/AContextID.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/persistence/AContextID.java
index 79fc8449f..6c85fa187 100644
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/persistence/AContextID.java
+++ b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/persistence/AContextID.java
@@ -130,4 +130,9 @@ public class AContextID implements UserContextID, HAContextID {
@Override
public void setContextIDType(int contextIDType) {}
+
+ @Override
+ public HAContextID copy() {
+ return null;
+ }
}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextHistoryRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextHistoryRestfulApi.java
deleted file mode 100644
index c7e188087..000000000
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextHistoryRestfulApi.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.linkis.cs.server;
-
-import org.apache.linkis.cs.common.entity.enumeration.ContextType;
-import org.apache.linkis.cs.common.entity.history.ContextHistory;
-import org.apache.linkis.cs.common.entity.source.ContextID;
-import org.apache.linkis.cs.common.exception.CSErrorException;
-import org.apache.linkis.cs.persistence.entity.PersistenceContextHistory;
-import org.apache.linkis.cs.persistence.entity.PersistenceContextID;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
-import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
-import org.apache.linkis.server.Message;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.servlet.http.HttpServletRequest;
-
-@RestController
-@RequestMapping(path = "/contextservice")
-public class ContextHistoryRestfulApi implements CsRestfulParent {
-
- @Autowired private CsScheduler csScheduler;
-
- @RequestMapping(path = "createHistory", method = RequestMethod.POST)
- public Message createHistory(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- ContextHistory history = new PersistenceContextHistory();
- history.setSource("server1:prot1");
- history.setContextType(ContextType.METADATA);
- ContextID contextID = new PersistenceContextID();
-
- contextID.setContextId("84716");
- // source and contextid cannot be empty
- if (StringUtils.isEmpty(history.getSource())) {
- throw new CSErrorException(97000, "history source cannot be empty");
- }
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.CREATE, contextID, history);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "removeHistory", method = RequestMethod.POST)
- public Message removeHistory(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- ContextHistory history = new PersistenceContextHistory();
- history.setSource("server1:prot1");
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- // source and contextid cannot be empty
- if (StringUtils.isEmpty(history.getSource())) {
- throw new CSErrorException(97000, "history source cannot be empty");
- }
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVE, contextID, history);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "getHistories", method = RequestMethod.GET)
- public Message getHistories(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, contextID);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "getHistory", method = RequestMethod.GET)
- public Message getHistory(HttpServletRequest req) throws InterruptedException, CSErrorException {
- // ContextID contextID, String source
- String source = "server1:prot1";
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- // source and contextid cannot be empty
- if (StringUtils.isEmpty(source)) {
- throw new CSErrorException(97000, "history source cannot be empty");
- }
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, contextID, source);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "searchHistory", method = RequestMethod.GET)
- public Message searchHistory(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- // ContextID contextID, String[] keywords
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- String[] keywords = new String[] {"keyword1", "keyword2"};
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SEARCH, contextID, keywords);
- return generateResponse(answerJob, "");
- }
-
- @Override
- public ServiceType getServiceType() {
- return ServiceType.CONTEXT_HISTORY;
- }
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
-}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextIDRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextIDRestfulApi.java
deleted file mode 100644
index e682c9f70..000000000
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextIDRestfulApi.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.linkis.cs.server;
-
-import org.apache.linkis.cs.common.entity.enumeration.ExpireType;
-import org.apache.linkis.cs.common.exception.CSErrorException;
-import org.apache.linkis.cs.persistence.entity.PersistenceContextID;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
-import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
-import org.apache.linkis.server.Message;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.servlet.http.HttpServletRequest;
-
-import java.util.Date;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-@RestController
-@RequestMapping(path = "/contextservice")
-public class ContextIDRestfulApi implements CsRestfulParent {
-
- @Autowired private CsScheduler csScheduler;
-
- @RequestMapping(path = "createContextID", method = RequestMethod.POST)
- public Message createContextID(HttpServletRequest req) throws InterruptedException {
- // contextID是client传过来的序列化的id
- PersistenceContextID contextID = new PersistenceContextID();
- contextID.setUser("hadoop");
- contextID.setExpireType(ExpireType.TODAY);
- contextID.setExpireTime(new Date());
- contextID.setInstance("cs-server1");
- contextID.setBackupInstance("cs-server2,cs-server3");
- contextID.setApplication("spark");
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.CREATE, contextID);
- return generateResponse(answerJob, "contextId");
- }
-
- @RequestMapping(path = "getContextID", method = RequestMethod.GET)
- public Message getContextID(
- HttpServletRequest req, @RequestParam(value = "contextId", required = false) String id)
- throws InterruptedException, CSErrorException {
- if (StringUtils.isEmpty(id)) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, id);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "updateContextID", method = RequestMethod.POST)
- public Message updateContextID(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- PersistenceContextID contextID = new PersistenceContextID();
- contextID.setUser("hadoop");
- contextID.setExpireType(ExpireType.NEVER);
- contextID.setExpireTime(new Date());
- contextID.setInstance("cs-server2");
- contextID.setBackupInstance("cs-server1,cs-server3");
- contextID.setApplication("hive");
- // TODO: 2020/2/25 这里要填响应的contextId
- contextID.setContextId("84714");
- if (StringUtils.isEmpty(contextID.getContextId())) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.UPDATE, contextID);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "resetContextID", method = RequestMethod.POST)
- public Message resetContextID(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- String id = null;
- if (StringUtils.isEmpty(id)) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.RESET, id);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "removeContextID", method = RequestMethod.POST)
- public Message removeContextID(HttpServletRequest req, @RequestBody JsonNode json)
- throws InterruptedException, CSErrorException {
- String id = json.get("contextId").textValue();
- if (StringUtils.isEmpty(id)) {
- throw new CSErrorException(97000, "contextId cannot be empty");
- }
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVE, id);
- return generateResponse(answerJob, "");
- }
-
- @Override
- public ServiceType getServiceType() {
- return ServiceType.CONTEXT_ID;
- }
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
-}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextListenerRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextListenerRestfulApi.java
deleted file mode 100644
index 09b10831b..000000000
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextListenerRestfulApi.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.linkis.cs.server;
-
-import org.apache.linkis.cs.common.entity.source.ContextID;
-import org.apache.linkis.cs.common.entity.source.ContextKey;
-import org.apache.linkis.cs.common.listener.ContextIDListener;
-import org.apache.linkis.cs.common.listener.ContextKeyListener;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
-import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
-import org.apache.linkis.server.Message;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.servlet.http.HttpServletRequest;
-
-@RestController
-@RequestMapping(path = "/contextservice")
-public class ContextListenerRestfulApi implements CsRestfulParent {
-
- @Autowired private CsScheduler csScheduler;
-
- @RequestMapping(path = "onBindIDListener", method = RequestMethod.POST)
- public Message onBindIDListener(HttpServletRequest req) throws InterruptedException {
- // ContextIDListener listener
- ContextIDListener listener = null;
- ContextID contextID = null;
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.BIND, contextID, listener);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "onBindKeyListener", method = RequestMethod.POST)
- public Message onBindKeyListener(HttpServletRequest req) throws InterruptedException {
- ContextKeyListener listener = null;
- ContextID contextID = null;
- ContextKey contextKey = null;
- HttpAnswerJob answerJob =
- submitRestJob(req, ServiceMethod.BIND, contextID, contextKey, listener);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "heartbeat", method = RequestMethod.POST)
- public Message heartbeat(HttpServletRequest req) throws InterruptedException {
- String source = null;
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.HEARTBEAT, source);
- return generateResponse(answerJob, "");
- }
-
- @Override
- public ServiceType getServiceType() {
- return ServiceType.CONTEXT_LISTENER;
- }
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
-}
diff --git a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextRestfulApi.java b/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextRestfulApi.java
deleted file mode 100644
index ff96f2b7c..000000000
--- a/linkis-public-enhancements/linkis-context-service/linkis-cs-server/src/test/java/org/apache/linkis/cs/server/ContextRestfulApi.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.linkis.cs.server;
-
-import org.apache.linkis.cs.common.entity.source.ContextID;
-import org.apache.linkis.cs.common.entity.source.ContextKey;
-import org.apache.linkis.cs.common.exception.CSErrorException;
-import org.apache.linkis.cs.persistence.entity.PersistenceContextID;
-import org.apache.linkis.cs.persistence.entity.PersistenceContextKey;
-import org.apache.linkis.cs.server.enumeration.ServiceMethod;
-import org.apache.linkis.cs.server.enumeration.ServiceType;
-import org.apache.linkis.cs.server.scheduler.CsScheduler;
-import org.apache.linkis.cs.server.scheduler.HttpAnswerJob;
-import org.apache.linkis.server.Message;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.servlet.http.HttpServletRequest;
-
-import java.util.Map;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@RestController
-@RequestMapping(path = "/contextservice")
-public class ContextRestfulApi implements CsRestfulParent {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ContextRestfulApi.class);
-
- @Autowired private CsScheduler csScheduler;
- private ObjectMapper objectMapper = new ObjectMapper();
-
- @RequestMapping(path = "createContext", method = RequestMethod.POST)
- public Message createContext(HttpServletRequest request) throws Exception {
-
- // request.getAuthType()
- // if (null == jsonNode.get(ContextHTTPConstant.PROJECT_NAME_STR) || null ==
- // jsonNode.get(ContextHTTPConstant.FLOW_NAME_STR)){
- // LOGGER.error("projectName or flowName is null");
- // throw new ErrorException(80035, "projectName or flowName is null");
- // }
- // String projectName =
- // jsonNode.get(ContextHTTPConstant.PROJECT_NAME_STR).getTextValue();
- // String flowName = jsonNode.get(ContextHTTPConstant.FLOW_NAME_STR).getTextValue();
- String projectName = "";
- String flowName = "";
- HttpAnswerJob answerJob = submitRestJob(request, ServiceMethod.GET, projectName, flowName);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "getContextValue", method = RequestMethod.POST)
- public Message getContextValue(HttpServletRequest req) throws InterruptedException {
- // ContextID contextID, ContextKey contextKey
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- ContextKey contextKey = new PersistenceContextKey();
- contextKey.setKey("flow1.node1");
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.GET, contextID, contextKey);
- return generateResponse(answerJob, "");
- }
-
- /* {
- "type":"And",
- "left":{
- "type":"ContextType",
- "contextType":"DATA"
- },
- "right":{
- "type":"And",
- "left":{
- "type":"ContextScope",
- "contextScope":"PRIVATE"
- },
- "right":{
- "type":"Regex",
- "regex":"[abc]]"
- }
- }
- }*/
- @RequestMapping(path = "searchContextValue", method = RequestMethod.POST)
- public Message searchContextValue(HttpServletRequest req, @RequestBody JsonNode jsonNode)
- throws InterruptedException {
- ContextID contextID =
- objectMapper.convertValue(jsonNode.get("contextID"), PersistenceContextID.class);
- Map<Object, Object> conditionMap =
- objectMapper.convertValue(
- jsonNode.get("condition"), new TypeReference<Map<Object, Object>>() {});
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SEARCH, contextID, conditionMap);
- return generateResponse(answerJob, "");
- }
-
- /* @RequestMapping(path = "searchContextValueByCondition",method = RequestMethod.GET)
- public Message searchContextValueByCondition( HttpServletRequest req, @RequestBody JsonNode jsonNode) throws InterruptedException {
- Condition condition = null;
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SEARCH, condition);
- return generateResponse(answerJob,"");
- }*/
-
- @RequestMapping(path = "setValueByKey", method = RequestMethod.POST)
- public Message setValueByKey(HttpServletRequest req)
- throws InterruptedException, CSErrorException {
- /*JSONSerializer jsonSerializer = new JSONSerializer();
- PersistenceContextID contextID = new PersistenceContextID();
- //// TODO: 2020/2/26 手动修改contextid
- contextID.setContextId("84716");
- ContextKey contextKey = new PersistenceContextKey();
- //必传
- contextKey.setContextScope(ContextScope.FRIENDLY);
- contextKey.setContextScope(ContextScope.PROTECTED);
- contextKey.setContextType(ContextType.METADATA);
- contextKey.setKey("flow1.node1");
- ContextValue contextValue = new PersistenceContextValue();
- CSTable csTable = new CSTable();
- csTable.setName("table1");
- csTable.setCreator("hadoop");
- String encode = jsonSerializer.encode(csTable);
- contextValue.setValue(encode);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SET, contextID, contextKey, contextValue);
- return generateResponse(answerJob,"");*/
- return null;
- }
-
- @RequestMapping(path = "setValue", method = RequestMethod.POST)
- public Message setValue(HttpServletRequest req) throws InterruptedException, CSErrorException {
- /*JSONSerializer jsonSerializer = new JSONSerializer();
- PersistenceContextID contextID = new PersistenceContextID();
- //// TODO: 2020/2/26 手动修改contextid
- contextID.setContextId("84716");
- ContextKey contextKey = new PersistenceContextKey();
- //必传
- contextKey.setContextScope(ContextScope.FRIENDLY);
- // TODO: 2020/2/26 type是必要参数
- contextKey.setContextType(ContextType.METADATA);
- contextKey.setContextScope(ContextScope.PROTECTED);
- contextKey.setKey("flow1.node2");
- ContextValue contextValue = new PersistenceContextValue();
- CSTable csTable = new CSTable();
- csTable.setName("tableupdate");
- csTable.setCreator("hadoopupdate");
- String encode = jsonSerializer.encode(csTable);
- contextValue.setValue(encode);
- ContextKeyValue contextKeyValue = new PersistenceContextKeyValue();
- contextKeyValue.setContextValue(contextValue);
- contextKeyValue.setContextKey(contextKey);
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.SET, contextID, contextKeyValue);
- return generateResponse(answerJob,"");*/
- return null;
- }
-
- @RequestMapping(path = "resetValue", method = RequestMethod.POST)
- public Message resetValue(HttpServletRequest req) throws InterruptedException {
- ContextID contextID = null;
- ContextKey contextKey = null;
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.RESET, contextID, contextKey);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "removeValue", method = RequestMethod.POST)
- public Message removeValue(HttpServletRequest req) throws InterruptedException {
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- ContextKey contextKey = new PersistenceContextKey();
- contextKey.setKey("flow1.node1");
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVE, contextID, contextKey);
- return generateResponse(answerJob, "");
- }
-
- @RequestMapping(path = "removeAllValue", method = RequestMethod.POST)
- public Message removeAllValue(HttpServletRequest req) throws InterruptedException {
- ContextID contextID = new PersistenceContextID();
- contextID.setContextId("84716");
- HttpAnswerJob answerJob = submitRestJob(req, ServiceMethod.REMOVEALL, contextID);
- return generateResponse(answerJob, "");
- }
-
- @Override
- public ServiceType getServiceType() {
- return ServiceType.CONTEXT;
- }
-
- @Override
- public CsScheduler getScheduler() {
- return this.csScheduler;
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org