How to identify and delete orphaned Spring Cloud Service 2.x backend apps
search cancel

How to identify and delete orphaned Spring Cloud Service 2.x backend apps

book

Article ID: 297158

calendar_today

Updated On:

Products

Support Only for Spring

Issue/Introduction

This article covers how to verify that all backend apps for Spring Cloud Service (SCS) 2.x are valid and how to clean orphaned services.


Environment

Product Version: 2.1

Resolution

To removed orphaned services for SCS version 2.x, follow these steps:

1. The backend app for SCS version 2.x are located at org/space, p-spring-cloud-services / instances

       For config server:     config-<GUID>
       For service registry:  eureka-<GUID>
       For circuit-breaker:   hystrix-<GUID>
                              turbine-<GUID>

 

     
cf apps shows you a complete list and orphaned services are not easily identifiable. 

For example:

Getting apps in org p-spring-cloud-services / space instances as admin...
OK

name                                          requested state   instances   memory   disk   urls
config-29891ef1-65a9-4003-823b-81afcfd67252   started           1/1         1G       1G     config-29891ef1-65a9-4003-823b-81afcfd67252.cfapps-53.slot-59.pez.vmware.com
config-2a9d2050-52fd-4b2f-b38a-333cd580406b   started           1/1         1G       1G     config-2a9d2050-52fd-4b2f-b38a-333cd580406b.cfapps-53.slot-59.pez.vmware.com
config-7bfdcd47-2d57-45ee-9cdc-5807982230bf   started           1/1         1G       1G     config-7bfdcd47-2d57-45ee-9cdc-5807982230bf.cfapps-53.slot-59.pez.vmware.com
config-83158adc-d11e-4e5e-bb5a-2120ad745780   started           1/1         1G       1G     config-83158adc-d11e-4e5e-bb5a-2120ad745780.cfapps-53.slot-59.pez.vmware.com


2. Create script "verify-scs-guids.sh". This script identifies which service / app are orphaned.  

a. Run this command:

vi verify-scs-guids.sh


b. Copy and paste the code below and save your changes.

#filename: verify-scs-guids.sh

#!/bin/sh

#extract all service guid to a file /tmp/scs-guids.txt
#-----------------------------------------------
cf target p-spring-cloud-services -s instances
echo " "
cf apps | grep "config-\|eureka-\|hystrix-" | awk '{print$1}' | cut -d"-" -f 2-6 > /tmp/scs-guids.txt


#read /tmp/scs-guids.txt and identify which service DO NOT exists. 
#----------------------
while read GUID
do
  #echo ""
  #echo "==========>> checking $GUID "
  if [ $(cf curl /v2/service_instances/$GUID | jq -r '.metadata.guid') == $GUID ]
  then
    echo "Found - service: $GUID"
  else
    echo "==Missing Service==================================="
    #echo "NOT found - service: $GUID"
    cf curl /v2/service_instances/$GUID | jq -r '.description'
    echo "-----app(s) to be deleted ---------"
    cf apps | grep $GUID
    echo " "

fi
done < /tmp/scs-guids.txt


#clean up
#--------
rm /tmp/scs-guids.txt



3. Make the script executable with this commnad:

$ chmod +x verify-scs-guids.sh


4. Execute the script with ./verify-scs-guids.sh. The script generates a report for all the SCS 2.x service guid(s). The report provides the name of the orphaned application.

For example:

bsamson-a01:~ bsamson$ ./verify-scs-guids.sh

api endpoint:   https://api.run-53.slot-59.pez.vmware.com
api version:    2.150.0
user:           admin
org:            p-spring-cloud-services
space:          instances

Found - service: 29891ef1-65a9-4003-823b-81afcfd67252
Found - service: 2a9d2050-52fd-4b2f-b38a-333cd580406b
Found - service: 7bfdcd47-2d57-45ee-9cdc-5807982230bf
==Missing Service===================================
The service instance could not be found: 83158adc-d11e-4e5e-bb5a-2120ad745780
-----app(s) to be deleted ---------
config-83158adc-d11e-4e5e-bb5a-2120ad745780   started           1/1         1G       1G     config-83158adc-d11e-4e5e-bb5a-2120ad745780.cfapps-53.slot-59.pez.vmware.com


5. Delete all the app(s) from the above report that returned "The service instance could not be found" with $ cf delete APP-NAME.

For example:

$ cf delete config-83158adc-d11e-4e5e-bb5a-2120ad745780


Upon completion on removing the orphaned SCS 2.1 backend app, we suggest to Check out for failed/errored service instances from SCS 2.x dashboard.

For more information on how to delete corrupt data from a service instance dashboard, refer to How to delete corrupt data on the SCS 2.x service instances dashboard.