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
Handling of the MongoDB way of saving the knowledge base.
- Author:
- Tomas Westling <tomas.westling@sonyericsson.com>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.sonyericsson.jenkins.plugins.bfa.db.KnowledgeBase
KnowledgeBase.KnowledgeBaseDescriptor
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMongoDBKnowledgeBase
(String host, int port, String dbName, String userName, Secret password, boolean enableStatistics, boolean successfulLogging) Standard constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddCause
(FailureCause cause) Saves a new cause to the db and generates a new id for the cause.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.void
convertFrom
(KnowledgeBase oldKnowledgeBase) Converts the existing old knowledge base into this one.protected void
convertRemoved
(MongoDBKnowledgeBase oldKnowledgeBase) Copies all causes flagged as removed from the old database to this one.boolean
equals
(KnowledgeBase oldKnowledgeBase) Called to see if the configuration has changed.boolean
static boolean
Checks if two objects equal each other, both being null counts as being equal.Gets the unique categories of all FailureCauses.Get the cause with the given id.Get the list of theFailureCause
's names and ids.Get the list ofFailureCause
s.Find out when the FailureCause identified by id was first created.Getter for the database name value.getHost()
Getter for the host value.Find the time at which the latest Failure occurred which matches the provided FailureCause.Getter for the MongoDB password.int
getPort()
Getter for the port value.protected List<FailureCause>
Gets all causes flagged as removed in a "raw" JSON format.Get a shallow list of theFailureCause
s.Getter for the MongoDB user name.int
hashCode()
boolean
If Statistics logging is enabled on this knowledge base or not.boolean
If all builds should be added to statistics logging, not just unsuccessful builds.boolean
isTls()
Whether to use TLS when connecting to the mongo server.void
removeBuildfailurecause
(Run build) Removes the build failure cause of particular build.removeCause
(String id) Removes the cause from the knowledge base.saveCause
(FailureCause cause) Saves a cause to the db.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.void
saveStatistics
(Statistics stat) Saves the Statistics.void
setRetryWrites
(boolean retryWrites) enable or disable retryWrites while connecting to the mongo server.void
setTls
(boolean tls) Set whether or not to use TLS when connecting to the mongo server.void
start()
Called when the KnowledgeBase should be up and running.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 com.sonyericsson.jenkins.plugins.bfa.db.KnowledgeBase
convertFromAbstract, removeBuildfailurecause
-
Field Details
-
COLLECTION_NAME
The name of the cause collection in the database.- See Also:
-
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
Getter for the MongoDB user name.- Returns:
- the user name.
-
getPassword
Getter for the MongoDB password.- Returns:
- the password.
-
getHost
Getter for the host value.- Returns:
- the host string.
-
getPort
public int getPort()Getter for the port value.- Returns:
- the port number.
-
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 classKnowledgeBase
-
stop
public void stop()Description copied from class:KnowledgeBase
Called when it is time to clean up after the KnowledgeBase.- Specified by:
stop
in classKnowledgeBase
-
getCauses
Description copied from class:KnowledgeBase
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.- Specified by:
getCauses
in classKnowledgeBase
- Returns:
- the full list of causes.
- See Also:
-
getCauseNames
Description copied from class:KnowledgeBase
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.- Specified by:
getCauseNames
in classKnowledgeBase
- Returns:
- the full list of the names and ids of the causes..
- See Also:
-
getShallowCauses
Description copied from class:KnowledgeBase
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.- Specified by:
getShallowCauses
in classKnowledgeBase
- Returns:
- a shallow list of all causes.
- See Also:
-
getCause
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 classKnowledgeBase
- Parameters:
id
- the id of the cause.- Returns:
- the cause or null if a cause with that id could not be found.
-
addCause
Description copied from class:KnowledgeBase
Saves a new cause to the db and generates a new id for the cause.- Specified by:
addCause
in classKnowledgeBase
- Parameters:
cause
- the cause to add.- Returns:
- the same cause but with a new id.
-
removeCause
Description copied from class:KnowledgeBase
Removes the cause from the knowledge base.- Specified by:
removeCause
in classKnowledgeBase
- Parameters:
id
- the id of the cause to remove.- Returns:
- the removed FailureCause.
-
addCause
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
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 anotherKnowledgeBase
implementation with a preexisting id that is being converted viaKnowledgeBase.convertFrom(KnowledgeBase)
.- Specified by:
saveCause
in classKnowledgeBase
- Parameters:
cause
- the cause to add.- Returns:
- the same cause but with a new id.
-
saveCause
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
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 classKnowledgeBase
- Parameters:
oldKnowledgeBase
- the old one.- Throws:
Exception
- if something in the KnowledgeBase handling goes wrong.
-
getCategories
Description copied from class:KnowledgeBase
Gets the unique categories of all FailureCauses.- Specified by:
getCategories
in classKnowledgeBase
- Returns:
- the list of categories.
-
convertRemoved
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
Gets all causes flagged as removed in a "raw" JSON format.- Returns:
- the list of removed causes.
- Throws:
Exception
- if so.
-
equals
Description copied from class:KnowledgeBase
Called to see if the configuration has changed.- Specified by:
equals
in classKnowledgeBase
- Parameters:
oldKnowledgeBase
- the previous config.- Returns:
- true if it is the same.
-
equals
-
equals
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() -
isEnableStatistics
public boolean isEnableStatistics()Description copied from class:KnowledgeBase
If Statistics logging is enabled on this knowledge base or not.- Specified by:
isEnableStatistics
in classKnowledgeBase
- 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 ifKnowledgeBase.isEnableStatistics()
is true.- Specified by:
isSuccessfulLogging
in classKnowledgeBase
- Returns:
- true if set, false otherwise or if not implemented
-
saveStatistics
Description copied from class:KnowledgeBase
Saves the Statistics.- Specified by:
saveStatistics
in classKnowledgeBase
- Parameters:
stat
- the Statistics.
-
getLatestFailureForCause
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 classKnowledgeBase
- Parameters:
id
- the FailureCause to match.- Returns:
- the time at which the latest Failure occurred.
-
getCreationDateForCause
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 classKnowledgeBase
- 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
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 classKnowledgeBase
- Parameters:
ids
- the ids of FailureCauses which occurred.seen
- the time at which the FailureCauses occurred.
-
removeBuildfailurecause
Description copied from class:KnowledgeBase
Removes the build failure cause of particular build.- Overrides:
removeBuildfailurecause
in classKnowledgeBase
- Parameters:
build
- the build.
-
getDescriptor
-