Class MongoDBKnowledgeBase

    • Field Detail

      • COLLECTION_NAME

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

        public static final String STATISTICS_COLLECTION_NAME
        The name of the statistics collection in the database.
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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 Detail

      • 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
      • 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:
        KnowledgeBase.getCauseNames()
      • 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:
        addCause(FailureCause)
      • 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:
        saveCause(FailureCause)
      • 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.
      • 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 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.
      • 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.