Skip to content

Commit

Permalink
Update workers API
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveengostu authored and sakshiag committed Jun 27, 2018
1 parent 2c17f72 commit 00b345f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 13 deletions.
48 changes: 35 additions & 13 deletions api/container/containerv1/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ import (

//Worker ...
type Worker struct {
Billing string `json:"billing,omitempty"`
ErrorMessage string `json:"errorMessage"`
ID string `json:"id"`
Isolation string `json:"isolation"`
KubeVersion string `json:"kubeVersion"`
MachineType string `json:"machineType"`
PrivateIP string `json:"privateIP"`
PrivateVlan string `json:"privateVlan"`
PublicIP string `json:"publicIP"`
PublicVlan string `json:"publicVlan"`
State string `json:"state"`
Status string `json:"status"`
TargetVersion string `json:"targetVersion"`
Billing string `json:"billing,omitempty"`
ErrorMessage string `json:"errorMessage"`
ID string `json:"id"`
Isolation string `json:"isolation"`
KubeVersion string `json:"kubeVersion"`
MachineType string `json:"machineType"`
PrivateIP string `json:"privateIP"`
PrivateVlan string `json:"privateVlan"`
PublicIP string `json:"publicIP"`
PublicVlan string `json:"publicVlan"`
Location string `json:"location"`
PoolID string `json:"poolid"`
PoolName string `json:"poolName"`
TrustedStatus string `json:"trustedStatus"`
ReasonForDelete string `json:"reasonForDelete"`
VersionEOS string `json:"versionEOS"`
MasterVersionEOS string `json:"masterVersionEOS"`
State string `json:"state"`
Status string `json:"status"`
TargetVersion string `json:"targetVersion"`
}

//WorkerParam ...
Expand All @@ -43,6 +50,7 @@ type WorkerUpdateParam struct {
//Workers ...
type Workers interface {
List(clusterName string, target ClusterTargetHeader) ([]Worker, error)
ListByWorkerPool(clusterIDOrName, workerPoolIDOrName string, showDeleted bool) ([]Worker, error)
Get(clusterName string, target ClusterTargetHeader) (Worker, error)
Add(clusterName string, params WorkerParam, target ClusterTargetHeader) error
Delete(clusterName string, workerD string, target ClusterTargetHeader) error
Expand Down Expand Up @@ -101,3 +109,17 @@ func (r *worker) List(name string, target ClusterTargetHeader) ([]Worker, error)
}
return workers, err
}

//ListByWorkerPool ...
func (r *worker) ListByWorkerPool(clusterIDOrName, workerPoolIDOrName string, showDeleted bool) ([]Worker, error) {
rawURL := fmt.Sprintf("/v1/clusters/%s/workers?showDeleted=%t", clusterIDOrName, showDeleted)
if len(workerPoolIDOrName) > 0 {
rawURL += "&pool=" + workerPoolIDOrName
}
workers := []Worker{}
_, err := r.client.Get(rawURL, &workers)
if err != nil {
return nil, err
}
return workers, err
}
42 changes: 42 additions & 0 deletions api/container/containerv1/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,48 @@ var _ = Describe("Workers", func() {
})
})
})
//ListByWorkerPool
Describe("ListByWorkerPool", func() {
Context("When retrieving available workers belong to a worker pool of a cluster is successful", func() {
BeforeEach(func() {
server = ghttp.NewServer()
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodGet, "/v1/clusters/myCluster/workers"),
ghttp.RespondWith(http.StatusOK, `[{"ErrorMessage":"","Isolation":"","MachineType":"free","KubeVersion":"","PrivateIP":"","PublicIP":"","PrivateVlan":"vlan","PublicVlan":"vlan","state":"normal","status":"ready"}]`),
),
)
})

It("should return available workers ", func() {
worker, err := newWorker(server.URL()).ListByWorkerPool("myCluster", "test", false)
Expect(err).NotTo(HaveOccurred())
Expect(worker).ShouldNot(BeNil())
for _, wObj := range worker {
Expect(wObj).ShouldNot(BeNil())
Expect(wObj.State).Should(Equal("normal"))
}
})
})
Context("When retrieving available workers is unsuccessful", func() {
BeforeEach(func() {
server = ghttp.NewServer()
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodGet, "/v1/clusters/myCluster/workers"),
ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve workers`),
),
)
})

It("should return error during retrieveing workers", func() {
worker, err := newWorker(server.URL()).ListByWorkerPool("myCluster", "test", false)
Expect(err).To(HaveOccurred())
Expect(worker).Should(BeNil())
Expect(len(worker)).Should(Equal(0))
})
})
})
//Delete
Describe("Delete", func() {
Context("When delete of worker is successful", func() {
Expand Down

0 comments on commit 00b345f

Please sign in to comment.