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

Add solr client. #106

Merged
merged 14 commits into from
Jul 30, 2024
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/elastic/go-elasticsearch/v6 v6.8.10
github.com/elastic/go-elasticsearch/v7 v7.15.1
github.com/elastic/go-elasticsearch/v8 v8.4.0
github.com/go-logr/logr v1.4.2
github.com/go-resty/resty/v2 v2.11.0
github.com/go-sql-driver/mysql v1.8.1
github.com/grafadruid/go-druid v0.0.6
Expand All @@ -31,7 +32,7 @@ require (
k8s.io/klog/v2 v2.130.1
kmodules.xyz/client-go v0.30.9
kmodules.xyz/custom-resources v0.30.0
kubedb.dev/apimachinery v0.47.0-rc.1
kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7
sigs.k8s.io/controller-runtime v0.18.4
xorm.io/xorm v1.3.6
)
Expand All @@ -57,7 +58,6 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
Expand Down Expand Up @@ -117,13 +117,13 @@ require (
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIi
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand Down Expand Up @@ -593,8 +593,8 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -651,8 +651,8 @@ golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -667,8 +667,8 @@ golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down Expand Up @@ -793,8 +793,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
kmodules.xyz/offshoot-api v0.30.0 h1:dq9F93pu4Q8rL9oTcCk+vGGy8vpS7RNt0GSwx7Bvhec=
kmodules.xyz/offshoot-api v0.30.0/go.mod h1:o9VoA3ImZMDBp3lpLb8+kc2d/KBxioRwCpaKDfLIyDw=
kubedb.dev/apimachinery v0.47.0-rc.1 h1:5DXoahPbJ1n1Fowa+lv3xobTWRLzDDKGhJaNiWjV/tk=
kubedb.dev/apimachinery v0.47.0-rc.1/go.mod h1:AUV5sXVwo77ctiYyrFWsSrhkuvy5fru5baiX7xF6LBA=
kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7 h1:HqdKBHKbi5fhHRHstoDggFXpX6v7r+2P8/XevDdHjeg=
kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7/go.mod h1:Gs/kwdVYmGjJmYmvCUNDmNbbprXqi/gbSj/JrsoM9sE=
kubeops.dev/petset v0.0.6 h1:0IbvxD9fadZfH+3iMZWzN6ZHsO0vX458JlioamwyPKQ=
kubeops.dev/petset v0.0.6/go.mod h1:A15vh0r979NsvL65DTIZKWsa/NoX9VapHBAEw1ZsdYI=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
Expand Down
3 changes: 2 additions & 1 deletion kafka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package kafka

import (
"fmt"
"time"

"fmt"

kafkago "github.com/IBM/sarama"
"k8s.io/klog/v2"
)
Expand Down
3 changes: 2 additions & 1 deletion kafka/connect/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"net"
"net/http"
"time"

"fmt"

"github.com/go-resty/resty/v2"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
1 change: 1 addition & 0 deletions mssqlserver/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mssql

import (
"context"

"fmt"

_ "github.com/microsoft/go-mssqldb"
Expand Down
1 change: 1 addition & 0 deletions pgpool/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pgpool

import (
"context"

"fmt"

olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
Expand Down
1 change: 1 addition & 0 deletions rabbitmq/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package rabbitmq
import (
"context"
"errors"

"fmt"
"strings"

Expand Down
1 change: 1 addition & 0 deletions singlestore/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/tls"
"crypto/x509"
"database/sql"

"fmt"

sql_driver "github.com/go-sql-driver/mysql"
Expand Down
47 changes: 47 additions & 0 deletions solr/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package solr

import (
"context"

"github.com/go-logr/logr"
"github.com/go-resty/resty/v2"
)

const (
writeCollectionName = "kubedb-system"
Action = "action"
ActionBackup = "BACKUP"
ActionRestore = "RESTORE"
ActionCreate = "CREATE"
ActionDeleteBackup = "DELETEBACKUP"
Name = "name"
Location = "location"
Repository = "repository"
Collection = "collection"
Async = "async"
PurgeUnused = "purgeUnused"
BackupId = "backupId"
DeleteStatus = "DELETESTATUS"
RequestStatus = "REQUESTSTATUS"
RequestId = "requestid"
NumShards = "numShards"
ReplicationFactor = "replicationFactor"
)

type SLClient interface {
GetClusterStatus() (*Response, error)
ListCollection() (*Response, error)
CreateCollection() (*Response, error)
WriteCollection() (*Response, error)
ReadCollection() (*Response, error)
BackupCollection(ctx context.Context, collection string, backupName string, location string, repository string) (*Response, error)
RestoreCollection(ctx context.Context, collection string, backupName string, location string, repository string, backupId int) (*Response, error)
FlushStatus(asyncId string) (*Response, error)
RequestStatus(asyncId string) (*Response, error)
DeleteBackup(ctx context.Context, backupName string, collection string, location string, repository string, backupId int, snap string) (*Response, error)
PurgeBackup(ctx context.Context, backupName string, collection string, location string, repository string, snap string) (*Response, error)
GetConfig() *Config
GetClient() *resty.Client
GetLog() logr.Logger
DecodeBackupResponse(data map[string]interface{}, collection string) ([]byte, error)
}
62 changes: 62 additions & 0 deletions solr/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package solr

import (
"context"
"io"
"net/http"

"github.com/go-logr/logr"
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type Client struct {
SLClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this pointer type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use pointer for embedded types

}

type ClientOptions struct {
KBClient client.Client
DB *api.Solr
Ctx context.Context
Log logr.Logger
}

type Config struct {
host string
connectionScheme string
transport *http.Transport
log logr.Logger
}

type Response struct {
Code int
header http.Header
body io.ReadCloser
}

type Doc struct {
Id int `json:"id,omitempty" yaml:"id,omitempty"`
DB string `json:"db,omitempty" yaml:"db,omitempty"`
}

type Data struct {
CommitWithin int `json:"commitWithin,omitempty" yaml:"commitWithin,omitempty"`
Overwrite bool `json:"overwrite,omitempty" yaml:"overwrite,omitempty"`
Doc *Doc `json:"doc,omitempty" yaml:"doc,omitempty"`
}

type ADD struct {
Add *Data `json:"add,omitempty" yaml:"add,omitempty"`
}

type QueryParams struct {
Query string `json:"query,omitempty" yaml:"query,omitempty"`
Limit int `json:"limit,omitempty" yaml:"limit,omitempty"`
}

type CreateParams struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Config string `json:"config,omitempty" yaml:"config,omitempty"`
NumShards int `json:"numShards,omitempty" yaml:"numShards,omitempty"`
ReplicationFactor int `json:"replicationFactor,omitempty" yaml:"replicationFactor,omitempty"`
}
Loading
Loading