Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Service Provisioning #339

Merged
merged 3 commits into from
Jan 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cf/api/service_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"fmt"

"github.com/cloudfoundry/cli/cf/configuration/core_config"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/net"
Expand Down Expand Up @@ -29,6 +30,8 @@ func (resource ServiceInstancesSummaries) ToModels() (instances []models.Service

instance := models.ServiceInstance{}
instance.Name = instanceSummary.Name
instance.State = instanceSummary.State
instance.StateDescription = instanceSummary.StateDescription
instance.ApplicationNames = applicationNames
instance.ServicePlan = servicePlan
instance.ServiceOffering = serviceOffering
Expand Down Expand Up @@ -57,8 +60,10 @@ type ServiceInstanceSummaryApp struct {
}

type ServiceInstanceSummary struct {
Name string
ServicePlan ServicePlanSummary `json:"service_plan"`
Name string
State string
StateDescription string `json:"state_description"`
ServicePlan ServicePlanSummary `json:"service_plan"`
}

type ServicePlanSummary struct {
Expand Down
32 changes: 18 additions & 14 deletions cf/api/service_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ var _ = Describe("ServiceSummaryRepository", func() {
}
],
"services": [
{
"guid": "my-service-instance-guid",
"name": "my-service-instance",
"bound_app_count": 2,
"service_plan": {
"guid": "service-plan-guid",
"name": "spark",
"service": {
"guid": "service-offering-guid",
"label": "cleardb",
"provider": "cleardb-provider",
"version": "n/a"
{
"guid": "my-service-instance-guid",
"name": "my-service-instance",
"bound_app_count": 2,
"state": "in progress",
"state_description": "50% done",
"service_plan": {
"guid": "service-plan-guid",
"name": "spark",
"service": {
"guid": "service-offering-guid",
"label": "cleardb",
"provider": "cleardb-provider",
"version": "n/a"
}
}
}
}
}
]
}`,
}
Expand All @@ -75,6 +77,8 @@ var _ = Describe("ServiceSummaryRepository", func() {

instance1 := serviceInstances[0]
Expect(instance1.Name).To(Equal("my-service-instance"))
Expect(instance1.State).To(Equal("in progress"))
Expect(instance1.StateDescription).To(Equal("50% done"))
Expect(instance1.ServicePlan.Name).To(Equal("spark"))
Expect(instance1.ServiceOffering.Label).To(Equal("cleardb"))
Expect(instance1.ServiceOffering.Label).To(Equal("cleardb"))
Expand Down
12 changes: 6 additions & 6 deletions cf/commands/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (cmd *ShowService) Run(c *cli.Context) {
}))
cmd.ui.Say(T("Status: {{.Status}}",
map[string]interface{}{
"Status": ServiceInstanceStateToStatus(serviceInstance.State, serviceInstance.IsUserProvided()),
"Status": terminal.EntityNameColor(ServiceInstanceStateToStatus(serviceInstance.State, serviceInstance.IsUserProvided())),
}))
cmd.ui.Say(T("Message: {{.Message}}",
map[string]interface{}{
Expand All @@ -94,12 +94,12 @@ func ServiceInstanceStateToStatus(state string, isUserProvidedService bool) stri
return ""
}
switch state {
case "creating":
return T("unavailable ({{.State}})", map[string]interface{}{"State": state})
case "in progress":
return T("create in progress")
case "failed":
return T("failed ({{.State}})", map[string]interface{}{"State": "creating"})
case "available", "":
return T("available")
return T("create failed")
case "succeeded", "":
return T("create succeeded")
default:
return ""
}
Expand Down
46 changes: 23 additions & 23 deletions cf/commands/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var _ = Describe("service command", func() {
serviceInstance := models.ServiceInstance{}
serviceInstance.Name = "service1"
serviceInstance.Guid = "service1-guid"
serviceInstance.State = "creating"
serviceInstance.State = "in progress"
serviceInstance.StateDescription = "creating resource - step 1"
serviceInstance.ServicePlan = plan
serviceInstance.ServiceOffering = offering
Expand All @@ -77,7 +77,7 @@ var _ = Describe("service command", func() {
}

It("shows the service", func() {
createServiceInstanceWithState("creating")
createServiceInstanceWithState("in progress")
runCommand("service1")

Expect(ui.Outputs).To(ContainSubstrings(
Expand All @@ -87,49 +87,49 @@ var _ = Describe("service command", func() {
[]string{"Description: ", "the-description"},
[]string{"Documentation url: ", "http://documentation.url"},
[]string{"Dashboard: ", "some-url"},
[]string{"Status: ", "unavailable (creating)"},
[]string{"Status: ", "create in progress"},
[]string{"Message: ", "creating resource - step 1"},
))
Expect(requirementsFactory.ServiceInstanceName).To(Equal("service1"))
})

Context("shows correct status information based on service instance state", func() {
It("shows status: `unavailable (creating)` when state is `creating`", func() {
createServiceInstanceWithState("creating")
It("shows status: `create in progress` when state is `in progress`", func() {
createServiceInstanceWithState("in progress")
runCommand("service1")

Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Status: ", "unavailable (creating)"},
[]string{"Status: ", "create in progress"},
))
Expect(requirementsFactory.ServiceInstanceName).To(Equal("service1"))
})

It("shows status: `available` when state is `available`", func() {
createServiceInstanceWithState("available")
It("shows status: `create succeeded` when state is `succeeded`", func() {
createServiceInstanceWithState("succeeded")
runCommand("service1")

Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Status: ", "available"},
[]string{"Status: ", "create succeeded"},
))
Expect(requirementsFactory.ServiceInstanceName).To(Equal("service1"))
})

It("shows status: `failed (creating)` when state is `failed`", func() {
It("shows status: `create failed` when state is `failed`", func() {
createServiceInstanceWithState("failed")
runCommand("service1")

Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Status: ", "failed (creating)"},
[]string{"Status: ", "create failed"},
))
Expect(requirementsFactory.ServiceInstanceName).To(Equal("service1"))
})

It("shows status: `available` when state is ``", func() {
It("shows status: `create succeeded` when state is ``", func() {
createServiceInstanceWithState("")
runCommand("service1")

Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Status: ", "available"},
[]string{"Status: ", "create succeeded"},
))
Expect(requirementsFactory.ServiceInstanceName).To(Equal("service1"))
})
Expand Down Expand Up @@ -175,24 +175,24 @@ var _ = Describe("ServiceInstanceStateToStatus", func() {
Context("when the service is not user provided", func() {
isUserProvided := false

It("returns status: `unavailable (creating)` when state: `creating`", func() {
status := ServiceInstanceStateToStatus("creating", isUserProvided)
Expect(status).To(Equal("unavailable (creating)"))
It("returns status: `create in progress` when state: `in progress`", func() {
status := ServiceInstanceStateToStatus("in progress", isUserProvided)
Expect(status).To(Equal("create in progress"))
})

It("returns status: `available` when state: `available`", func() {
status := ServiceInstanceStateToStatus("available", isUserProvided)
Expect(status).To(Equal("available"))
It("returns status: `create succeeded` when state: `succeeded`", func() {
status := ServiceInstanceStateToStatus("succeeded", isUserProvided)
Expect(status).To(Equal("create succeeded"))
})

It("returns status: `failed (creating)` when state: `failed`", func() {
It("returns status: `create failed` when state: `failed`", func() {
status := ServiceInstanceStateToStatus("failed", isUserProvided)
Expect(status).To(Equal("failed (creating)"))
Expect(status).To(Equal("create failed"))
})

It("returns status: `available` when state: ``", func() {
It("returns status: `create succeeded` when state: ``", func() {
status := ServiceInstanceStateToStatus("", isUserProvided)
Expect(status).To(Equal("available"))
Expect(status).To(Equal("create succeeded"))
})
})

Expand Down
6 changes: 3 additions & 3 deletions cf/commands/service/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = Describe("services", func() {

serviceInstance := models.ServiceInstance{}
serviceInstance.Name = "my-service-1"
serviceInstance.State = "creating"
serviceInstance.State = "in progress"
serviceInstance.StateDescription = "fake state description"
serviceInstance.ServicePlan = plan
serviceInstance.ApplicationNames = []string{"cli1", "cli2"}
Expand Down Expand Up @@ -112,8 +112,8 @@ var _ = Describe("services", func() {
[]string{"Getting services in org", "my-org", "my-space", "my-user"},
[]string{"name", "service", "plan", "bound apps", "status"},
[]string{"OK"},
[]string{"my-service-1", "cleardb", "spark", "cli1, cli2", "unavailable (creating)"},
[]string{"my-service-2", "cleardb", "spark-2", "cli1", "available"},
[]string{"my-service-1", "cleardb", "spark", "cli1, cli2", "create in progress"},
[]string{"my-service-2", "cleardb", "spark-2", "cli1", "create succeeded"},
[]string{"my-service-provided-by-user", "user-provided", "", "", ""},
))
})
Expand Down
14 changes: 7 additions & 7 deletions cf/i18n/resources/de_DE.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -4325,8 +4325,8 @@
"modified": false
},
{
"id": "available",
"translation": "available",
"id": "create succeeded",
"translation": "create succeeded",
"modified": false
},
{
Expand Down Expand Up @@ -4410,8 +4410,8 @@
"modified": false
},
{
"id": "failed ({{.State}})",
"translation": "failed ({{.State}})",
"id": "create failed",
"translation": "create failed",
"modified": false
},
{
Expand Down Expand Up @@ -4705,8 +4705,8 @@
"modified": true
},
{
"id": "unavailable ({{.State}})",
"translation": "unavailable ({{.State}})",
"id": "create in progress",
"translation": "create in progress",
"modified": false
},
{
Expand Down Expand Up @@ -4859,4 +4859,4 @@
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
}
]
]
14 changes: 7 additions & 7 deletions cf/i18n/resources/en_US.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -4325,8 +4325,8 @@
"modified": false
},
{
"id": "available",
"translation": "available",
"id": "create succeeded",
"translation": "create succeeded",
"modified": false
},
{
Expand Down Expand Up @@ -4410,8 +4410,8 @@
"modified": false
},
{
"id": "failed ({{.State}})",
"translation": "failed ({{.State}})",
"id": "create failed",
"translation": "create failed",
"modified": false
},
{
Expand Down Expand Up @@ -4705,8 +4705,8 @@
"modified": false
},
{
"id": "unavailable ({{.State}})",
"translation": "unavailable ({{.State}})",
"id": "create in progress",
"translation": "create in progress",
"modified": false
},
{
Expand Down Expand Up @@ -4859,4 +4859,4 @@
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
}
]
]
14 changes: 7 additions & 7 deletions cf/i18n/resources/es_ES.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -4325,8 +4325,8 @@
"modified": false
},
{
"id": "available",
"translation": "available",
"id": "create succeeded",
"translation": "create succeeded",
"modified": false
},
{
Expand Down Expand Up @@ -4410,8 +4410,8 @@
"modified": false
},
{
"id": "failed ({{.State}})",
"translation": "failed ({{.State}})",
"id": "create failed",
"translation": "create failed",
"modified": false
},
{
Expand Down Expand Up @@ -4705,8 +4705,8 @@
"modified": true
},
{
"id": "unavailable ({{.State}})",
"translation": "unavailable ({{.State}})",
"id": "create in progress",
"translation": "create in progress",
"modified": false
},
{
Expand Down Expand Up @@ -4859,4 +4859,4 @@
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instancias",
"modified": false
}
]
]
14 changes: 7 additions & 7 deletions cf/i18n/resources/fr_FR.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -4325,8 +4325,8 @@
"modified": false
},
{
"id": "available",
"translation": "available",
"id": "create succeeded",
"translation": "create succeeded",
"modified": false
},
{
Expand Down Expand Up @@ -4410,8 +4410,8 @@
"modified": false
},
{
"id": "failed ({{.State}})",
"translation": "failed ({{.State}})",
"id": "create failed",
"translation": "create failed",
"modified": false
},
{
Expand Down Expand Up @@ -4705,8 +4705,8 @@
"modified": true
},
{
"id": "unavailable ({{.State}})",
"translation": "unavailable ({{.State}})",
"id": "create in progress",
"translation": "create in progress",
"modified": false
},
{
Expand Down Expand Up @@ -4859,4 +4859,4 @@
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
}
]
]
Loading