From b1661698c299c60a23b0f0f136355710e06570ac Mon Sep 17 00:00:00 2001
From: lenhattan86 <lenhattan86@users.noreply.github.com>
Date: Tue, 12 Jan 2021 16:18:09 -0800
Subject: [PATCH] GetJobSummary API (#8)

* Adds GetJobSummary API
---
 realis.go          | 13 +++++++++++++
 realis_e2e_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/realis.go b/realis.go
index 6299986..a7c536e 100644
--- a/realis.go
+++ b/realis.go
@@ -348,6 +348,19 @@ func (c *Client) GetJobUpdateSummaries(jobUpdateQuery *aurora.JobUpdateQuery) (*
 	return resp.GetResult_().GetGetJobUpdateSummariesResult_(), nil
 }
 
+func (c *Client) GetJobSummary(role string) (*aurora.JobSummaryResult_, error) {
+
+	resp, retryErr := c.thriftCallWithRetries(false, func() (*aurora.Response, error) {
+		return c.readonlyClient.GetJobSummary(context.TODO(), role)
+	})
+
+	if retryErr != nil {
+		return nil, errors.Wrap(retryErr, "error getting job summaries from Aurora Scheduler")
+	}
+
+	return resp.GetResult_().GetJobSummaryResult_(), nil
+}
+
 func (c *Client) GetJobs(role string) (*aurora.GetJobsResult_, error) {
 
 	var result *aurora.GetJobsResult_
diff --git a/realis_e2e_test.go b/realis_e2e_test.go
index 38e39e7..884a485 100644
--- a/realis_e2e_test.go
+++ b/realis_e2e_test.go
@@ -823,3 +823,51 @@ func TestRealisClient_BatchAwareAutoPause(t *testing.T) {
 	}
 	assert.NoError(t, r.KillJob(strategy.JobKey()))
 }
+
+// Test configuring an executor that doesn't exist for CreateJob API
+func TestRealisClient_GetJobSummary(t *testing.T) {
+	role := "vagrant"
+	// Create a single job
+	job := realis.NewJobUpdate().
+		Environment("prod").
+		Role(role).
+		Name("TestGetJobSummary").
+		ThermosExecutor(thermosExec).
+		CPU(.25).
+		RAM(4).
+		Disk(10).
+		InstanceCount(3).
+		WatchTime(20 * time.Second).
+		IsService(true).
+		BatchSize(2)
+
+	result, err := r.CreateService(job)
+
+	assert.NoError(t, err)
+	assert.NotNil(t, result)
+
+	var ok bool
+	var mErr error
+
+	if ok, mErr = r.MonitorJobUpdate(*result.GetKey(), 5*time.Second, 4*time.Minute); !ok || mErr != nil {
+		// Update may already be in a terminal state so don't check for error
+		err := r.AbortJobUpdate(*result.GetKey(), "Monitor timed out.")
+
+		err = r.KillJob(job.JobKey())
+
+		assert.NoError(t, err)
+	}
+
+	assert.True(t, ok)
+	assert.NoError(t, mErr)
+	// get job summary of the role
+	summary, mErr := r.GetJobSummary(role)
+	assert.NoError(t, mErr)
+	assert.NotNil(t, summary)
+	assert.Equal(t, len(summary.Summaries), 1)
+
+	// Kill task test task after confirming it came up fine
+	err = r.KillJob(job.JobKey())
+
+	assert.NoError(t, err)
+}