Merge pull request #16 from smothiki/readonly
add function to get readonly scheduler client
This commit is contained in:
commit
811169a266
2 changed files with 33 additions and 8 deletions
|
@ -17,11 +17,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/rdelval/gorealis"
|
"github.com/rdelval/gorealis"
|
||||||
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
||||||
"github.com/rdelval/gorealis/response"
|
"github.com/rdelval/gorealis/response"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -344,6 +345,21 @@ func main() {
|
||||||
}
|
}
|
||||||
print(config.String())
|
print(config.String())
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case "updatesummary":
|
||||||
|
|
||||||
|
fmt.Println("Getting job update summary")
|
||||||
|
jobquery := &aurora.JobUpdateQuery{
|
||||||
|
Role: &job.JobKey().Role,
|
||||||
|
JobKey: job.JobKey(),
|
||||||
|
}
|
||||||
|
updatesummary, err := r.GetJobUpdateSummaries(jobquery)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error while getting update summary: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println(updatesummary)
|
||||||
|
|
||||||
case "taskStatus":
|
case "taskStatus":
|
||||||
fmt.Println("Getting task status")
|
fmt.Println("Getting task status")
|
||||||
taskQ := &aurora.TaskQuery{Role: job.JobKey().Role,
|
taskQ := &aurora.TaskQuery{Role: job.JobKey().Role,
|
||||||
|
@ -352,7 +368,7 @@ func main() {
|
||||||
}
|
}
|
||||||
tasks, err := r.GetTaskStatus(taskQ)
|
tasks, err := r.GetTaskStatus(taskQ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error: %+v\n ",err )
|
fmt.Printf("error: %+v\n ", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Printf("length: %d\n ", len(tasks))
|
fmt.Printf("length: %d\n ", len(tasks))
|
||||||
|
|
19
realis.go
19
realis.go
|
@ -17,13 +17,14 @@ package realis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"net/http"
|
||||||
|
"net/http/cookiejar"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.apache.org/thrift.git/lib/go/thrift"
|
"git.apache.org/thrift.git/lib/go/thrift"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
||||||
"github.com/rdelval/gorealis/response"
|
"github.com/rdelval/gorealis/response"
|
||||||
"net/http"
|
|
||||||
"net/http/cookiejar"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Realis interface {
|
type Realis interface {
|
||||||
|
@ -43,11 +44,13 @@ type Realis interface {
|
||||||
ScheduleCronJob(auroraJob Job) (*aurora.Response, error)
|
ScheduleCronJob(auroraJob Job) (*aurora.Response, error)
|
||||||
StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error)
|
StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error)
|
||||||
StartCronJob(key *aurora.JobKey) (*aurora.Response, error)
|
StartCronJob(key *aurora.JobKey) (*aurora.Response, error)
|
||||||
|
GetJobUpdateSummaries(jobUpdateQuery *aurora.JobUpdateQuery) (*aurora.Response, error)
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
type realisClient struct {
|
type realisClient struct {
|
||||||
client *aurora.AuroraSchedulerManagerClient
|
client *aurora.AuroraSchedulerManagerClient
|
||||||
|
readonlyClient *aurora.ReadOnlySchedulerClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper object to provide future flexibility
|
// Wrapper object to provide future flexibility
|
||||||
|
@ -59,7 +62,8 @@ type RealisConfig struct {
|
||||||
// Create a new Client with a default transport layer
|
// Create a new Client with a default transport layer
|
||||||
func NewClient(config RealisConfig) Realis {
|
func NewClient(config RealisConfig) Realis {
|
||||||
return realisClient{
|
return realisClient{
|
||||||
client: aurora.NewAuroraSchedulerManagerClientFactory(config.transport, config.protoFactory)}
|
client: aurora.NewAuroraSchedulerManagerClientFactory(config.transport, config.protoFactory),
|
||||||
|
readonlyClient: aurora.NewReadOnlySchedulerClientFactory(config.transport, config.protoFactory)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a default Thrift Transport object for communications in gorealis using an HTTP Post Client
|
// Creates a default Thrift Transport object for communications in gorealis using an HTTP Post Client
|
||||||
|
@ -132,6 +136,7 @@ func basicAuth(username, password string) string {
|
||||||
// Releases resources associated with the realis client.
|
// Releases resources associated with the realis client.
|
||||||
func (r realisClient) Close() {
|
func (r realisClient) Close() {
|
||||||
r.client.Transport.Close()
|
r.client.Transport.Close()
|
||||||
|
r.readonlyClient.Transport.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uses predefined set of states to retrieve a set of active jobs in Apache Aurora.
|
// Uses predefined set of states to retrieve a set of active jobs in Apache Aurora.
|
||||||
|
@ -156,6 +161,10 @@ func (r realisClient) GetInstanceIds(key *aurora.JobKey, states map[aurora.Sched
|
||||||
return jobInstanceIds, nil
|
return jobInstanceIds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r realisClient) GetJobUpdateSummaries(jobUpdateQuery *aurora.JobUpdateQuery) (*aurora.Response, error) {
|
||||||
|
return r.readonlyClient.GetJobUpdateSummaries(jobUpdateQuery)
|
||||||
|
}
|
||||||
|
|
||||||
// Kill specific instances of a job.
|
// Kill specific instances of a job.
|
||||||
func (r realisClient) KillInstances(key *aurora.JobKey, instances ...int32) (*aurora.Response, error) {
|
func (r realisClient) KillInstances(key *aurora.JobKey, instances ...int32) (*aurora.Response, error) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue