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 ClassesNested classes/interfaces inherited from class com.sonyericsson.jenkins.plugins.bfa.db.KnowledgeBase
KnowledgeBase.KnowledgeBaseDescriptor -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMongoDBKnowledgeBase(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.voidconvertFrom(KnowledgeBase oldKnowledgeBase) Converts the existing old knowledge base into this one.protected voidconvertRemoved(MongoDBKnowledgeBase oldKnowledgeBase) Copies all causes flagged as removed from the old database to this one.booleanequals(KnowledgeBase oldKnowledgeBase) Called to see if the configuration has changed.booleanstatic booleanChecks 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 ofFailureCauses.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.intgetPort()Getter for the port value.protected List<FailureCause>Gets all causes flagged as removed in a "raw" JSON format.Get a shallow list of theFailureCauses.Getter for the MongoDB user name.inthashCode()booleanIf Statistics logging is enabled on this knowledge base or not.booleanIf all builds should be added to statistics logging, not just unsuccessful builds.booleanisTls()Whether to use TLS when connecting to the mongo server.voidremoveBuildfailurecause(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.voidsaveStatistics(Statistics stat) Saves the Statistics.voidsetRetryWrites(boolean retryWrites) enable or disable retryWrites while connecting to the mongo server.voidsetTls(boolean tls) Set whether or not to use TLS when connecting to the mongo server.voidstart()Called when the KnowledgeBase should be up and running.voidstop()Called when it is time to clean up after the KnowledgeBase.voidupdateLastSeen(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:KnowledgeBaseCalled when the KnowledgeBase should be up and running.- Specified by:
startin classKnowledgeBase
-
stop
public void stop()Description copied from class:KnowledgeBaseCalled when it is time to clean up after the KnowledgeBase.- Specified by:
stopin classKnowledgeBase
-
getCauses
Description copied from class:KnowledgeBaseGet the list ofFailureCauses. 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:
getCausesin classKnowledgeBase- Returns:
- the full list of causes.
- See Also:
-
getCauseNames
Description copied from class:KnowledgeBaseGet 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:
getCauseNamesin classKnowledgeBase- Returns:
- the full list of the names and ids of the causes..
- See Also:
-
getShallowCauses
Description copied from class:KnowledgeBaseGet a shallow list of theFailureCauses. 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:
getShallowCausesin classKnowledgeBase- Returns:
- a shallow list of all causes.
- See Also:
-
getCause
Description copied from class:KnowledgeBaseGet 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:
getCausein 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:KnowledgeBaseSaves a new cause to the db and generates a new id for the cause.- Specified by:
addCausein classKnowledgeBase- Parameters:
cause- the cause to add.- Returns:
- the same cause but with a new id.
-
removeCause
Description copied from class:KnowledgeBaseRemoves the cause from the knowledge base.- Specified by:
removeCausein 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:KnowledgeBaseSaves a cause to the db. Assumes that the id is kept from when it was fetched. Can also be an existing cause in anotherKnowledgeBaseimplementation with a preexisting id that is being converted viaKnowledgeBase.convertFrom(KnowledgeBase).- Specified by:
saveCausein 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:KnowledgeBaseConverts 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:
convertFromin classKnowledgeBase- Parameters:
oldKnowledgeBase- the old one.- Throws:
Exception- if something in the KnowledgeBase handling goes wrong.
-
getCategories
Description copied from class:KnowledgeBaseGets the unique categories of all FailureCauses.- Specified by:
getCategoriesin 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:KnowledgeBaseCalled to see if the configuration has changed.- Specified by:
equalsin 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:KnowledgeBaseIf Statistics logging is enabled on this knowledge base or not.- Specified by:
isEnableStatisticsin classKnowledgeBase- Returns:
- true if so. False if not or not implemented.
-
isSuccessfulLogging
public boolean isSuccessfulLogging()Description copied from class:KnowledgeBaseIf all builds should be added to statistics logging, not just unsuccessful builds. Only relevant ifKnowledgeBase.isEnableStatistics()is true.- Specified by:
isSuccessfulLoggingin classKnowledgeBase- Returns:
- true if set, false otherwise or if not implemented
-
saveStatistics
Description copied from class:KnowledgeBaseSaves the Statistics.- Specified by:
saveStatisticsin classKnowledgeBase- Parameters:
stat- the Statistics.
-
getLatestFailureForCause
Description copied from class:KnowledgeBaseFind 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:
getLatestFailureForCausein classKnowledgeBase- Parameters:
id- the FailureCause to match.- Returns:
- the time at which the latest Failure occurred.
-
getCreationDateForCause
Description copied from class:KnowledgeBaseFind 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:
getCreationDateForCausein 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:KnowledgeBaseSet 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:
updateLastSeenin classKnowledgeBase- Parameters:
ids- the ids of FailureCauses which occurred.seen- the time at which the FailureCauses occurred.
-
removeBuildfailurecause
Description copied from class:KnowledgeBaseRemoves the build failure cause of particular build.- Overrides:
removeBuildfailurecausein classKnowledgeBase- Parameters:
build- the build.
-
getDescriptor
-