Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli(engine): optimize tiflow cli #6648

Merged
merged 6 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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