Skip to content

Commit

Permalink
Merge pull request #24 from openGemini/sp-https
Browse files Browse the repository at this point in the history
chore: support https and username
  • Loading branch information
xiangyu5632 authored Jan 7, 2025
2 parents 281e51b + 829d5dc commit 673c67b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
34 changes: 33 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#!/bin/bash
go mod tidy
go build .

num=$#

if [ "$num" -gt "0" ]; then
GOOS=linux GOARCH=amd64 go build -mod=mod -o dataMigrate-linux-amd64 ./
GOOS=linux GOARCH=arm64 go build -mod=mod -o dataMigrate-linux-arm64 ./
GOOS=darwin GOARCH=amd64 go build -mod=mod -o dataMigrate-darwin-amd64 ./
GOOS=darwin GOARCH=arm64 go build -mod=mod -o dataMigrate-darwin-arm64 ./
GOOS=windows GOARCH=amd64 go build -mod=mod -o dataMigrate-windows-amd64.exe ./

version=0.4.0
mv dataMigrate-linux-amd64 dataMigrate
tar -cvzf dataMigrate-$version-linux-amd64.tar.gz ./dataMigrate
rm -rf ./dataMigrate

mv dataMigrate-linux-arm64 dataMigrate
tar -cvzf dataMigrate-$version-linux-arm64.tar.gz ./dataMigrate
rm -rf ./dataMigrate

mv dataMigrate-darwin-arm64 dataMigrate
tar -cvzf dataMigrate-$version-darwin-arm64.tar.gz ./dataMigrate
rm -rf ./dataMigrate

mv dataMigrate-darwin-amd64 dataMigrate
tar -cvzf dataMigrate-$version-darwin-amd64.tar.gz ./dataMigrate
rm -rf ./dataMigrate

mv dataMigrate-windows-amd64.exe dataMigrate.exe
zip -o dataMigrate-$version-windows-amd64.zip ./dataMigrate.exe
rm -rf ./dataMigrate.exe
else
go build .
fi
25 changes: 21 additions & 4 deletions src/geminiservice.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package src

import (
"fmt"
"time"

client "github.com/influxdata/influxdb1-client/v2"
"github.com/pkg/errors"
"time"
)

type GeminiService interface {
Expand All @@ -13,18 +15,33 @@ type GeminiService interface {
var _ GeminiService = (*geminiService)(nil)

type geminiService struct {
out string
out string
username string
password string
useSsl bool
}

func NewGeminiService(cmd *DataMigrateCommand) *geminiService {
return &geminiService{
out: cmd.opt.Out,
out: cmd.opt.Out,
username: cmd.opt.Username,
password: cmd.opt.Password,
useSsl: cmd.opt.Ssl,
}
}

func (g *geminiService) getUrl() string {
url := fmt.Sprintf("http://%s", g.out)
if g.useSsl {
url = fmt.Sprintf("https://%s", g.out)
}
return url
}

func (g *geminiService) GetShardGroupDuration(database string) (time.Duration, error) {
c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: "http://" + g.out,
Addr: g.getUrl(),
InsecureSkipVerify: true,
})
if err != nil {
return 0, errors.WithStack(err)
Expand Down
26 changes: 22 additions & 4 deletions src/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package src

import (
"fmt"
"github.com/golang/groupcache/lru"
"github.com/influxdata/influxdb/tsdb/engine/tsm1"
client "github.com/influxdata/influxdb1-client/v2"
"os"
"sort"
"sync"

"github.com/golang/groupcache/lru"
"github.com/influxdata/influxdb/tsdb/engine/tsm1"
client "github.com/influxdata/influxdb1-client/v2"
)

type Migrator interface {
Expand Down Expand Up @@ -65,6 +66,9 @@ type migrator struct {
startTime int64
endTime int64
batchSize int
userName string
password string
useSsl bool

files *[]tsm1.TSMFile
// series to fields
Expand Down Expand Up @@ -124,6 +128,9 @@ func NewMigrator(cmd *DataMigrateCommand, info *shardGroupInfo) *migrator {
batchSize: cmd.opt.BatchSize,
mstCache: mstCachePool.Get().(*lru.Cache),
tagsCache: tagsCachePool.Get().(*lru.Cache),
userName: cmd.opt.Username,
password: cmd.opt.Password,
useSsl: cmd.opt.Ssl,
}
mig.stat.rowsRead = 0
mig.stat.tagsRead = make(map[string]struct{})
Expand Down Expand Up @@ -195,11 +202,22 @@ func (m *migrator) releaseTSMReaders() {
}
}

func (m *migrator) getToAddr() string {
addr := fmt.Sprintf("http://%s", m.out)
if m.useSsl {
addr = fmt.Sprintf("https://%s", m.out)
}
return addr
}

func (m *migrator) writeCurrentFiles() error {
defer m.releaseTSMReaders()

c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: "http://" + m.out,
InsecureSkipVerify: true,
Addr: m.getToAddr(),
Username: m.userName,
Password: m.password,
})
if err != nil {
logger.LogString("Error creating openGemini Client: "+err.Error(), TOLOGFILE|TOCONSOLE, LEVEL_ERROR)
Expand Down

0 comments on commit 673c67b

Please sign in to comment.