Class MongoDBKnowledgeBase

java.lang.Object
com.sonyericsson.jenkins.plugins.bfa.db.KnowledgeBase
com.sonyericsson.jenkins.plugins.bfa.db.MongoDBKnowledgeBase
All Implemented Interfaces:
Describable<KnowledgeBase>, Serializable

public class MongoDBKnowledgeBase extends KnowledgeBase
Handling of the MongoDB way of saving the knowledge base.
Author:
Tomas Westling <tomas.westling@sonyericsson.com>
See Also:
  • Field Details

    • COLLECTION_NAME

      public static final String COLLECTION_NAME
      The name of the cause collection in the database.
      See Also:
    • STATISTICS_COLLECTION_NAME

      public static final String STATISTICS_COLLECTION_NAME
      The name of the statistics collection in the database.
      See Also:
  • Constructor Details

    • MongoDBKnowledgeBase

      @DataBoundConstructor public MongoDBKnowledgeBase(String host, int port, String dbName, String userName, Secret password, boolean enableStatistics, boolean successfulLogging)
      Standard constructor.
      Parameters:
      host - the host to connect to.
      port - the port to connect to.
      dbName - the database name to connect to.
      userName - the user name for the database.
      password - the password for the database.
      enableStatistics - if statistics logging should be enabled or not.
      successfulLogging - if all builds should be logged to the statistics DB
  • Method Details

    • getUserName

      public String getUserName()
      Getter for the MongoDB user name.
      Returns:
      the user name.
    • getPassword

      public Secret getPassword()
      Getter for the MongoDB password.
      Returns:
      the password.
    • getHost

      public String getHost()
      Getter for the host value.
      Returns:
      the host string.
    • getPort

      public int getPort()
      Getter for the port value.
      Returns:
      the port number.
    • getDbName

      public String getDbName()
      Getter for the database name value.
      Returns:
      the database name string.
    • isTls

      public boolean isTls()
      Whether to use TLS when connecting to the mongo server.
      Returns:
      the tls option
    • setTls

      @DataBoundSetter public void setTls(boolean tls)
      Set whether or not to use TLS when connecting to the mongo server.
      Parameters:
      tls - the tls option
    • setRetryWrites

      @DataBoundSetter public void setRetryWrites(boolean retryWrites)
      enable or disable retryWrites while connecting to the mongo server.
      Parameters:
      retryWrites - the retryWrites option
    • start

      public void start()
      Description copied from class: KnowledgeBase
      Called when the KnowledgeBase should be up and running.
      Specified by:
      start in class KnowledgeBase
    • stop

      public void stop()
      Description copied from class: KnowledgeBase
      Called when it is time to clean up after the KnowledgeBase.
      Specified by:
      stop in class KnowledgeBase
    • getCauses

      public Collection<FailureCause> getCauses()
      Description copied from class: KnowledgeBase
      Get the list of FailureCauses. It is intended to be used in the scanning phase hence it should be returned as quickly as possible, so the list could be cached.
      Specified by:
      getCauses in class KnowledgeBase
      Returns:
      the full list of causes.
      See Also:
    • getCauseNames

      public Collection<FailureCause> getCauseNames()
      Description copied from class: KnowledgeBase
      Get the list of the FailureCause's names and ids. The list should be the latest possible from the DB as they will be used for editing. The objects returned should contain at least the id and the name of the cause.
      Specified by:
      getCauseNames in class KnowledgeBase
      Returns:
      the full list of the names and ids of the causes..
      See Also:
    • getShallowCauses

      public Collection<FailureCause> getShallowCauses()
      Description copied from class: KnowledgeBase
      Get a shallow list of the FailureCauses. The list should be the latest possible from the DB as they will be used in the list of causes to edit. shallow meaning no indications but information enough to show a nice list; at least id and name but description, comment, lastOccurred and categories are preferred as well.
      Specified by:
      getShallowCauses in class KnowledgeBase
      Returns:
      a shallow list of all causes.
      See Also:
    • getCause

      public FailureCause getCause(String id)
      Description copied from class: KnowledgeBase
      Get the cause with the given id. The cause returned is intended to be edited right away, so it should be as fresh from the db as possible.
      Specified by:
      getCause in class KnowledgeBase
      Parameters:
      id - the id of the cause.
      Returns:
      the cause or null if a cause with that id could not be found.
    • addCause

      public FailureCause addCause(FailureCause cause)
      Description copied from class: KnowledgeBase
      Saves a new cause to the db and generates a new id for the cause.
      Specified by:
      addCause in class KnowledgeBase
      Parameters:
      cause - the cause to add.
      Returns:
      the same cause but with a new id.
    • removeCause

      public FailureCause removeCause(String id)
      Description copied from class: KnowledgeBase
      Removes the cause from the knowledge base.
      Specified by:
      removeCause in class KnowledgeBase
      Parameters:
      id - the id of the cause to remove.
      Returns:
      the removed FailureCause.
    • addCause

      public FailureCause addCause(FailureCause cause, boolean doUpdate)
      Does not update the cache, used when we know we will have a lot of save/add calls all at once, e.g. during a convert.
      Parameters:
      cause - the FailureCause to add.
      doUpdate - true if a cache update should be made, false if not.
      Returns:
      the added FailureCause.
      See Also:
    • saveCause

      public FailureCause saveCause(FailureCause cause)
      Description copied from class: KnowledgeBase
      Saves a cause to the db. Assumes that the id is kept from when it was fetched. Can also be an existing cause in another KnowledgeBase implementation with a preexisting id that is being converted via KnowledgeBase.convertFrom(KnowledgeBase).
      Specified by:
      saveCause in class KnowledgeBase
      Parameters:
      cause - the cause to add.
      Returns:
      the same cause but with a new id.
    • saveCause

      public FailureCause saveCause(FailureCause cause, boolean doUpdate)
      Does not update the cache, used when we know we will have a lot of save/add calls all at once, e.g. during a convert.
      Parameters:
      cause - the FailureCause to save.
      doUpdate - true if a cache update should be made, false if not.
      Returns:
      the saved FailureCause.
      See Also:
    • convertFrom

      public void convertFrom(KnowledgeBase oldKnowledgeBase) throws Exception
      Description copied from class: KnowledgeBase
      Converts the existing old knowledge base into this one. Will be called after the creation of a new object when then Jenkins config is saved, So it could just be that the old one is exactly the same as this one.
      Specified by:
      convertFrom in class KnowledgeBase
      Parameters:
      oldKnowledgeBase - the old one.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • getCategories

      public List<String> getCategories()
      Description copied from class: KnowledgeBase
      Gets the unique categories of all FailureCauses.
      Specified by:
      getCategories in class KnowledgeBase
      Returns:
      the list of categories.
    • convertRemoved

      protected void convertRemoved(MongoDBKnowledgeBase oldKnowledgeBase) throws Exception
      Copies all causes flagged as removed from the old database to this one.
      Parameters:
      oldKnowledgeBase - the old database.
      Throws:
      Exception - if something goes wrong.
    • getRemovedCauses

      protected List<FailureCause> getRemovedCauses() throws Exception
      Gets all causes flagged as removed in a "raw" JSON format.
      Returns:
      the list of removed causes.
      Throws:
      Exception - if so.
    • equals

      public boolean equals(KnowledgeBase oldKnowledgeBase)
      Description copied from class: KnowledgeBase
      Called to see if the configuration has changed.
      Specified by:
      equals in class KnowledgeBase
      Parameters:
      oldKnowledgeBase - the previous config.
      Returns:
      true if it is the same.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • equals

      public static boolean equals(Object firstObject, Object secondObject)
      Checks if two objects equal each other, both being null counts as being equal.
      Parameters:
      firstObject - the firstObject.
      secondObject - the secondObject.
      Returns:
      true if equal or both null, false otherwise.
    • hashCode

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

      public boolean isEnableStatistics()
      Description copied from class: KnowledgeBase
      If Statistics logging is enabled on this knowledge base or not.
      Specified by:
      isEnableStatistics in class KnowledgeBase
      Returns:
      true if so. False if not or not implemented.
    • isSuccessfulLogging

      public boolean isSuccessfulLogging()
      Description copied from class: KnowledgeBase
      If all builds should be added to statistics logging, not just unsuccessful builds. Only relevant if KnowledgeBase.isEnableStatistics() is true.
      Specified by:
      isSuccessfulLogging in class KnowledgeBase
      Returns:
      true if set, false otherwise or if not implemented
    • saveStatistics

      public void saveStatistics(Statistics stat)
      Description copied from class: KnowledgeBase
      Saves the Statistics.
      Specified by:
      saveStatistics in class KnowledgeBase
      Parameters:
      stat - the Statistics.
    • getLatestFailureForCause

      public Date getLatestFailureForCause(String id)
      Description copied from class: KnowledgeBase
      Find the time at which the latest Failure occurred which matches the provided FailureCause. This method needs to be implemented in subclass if last seen-functionality is to be supported.
      Overrides:
      getLatestFailureForCause in class KnowledgeBase
      Parameters:
      id - the FailureCause to match.
      Returns:
      the time at which the latest Failure occurred.
    • getCreationDateForCause

      public Date getCreationDateForCause(String id)
      Description copied from class: KnowledgeBase
      Find out when the FailureCause identified by id was first created. This method needs to be implemented in subclass if last modified-functionality is to work correctly when upgrading from a version without this functionality.
      Overrides:
      getCreationDateForCause in class KnowledgeBase
      Parameters:
      id - the id of the FailureCause which info to retrieve.
      Returns:
      the Date at which the cause was created, or unix epoch if unknown.
    • updateLastSeen

      public void updateLastSeen(List<String> ids, Date seen)
      Description copied from class: KnowledgeBase
      Set the time at which FailureCauses identified by ids last occurred. This method needs to be implemented in subclass if last seen-functionality is to be supported.
      Overrides:
      updateLastSeen in class KnowledgeBase
      Parameters:
      ids - the ids of FailureCauses which occurred.
      seen - the time at which the FailureCauses occurred.
    • removeBuildfailurecause

      public void removeBuildfailurecause(Run build)
      Description copied from class: KnowledgeBase
      Removes the build failure cause of particular build.
      Overrides:
      removeBuildfailurecause in class KnowledgeBase
      Parameters:
      build - the build.
    • getDescriptor

      public Descriptor<KnowledgeBase> getDescriptor()