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

Write APIs CLI commands #64

Merged
merged 32 commits into from
Mar 19, 2020
Merged

Write APIs CLI commands #64

merged 32 commits into from
Mar 19, 2020

Conversation

DimitarPetrov
Copy link
Member

@DimitarPetrov DimitarPetrov commented Mar 16, 2020

What is included

See examples below!

  • --mode sync/async flag to each command that support async execution
  • smctl status command to check an asynchronous operations status
  • single-resource is now displayed in as vertical table (example below)
  • smctl provision
  • smctl deprovision
  • smctl bind
  • smctl unbind
  • Split SM client tests in multiple files because it grew too much
  • Bindings containing the service instance name for easier usage
  • Return the ready field of each resource so you can see which resource is ok to use

Examples

▶ smctl delete-broker overview-broker-subacc-cfdev-tenant-id --mode async
Do you really want to delete broker with name [overview-broker-subacc-cfdev-tenant-id] (Y/n): yes
Service Broker overview-broker-subacc-cfdev-tenant-id successfully scheduled for deletion. To see status of the operation use:
smctl status /v1/service_brokers/f50afb9b-fde6-46a9-9b91-017862c4e47b/operations/5db85a30-98e4-4edf-ab3c-e3249bc6b55e

▶ smctl status /v1/service_brokers/f50afb9b-fde6-46a9-9b91-017862c4e47b/operations/5db85a30-98e4-4edf-ab3c-e3249bc6b55e

| ID     | 5db85a30-98e4-4edf-ab3c-e3249bc6b55e                                                                                                                                                               |
| Type   | delete                                                                                                                                                                                             |
| State  | failed                                                                                                                                                                                             |
| Error  | {"error":"ExistingReferenceEntity","description":"Error deleting entity /v1/service_brokers: Could not delete entity /v1/service_brokers due to existing reference entity /v1/service_instances"}  |

▶ smctl get-broker overview-broker-subacc-cfdev-tenant-id

| ID           | f50afb9b-fde6-46a9-9b91-017862c4e47b                                                                                                                                                                             |
| Name         | overview-broker-subacc-cfdev-tenant-id                                                                                                                                                                           |
| URL          | http://sm-test-broker:8083                                                                                                                                                                                       |
| Description  | dsk                                                                                                                                                                                                              |
| Created      | 2020-03-13T11:44:38.786787Z                                                                                                                                                                                      |
| Updated      | 2020-03-13T11:44:38.884939Z                                                                                                                                                                                      |
| Labels       | subaccount_id=subacc-cfdev-tenant-id                                                                                                                                                                             |
| Last Op      | delete failed {"error":"ExistingReferenceEntity","description":"Error deleting entity /v1/service_brokers: Could not delete entity /v1/service_brokers due to existing reference entity /v1/service_instances"}  |
▶ smctl provision asd3 overview-service simple
Service Instance asd3 successfully scheduled for provisioning. To see status of the operation use:
smctl status /v1/service_instances/33f65d83-cb03-4f00-a840-6d9ab88ba709/operations/4de8969d-cf03-4df3-903e-ae9dab955644

▶ smctl status /v1/service_instances/33f65d83-cb03-4f00-a840-6d9ab88ba709/operations/4de8969d-cf03-4df3-903e-ae9dab955644

| ID     | 4de8969d-cf03-4df3-903e-ae9dab955644  |
| Type   | create                                |
| State  | succeeded                             |

▶ smctl li
3 service instances.
ID                                    Name  Service Plan ID                       Platform ID      Created                      Updated                      Ready  Usable  Labels
------------------------------------  ----  ------------------------------------  ---------------  ---------------------------  ---------------------------  -----  ------  ------------------------------------
e92793b9-16e2-460e-afa8-11b5eb984a63  asd   05159b8e-ce6c-4458-afae-394b244efa27  service-manager  2020-03-16T11:59:11.207762Z  2020-03-16T11:59:12.253548Z  true   true    subaccount_id=subacc-cfdev-tenant-id
9cfb0c3b-5ebd-40d0-a0a5-0ea167e8dfa1  asd2  05159b8e-ce6c-4458-afae-394b244efa27  service-manager  2020-03-16T13:36:44.69134Z   2020-03-16T13:36:45.733201Z  true   true    subaccount_id=subacc-cfdev-tenant-id
33f65d83-cb03-4f00-a840-6d9ab88ba709  asd3  05159b8e-ce6c-4458-afae-394b244efa27  service-manager  2020-03-16T14:05:43.507642Z  2020-03-16T14:05:44.550502Z  true   true    subaccount_id=subacc-cfdev-tenant-id

▶ smctl get-instance asd3
One service instance.
| ID               | 33f65d83-cb03-4f00-a840-6d9ab88ba709  |
| Name             | asd3                                  |
| Service Plan ID  | 05159b8e-ce6c-4458-afae-394b244efa27  |
| Platform ID      | service-manager                       |
| Created          | 2020-03-16T14:05:43.507642Z           |
| Updated          | 2020-03-16T14:05:44.550502Z           |
| Ready            | true                                  |
| Usable           | true                                  |
| Labels           | subaccount_id=subacc-cfdev-tenant-id  |
| Last Op          | create succeeded                      |
▶ smctl bind asd2 test3 --mode sync

| ID                     | bffcfd42-09f7-4192-b561-935692ccb240                |
| Name                   | test3                                               |
| Service Instance Name  |                                                     |
| Service Instance ID    | 9cfb0c3b-5ebd-40d0-a0a5-0ea167e8dfa1                |
| Credentials            | {"password":"0ImqRMpm9lcZhsXS","username":"admin"}  |
| Created                | 2020-03-16T14:19:54.44907Z                          |
| Updated                | 2020-03-16T14:19:55.500341272Z                      |
| Ready                  | true                                                |
| Labels                 | subaccount_id=subacc-cfdev-tenant-id                |
| Last Op                | -                                                   |


▶ smctl list-bindings
4 service bindings.
ID                                    Name   Instance Name  Credentials                                         Created                      Updated                      Ready  Labels
------------------------------------  -----  -------------  --------------------------------------------------  ---------------------------  ---------------------------  -----  ------------------------------------
598832ba-70af-48c9-8251-540abe2c003b  test   asd            {"password":"0ImqRMpm9lcZhsXS","username":"admin"}  2020-03-16T13:36:29.716254Z  2020-03-16T13:36:30.76686Z   true   subaccount_id=subacc-cfdev-tenant-id
6c6ff13c-75e0-4fe7-a31c-1ec23c8f1289  test   asd2           {"password":"0ImqRMpm9lcZhsXS","username":"admin"}  2020-03-16T13:36:53.02376Z   2020-03-16T13:36:54.065749Z  true   subaccount_id=subacc-cfdev-tenant-id
4cadea9e-502a-4848-b913-1764f3ac4330  test2  asd2           {"password":"0ImqRMpm9lcZhsXS","username":"admin"}  2020-03-16T14:09:33.35636Z   2020-03-16T14:09:34.40252Z   true   subaccount_id=subacc-cfdev-tenant-id
bffcfd42-09f7-4192-b561-935692ccb240  test3  asd2           {"password":"0ImqRMpm9lcZhsXS","username":"admin"}  2020-03-16T14:19:54.44907Z   2020-03-16T14:19:55.500341Z  true   subaccount_id=subacc-cfdev-tenant-id

▶ smctl get-binding test3
One service binding.
| ID             | bffcfd42-09f7-4192-b561-935692ccb240                |
| Name           | test3                                               |
| Instance Name  | asd2                                                |
| Credentials    | {"password":"0ImqRMpm9lcZhsXS","username":"admin"}  |
| Created        | 2020-03-16T14:19:54.44907Z                          |
| Updated        | 2020-03-16T14:19:55.500341Z                         |
| Ready          | true                                                |
| Labels         | subaccount_id=subacc-cfdev-tenant-id                |
| Last Op        | create succeeded                                    |

@DimitarPetrov DimitarPetrov added the requests review PR is waiting for review label Mar 16, 2020
@coveralls
Copy link

coveralls commented Mar 16, 2020

Coverage Status

Coverage increased (+3.03%) to 84.056% when pulling cf4ae94 on write-api-adoption into 1099c82 on master.

@dpanayotov
Copy link
Member

dpanayotov commented Mar 16, 2020

Tested 1-2 commands, will continue later:
0. get-instance alias is gb - old typo maybe

  1. last op seems to be missing when deprovision fails
    Deprovision:
go run main.go deprovision my-instance
Do you really want to delete instance with name [my-instance] (Y/n): y
Service Instance my-instance successfully scheduled for deletion. To see status of the operation use:
smctl poll /v1/service_instances/61000e36-81de-45f3-9c0d-612b41846ce0/operations/098b5fdd-431e-42b4-a52d-1575a52be405

Get:

go run main.go get-instance my-instance
One service instance.
| ID               | 61000e36-81de-45f3-9c0d-612b41846ce0                |
| Name             | my-instance                                         |
| Service Plan ID  | b426cb34-b92e-41d4-a64d-497b143296f5                |
| Platform ID      | service-manager                                     |
| Created          | 2020-03-05T07:53:31.694965Z                         |
| Updated          | 2020-03-05T07:55:38.442491Z                         |
| Ready            | false                                               |
| Usable           | true                                                |
| Labels           | subaccount_id=39152471-70a7-4e8d-8539-5469f31dbee1  |

Poll:

go run main.go poll /v1/service_instances/61000e36-81de-45f3-9c0d-612b41846ce0/operations/098b5fdd-431e-42b4-a52d-1575a52be405

| ID     | 098b5fdd-431e-42b4-a52d-1575a52be405                                                                                                                                                                                                                                                                                                               |
| Type   | delete                                                                                                                                                                                                                                                                                                                                             |
| State  | failed                                                                                                                                                                                                                                                                                                                                             |
| Error  | {"error":"BrokerError","description":"Failed deprovisioning request instanceID: 61000e36-81de-45f3-9c0d-612b41846ce0, planID: <plan_name>, serviceID: <service-name>, acceptsIncomplete: true: Status: 500; ErrorMessage: \u003cnil\u003e; Description: Service instance 61000e36-81de-45f3-9c0d-612b41846ce0 does not exist.; ResponseError: \u003cnil\u003e"}  |
  1. Generally, the concept of poll is weird to me.
go run main.go provision test1234 <service> <plan>
Service Instance test1234 successfully scheduled for provisioning. To see status of the operation use:
smctl poll /v1/service_instances/7487e899-8bf6-45b5-8e61-b32c33c9de65/operations/6f57c79b-a7a8-4333-b860-b6b92163c809

It seems natural to say smctl get-instance test1234 which would show the instance and the status even if the provision failed, but I get

go run main.go get-instance test1234
No instance found with name: test1234%

and I have to call poll to see why provisioning failed. Can't /v1/:resource_type/:resource_id?last_op be reused instead of making a poll command?

  1. Does it make sense to extract only get-resource and have it polished in a separate PR, then we can continue with the next commands? For example we can improve get-instance with the above cases and from usability point of view returning service-plan-id is not very helpful and might be better to translate this to plan and offering name.

pankrator
pankrator previously approved these changes Mar 16, 2020
return err
}
if len(plans.ServicePlans) != 1 {
return fmt.Errorf("exactly one service plan with name %s for offering with id %s ecpected", pi.planName, pi.instance.ServiceID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "ecpected"

@@ -56,13 +55,9 @@ func (gb *GetInstanceCmd) Run() error {
return nil
}

resultInstances := &types.ServiceInstances{}
resultInstances := &types.ServiceInstances{Vertical: true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use types.ServiceInstance and remove the Vertical property of the plural type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case, where you can have more than one instance with the same name. However this cases are rare and if there is such a situation the instances probably wouldn't be too much. That's why decided to make it vertical, since most of the time the instance will be just one and the readability would be significantly improved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there 2 instances and it looks good then it is ok for me

@DimitarPetrov
Copy link
Member Author

@dpanayotov

For me failed deprovision operations is returned, are you sure you use latest SM and everything is dep ensured, since this functionality become available in SM this morning.

▶ smctl deprovision asd2
Do you really want to delete instance with name [asd2] (Y/n): y
Service Instance asd2 successfully scheduled for deletion. To see status of the operation use:
smctl poll /v1/service_instances/9cfb0c3b-5ebd-40d0-a0a5-0ea167e8dfa1/operations/75ef1992-f39b-46fd-a130-8bdbc8a05cf4

▶ smctl get-instance asd2
One service instance.
| ID               | 9cfb0c3b-5ebd-40d0-a0a5-0ea167e8dfa1                                                                       |
| Name             | asd2                                                                                                       |
| Service Plan ID  | 05159b8e-ce6c-4458-afae-394b244efa27                                                                       |
| Platform ID      | service-manager                                                                                            |
| Created          | 2020-03-16T13:36:44.69134Z                                                                                 |
| Updated          | 2020-03-16T13:36:45.733201Z                                                                                |
| Ready            | true                                                                                                       |
| Usable           | true                                                                                                       |
| Labels           | subaccount_id=subacc-cfdev-tenant-id                                                                       |
| Last Op          | delete failed {"error":"BadRequest","description":"could not delete instance due to 3 existing bindings"}  |

The concept of poll is introduced, due to the case when you create an instance, but it fails before the point when the instance is stored in the SM DB. In this situation the only trace of this operation is the operation in SM DB itself. However there is no any way to get the operation which failed in so early stage and not entity for it is created.

If you have any ideas I am willing to enhance the commands in different PRs, if this will speed up the review process.

@dpanayotov
Copy link
Member

@DimitarPetrov For debugging purposes it would make sense to have the option to get the operation in such case. For the happy path (failure to provision is still a happy path), this seems like an overhead and unnecessary information. Provision can tell me something like Successfully scheduled provision operation :operation_id for Instance :instance_id Now if I call get-instance :instance_name I should see the instance in some state (in progress; created; failed) in any case except when SM crashed before putting the record in. In the unlikely case that I don't see it, I know the IDs and can use the poll command (or something like smctl status service_instance --resource :resource_id --operation :operation_id if we want to hide the API endpoint)

@DimitarPetrov
Copy link
Member Author

@dpanayotov
It is not that uncommon to have such situation as crash of SM.
For example conflicting instance is such a case, which is not unlikely. Let's discuss it offline and decide if we can tweak something in SM or change the interface.

return fmt.Errorf("more than one service instance with name %s found. Use --id flag to specify id of the binding to be deleted", ubc.instanceName)
}

bindingsToDelte, err := ubc.Client.ListBindings(&query.Parameters{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: typo in bindingsToDelte

@@ -39,13 +32,13 @@ var _ = Describe("Register Broker Command test", func() {
command = NewRegisterBrokerCmd(context)
})

validRegisterBrokerExecution := func(args []string) *cobra.Command {
validAsyncRegisterBrokerExecution := func(args []string, location string) *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: in all other similar methods to this one, the location parameter always comes first. For consistency reasons, is it a good idea to switch the arguments here?

sync, errSyncFlag := c.Flags().GetBool("sync")

if errAsyncFlag == nil && errSyncFlag == nil {
return fmt.Errorf("ambiguas flags provided sync and async")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: typo ambiguas

ataleksandrov
ataleksandrov previously approved these changes Mar 19, 2020
Copy link

@ataleksandrov ataleksandrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@DimitarPetrov DimitarPetrov merged commit 8fe7688 into master Mar 19, 2020
@DimitarPetrov DimitarPetrov deleted the write-api-adoption branch March 19, 2020 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requests review PR is waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants