Skip to content

Commit 5b33665

Browse files
committed
Support for in-container Java experiments
Signed-off-by: xcaspar <changjun.xcj@alibaba-inc.com>
1 parent 2960725 commit 5b33665

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ tags
4646
target
4747
coverage.txt
4848
vendor
49+
/build/cache
4950

5051
# Website
5152
site-build

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GO=env $(GO_ENV) $(GO_MODULE) go
77
UNAME := $(shell uname)
88

99
ifeq ($(BLADE_VERSION), )
10-
BLADE_VERSION=1.4.0
10+
BLADE_VERSION=1.5.0
1111
endif
1212

1313
BUILD_TARGET=target
@@ -19,6 +19,8 @@ BUILD_IMAGE_PATH=build/image/blade
1919
OS_YAML_FILE_NAME=chaosblade-cri-spec-$(BLADE_VERSION).yaml
2020
OS_YAML_FILE_PATH=$(BUILD_TARGET_YAML)/$(OS_YAML_FILE_NAME)
2121

22+
CHAOSBLADE_PATH=build/cache/chaosblade
23+
2224
ifeq ($(GOOS), linux)
2325
GO_FLAGS=-ldflags="-linkmode external -extldflags -static"
2426
endif
@@ -32,7 +34,7 @@ pre_build:
3234
mkdir -p $(BUILD_TARGET_YAML)
3335

3436
build_yaml: build/spec.go
35-
$(GO) run $< $(OS_YAML_FILE_PATH)
37+
$(GO) run $< $(OS_YAML_FILE_PATH) $(CHAOSBLADE_PATH)/yaml/chaosblade-jvm-spec-$(BLADE_VERSION).yaml
3638

3739
# test
3840
test:

build/spec.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ import (
2828

2929
// main creates a yaml file of the experiments in the project
3030
func main() {
31-
if len(os.Args) != 2 {
31+
if len(os.Args) < 2 {
3232
log.Panicln("less yaml file path")
3333
}
34+
if len(os.Args) == 3 {
35+
exec.JvmSpecFileForYaml = os.Args[2]
36+
}
3437
err := util.CreateYamlFile(getModels(), os.Args[1])
3538
if err != nil {
3639
log.Panicf("create yaml file error, %v", err)

exec/application.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 1999-2020 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package exec
18+
19+
import (
20+
"fmt"
21+
"path"
22+
23+
"github.com/chaosblade-io/chaosblade-spec-go/spec"
24+
"github.com/chaosblade-io/chaosblade-spec-go/util"
25+
"github.com/sirupsen/logrus"
26+
27+
"github.com/chaosblade-io/chaosblade-exec-cri/version"
28+
)
29+
30+
var JvmSpecFileForYaml = ""
31+
32+
// getJvmModels returns java experiment specs
33+
func getJvmModels() []spec.ExpModelCommandSpec {
34+
var jvmSpecFile = path.Join(util.GetYamlHome(), fmt.Sprintf("chaosblade-jvm-spec-%s.yaml", version.BladeVersion))
35+
if JvmSpecFileForYaml != "" {
36+
jvmSpecFile = JvmSpecFileForYaml
37+
}
38+
modelCommandSpecs := make([]spec.ExpModelCommandSpec, 0)
39+
models, err := util.ParseSpecsToModel(jvmSpecFile, nil)
40+
if err != nil {
41+
logrus.Warningf("parse java spec failed, so skip it, %s", err)
42+
return modelCommandSpecs
43+
}
44+
for idx := range models.Models {
45+
modelCommandSpecs = append(modelCommandSpecs, &models.Models[idx])
46+
}
47+
return modelCommandSpecs
48+
}

exec/model.go

+2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ func NewCriExpModelSpec() *dockerExpModelSpec {
4242
networkCommandModelSpec,
4343
}
4444

45+
javaExpModelSpecs := getJvmModels()
4546
execInContainerModelSpecs := []spec.ExpModelCommandSpec{
4647
newProcessCommandModelSpecForDocker(),
4748
newCpuCommandModelSpecForDocker(),
4849
newDiskCommandSpecForDocker(),
4950
newMemCommandModelSpecForDocker(),
5051
newFileCommandSpecForDocker(),
5152
}
53+
execInContainerModelSpecs = append(execInContainerModelSpecs, javaExpModelSpecs...)
5254
containerSelfModelSpec := NewContainerCommandSpec()
5355

5456
spec.AddExecutorToModelSpec(NewNetWorkSidecarExecutor(), networkCommandModelSpec)

version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
package version
1818

1919
// Default version is latest, you can specify the value at compile time, see Makefile in chaosblade project for the details
20-
var BladeVersion = "latest"
20+
var BladeVersion = "1.5.0"

0 commit comments

Comments
 (0)