Moved Realis to be an interface for future testing classes. Removed AddURI API as AddURIs is able to do the same thing
This commit is contained in:
parent
5fc5aa8fc5
commit
c610974208
5 changed files with 32 additions and 26 deletions
|
@ -243,7 +243,7 @@ job = realis.NewJob().
|
||||||
InstanceCount(1).
|
InstanceCount(1).
|
||||||
AddPorts(1).
|
AddPorts(1).
|
||||||
AddLabel("fileName", "sample-app/docker-compose.yml").
|
AddLabel("fileName", "sample-app/docker-compose.yml").
|
||||||
AddURI("https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz", true, true)
|
AddURIs(true, true, "https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz")
|
||||||
```
|
```
|
||||||
|
|
||||||
Using a vagrant setup as an example, we can run the following command to create a compose job:
|
Using a vagrant setup as an example, we can run the following command to create a compose job:
|
||||||
|
|
|
@ -28,7 +28,7 @@ job = realis.NewJob().
|
||||||
InstanceCount(1).
|
InstanceCount(1).
|
||||||
AddPorts(1).
|
AddPorts(1).
|
||||||
AddLabel("fileName", "sample-app/docker-compose.yml").
|
AddLabel("fileName", "sample-app/docker-compose.yml").
|
||||||
AddURI("https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz", true, true)
|
AddURIs(true, true, "https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz")
|
||||||
```
|
```
|
||||||
|
|
||||||
* Use client to send a job to Aurora:
|
* Use client to send a job to Aurora:
|
||||||
|
|
|
@ -82,7 +82,7 @@ func main() {
|
||||||
InstanceCount(1).
|
InstanceCount(1).
|
||||||
AddPorts(1).
|
AddPorts(1).
|
||||||
AddLabel("fileName", "sample-app/docker-compose.yml").
|
AddLabel("fileName", "sample-app/docker-compose.yml").
|
||||||
AddURI("https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz", true, true)
|
AddURIs(true, true, "https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz")
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
fmt.Println("Only thermos and compose are supported for now")
|
fmt.Println("Only thermos and compose are supported for now")
|
||||||
|
|
17
job.go
17
job.go
|
@ -139,22 +139,18 @@ func (a *Job) JobKey() *aurora.JobKey {
|
||||||
return a.jobConfig.Key
|
return a.jobConfig.Key
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add URI to fetch using the mesos fetcher. Scheduler must have --enable_mesos_fetcher flag
|
// Add a list of URIs with the same extract and cache configuration. Scheduler must have
|
||||||
// enabled.
|
// --enable_mesos_fetcher flag enabled. Currently there is no duplicate detection.
|
||||||
func (a *Job) AddURI(value string, extract bool, cache bool) *Job {
|
|
||||||
a.jobConfig.TaskConfig.MesosFetcherUris[&aurora.MesosFetcherURI{value, &extract, &cache}] = true
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a list of URIs with the same extract and cache configuration.
|
|
||||||
func (a *Job) AddURIs(extract bool, cache bool, values ...string) *Job {
|
func (a *Job) AddURIs(extract bool, cache bool, values ...string) *Job {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
a.jobConfig.TaskConfig.MesosFetcherUris[&aurora.MesosFetcherURI{value, &extract, &cache}] = true
|
a.jobConfig.
|
||||||
|
TaskConfig.
|
||||||
|
MesosFetcherUris[&aurora.MesosFetcherURI{value, &extract, &cache}] = true
|
||||||
}
|
}
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a Mesos label to the job. Note that as of Aurora 0.15.0, Aurora will add the
|
// Adds a Mesos label to the job. Note that Aurora will add the
|
||||||
// prefix "org.apache.aurora.metadata." to the beginning of each key.
|
// prefix "org.apache.aurora.metadata." to the beginning of each key.
|
||||||
func (a *Job) AddLabel(key string, value string) *Job {
|
func (a *Job) AddLabel(key string, value string) *Job {
|
||||||
a.jobConfig.TaskConfig.Metadata[&aurora.Metadata{key, value}] = true
|
a.jobConfig.TaskConfig.Metadata[&aurora.Metadata{key, value}] = true
|
||||||
|
@ -172,7 +168,6 @@ func (a *Job) AddNamedPorts(names ...string) *Job {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Adds a request for a number of ports to the job configuration. The names chosen for these ports
|
// Adds a request for a number of ports to the job configuration. The names chosen for these ports
|
||||||
// will be org.apache.aurora.portX, where X is the current port count for the job configuration
|
// will be org.apache.aurora.portX, where X is the current port count for the job configuration
|
||||||
// starting at 0. These are random ports as it's not currently possible to request
|
// starting at 0. These are random ports as it's not currently possible to request
|
||||||
|
|
35
realis.go
35
realis.go
|
@ -27,7 +27,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Realis struct {
|
type Realis interface {
|
||||||
|
AbortJobUpdate(key *aurora.JobKey, updateId string, message string) (*aurora.Response, error)
|
||||||
|
AddInstances(instKey *aurora.InstanceKey, count int32) (*aurora.Response, error)
|
||||||
|
CreateJob(auroraJob *Job) (*aurora.Response, error)
|
||||||
|
KillJob(key *aurora.JobKey) (*aurora.Response, error)
|
||||||
|
KillInstance(key *aurora.JobKey, instanceId int32) (*aurora.Response, error)
|
||||||
|
RestartJob(key *aurora.JobKey) (*aurora.Response, error)
|
||||||
|
StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error)
|
||||||
|
Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
type realisClient struct {
|
||||||
client *aurora.AuroraSchedulerManagerClient
|
client *aurora.AuroraSchedulerManagerClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,14 +48,14 @@ 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 {
|
||||||
|
|
||||||
httpTrans := (config.transport).(*thrift.THttpClient)
|
httpTrans := (config.transport).(*thrift.THttpClient)
|
||||||
httpTrans.SetHeader("User-Agent", "GoRealis v0.1")
|
httpTrans.SetHeader("User-Agent", "GoRealis v0.1")
|
||||||
|
|
||||||
protocolFactory := thrift.NewTJSONProtocolFactory()
|
protocolFactory := thrift.NewTJSONProtocolFactory()
|
||||||
|
|
||||||
return &Realis{client: aurora.NewAuroraSchedulerManagerClientFactory(config.transport, protocolFactory)}
|
return realisClient{client: aurora.NewAuroraSchedulerManagerClientFactory(config.transport, protocolFactory)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a default configuration of the transport layer, requires a URL to test connection with.
|
// Create a default configuration of the transport layer, requires a URL to test connection with.
|
||||||
|
@ -84,12 +95,12 @@ func basicAuth(username, password string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Releases resources associated with the realis client.
|
// Releases resources associated with the realis client.
|
||||||
func (r *Realis) Close() {
|
func (r realisClient) Close() {
|
||||||
r.client.Transport.Close()
|
r.client.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.
|
||||||
func (r *Realis) getActiveInstanceIds(key *aurora.JobKey) (map[int32]bool, error) {
|
func (r realisClient) getActiveInstanceIds(key *aurora.JobKey) (map[int32]bool, error) {
|
||||||
taskQ := &aurora.TaskQuery{Role: key.Role,
|
taskQ := &aurora.TaskQuery{Role: key.Role,
|
||||||
Environment: key.Environment,
|
Environment: key.Environment,
|
||||||
JobName: key.Name,
|
JobName: key.Name,
|
||||||
|
@ -111,7 +122,7 @@ func (r *Realis) getActiveInstanceIds(key *aurora.JobKey) (map[int32]bool, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill a specific instance of a job.
|
// Kill a specific instance of a job.
|
||||||
func (r *Realis) KillInstance(key *aurora.JobKey, instanceId int32) (*aurora.Response, error) {
|
func (r realisClient) KillInstance(key *aurora.JobKey, instanceId int32) (*aurora.Response, error) {
|
||||||
|
|
||||||
instanceIds := make(map[int32]bool)
|
instanceIds := make(map[int32]bool)
|
||||||
instanceIds[instanceId] = true
|
instanceIds[instanceId] = true
|
||||||
|
@ -126,7 +137,7 @@ func (r *Realis) KillInstance(key *aurora.JobKey, instanceId int32) (*aurora.Res
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends a kill message to the scheduler for all active tasks under a job.
|
// Sends a kill message to the scheduler for all active tasks under a job.
|
||||||
func (r *Realis) KillJob(key *aurora.JobKey) (*aurora.Response, error) {
|
func (r realisClient) KillJob(key *aurora.JobKey) (*aurora.Response, error) {
|
||||||
|
|
||||||
instanceIds, err := r.getActiveInstanceIds(key)
|
instanceIds, err := r.getActiveInstanceIds(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -147,7 +158,7 @@ func (r *Realis) KillJob(key *aurora.JobKey) (*aurora.Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends a create job message to the scheduler with a specific job configuration.
|
// Sends a create job message to the scheduler with a specific job configuration.
|
||||||
func (r *Realis) CreateJob(auroraJob *Job) (*aurora.Response, error) {
|
func (r realisClient) CreateJob(auroraJob *Job) (*aurora.Response, error) {
|
||||||
response, err := r.client.CreateJob(auroraJob.jobConfig)
|
response, err := r.client.CreateJob(auroraJob.jobConfig)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -158,7 +169,7 @@ func (r *Realis) CreateJob(auroraJob *Job) (*aurora.Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restarts all active tasks under a job configuration.
|
// Restarts all active tasks under a job configuration.
|
||||||
func (r *Realis) RestartJob(key *aurora.JobKey) (*aurora.Response, error) {
|
func (r realisClient) RestartJob(key *aurora.JobKey) (*aurora.Response, error) {
|
||||||
|
|
||||||
instanceIds, err := r.getActiveInstanceIds(key)
|
instanceIds, err := r.getActiveInstanceIds(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -179,7 +190,7 @@ func (r *Realis) RestartJob(key *aurora.JobKey) (*aurora.Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all tasks under a job configuration. Currently there's no support for canary deployments.
|
// Update all tasks under a job configuration. Currently there's no support for canary deployments.
|
||||||
func (r *Realis) StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error) {
|
func (r realisClient) StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.Response, error) {
|
||||||
|
|
||||||
response, err := r.client.StartJobUpdate(updateJob.req, message)
|
response, err := r.client.StartJobUpdate(updateJob.req, message)
|
||||||
|
|
||||||
|
@ -191,7 +202,7 @@ func (r *Realis) StartJobUpdate(updateJob *UpdateJob, message string) (*aurora.R
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abort Job Update on Aurora. Requires the updateId which can be obtained on the Aurora web UI.
|
// Abort Job Update on Aurora. Requires the updateId which can be obtained on the Aurora web UI.
|
||||||
func (r *Realis) AbortJobUpdate(
|
func (r realisClient) AbortJobUpdate(
|
||||||
key *aurora.JobKey,
|
key *aurora.JobKey,
|
||||||
updateId string,
|
updateId string,
|
||||||
message string) (*aurora.Response, error) {
|
message string) (*aurora.Response, error) {
|
||||||
|
@ -207,7 +218,7 @@ func (r *Realis) AbortJobUpdate(
|
||||||
|
|
||||||
// Scale up the number of instances under a job configuration using the configuration for specific
|
// Scale up the number of instances under a job configuration using the configuration for specific
|
||||||
// instance to scale up.
|
// instance to scale up.
|
||||||
func (r *Realis) AddInstances(instKey *aurora.InstanceKey, count int32) (*aurora.Response, error) {
|
func (r realisClient) AddInstances(instKey *aurora.InstanceKey, count int32) (*aurora.Response, error) {
|
||||||
|
|
||||||
response, err := r.client.AddInstances(instKey, count)
|
response, err := r.client.AddInstances(instKey, count)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue