Class FrontCacheClient

java.lang.Object
org.frontcache.client.FrontCacheClient

public class FrontCacheClient extends Object
  • Field Details

    • CONNECTION_TIMEOUT

      public static int CONNECTION_TIMEOUT
    • WARMER_UNSUPPORTED

      public static final String WARMER_UNSUPPORTED
      The errorDescription of every warmer call made to a node that does not know the action. Such a node answers with a ping, which parses into any response class with responseStatus=OK - so without this, a start sent to an older node would be reported as a run that started. Reporting a run that never began is the worst outcome available here, and a mixed fleet is the normal state.
      See Also:
  • Constructor Details

    • FrontCacheClient

      public FrontCacheClient(String frontcacheURL, String apiKey)
      Parameters:
      frontcacheURL -
      apiKey -
  • Method Details

    • removeFromCache

      public String removeFromCache(String filter)
      Parameters:
      filter -
      Returns:
    • removeFromCacheAll

      public String removeFromCacheAll()
      Returns:
    • purge

      public String purge()
      Triggers purge of expired entries on the edge.
      Returns:
      raw edge response, or an error message string
    • backup

      public BackupActionResponse backup()
      Triggers a backup of the on-disk (L2) index on the edge.
      Returns:
      BackupActionResponse with the status message, or null if the edge is not available
    • getCacheState

      public Map<String,String> getCacheState()
    • getCacheStateActionResponse

      public CacheStatusActionResponse getCacheStateActionResponse()
      Returns:
    • getNodeStatsActionResponse

      public NodeStatsActionResponse getNodeStatsActionResponse()
      The cheap, pollable view of a node - cache sizes per tier plus JVM heap, CPU and uptime.

      The fallback is the point

      The console upgrades independently of the fleet, in either order, so this has to work against a node that has never heard of get-node-stats. Such a node answers an unrecognized action with a PING response rather than an error, which would otherwise render as a panel of dashes with nothing in any log. Detecting the ping and retrying with get-cache-state gets the one number an older node does have - the entry count - and leaves the rest UNKNOWN so the console can show it as "not reported" instead of zero. Same shape as getResilienceConfigActionResponse(), which does this for the 2.7 rename.
      Returns:
      the node's stats, or null when the edge could not be reached at all
    • getCachedKeys

      public boolean getCachedKeys(OutputStream os)
      Writes keys to provided output stream
      Parameters:
      os -
      Returns:
    • dumpKeys

      public DumpKeysActionResponse dumpKeys()
      Triggers dumping of cached keys to a file on the edge (./warmer dir).
      Returns:
      DumpKeysActionResponse with the status message, or null if the edge is not available
    • getFallbackConfigsActionResponse

      public GetFallbackConfigActionResponse getFallbackConfigsActionResponse()
      Returns:
    • getFallbackEntries

      public Set<FallbackConfigEntry> getFallbackEntries()
      Returns:
      the fallback entries this edge has loaded, or null when the edge could not be reached
    • getFallbackConfigs

      @Deprecated public Map<String, Set<FallbackConfigEntry>> getFallbackConfigs()
      Deprecated.
      pre-2.7 shape: a single-entry map keyed by domain. Use getFallbackEntries().
    • getBotsActionResponse

      public GetBotsActionResponse getBotsActionResponse()
      Returns:
    • getBotKeywords

      public Set<String> getBotKeywords()
      Returns:
      the bot user-agent keywords this edge is using, or null when the edge could not be reached
    • getBotRules

      public List<BotRuleEntry> getBotRules()
      Returns:
      the bot classification rules this edge is running, in evaluation order and with their hit counts, or null when the edge could not be reached OR is older than 2.9.0 (which knows only getBotKeywords())
    • getBots

      @Deprecated public Map<String, Set<String>> getBots()
      Deprecated.
      pre-2.7 shape: a single-entry map keyed by domain. Use getBotKeywords().
    • getDynamicURLsActionResponse

      public GetDynamicURLsActionResponse getDynamicURLsActionResponse()
      Returns:
    • getDynamicUrlPatterns

      public Set<String> getDynamicUrlPatterns()
      Returns:
      the never-cached URL patterns this edge is using, or null when the edge could not be reached
    • getDynamicURLs

      @Deprecated public Map<String, Set<String>> getDynamicURLs()
      Deprecated.
      pre-2.7 shape: a single-entry map keyed by domain. Use getDynamicUrlPatterns().
    • getFallbacksConfigActionResponse

      public GetFallbacksConfigActionResponse getFallbacksConfigActionResponse()
      The raw conf/fallbacks.conf of this edge - what the console's Fallback Config screen renders. The parsed counterpart is getFallbackEntries(); note the two action names are one letter apart, see FrontcacheAction.GET_FALLBACKS_CONFIG.
      Returns:
      the response, which carries either the file or a "not found" error; null if the edge could not be reached at all
    • getFallbacksConfig

      public String getFallbacksConfig()
    • getDynamicURLsConfigActionResponse

      public GetDynamicURLsConfigActionResponse getDynamicURLsConfigActionResponse()
      The raw conf/dynamic-urls.conf of this edge - what the console's Dynamic URLs screen renders. The parsed counterpart is getDynamicURLsActionResponse().
      Returns:
      the response, which carries either the file or a "not found" error; null if the edge could not be reached at all
    • getDynamicURLsConfig

      public String getDynamicURLsConfig()
    • getBotsConfigActionResponse

      public GetBotsConfigActionResponse getBotsConfigActionResponse()
      The raw conf/bots.conf of this edge - what the console's Bot Configs screen renders. The parsed counterpart is getBotsActionResponse().
      Returns:
      the response, which carries either the file or a "not found" error; null if the edge could not be reached at all
    • getBotsConfig

      public String getBotsConfig()
    • getGuardRulesActionResponse

      public GetGuardRulesActionResponse getGuardRulesActionResponse()
      Returns:
      guard rules this edge is running, in evaluation order, with hit counts
    • getGuardRules

      public List<GuardRuleEntry> getGuardRules()
    • getGuardConfigActionResponse

      public GetGuardConfigActionResponse getGuardConfigActionResponse()
      Returns:
    • getGuardConfig

      public String getGuardConfig()
    • getResilienceConfigActionResponse

      public GetResilienceConfigActionResponse getResilienceConfigActionResponse()
      Asks for the raw resilience config, falling back to the pre-2.7 action name when the edge does not recognize the current one. The fallback is needed because an unknown action is not an error on the wire: the management servlet answers it with a ping response, which would render the console's panel empty with nothing in any log to explain why. A ping is therefore the signal to retry with the old name - a precise test, since this client never sends ping itself.
      Returns:
      the response, or null when the edge could not be reached
    • getResilienceConfig

      public String getResilienceConfig()
      Returns:
      the raw contents of the edge's conf/resilience.properties, or null when the edge could not be reached
    • getConfigFile

      public String getConfigFile(ConfigFile configFile)
      The raw content of any of the five editable config files, by logical id. Dispatches to the per-file getters rather than replacing them: each one carries its own wire-format compatibility (the resilience getter retries with the pre-2.7 action name, the others read a field an older node may not send), and folding that into one call would drop it.
      Returns:
      the file's content, null when the edge could not be reached or has no such file
    • setConfig

      public SetConfigActionResponse setConfig(ConfigFile configFile, String content, String baseHash, boolean apply)
      Writes one config file on the edge and applies it.

      A ping means the node predates this action

      An unrecognized action is answered with a ping, not an error, so without this check a save to an older node would parse into a response with responseStatus=OK and written=false - i.e. the console would report a success that never happened. That is the worst outcome available here, and a mixed fleet is the normal state: the console upgrades independently of the nodes, in either order.
      Parameters:
      baseHash - sha-256 of the content being replaced, or null to skip the concurrency check
      Returns:
      the outcome, or null when the edge could not be reached at all
    • getWarmerStatus

      public WarmerStatusActionResponse getWarmerStatus()
    • getWarmerLists

      public WarmerListsActionResponse getWarmerLists()
    • getWarmerList

      public WarmerListActionResponse getWarmerList(String name, String grep)
      Parameters:
      grep - a search, or null
    • downloadWarmerList

      public String downloadWarmerList(String name, OutputStream os)
      Streams a whole list into os (raw=true) - never through memory, so a 64 MB list can pass through the console to a browser.
      Returns:
      null on success, otherwise why not
    • putWarmerList

      public WarmerListActionResponse putWarmerList(String name, InputStream body, long length, String baseHash)
      Creates or replaces a list. The list goes as the request BODY, with the parameters in the query string: Jetty refuses a form body over 200,000 bytes (on the console's container and the node's), and a list will reach that - the config files never have.
      Parameters:
      length - the body's length, or -1 to send it chunked
      baseHash - the hash the list had when it was read, or null to skip the concurrency check
    • deleteWarmerList

      public WarmerListActionResponse deleteWarmerList(String name)
    • warmerPreflight

      public WarmerPreflightActionResponse warmerPreflight(WarmerRunParams run)
    • warmerStart

      public WarmerStatusActionResponse warmerStart(WarmerRunParams run)
    • warmerUpdate

      public WarmerStatusActionResponse warmerUpdate(Long delayMs, Integer concurrency)
      A null leaves that setting as it is.
    • warmerPause

      public WarmerStatusActionResponse warmerPause()
    • warmerResume

      public WarmerStatusActionResponse warmerResume()
    • warmerStop

      public WarmerStatusActionResponse warmerStop()
    • reloadResilience

      public ReloadResilienceActionResponse reloadResilience()
      Reloads the edge's conf/resilience.properties.
      Returns:
      the outcome - getWarnings() carries what could not be applied - or null when the edge could not be reached
    • reloadDynamicURLs

      public ReloadDynamicUrlsActionResponse reloadDynamicURLs()
      Reloads the edge's conf/dynamic-urls.conf.
      Returns:
      the outcome - getPatternCount() is how many patterns survived the parse - or null when the edge could not be reached
    • getHystrixConfigActionResponse

      @Deprecated public GetResilienceConfigActionResponse getHystrixConfigActionResponse()
      Deprecated.
    • getHystrixConfig

      @Deprecated public String getHystrixConfig()
      Deprecated.
      pre-2.7 name of getResilienceConfig()
    • getFromCacheActionResponse

      public GetFromCacheActionResponse getFromCacheActionResponse(String key)
      Returns:
    • getFromCache

      public WebResponse getFromCache(String key)
    • putToCache

      public boolean putToCache(String key, WebResponse webResponse)
      Pushes a WebResponse entry into the remote node's cache. Used by the replication engine to write entries from a source edge to a target edge.
      Parameters:
      key - the cache key (normalised path)
      webResponse - the entry to store
      Returns:
      true if the entry was stored successfully
    • getCachedKeysSet

      public Set<String> getCachedKeysSet()
      Fetches all cached keys from the remote node and returns them as a Set. Used by the replication engine to compute the diff between source and target.
      Returns:
      set of cached keys, or empty set on error
    • getFrontCacheURL

      public String getFrontCacheURL()
    • getName

      public String getName()
      http://localhost:8080/ -> localhost:8080
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object