-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: wufan <[email protected]>
- Loading branch information
Showing
40 changed files
with
729 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...c/main/java/com/alibaba/chaosblade/exec/common/aop/matcher/busi/BusinessParamMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.alibaba.chaosblade.exec.common.aop.matcher.busi; | ||
|
||
import com.alibaba.chaosblade.exec.common.aop.CustomMatcher; | ||
import com.alibaba.chaosblade.exec.common.util.BusinessParamUtil; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public class BusinessParamMatcher implements CustomMatcher { | ||
private static final BusinessParamMatcher INSTANCE = new BusinessParamMatcher(); | ||
|
||
private BusinessParamMatcher() { | ||
} | ||
|
||
public static BusinessParamMatcher getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean match(String commandValue, Object originValue) { | ||
Map<String, String> businessData = (Map<String, String>) originValue; | ||
List<BusinessParamUtil.BusinessParam> businessParams = BusinessParamUtil.parseFromJsonStr(commandValue); | ||
for (BusinessParamUtil.BusinessParam businessParam : businessParams) { | ||
if (!businessData.containsKey(businessParam.getKey())) { | ||
return false; | ||
} | ||
if (!businessData.get(businessParam.getKey()).equals(businessParam.getValue())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean regexMatch(String commandValue, Object originValue) { | ||
return false; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...mon/src/main/java/com/alibaba/chaosblade/exec/common/center/DefaultSPIServiceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.alibaba.chaosblade.exec.common.center; | ||
|
||
|
||
import java.util.*; | ||
|
||
public class DefaultSPIServiceManager implements SPIServiceManager { | ||
private static Map<String, List<Object>> spiMap; | ||
|
||
static { | ||
spiMap = new HashMap<String, List<Object>>(); | ||
} | ||
|
||
@Override | ||
public void load() { | ||
|
||
} | ||
@Override | ||
public List<Object> getServices(String className, ClassLoader classLoader) { | ||
if (spiMap.containsKey(className)) { | ||
return spiMap.get(className); | ||
} | ||
synchronized (this) { | ||
if (spiMap.containsKey(className)) { | ||
return spiMap.get(className); | ||
} | ||
List<Object> services = loadService(className, classLoader); | ||
spiMap.put(className, services); | ||
return services; | ||
} | ||
} | ||
|
||
public List<Object> loadService(String className, ClassLoader classLoader) { | ||
Class clazz; | ||
try { | ||
clazz = classLoader.loadClass(className); | ||
} catch (ClassNotFoundException e) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
ServiceLoader serviceLoader = ServiceLoader.load(clazz, classLoader); | ||
List<Object> objects = new ArrayList<Object>(); | ||
for (Object object : serviceLoader) { | ||
objects.add(object); | ||
} | ||
return objects; | ||
} | ||
|
||
@Override | ||
public void unload() { | ||
spiMap.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...xec-common/src/main/java/com/alibaba/chaosblade/exec/common/center/SPIServiceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alibaba.chaosblade.exec.common.center; | ||
|
||
import java.util.List; | ||
|
||
public interface SPIServiceManager extends ManagerService{ | ||
List<Object> getServices(String className, ClassLoader classLoader); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 26 additions & 3 deletions
29
...c-common/src/main/java/com/alibaba/chaosblade/exec/common/context/ThreadLocalContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,45 @@ | ||
package com.alibaba.chaosblade.exec.common.context; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public class ThreadLocalContext { | ||
|
||
private static ThreadLocalContext DEFAULT = new ThreadLocalContext(); | ||
private InheritableThreadLocal<Object> local = new InheritableThreadLocal<Object>(); | ||
private InheritableThreadLocal<Content> local = new InheritableThreadLocal<Content>(); | ||
|
||
public static ThreadLocalContext getInstance() { | ||
return DEFAULT; | ||
} | ||
|
||
public void set(Object value) { | ||
public void set(Content value) { | ||
local.set(value); | ||
} | ||
|
||
public Object get() { | ||
public Content get() { | ||
return local.get(); | ||
} | ||
|
||
public static class Content{ | ||
private StackTraceElement[] stackTraceElements; | ||
private Map<String, Map<String, String>> businessData; | ||
|
||
public StackTraceElement[] getStackTraceElements() { | ||
return stackTraceElements; | ||
} | ||
|
||
public void setStackTraceElements(StackTraceElement[] stackTraceElements) { | ||
this.stackTraceElements = stackTraceElements; | ||
} | ||
|
||
public Map<String, Map<String, String>> getBusinessData() { | ||
return businessData; | ||
} | ||
|
||
public void settValue(Map<String, Map<String, String>> businessData) { | ||
this.businessData = businessData; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...main/java/com/alibaba/chaosblade/exec/common/model/matcher/BusinessParamsMatcherSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.alibaba.chaosblade.exec.common.model.matcher; | ||
|
||
import com.alibaba.chaosblade.exec.common.aop.PredicateResult; | ||
import com.alibaba.chaosblade.exec.common.constant.ModelConstant; | ||
import com.alibaba.chaosblade.exec.common.util.BusinessParamUtil; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public class BusinessParamsMatcherSpec extends BasePredicateMatcherSpec { | ||
@Override | ||
public String getName() { | ||
return ModelConstant.BUSINESS_PARAMS; | ||
} | ||
|
||
@Override | ||
public String getDesc() { | ||
return "business parmas"; | ||
} | ||
|
||
@Override | ||
public boolean noArgs() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean required() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public PredicateResult predicate(MatcherModel matcherModel) { | ||
String bParam = matcherModel.get(ModelConstant.BUSINESS_PARAMS); | ||
List<BusinessParamUtil.BusinessParam> params = BusinessParamUtil.parseFromJsonStr(bParam); | ||
if (params == null || params.isEmpty()) { | ||
return PredicateResult.fail(getName() + " illegal json"); | ||
} | ||
return PredicateResult.success(); | ||
} | ||
} |
Oops, something went wrong.