javarestpropertiesload-balancingapache-commons-config

How to temporarily fail/disable REST APIs at runtime?


I am working on an REST service which primarily provides 2 APIs: PUT request and GET request. During a disaster recovery, the service will be in a state where it cannot accept new PUT requests, but can still be able to provide response for GET requests. I am looking to see how I can temporarily disable/fail incoming PUT API calls (by returning 500s or anything other than 200) at runtime, while the service is actively undergoing a disaster recovery. The service runs on a set of hosts behind a load-balancer, with auto-scaling enabled. The PUT API requests need to be disabled temporarily on all the hosts running the service.

I have com across this post on updating configurations at runtime: java update properties file run time, but it looked like this requires manually updating the properties file on each of the hosts, which might not be optimal if we have a large number of hosts running the service.

Wondering if there are other approaches to achieve this. Thanks in advance!


Solution

  • Mostly, Load-Balancer placed behind firewall. If you have access to your firewall, you can set a task before starting disaster recovery for set a rule in your firewall and blocking any connection to your target service or method using firewall. After DR completed, set a task for drop the rule and allow connections.