Class FrontCacheClient

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

public class FrontCacheClient extends Object
  • Field Details

    • CONNECTION_TIMEOUT

      public static int CONNECTION_TIMEOUT
  • 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
    • setPluginConfig

      public SetConfigActionResponse setPluginConfig(String pluginId, String fileName, String content, String baseHash, boolean apply)
      Writes a plugin's config on the edge and applies it - set-config with file=plugin:<id>, so every gate of setConfig(ConfigFile, String, String, boolean) applies. A node that predates plugin configs refuses the id as an unknown file.
      Parameters:
      fileName - the file as getPluginConfig(String) named it, for messages only
      Returns:
      the outcome, or null when the edge could not be reached at all
    • getPluginConfig

      public GetPluginConfigActionResponse getPluginConfig(String pluginId)
      A plugin's raw config on the edge.
      Returns:
      the answer - status ERROR when the edge has no such plugin, pluginConfig null when its file is absent - or null when the edge could not be reached. A node that predates the action (a ping) is answered as one with no such plugin.
    • reloadPluginConfig

      public ReloadPluginConfigActionResponse reloadPluginConfig(String pluginId)
      Re-reads a plugin's config on the edge - reload-plugin-config?plugin=<id>: the file already on the node's disk, applied (a running plugin keeps the config it had when it refuses the new one; one whose last start failed on its config is started).
      Returns:
      the answer - applied false with status ERROR and the reasons in errors when the plugin refused it or has no config - or null when the edge could not be reached. A node that predates the action (a ping) is answered as an ERROR, never as a reload that succeeded.
    • call

      public <T extends org.frontcache.io.ActionResponse> T call(Map<String,String> params, Class<T> type)
      One management call, answered as JSON. The action is params.get("action"). A node that does not know the action answers a ping, which parses into any response class with responseStatus=OK - so a caller must check isPing(ActionResponse) before reading the answer as a success. That is how a module's client tells "this node has no such action" (a Community node, or one that predates it) from an answer.
      Returns:
      the answer, or null when the node could not be reached or did not answer JSON
    • callWithBody

      public <T extends org.frontcache.io.ActionResponse> T callWithBody(Map<String,String> queryParams, InputStream body, long length, String contentType, Class<T> type)
      A management call whose payload is 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), so a large payload cannot be a form field.
      Parameters:
      length - the body's length, or -1 to send it chunked
      Returns:
      as call(Map, Class)
    • callStreaming

      public <T extends org.frontcache.io.ActionResponse> T callStreaming(Map<String,String> params, String rawContentTypePrefix, OutputStream os, Class<T> type) throws IOException
      A management call whose answer may be a raw body: streamed into os - never through memory - when its Content-Type starts with rawContentTypePrefix, otherwise read as JSON (a refusal, or a ping from a node that does not know the action).
      Returns:
      null when the body was streamed, otherwise the JSON answer
      Throws:
      IOException - when the node could not be reached or the answer could not be read
    • isPing

      public static boolean isPing(org.frontcache.io.ActionResponse response)
      Whether response is the ping a node answers an action it does not know with.
    • 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