0

Can someone help me understand how PCF Tasks in Active/Passive environment would work? It's my understanding that when deployed in Active, and mirrored in a Passive environment that the PCF Tasks would still run on the defined Job Schedules regardless if it's running on active or passive.

If this is true, is there a way for my PCF Task (a Java application) to programmatically check if it's running on Passive (then do nothing), or Active (do my operations)? I don't want to perform tasks on Passive until failover happens (where passive becomes Active, and active becomes Passive) and I only have one Task running from Active at any given time.

I tried getting the A Record from the FQDN (my apps route hostname) and then comparing it to localhost IP to determine if my running current IP matches the resolved hostname IP and therefore I'm running on Active... but I believe I am only getting an IP of a private Diego Cell or something (not sure yet).

    private boolean isActive() {
        try {
            InetAddress inetHost = InetAddress.getByName(properties.getFqdn());
            InetAddress inetSelf = InetAddress.getLocalHost();
            
            logger.info("host FQDN IP: {}, self localhost IP: {}", inetHost.getHostAddress(), inetSelf.getHostAddress());
            if (null != inetHost && null != inetSelf) { return (inetHost.getHostAddress().equals(inetSelf.getHostAddress())); }
        } catch (UnknownHostException e) {
            logger.error(e.getMessage());
        }
        return false;
    }

What am I missing here? Doesn't seem like it should be that complicated given that Tasks are part of PCF and Active/Passive is a normal and preferred setup.

I'd really just like Tasks during failover or failback to just start/stop working without any additional interactions.

Thank you for any suggestions!

Gary Tessman
  • 433
  • 4
  • 3
  • While active/passive is a common setup, it's not formally part of the platform and my understanding is that exact implementations can differ. Because it's not formally part of the platform, I don't believe there's anything in say `VCAP_APPLICATION` or other env variables you could look at to determine the status. DNS might give you some clues but you'd have to be careful with DNS TTL. Even with a short TTL, there could still be some delay before your DNS records update. You might want to see if you can as part of failover trigger apps and scheduled tasks to start running. – Daniel Mikusa Feb 17 '22 at 21:35
  • Thank you Daniel. Yes `VCAP_APPLICATION` is where I started. I can see what environment it's running on and modify some flag in Config Server to enable/disable but wanted didn't want the manual interaction. It would be a nice add to have environment variable to help determine active vs passive. I do like the idea of having tasks enabled as part of failover. I'll look into that some more. Appreciate your reply! – Gary Tessman Feb 23 '22 at 22:41
  • `It would be a nice add to have environment variable to help determine active vs passive.` -> your failover could add something to the running environment variable group. That would be exposed to all apps. The only catch is that you'd have to restart all the apps after that change since env variable changes require a restart to take effect. – Daniel Mikusa Feb 24 '22 at 13:30

0 Answers0