SAP / cf-html5-apps-repo-cli-plugin

Cloud Foundry CLI plugin to work with SAP Cloud HTML5 Applications Repository
Apache License 2.0
43 stars 5 forks source link

Deleting the destination after undeploying is not working #35

Open LalithManokar opened 4 years ago

LalithManokar commented 4 years ago

Description

I have deployed the application using MTA and done the

cf undeploy <mtar_id>

then i try to run the command

cf html5-delete -d -n demohelium-*

mtar id is "demohelium" html5-version is 1.4.3

Environment

canary business application studio

CLI Output

08:22:52.350682 Initializing command 'html5-delete'
08:22:52.350749 Configuration file does not exist. No cache to crear
08:22:52.350759 Executing command 'html5-delete': args: '[-d -n demohelium-*]'
08:22:52.350790 Deleting service instances by IDs: []
08:22:52.350797 Getting context (org/space/username)
08:22:52.351970 Resolving service instances by name prefix 'demohelium-*'
08:22:52.351989 Making request to: /v2/service_instances?q=space_guid:895719b1-fdff-4828-9a5c-884f9544db16
Screen Shot 2020-06-09 at 1 55 27 PM Screen Shot 2020-06-09 at 1 55 38 PM
micellius commented 4 years ago

@lalithmanokar , thanks for reporting an issue!

Can you please run cf s after you deployed and MTAR, before you run cf undeploy <mtar_id>. I'd like to see the service instances created during MTAR deployment (mostly their names).

Did you use --delete-services and --delete-service-keys when you use cf undeploy <mtar_id>? If yes, you'll not be able to run cf html5-delete -d -n <service_name_prefix>-*, since services are already deleted, and therefore CLI will not be able to find them and corresponding destinations.

In case of running cf html5-delete -d -n <service_name_prefix>-* CLI works the following way:

  1. Find all service instances in the current space, which name starts with <service_name_prefix>-.
  2. Take IDs of these services and look for destinations having them as value of app_host_id or html5-apps-repo.app_host_id custom property.
  3. If matching destinations found, take the value of sap.cloud.service of such destinations and delete all destinations that have the same value of sap.cloud.service.
  4. Delete service instances found on step 1.

So, if service instances were removed with cf undeploy --delete-services --delete-service-keys, CLI will not be able to proceed after step 1. You'll need to use app-host-id values found in output of cf html5-list -d instead of using -n option.

LalithManokar commented 4 years ago

HI,

I have got the steps to delete the mta based applications like below

How to use After running cf undeploy , run cf html5-delete -d -n '-*' to delete all service instances, which name starts from -, and related destinations to XSUAA and HTML5 Repo

As you suggested i am trying to delete the using the apphost id

cf html5-delete -d  3a645154-70e7-42b3-8174-963dc0f5401c
11:08:53.857170 Initializing command 'html5-delete'
11:08:53.857222 Configuration file does not exist. No cache to crear
11:08:53.857231 Executing command 'html5-delete': args: '[-d 3a645154-70e7-42b3-8174-963dc0f5401c]'
11:08:53.857253 Deleting service instances by IDs: [3a645154-70e7-42b3-8174-963dc0f5401c]
11:08:53.857262 Getting context (org/space/username)
Deleting service instances with IDs 3a645154-70e7-42b3-8174-963dc0f5401c and associated destinations in org heliumdemosp / space helium as I307469...
11:08:53.930710 Getting destination service context
11:08:53.930727 Getting list of services
11:08:53.931108 Making request to: /v2/spaces/895719b1-fdff-4828-9a5c-884f9544db16/services
11:08:56.229500 Looking for 'destination' service
11:08:56.229526 Destination service found: &{Name:destination GUID:be381e3b-0d69-47bc-a044-63f69733acfe}
11:08:56.229543 Getting service plans for 'destination' service (GUID: be381e3b-0d69-47bc-a044-63f69733acfe)
11:08:56.229547 Making request to: /v2/service_plans?q=service_guid:be381e3b-0d69-47bc-a044-63f69733acfe
11:08:56.643667 Destination service 'lite' plan found: &{Name:lite GUID:821497d5-8d07-4748-bf78-48495eec823b}
11:08:56.643705 Getting service instances of 'destination' service 'lite' plan (&{Name:lite GUID:821497d5-8d07-4748-bf78-48495eec823b})
11:08:56.643719 Making request to: /v2/service_instances?q=service_plan_guid%20IN%20821497d5-8d07-4748-bf78-48495eec823b%3Bspace_guid:895719b1-fdff-4828-9a5c-884f9544db16
11:08:56.898279 Using service instance of 'destination' service 'lite' plan: {Name:heliumdemo-destination-service GUID:9fdb8dcb-92e8-4c69-86d3-7a6e7efa8853 UpdatedAt:2020-06-09T07:09:16Z LastOperation:{Type:create State:succeeded Description: UpdatedAt:2020-06-09T07:09:16Z CreatedAt:2020-06-09T07:09:16Z}}
11:08:56.898353 Creating service key for 'destination' service 'lite' plan
11:08:56.898364 Making request to: /v2/service_keys
FAILED
Could not create destination context: Could not create service key of heliumdemo-destination-service service instance: 
Service broker error: Service broker destination-service-broker failed with: An error occurred during operation: Create service instance binding e9d32b4b-e089-43d6-b720-5e52bd68a8cf. Please try again later.

why it is trying to create?

Regards, lalith. S

micellius commented 4 years ago

Since the -d flag was specified, HTML5 plugin need to access destination service (to delete destination configuration). In order to do that it needs valid JWT, which in it's turn may be created using service key of destination service instance. Therefore, to delete destination configuration, HTML5 plugin temporary creates destination service instance (if there is no existing one in the space already) and service key for it. After deletion of destination configuration, temporary created artefacts (service instance and key) are deleted as well.

LalithManokar commented 4 years ago
Screen Shot 2020-06-10 at 1 06 02 PM

i can able to delete and i can see the logs via debug mode but without debug mode i can see the warning message but not a success message

Regards, Lalith. S

gregorwolf commented 1 year ago

Hi @LalithManokar,

this issue was mentioned in Destination when deleting an application. Please check if the option that I show in my commit: switch from subaccount to instance destinations instead of using subaccount destinations I've switched to instance destinations in my sample application. This destinations get deleted when the destination service instance is getting deleted.

Best Regards Gregor