-
Notifications
You must be signed in to change notification settings - Fork 98
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: tiny-x <[email protected]>
- Loading branch information
Showing
16 changed files
with
395 additions
and
29 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
16 changes: 16 additions & 0 deletions
16
...de-box-scenario-api/src/main/java/com/alibaba/chaosblade/box/scenario/api/init/Scene.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,16 @@ | ||
package com.alibaba.chaosblade.box.scenario.api.init; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author yefei | ||
*/ | ||
@Data | ||
public class Scene { | ||
|
||
private String sceneCode; | ||
|
||
private List<SceneParam> sceneParams; | ||
} |
24 changes: 24 additions & 0 deletions
24
...x-scenario-api/src/main/java/com/alibaba/chaosblade/box/scenario/api/init/SceneParam.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,24 @@ | ||
package com.alibaba.chaosblade.box.scenario.api.init; | ||
|
||
import com.alibaba.chaosblade.box.common.jackson.JsonToStringDeserializer; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author yefei | ||
*/ | ||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class SceneParam { | ||
|
||
private String name; | ||
|
||
private String alias; | ||
|
||
private String description; | ||
|
||
@JsonDeserialize(using = JsonToStringDeserializer.class) | ||
private String component; | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...src/main/java/com/alibaba/chaosblade/box/scenario/api/init/SceneParamComponentLoader.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,71 @@ | ||
package com.alibaba.chaosblade.box.scenario.api.init; | ||
|
||
import cn.hutool.core.collection.CollUtil; | ||
import cn.hutool.core.io.IoUtil; | ||
import cn.hutool.core.io.resource.ResourceUtil; | ||
import cn.hutool.core.util.StrUtil; | ||
import com.alibaba.chaosblade.box.common.utils.JsonUtils; | ||
import com.alibaba.chaosblade.box.dao.model.SceneDO; | ||
import com.alibaba.chaosblade.box.dao.model.SceneParamDO; | ||
import com.alibaba.chaosblade.box.dao.repository.SceneParamRepository; | ||
import com.alibaba.chaosblade.box.dao.repository.SceneRepository; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author yefei | ||
*/ | ||
@Component | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
public class SceneParamComponentLoader implements InitializingBean { | ||
|
||
@Autowired | ||
private SceneRepository sceneRepository; | ||
|
||
@Autowired | ||
private SceneParamRepository sceneParamRepository; | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
InputStream stream = ResourceUtil.getStream("scene_param_component.json"); | ||
|
||
List<Scene> scenes = JsonUtils.readValue(new TypeReference<List<Scene>>() { | ||
}, IoUtil.readBytes(stream)); | ||
|
||
if (CollUtil.isEmpty(scenes)) { | ||
return; | ||
} | ||
|
||
for (Scene scene : scenes) { | ||
List<SceneDO> sceneDOS = sceneRepository.selectByCode(scene.getSceneCode()); | ||
|
||
sceneDOS.forEach(sceneDO -> { | ||
List<SceneParam> sceneParams = scene.getSceneParams(); | ||
if (CollUtil.isNotEmpty(sceneParams)) { | ||
Map<String, SceneParam> map = sceneParams.stream().collect(Collectors.toMap(SceneParam::getName, u -> u)); | ||
List<SceneParamDO> sceneParamDOS = sceneParamRepository | ||
.selectList(SceneParamDO.builder().sceneId(sceneDO.getId()).build()); | ||
|
||
sceneParamDOS.forEach(sceneParamDO -> { | ||
SceneParam sceneParam = map.get(sceneParamDO.getParamName()); | ||
if (sceneParam != null && StrUtil.isEmpty(sceneParamDO.getComponent())) { | ||
sceneParamRepository.updateByPrimaryKey(sceneParamDO.getId(), | ||
SceneParamDO.builder() | ||
.component(sceneParam.getComponent()) | ||
.build()); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
...de-box-scenario/chaosblade-box-scenario-api/src/main/resources/scene_param_component.json
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,168 @@ | ||
[ | ||
{ | ||
"sceneCode": "chaosblade.cpu.fullload", | ||
"sceneParams": [ | ||
{ | ||
"name": "cpu-count", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "number", | ||
"required": false | ||
} | ||
}, | ||
{ | ||
"name": "cpu-percent", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "range", | ||
"required": false, | ||
"minValue": "0", | ||
"maxValue": "100", | ||
"values": [] | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"sceneCode": "chaosblade.mem.load", | ||
"sceneParams": [ | ||
{ | ||
"name": "reserve", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "number", | ||
"required": false | ||
} | ||
}, | ||
{ | ||
"name": "rate", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "number", | ||
"required": false | ||
} | ||
}, | ||
{ | ||
"name": "mem-percent", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "range", | ||
"required": false, | ||
"minValue": "0", | ||
"maxValue": "100", | ||
"values": [] | ||
} | ||
}, | ||
{ | ||
"name": "mode", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "select", | ||
"required": false, | ||
"minValue": "0", | ||
"maxValue": "100", | ||
"values": [ | ||
{ | ||
"key": 0, | ||
"label": "ram", | ||
"value": "ram" | ||
}, | ||
{ | ||
"key": 1, | ||
"label": "cache", | ||
"value": "cache" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"sceneCode": "chaosblade.jvm.script", | ||
"sceneParams": [ | ||
{ | ||
"name": "script-type", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "select", | ||
"required": false, | ||
"values": [ | ||
{ | ||
"key": 0, | ||
"label": "java", | ||
"value": "java" | ||
}, | ||
{ | ||
"key": 1, | ||
"label": "groovy", | ||
"value": "groovy" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "script-content", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "script", | ||
"required": false | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"sceneCode": "chaosblade.dubbo.delay", | ||
"sceneParams": [ | ||
{ | ||
"name": "consumer", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "radio", | ||
"required": false, | ||
"values": [ | ||
{ | ||
"key": 0, | ||
"label": "是", | ||
"value": "true" | ||
}, | ||
{ | ||
"key": 1, | ||
"label": "否", | ||
"value": "false" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "provider", | ||
"alias": "", | ||
"description": "", | ||
"component": { | ||
"type": "radio", | ||
"required": false, | ||
"values": [ | ||
{ | ||
"key": 0, | ||
"label": "是", | ||
"value": "true" | ||
}, | ||
{ | ||
"key": 1, | ||
"label": "否", | ||
"value": "false" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
] |
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
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
Oops, something went wrong.