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
FailureCause
s. Extend this class and put @Extension
on
the descriptor to provide your own.- Author:
- Robert Sandell <robert.sandell@sonyericsson.com>
- See Also:
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract FailureCause
addCause
(FailureCause cause) Saves a new cause to the db and generates a new id for the cause.abstract void
convertFrom
(KnowledgeBase oldKnowledgeBase) Converts the existing old knowledge base into this one.protected void
convertFromAbstract
(KnowledgeBase oldKnowledgeBase) Does a full copy of the data in the old one to this one.abstract boolean
equals
(KnowledgeBase oldKnowledgeBase) Called to see if the configuration has changed.Gets the unique categories of all FailureCauses.abstract FailureCause
Get the cause with the given id.abstract Collection<FailureCause>
Get the list of theFailureCause
's names and ids.abstract Collection<FailureCause>
Get the list ofFailureCause
s.Find out when the FailureCause identified by id was first created.Find the time at which the latest Failure occurred which matches the provided FailureCause.abstract Collection<FailureCause>
Get a shallow list of theFailureCause
s.abstract boolean
If Statistics logging is enabled on this knowledge base or not.abstract boolean
If all builds should be added to statistics logging, not just unsuccessful builds.void
Deprecated.void
removeBuildfailurecause
(Run build) Removes the build failure cause of particular build.abstract FailureCause
removeCause
(String id) Removes the cause from the knowledge base.abstract FailureCause
saveCause
(FailureCause cause) Saves a cause to the db.abstract void
saveStatistics
(Statistics stat) Saves the Statistics.abstract void
start()
Called when the KnowledgeBase should be up and running.abstract void
stop()
Called when it is time to clean up after the KnowledgeBase.void
updateLastSeen
(List<String> ids, Date seen) Set the time at which FailureCauses identified by ids last occurred.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface hudson.model.Describable
getDescriptor
-
Constructor Details
-
KnowledgeBase
public KnowledgeBase()
-
-
Method Details
-
getCauses
Get the list ofFailureCause
s. 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
Get the list of theFailureCause
'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
Get a shallow list of theFailureCause
s. 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
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
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
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
Saves a cause to the db. Assumes that the id is kept from when it was fetched. Can also be an existing cause in anotherKnowledgeBase
implementation with a preexisting id that is being converted viaconvertFrom(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
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
Gets the unique categories of all FailureCauses.- Returns:
- the list of categories.
- Throws:
Exception
- if something in the KnowledgeBase handling goes wrong.
-
convertFromAbstract
Does a full copy of the data in the old one to this one. Using the public api, can be used by implementations ofconvertFrom(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
Called to see if the configuration has changed.- Parameters:
oldKnowledgeBase
- the previous config.- Returns:
- true if it is the same.
-
start
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 ifisEnableStatistics()
is true.- Returns:
- true if set, false otherwise or if not implemented
-
saveStatistics
Saves the Statistics.- Parameters:
stat
- the Statistics.- Throws:
Exception
- if something in the KnowledgeBase handling goes wrong.
-
getLatestFailureForCause
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
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
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.Removes the build failure cause of particular build.- Parameters:
build
- the build.- Throws:
Exception
- if something in the KnowledgeBase handling goes wrong.
-
removeBuildfailurecause
Removes the build failure cause of particular build.- Parameters:
build
- the build.- Throws:
Exception
- if something in the KnowledgeBase handling goes wrong.
-
removeBuildfailurecause(hudson.model.Run)