Skip to content

oceanbase/obshell-sdk-go

license English doc Chinese doc

English | Chinese

OBShell-SDK-GO is an SDK provided by theOceanBase Community to facilitate developers with quick access to OBShell services, allowing them to conveniently call OBShell interfaces using this SDK.

Install

go get github.com/oceanbase/obshell-sdk-go@master

Quick Start

Please ensure that OBShell is running when using it.

Create a Client

You can choose to create a single-version client.

package main

import (
	"github.com/oceanbase/obshell-sdk-go/services/v1"
)

func main() {
	client, err := v1.NewClientWithPassword("11.11.11.1", 2886, "***")
	if err != nil {
        // Handle error.
		return
	}
}

Or create a multi-version client set.

package main

import (
	"github.com/oceanbase/obshell-sdk-go/services"
)

func main() {
	clientset, err := services.NewClientWithPassword("11.11.11.1", 2886, "****")
	if err != nil {
        // Handle error.
		return
	}
}

Deploy Cluster

package main

import (
	"github.com/oceanbase/obshell-sdk-go/services"
	"github.com/oceanbase/obshell-sdk-go/services/v1"
)

func main() {
	client, err := services.NewClientWithPassword("11.11.11.1", 2886, "****")
	if err != nil {
		return
	}
	joinReqeust1 := client.V1().NewJoinRequest("11.11.11.1", 2886, "zone1")
	if _, err := client.V1().JoinSyncWithRequest(joinReqeust1); err != nil {
		return
	}

	joinReqeust2 := client.V1().NewJoinRequest("11.11.11.2", 2886, "zone2")
	if _, err := client.V1().JoinSyncWithRequest(joinReqeust2); err != nil {
		return
	}

	joinReqeust3 := client.V1().NewJoinRequest("11.11.11.3", 2886, "zone3")
	if _, err := client.V1().JoinSyncWithRequest(joinReqeust3); err != nil {
		return
	}

	// Configure the cluster.
	configObclusterReq := client.V1().NewConfigObclusterRequest("obshell-sdk-test", 12358).SetRootPwd("****")
	if _, err := client.V1().ConfigObclusterSyncWithRequest(configObclusterReq); err != nil {
		return
	}

	// Configure the observers.
	configs := map[string]string{
		"datafile_size": "24G", "cpu_count": "16", "memory_limit": "16G", "system_memory": "8G", "log_disk_size": "24G",
	}
	configObserverReq := client.V1().NewConfigObserverRequest(configs, v1.SCOPE_GLOBAL)
	if _, err := client.V1().ConfigObserverSyncWithRequest(configObserverReq); err != nil {
		return
	}

	// Initialize the cluster.
	initReq := client.V1().NewInitRequest()
	if _, err := client.V1().InitSyncWithRequest(initReq); err != nil {
		return
	}
}

Scale out

package main

import (
	"github.com/oceanbase/obshell-sdk-go/services"
)

func main() {
	client, err := services.NewClientWithPassword("11.11.11.1", 2886, "****")
	if err != nil {
		return
	}

	// OBShell prior to 4.2.3.0 should use mysqlPort(rpcPort) instead of mysql_port(rpc_port).
	configs := map[string]string{
		"mysql_port": "2881", "rpc_port": "2882", "datafile_size": "24G", "cpu_count": "16", "memory_limit": "16G", "system_memory": "8G", "log_disk_size": "24G",
	}

	// Scale out a new server in zone3.
	scaleOutReq := client.V1().NewScaleOutRequest("11.11.11.3", 2886, "zone3", configs)
	if _, err := client.V1().ScaleOutSyncWithRequest(scaleOutReq); err != nil {
		return
	}
}

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages