Skip to content

Commit

Permalink
Merge branch 'master' into history-thrift-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vytautas-karpavicius authored Oct 26, 2020
2 parents 6e2ac85 + ad06c81 commit b35bc07
Show file tree
Hide file tree
Showing 201 changed files with 14,917 additions and 3,772 deletions.
52 changes: 48 additions & 4 deletions .gen/go/replicator/replicator.go

Large diffs are not rendered by default.

204 changes: 189 additions & 15 deletions .gen/go/shared/shared.go

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions .gen/proto/gogo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

980 changes: 490 additions & 490 deletions .gen/proto/message.pb.go

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
The MIT License (MIT)

Copyright (c) 2017-2020 Uber Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ cadence-canary: $(ALL_SRC)
@echo "compiling cadence-canary with OS: $(GOOS), ARCH: $(GOARCH)"
go build -o cadence-canary cmd/canary/main.go

go-generate-format: go-generate fmt

go-generate:
GO111MODULE=off go get -u github.com/myitcv/gobin
GOOS= GOARCH= gobin -mod=readonly github.com/golang/mock/mockgen
GOOS= GOARCH= gobin -mod=readonly github.com/dmarkham/enumer
@echo "running go generate ./..."
@go generate ./...
@echo "running go run cmd/tools/copyright/licensegen.go"
@go run cmd/tools/copyright/licensegen.go

lint:
@echo "running linter"
Expand Down
2 changes: 1 addition & 1 deletion client/clientBean.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../LICENSE -package $GOPACKAGE -source $GOFILE -destination clientBean_mock.go -self_package github.com/uber/cadence/client
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination clientBean_mock.go -self_package github.com/uber/cadence/client

package client

Expand Down
5 changes: 2 additions & 3 deletions client/clientBean_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *server) startService() common.Daemon {
}

params.ESConfig = advancedVisStore.ElasticSearch
esClient, err := elasticsearch.NewClient(params.ESConfig)
esClient, err := elasticsearch.NewGenericClient(params.ESConfig, s.cfg.Persistence.VisibilityConfig, params.Logger)
if err != nil {
log.Fatalf("error creating elastic search client: %v", err)
}
Expand Down
119 changes: 104 additions & 15 deletions cmd/tools/copyright/licensegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package main

import (
"bufio"
"errors"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -40,17 +41,26 @@ type (

// command line config params
config struct {
rootDir string
verifyOnly bool
rootDir string
verifyOnly bool
temporalAddMode bool
temporalModifyMode bool
filePaths string
}
)

// licenseFileName is the name of the license file
const licenseFileName = "LICENSE"

// unique prefix that identifies a license header
const licenseHeaderPrefixOld = "// Copyright (c)"
const licenseHeaderPrefixOld = "Copyright (c)"
const licenseHeaderPrefix = "// The MIT License (MIT)"
const cadenceCopyright = "// Copyright (c) 2017-2020 Uber Technologies Inc."
const cadenceModificationHeader = "// Modifications Copyright (c) 2020 Uber Technologies Inc."
const temporalCopyright = "// Copyright (c) 2020 Temporal Technologies, Inc."
const temporalPartialCopyright = "// Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc."

const firstLinesToCheck = 10

var (
// directories to be excluded
Expand All @@ -69,15 +79,38 @@ func main() {
flag.StringVar(&cfg.rootDir, "rootDir", ".", "project root directory")
flag.BoolVar(&cfg.verifyOnly, "verifyOnly", false,
"don't automatically add headers, just verify all files")
flag.BoolVar(&cfg.temporalAddMode, "temporalAddMode", false, "add copyright for new file copied from temporal")
flag.BoolVar(&cfg.temporalModifyMode, "temporalModifyMode", false, "add copyright for existing file which has parts copied from temporal")
flag.StringVar(&cfg.filePaths, "filePaths", "", "comma separated list of files to run temporal license on")
flag.Parse()

if err := verifyCfg(cfg); err != nil {
fmt.Println(err)
os.Exit(-1)
}

task := newAddLicenseHeaderTask(&cfg)
if err := task.run(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

func verifyCfg(cfg config) error {
if cfg.verifyOnly {
if cfg.temporalModifyMode || cfg.temporalAddMode {
return errors.New("invalid config, can only specify one of temporalAddMode, temporalModifyMode or verifyOnly")
}
}
if cfg.temporalAddMode && cfg.temporalModifyMode {
return errors.New("invalid config, can only specify temporalAddMode or temporalModifyMode")
}
if (cfg.temporalModifyMode || cfg.temporalAddMode) && len(cfg.filePaths) == 0 {
return errors.New("invalid config, when running in temporalAddMode or temporalModifyMode must provide filePaths")
}
return nil
}

func newAddLicenseHeaderTask(cfg *config) *addLicenseHeaderTask {
return &addLicenseHeaderTask{
config: cfg,
Expand All @@ -89,12 +122,28 @@ func (task *addLicenseHeaderTask) run() error {
if err != nil {
return fmt.Errorf("error reading license file, errr=%v", err.Error())
}

task.license, err = commentOutLines(string(data))
if err != nil {
return fmt.Errorf("copyright header failed to comment out lines, err=%v", err.Error())
}

if task.config.temporalAddMode {
task.license = fmt.Sprintf("%v\n\n%v\n\n%v", cadenceModificationHeader, temporalCopyright, task.license)
} else if task.config.temporalModifyMode {
task.license = fmt.Sprintf("%v\n\n%v\n\n%v", cadenceCopyright, temporalPartialCopyright, task.license)
}
if task.config.temporalModifyMode || task.config.temporalAddMode {
filePaths, fileInfos, err := getFilePaths(task.config.filePaths)
if err != nil {
return err
}
for i := 0; i < len(filePaths); i++ {
if err := task.handleFile(filePaths[i], fileInfos[i], nil); err != nil {
return err
}
}
return nil
}
task.license = fmt.Sprintf("%v\n\n%v\n\n%v", licenseHeaderPrefix, cadenceCopyright, task.license)
err = filepath.Walk(task.config.rootDir, task.handleFile)
if err != nil {
return fmt.Errorf("copyright header check failed, err=%v", err.Error())
Expand All @@ -120,7 +169,7 @@ func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo,
return nil
}

if !strings.HasSuffix(fileInfo.Name(), ".go") {
if !strings.HasSuffix(fileInfo.Name(), ".go") && !strings.HasSuffix(fileInfo.Name(), ".proto") {
return nil
}

Expand All @@ -131,19 +180,20 @@ func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo,
return err
}

scanner := bufio.NewScanner(f)
readLineSucc := scanner.Scan()
if !readLineSucc {
return fmt.Errorf("fail to read first line of file %v", path)
ok, err := hasCopyright(f)
if err != nil {
return err
}
firstLine := strings.TrimSpace(scanner.Text())
if err := scanner.Err(); err != nil {

if err := f.Close(); err != nil {
return err
}
f.Close()

if strings.Contains(firstLine, licenseHeaderPrefixOld) || strings.Contains(firstLine, licenseHeaderPrefix) {
return nil // file already has the copyright header
if ok {
if task.config.temporalModifyMode || task.config.temporalAddMode {
return fmt.Errorf("when running in temporalModifyMode or temporalAddMode please first remove existing license header: %v", path)
}
return nil
}

// at this point, src file is missing the header
Expand All @@ -163,6 +213,27 @@ func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo,
return ioutil.WriteFile(path, []byte(task.license+string(data)), defaultFilePerms)
}

func hasCopyright(f *os.File) (bool, error) {
scanner := bufio.NewScanner(f)
lineSuccess := scanner.Scan()
if !lineSuccess {
return false, fmt.Errorf("fail to read first line of file %v", f.Name())
}
i := 0
for i < firstLinesToCheck && lineSuccess {
i++
line := strings.TrimSpace(scanner.Text())
if err := scanner.Err(); err != nil {
return false, err
}
if lineHasCopyright(line) {
return true, nil
}
lineSuccess = scanner.Scan()
}
return false, nil
}

func isFileAutogenerated(path string) bool {
return strings.HasPrefix(path, ".gen")
}
Expand All @@ -189,3 +260,21 @@ func commentOutLines(str string) (string, error) {
}
return strings.Join(lines, ""), nil
}

func lineHasCopyright(line string) bool {
return strings.Contains(line, licenseHeaderPrefixOld) ||
strings.Contains(line, licenseHeaderPrefix)
}

func getFilePaths(filePaths string) ([]string, []os.FileInfo, error) {
paths := strings.Split(filePaths, ",")
var fileInfos []os.FileInfo
for _, p := range paths {
fileInfo, err := os.Stat(p)
if err != nil {
return nil, nil, err
}
fileInfos = append(fileInfos, fileInfo)
}
return paths, fileInfos, nil
}
12 changes: 6 additions & 6 deletions common/archiver/filestore/queryParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../../../LICENSE -package $GOPACKAGE -source queryParser.go -destination queryParser_mock.go -mock_names Interface=MockQueryParser
//go:generate mockgen -package $GOPACKAGE -source queryParser.go -destination queryParser_mock.go -mock_names Interface=MockQueryParser

package filestore

Expand Down Expand Up @@ -103,7 +103,7 @@ func (p *queryParser) convertWhereExpr(expr sqlparser.Expr, parsedQuery *parsedQ
case *sqlparser.ParenExpr:
return p.convertParenExpr(expr.(*sqlparser.ParenExpr), parsedQuery)
default:
return errors.New("only comparsion and \"and\" expression is supported")
return errors.New("only comparison and \"and\" expression is supported")
}
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func (p *queryParser) convertComparisonExpr(compExpr *sqlparser.ComparisonExpr,
return err
}
if op != "=" {
return fmt.Errorf("only operation = is support for %s", WorkflowID)
return fmt.Errorf("only operator = is supported for %s with file system", WorkflowID)
}
if parsedQuery.workflowID != nil && *parsedQuery.workflowID != val {
parsedQuery.emptyResult = true
Expand All @@ -151,7 +151,7 @@ func (p *queryParser) convertComparisonExpr(compExpr *sqlparser.ComparisonExpr,
return err
}
if op != "=" {
return fmt.Errorf("only operation = is support for %s", RunID)
return fmt.Errorf("only operator = is supported for %s with file system", RunID)
}
if parsedQuery.runID != nil && *parsedQuery.runID != val {
parsedQuery.emptyResult = true
Expand All @@ -164,7 +164,7 @@ func (p *queryParser) convertComparisonExpr(compExpr *sqlparser.ComparisonExpr,
return err
}
if op != "=" {
return fmt.Errorf("only operation = is support for %s", WorkflowType)
return fmt.Errorf("only operator = is supported for %s with file system", WorkflowType)
}
if parsedQuery.workflowTypeName != nil && *parsedQuery.workflowTypeName != val {
parsedQuery.emptyResult = true
Expand All @@ -178,7 +178,7 @@ func (p *queryParser) convertComparisonExpr(compExpr *sqlparser.ComparisonExpr,
val = valStr
}
if op != "=" {
return fmt.Errorf("only operation = is support for %s", CloseStatus)
return fmt.Errorf("only operator = is supported for %s with file system", CloseStatus)
}
status, err := convertStatusStr(val)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions common/archiver/filestore/queryParser_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b35bc07

Please sign in to comment.