Skip to content

Commit

Permalink
cli(engine): optimize tiflow cli (#6648)
Browse files Browse the repository at this point in the history
close #6600
  • Loading branch information
CharlesCheung96 authored Aug 8, 2022
1 parent ea85235 commit 9113a0d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions engine/pkg/cmd/cli/cli_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ import (
"github.com/pingcap/tiflow/engine/enginepb"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/pingcap/tiflow/engine/pkg/tenant"
"github.com/pingcap/tiflow/pkg/errors"
)

// defaultMasterAddr is the default master address.
const defaultMasterAddr = "127.0.0.1:10240"

// jobGeneralOptions defines some general options of job management
type jobGeneralOptions struct {
projectID string
Expand Down Expand Up @@ -61,12 +64,13 @@ func (o *jobGeneralOptions) addFlags(cmd *cobra.Command) {
// validate checks that the provided job options are valid.
func (o *jobGeneralOptions) validate(ctx context.Context, cmd *cobra.Command) error {
if len(o.masterAddrs) == 0 {
return errors.ErrInvalidCliParameter.GenWithStack("master-addrs can't be nil")
o.masterAddrs = []string{defaultMasterAddr}
log.Warn("the master-addrs are not assigned, use default addr: " + defaultMasterAddr)
}

// TODO support https.
dialURL := o.masterAddrs[0]
grpcConn, err := grpc.Dial(dialURL)
grpcConn, err := grpc.Dial(dialURL, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return perrors.Trace(err)
}
Expand Down
8 changes: 7 additions & 1 deletion engine/pkg/cmd/cli/cli_job_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type jobCreateOptions struct {
jobTypeStr string
jobConfigStr string

jobID string
jobType engineModel.JobType
jobConfig []byte
}
Expand All @@ -50,8 +51,9 @@ func (o *jobCreateOptions) addFlags(cmd *cobra.Command) {
return
}

cmd.Flags().StringVar(&o.jobTypeStr, "job-type", "", "job type")
cmd.Flags().StringVar(&o.jobTypeStr, "job-type", "", "job type, one of [FakeJob, CVSDemo, DM]")
cmd.Flags().StringVar(&o.jobConfigStr, "job-config", "", "path of config file for the job")
cmd.Flags().StringVar(&o.jobID, "job-id", "", "job id")
}

// validate checks that the provided job options are valid.
Expand All @@ -77,6 +79,10 @@ func (o *jobCreateOptions) validate(ctx context.Context, cmd *cobra.Command) err
}

func openFileAndReadString(path string) (content []byte, err error) {
if path == "" {
log.Warn("create job with empty config file")
return nil, nil
}
fp, err := os.Open(path)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion engine/test/integration_tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ mkdir -p $OUT_DIR || true

if [ "${1-}" = 'debug' ]; then
shift
if [[ ${1} ]]; then
if [[ $# -lt 0 ]]; then
cnf=$*
else
cnf="$DOCKER_COMPOSE_DIR/1m1e.yaml"
echo "got empty file, use default config: ${cnf}"
fi

trap "stop_engine_cluster $cnf" EXIT
Expand Down

0 comments on commit 9113a0d

Please sign in to comment.