add function to get readonly scheduler client

This commit is contained in:
smothiki 2017-03-09 11:37:03 -08:00
parent 51699eda4e
commit 97fbec9eaf
2 changed files with 33 additions and 8 deletions

View file

@ -17,11 +17,12 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/rdelval/gorealis"
"github.com/rdelval/gorealis/gen-go/apache/aurora"
"github.com/rdelval/gorealis/response"
"io/ioutil"
"os"
)
func main() {
@ -344,6 +345,21 @@ func main() {
}
print(config.String())
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":
fmt.Println("Getting task status")
taskQ := &aurora.TaskQuery{Role: job.JobKey().Role,
@ -352,7 +368,7 @@ func main() {
}
tasks, err := r.GetTaskStatus(taskQ)
if err != nil {
fmt.Printf("error: %+v\n ",err )
fmt.Printf("error: %+v\n ", err)
os.Exit(1)
}
fmt.Printf("length: %d\n ", len(tasks))

View file

@ -17,13 +17,14 @@ package realis
import (
"encoding/base64"
"net/http"
"net/http/cookiejar"
"time"
"git.apache.org/thrift.git/lib/go/thrift"
"github.com/pkg/errors"
"github.com/rdelval/gorealis/gen-go/apache/aurora"
"github.com/rdelval/gorealis/response"
"net/http"
"net/http/cookiejar"
"time"
)
type Realis interface {
@ -43,11 +44,13 @@ type Realis interface {
ScheduleCronJob(auroraJob Job) (*aurora.Response, error)
StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error)
StartCronJob(key *aurora.JobKey) (*aurora.Response, error)
GetJobUpdateSummaries(jobUpdateQuery *aurora.JobUpdateQuery) (*aurora.Response, error)
Close()
}
type realisClient struct {
client *aurora.AuroraSchedulerManagerClient
client *aurora.AuroraSchedulerManagerClient
readonlyClient *aurora.ReadOnlySchedulerClient
}
// Wrapper object to provide future flexibility
@ -59,7 +62,8 @@ type RealisConfig struct {
// Create a new Client with a default transport layer
func NewClient(config RealisConfig) Realis {
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
@ -132,6 +136,7 @@ func basicAuth(username, password string) string {
// Releases resources associated with the realis client.
func (r realisClient) Close() {
r.client.Transport.Close()
r.readonlyClient.Transport.Close()
}
// 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
}
func (r realisClient) GetJobUpdateSummaries(jobUpdateQuery *aurora.JobUpdateQuery) (*aurora.Response, error) {
return r.readonlyClient.GetJobUpdateSummaries(jobUpdateQuery)
}
// Kill specific instances of a job.
func (r realisClient) KillInstances(key *aurora.JobKey, instances ...int32) (*aurora.Response, error) {