Skip to content

Commit

Permalink
Support for in-container Java experiments
Browse files Browse the repository at this point in the history
Signed-off-by: xcaspar <[email protected]>
  • Loading branch information
xcaspar committed Dec 16, 2021
1 parent 2960725 commit 5b33665
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tags
target
coverage.txt
vendor
/build/cache

# Website
site-build
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GO=env $(GO_ENV) $(GO_MODULE) go
UNAME := $(shell uname)

ifeq ($(BLADE_VERSION), )
BLADE_VERSION=1.4.0
BLADE_VERSION=1.5.0
endif

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

CHAOSBLADE_PATH=build/cache/chaosblade

ifeq ($(GOOS), linux)
GO_FLAGS=-ldflags="-linkmode external -extldflags -static"
endif
Expand All @@ -32,7 +34,7 @@ pre_build:
mkdir -p $(BUILD_TARGET_YAML)

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

# test
test:
Expand Down
5 changes: 4 additions & 1 deletion build/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ import (

// main creates a yaml file of the experiments in the project
func main() {
if len(os.Args) != 2 {
if len(os.Args) < 2 {
log.Panicln("less yaml file path")
}
if len(os.Args) == 3 {
exec.JvmSpecFileForYaml = os.Args[2]
}
err := util.CreateYamlFile(getModels(), os.Args[1])
if err != nil {
log.Panicf("create yaml file error, %v", err)
Expand Down
48 changes: 48 additions & 0 deletions exec/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package exec

import (
"fmt"
"path"

"github.com/chaosblade-io/chaosblade-spec-go/spec"
"github.com/chaosblade-io/chaosblade-spec-go/util"
"github.com/sirupsen/logrus"

"github.com/chaosblade-io/chaosblade-exec-cri/version"
)

var JvmSpecFileForYaml = ""

// getJvmModels returns java experiment specs
func getJvmModels() []spec.ExpModelCommandSpec {
var jvmSpecFile = path.Join(util.GetYamlHome(), fmt.Sprintf("chaosblade-jvm-spec-%s.yaml", version.BladeVersion))
if JvmSpecFileForYaml != "" {
jvmSpecFile = JvmSpecFileForYaml
}
modelCommandSpecs := make([]spec.ExpModelCommandSpec, 0)
models, err := util.ParseSpecsToModel(jvmSpecFile, nil)
if err != nil {
logrus.Warningf("parse java spec failed, so skip it, %s", err)
return modelCommandSpecs
}
for idx := range models.Models {
modelCommandSpecs = append(modelCommandSpecs, &models.Models[idx])
}
return modelCommandSpecs
}
2 changes: 2 additions & 0 deletions exec/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ func NewCriExpModelSpec() *dockerExpModelSpec {
networkCommandModelSpec,
}

javaExpModelSpecs := getJvmModels()
execInContainerModelSpecs := []spec.ExpModelCommandSpec{
newProcessCommandModelSpecForDocker(),
newCpuCommandModelSpecForDocker(),
newDiskCommandSpecForDocker(),
newMemCommandModelSpecForDocker(),
newFileCommandSpecForDocker(),
}
execInContainerModelSpecs = append(execInContainerModelSpecs, javaExpModelSpecs...)
containerSelfModelSpec := NewContainerCommandSpec()

spec.AddExecutorToModelSpec(NewNetWorkSidecarExecutor(), networkCommandModelSpec)
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
package version

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

0 comments on commit 5b33665

Please sign in to comment.