Class KnowledgeBase

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

public abstract class KnowledgeBase extends Object implements Describable<KnowledgeBase>, Serializable
Base class for storage implementations of FailureCauses. Extend this class and put @Extension on the descriptor to provide your own.
Author:
Robert Sandell <robert.sandell@sonyericsson.com>
See Also:
  • Constructor Details

    • KnowledgeBase

      public KnowledgeBase()
  • Method Details

    • getCauses

      public abstract Collection<FailureCause> getCauses() throws Exception
      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.
      Returns:
      the full list of causes.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • getCauseNames

      public abstract Collection<FailureCause> getCauseNames() throws Exception
      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.
      Returns:
      the full list of the names and ids of the causes.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • getShallowCauses

      public abstract Collection<FailureCause> getShallowCauses() throws Exception
      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.
      Returns:
      a shallow list of all causes.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
      See Also:
    • getCause

      public abstract FailureCause getCause(String id) throws Exception
      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.
      Parameters:
      id - the id of the cause.
      Returns:
      the cause or null if a cause with that id could not be found.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • addCause

      public abstract FailureCause addCause(FailureCause cause) throws Exception
      Saves a new cause to the db and generates a new id for the cause.
      Parameters:
      cause - the cause to add.
      Returns:
      the same cause but with a new id.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • removeCause

      public abstract FailureCause removeCause(String id) throws Exception
      Removes the cause from the knowledge base.
      Parameters:
      id - the id of the cause to remove.
      Returns:
      the removed FailureCause.
      Throws:
      Exception - if so.
    • saveCause

      public abstract FailureCause saveCause(FailureCause cause) throws Exception
      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 convertFrom(KnowledgeBase).
      Parameters:
      cause - the cause to add.
      Returns:
      the same cause but with a new id.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • convertFrom

      public abstract void convertFrom(KnowledgeBase oldKnowledgeBase) throws Exception
      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.
      Parameters:
      oldKnowledgeBase - the old one.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • getCategories

      public abstract List<String> getCategories() throws Exception
      Gets the unique categories of all FailureCauses.
      Returns:
      the list of categories.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • convertFromAbstract

      protected void convertFromAbstract(KnowledgeBase oldKnowledgeBase) throws Exception
      Does a full copy of the data in the old one to this one. Using the public api, can be used by implementations of convertFrom(KnowledgeBase) to handle conversion from an unknown source type.
      Parameters:
      oldKnowledgeBase - the old one.
      Throws:
      Exception - if anything goes wrong in the KnowledgeBase handling.
      See Also:
    • equals

      public abstract boolean equals(KnowledgeBase oldKnowledgeBase)
      Called to see if the configuration has changed.
      Parameters:
      oldKnowledgeBase - the previous config.
      Returns:
      true if it is the same.
    • start

      public abstract void start() throws Exception
      Called when the KnowledgeBase should be up and running.
      Throws:
      Exception - if anything goes wrong during the startup.
    • stop

      public abstract void stop()
      Called when it is time to clean up after the KnowledgeBase.
    • isEnableStatistics

      public abstract boolean isEnableStatistics()
      If Statistics logging is enabled on this knowledge base or not.
      Returns:
      true if so. False if not or not implemented.
    • isSuccessfulLogging

      public abstract boolean isSuccessfulLogging()
      If all builds should be added to statistics logging, not just unsuccessful builds. Only relevant if isEnableStatistics() is true.
      Returns:
      true if set, false otherwise or if not implemented
    • saveStatistics

      public abstract void saveStatistics(Statistics stat) throws Exception
      Saves the Statistics.
      Parameters:
      stat - the Statistics.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • getLatestFailureForCause

      public Date getLatestFailureForCause(String id)
      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.
      Parameters:
      id - the FailureCause to match.
      Returns:
      the time at which the latest Failure occurred.
    • updateLastSeen

      public void updateLastSeen(List<String> ids, Date seen)
      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.
      Parameters:
      ids - the ids of FailureCauses which occurred.
      seen - the time at which the FailureCauses occurred.
    • getCreationDateForCause

      public Date getCreationDateForCause(String id)
      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.
      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.
    • removeBuildfailurecause

      @Deprecated public void removeBuildfailurecause(AbstractBuild build) throws Exception
      Removes the build failure cause of particular build.
      Parameters:
      build - the build.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.
    • removeBuildfailurecause

      public void removeBuildfailurecause(Run build) throws Exception
      Removes the build failure cause of particular build.
      Parameters:
      build - the build.
      Throws:
      Exception - if something in the KnowledgeBase handling goes wrong.