Class ConnectorJsonNodeReader

java.lang.Object
org.sentrysoftware.maven.metricshub.connector.producer.ConnectorJsonNodeReader

public class ConnectorJsonNodeReader extends Object
Implementation for reading information from a JSON structure representing a connector.

This class provides methods to extract various fields and information from a JsonNode representing a connector. It serves as an utility for reading data associated with a connector. Various methods are available to retrieve specific attributes such as supersedes, detection, criteria or other relevant details.

Instances of this class are typically created with a JsonNode containing connector information, and the provided methods can then be used to access and extract specific details from the JSON structure.

  • Constructor Details

    • ConnectorJsonNodeReader

      public ConnectorJsonNodeReader()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Retrieves the display name property of the connector located under the connector JSON node.
      Returns:
      The display name as a String.
    • getInformationOrDefault

      public String getInformationOrDefault(String defaultValue)
      Retrieves the information property of the connector, if available.
      Parameters:
      defaultValue - The default value to return if the information property is null or represents a JSON null.
      Returns:
      The information property as a String, or the specified default value if not present.
    • getPlatformsOrDefault

      public String getPlatformsOrDefault(String defaultValue)
      Retrieves the platforms property of the connector, if available.
      Parameters:
      defaultValue - The default value to return if the platforms property is null or represents a JSON null.
      Returns:
      The platforms property as a String, or the specified default value if not present.
    • getSupersedes

      public List<String> getSupersedes()
      Retrieves the list of supersedes values from the connector's detection property, if available.
      Returns:
      A list of strings representing the supersedes values, or an empty list if not present.
    • getAppliesTo

      public List<String> getAppliesTo()
      Retrieves the list of appliesTo (OS) values from the connector's detection property, if available.
      Returns:
      A list of strings representing the OS values, or an empty list if not present.
    • getRequiredMetricsHubVersion

      public String getRequiredMetricsHubVersion()
      Retrieves the required MetricsHub version from the connector's detection criteria.

      This method retrieves the required MetricsHub version by extracting the detection criteria obtained from the connector. It looks for criteria of type "productRequirements" and extracts the associated engine version. If no matching criteria are found or the necessary information is not available, the method returns null.

      Returns:
      The required MetricsHub version, or null if the information is not available.
    • getReliesOnOrDefault

      public String getReliesOnOrDefault(String defaultValue)
      Retrieves the reliesOn property of the connector, if available.
      Parameters:
      defaultValue - The default value to return if the reliesOn property is null or represents a JSON null.
      Returns:
      The reliesOn property as a String, or the specified default value if not present.
    • getTechnologies

      public Set<TechnologyType> getTechnologies()
      Retrieves the set of TechnologyTypes used by the monitor jobs in the connector.

      This method iterates through the monitors defined in the connector and collects the TechnologyTypes associated with their discovery, collect, and simple jobs. The result is a set of unique technology types.

      Returns:
      A Set of TechnologyTypes used by monitors in the connector.
    • getMonitors

      public Optional<com.fasterxml.jackson.databind.JsonNode> getMonitors()
      Gets the monitors from the connector.
      Returns:
      The monitors as an Optional of JsonNode.
    • getSudoCommands

      public List<String> getSudoCommands()
      Retrieves a list of sudo commands configured in the connector.

      This method retrieves the sudo commands defined in the "sudoCommands" section of the connector. The commands are returned as a List of strings. If the "sudoCommands" section is not present or is not of the expected type, an empty list is returned.

      Returns:
      A List of strings representing the sudo commands set in the connector.
    • getConnectionTypes

      public Set<String> getConnectionTypes()
      Retrieves a set of connection types specified in the connector's detection.

      This method looks for the "connectionTypes" field within the "detection" section of the connector configuration. If the "detection" section is present and contains the "connectionTypes" field, the method returns a Set of case-insensitive strings representing the connection types. If the "detection" section or the "connectionTypes" field is not present or is not of the expected type, an empty set is returned.

      Returns:
      A case-insensitive Set of strings representing the connection types (local and/or remote).
    • isAutoDetectionDisabled

      public boolean isAutoDetectionDisabled()
      Checks if auto-detection is disabled for the connector.

      This method looks for the presence of the "disableAutoDetection" field within the "detection" section of the connector. If the field is present and is a boolean value, the method returns its boolean value. If the "detection" section or the "disableAutoDetection" field is not present or is not a boolean, the method assumes auto-detection is enabled and returns false.

      Returns:
      true if auto-detection is explicitly disabled, false if explicitly enabled, or false if the configuration is not present.
    • getOnLastResort

      public String getOnLastResort()
      Retrieves the "onLastResort" configuration value from the connector's detection section.
      Returns:
      The "onLastResort" configuration value as a string, or null if not configured.
    • getCriteria

      public List<com.fasterxml.jackson.databind.JsonNode> getCriteria()
      Retrieves the detection criteria as a list of JsonNode objects from the connector's detection section.
      Returns:
      A list of JsonNode objects representing the detection criteria, or an empty list if not configured.
    • getMonitorMetrics

      public Set<String> getMonitorMetrics(com.fasterxml.jackson.databind.JsonNode monitor)
      Retrieves the metric keys from the specified monitor node.
      Parameters:
      monitor - The monitor node as a JsonNode.
      Returns:
      A Set containing the metric keys.
    • getMonitorAttributes

      public Set<String> getMonitorAttributes(com.fasterxml.jackson.databind.JsonNode monitor)
      Retrieves the attribute keys from the specified monitor node.
      Parameters:
      monitor - The monitor node as a JsonNode.
      Returns:
      A Set containing the attribute keys.
    • getMonitorJobs

      public com.fasterxml.jackson.databind.JsonNode[] getMonitorJobs(com.fasterxml.jackson.databind.JsonNode monitor)
      Retrieves the monitor's jobs from the specified monitor node.
      Parameters:
      monitor - The monitor node as a JsonNode.
      Returns:
      An array containing the monitor's jobs
    • extractMetricName

      public static final String extractMetricName(String name)
      This method removes attribute parts from the metric name
      Parameters:
      name - metric name with or without attributes
      Returns:
      metric name without attributes
    • hasBladeMonitorJob

      public boolean hasBladeMonitorJob()
      Checks if there is a blade monitor job with mapping directives.
      Returns:
      true if there is a blade monitor job with mapping directives, otherwise false.
    • getTags

      public List<String> getTags()
      Retrieves a list of tags from the detection JSON node.
      Returns:
      a list of tags as strings, or an empty list if no tags are found.
    • getVariablesNames

      public Set<String> getVariablesNames()
      Retrieves all variable names from the connector template. Variables are expected to be in the format: ${var::variableName}.
      Returns:
      a set of unique variable names found within the connector template.
    • getDefaultVariables

      public Map<String,ConnectorDefaultVariable> getDefaultVariables()
      Retrieves the default connector variables declared in the connector. These variables include their descriptions and default values.
      Returns:
      a map of variable names to their corresponding ConnectorDefaultVariable objects, each containing a description and a default value. Returns an empty map if no variables are declared.
    • getRelativePath

      public String getRelativePath()
      Retrieves the relative path of the connector that was saved during parsing. This path is used to generate a link to the connector's source code.
      Returns:
      The saved relative path as a string.