com.sonyericsson.jenkins.plugins.bfa.db
Class KnowledgeBase

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

public abstract class KnowledgeBase
extends Object
implements hudson.model.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:
Serialized Form

Nested Class Summary
static class KnowledgeBase.KnowledgeBaseDescriptor
          Descriptor for KnowledgeBases.
 
Constructor Summary
KnowledgeBase()
           
 
Method Summary
abstract  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.
abstract  List<String> getCategories()
          Gets the unique categories of all FailureCauses.
abstract  FailureCause getCause(String id)
          Get the cause with the given id.
abstract  Collection<FailureCause> getCauseNames()
          Get the list of the FailureCause's names and ids.
abstract  Collection<FailureCause> getCauses()
          Get the list of FailureCauses.
 List<ObjectCountPair<String>> getFailureCauseNames(GraphFilterBuilder filter)
          Gets a list of ObjectCountPairs where each pair contains a unique FailureCause-name as key and the number of times that failure cause was triggered as count.
 Map<Integer,List<FailureCause>> getFailureCausesPerBuild(GraphFilterBuilder filter)
          Gets a map where a lists of failure causes are mapped by the build number for which they were triggered.
 List<FailureCauseTimeInterval> getFailureCausesPerTime(int intervalSize, GraphFilterBuilder filter, boolean byCategories)
          Fetches failure causes grouped in time intervals.
 List<ObjectCountPair<String>> getNbrOfFailureCategoriesPerName(GraphFilterBuilder filter, int limit)
          Gets a list of ObjectCountPair where each pair contains a unique failure category string as key and the number of times that the failure cause category was triggered as count.
 List<ObjectCountPair<FailureCause>> getNbrOfFailureCauses(GraphFilterBuilder filter)
          Gets a list of ObjectCountPair where each pair contains a unique FailureCause as key and the number of times that failure cause was triggered as count.
 List<ObjectCountPair<String>> getNbrOfFailureCausesPerId(GraphFilterBuilder filter, int limit)
          Gets a list of ObjectCountPair where each pair contains a unique FailureCause id as key and a belonging count value for how many times that FailureCause was triggered.
 long getNbrOfNullFailureCauses(GraphFilterBuilder filter)
          Counts how many statistics posts there are without FailureCause (null) for a given filter.
abstract  Collection<FailureCause> getShallowCauses()
          Get a shallow list of the FailureCauses.
 List<Statistics> getStatistics(GraphFilterBuilder filter, int limit)
          Gets Statistics data.
 Map<org.jfree.data.time.TimePeriod,Double> getUnknownFailureCauseQuotaPerTime(int intervalSize, GraphFilterBuilder filter)
          Gets the quota of unknown failure causes mapped by time periods.
 int hashCode()
           
abstract  boolean isStatisticsEnabled()
          If Statistics logging is enabled on this knowledge base or not.
abstract  boolean isSuccessfulLoggingEnabled()
          If all builds should be added to statistics logging, not just unsuccessful builds.
abstract  void removeBuildfailurecause(hudson.model.AbstractBuild 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface hudson.model.Describable
getDescriptor
 

Constructor Detail

KnowledgeBase

public KnowledgeBase()
Method Detail

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 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:
getCauseNames()

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:
convertFrom(KnowledgeBase)

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.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

isStatisticsEnabled

public abstract boolean isStatisticsEnabled()
If Statistics logging is enabled on this knowledge base or not.

Returns:
true if so. False if not or not implemented.

isSuccessfulLoggingEnabled

public abstract boolean isSuccessfulLoggingEnabled()
If all builds should be added to statistics logging, not just unsuccessful builds. Only relevant if isStatisticsEnabled() 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.

getStatistics

public List<Statistics> getStatistics(GraphFilterBuilder filter,
                                      int limit)
                               throws Exception
Gets Statistics data. This method needs to be implemented in subclass for graph support.

Parameters:
filter - the filter to use when fetching data
limit - number of statistics items to fetch, set to nonpositive value to fetch all
Returns:
the list of statistics.
Throws:
Exception - if something in the KnowledgeBase handling goes wrong.

getNbrOfFailureCauses

public List<ObjectCountPair<FailureCause>> getNbrOfFailureCauses(GraphFilterBuilder filter)
Gets a list of ObjectCountPair where each pair contains a unique FailureCause as key and the number of times that failure cause was triggered as count. The list is sorted by counts, meaning that the FailureCause that has been triggered the most comes first. This method needs to be implemented in subclass for graph support.

Parameters:
filter - the filter to use when fetching data
Returns:
list of ObjectCountPairs.

getUnknownFailureCauseQuotaPerTime

public Map<org.jfree.data.time.TimePeriod,Double> getUnknownFailureCauseQuotaPerTime(int intervalSize,
                                                                                     GraphFilterBuilder filter)
Gets the quota of unknown failure causes mapped by time periods. This method needs to be implemented in subclass for graph support.

Parameters:
intervalSize - the interval sizes in which the data is grouped. Should be set to Calendar.MONTH, Calendar.DATE or Calendar.HOUR_OF_DAY.
filter - The filter to use when fetching the data
Returns:
failure cause quotas

getFailureCauseNames

public List<ObjectCountPair<String>> getFailureCauseNames(GraphFilterBuilder filter)
Gets a list of ObjectCountPairs where each pair contains a unique FailureCause-name as key and the number of times that failure cause was triggered as count. This list is sorted by counts, meaning that the FailureCause that has been triggered the most comes first. This method needs to be implemented in subclass for graph support.

Parameters:
filter - The filter to use when fetching the data
Returns:
List of ObjectCountPairs that consist of a name and count

getNbrOfNullFailureCauses

public long getNbrOfNullFailureCauses(GraphFilterBuilder filter)
Counts how many statistics posts there are without FailureCause (null) for a given filter. This method needs to be implemented in subclass for graph support.

Parameters:
filter - the filter to use when fetching data
Returns:
number of statistics posts without FailureCause

getNbrOfFailureCategoriesPerName

public List<ObjectCountPair<String>> getNbrOfFailureCategoriesPerName(GraphFilterBuilder filter,
                                                                      int limit)
Gets a list of ObjectCountPair where each pair contains a unique failure category string as key and the number of times that the failure cause category was triggered as count. The list is sorted by counts, meaning that the Category that has been triggered the most comes first. This method needs to be implemented in subclass for graph support.

Parameters:
filter - the filter to use when fetching data
limit - the number of categories to fetch, set to nonpositive value to fetch all
Returns:
list of ObjectCountPairs

getFailureCausesPerBuild

public Map<Integer,List<FailureCause>> getFailureCausesPerBuild(GraphFilterBuilder filter)
Gets a map where a lists of failure causes are mapped by the build number for which they were triggered. This method needs to be implemented in subclass for graph support.

Parameters:
filter - the filter to use when fetching data
Returns:
map of failure causes

getFailureCausesPerTime

public List<FailureCauseTimeInterval> getFailureCausesPerTime(int intervalSize,
                                                              GraphFilterBuilder filter,
                                                              boolean byCategories)
Fetches failure causes grouped in time intervals. The returned list does not have to be sorted, and one list element is created for each FailureCause for each time interval there exist data. This method needs to be implemented in subclass for graph support.

Parameters:
intervalSize - the interval sizes in which the data is grouped. Should be set to Calendar.MONTH, Calendar.DATE or Calendar.HOUR_OF_DAY.
filter - the filter to use when fetching data
byCategories - set to true in order to group failure causes by their categories
Returns:
list of FailureCauseTimeIntervals

getNbrOfFailureCausesPerId

public List<ObjectCountPair<String>> getNbrOfFailureCausesPerId(GraphFilterBuilder filter,
                                                                int limit)
Gets a list of ObjectCountPair where each pair contains a unique FailureCause id as key and a belonging count value for how many times that FailureCause was triggered. This method needs to be implemented in subclass for graph support.

Parameters:
filter - the filter to use when fetching data
limit - the number of items to fetch, set to nonpositive value to fetch all
Returns:
list of ObjectCountPairs

removeBuildfailurecause

public abstract void removeBuildfailurecause(hudson.model.AbstractBuild build)
                                      throws Exception
Removes the build failure cause of particular build.

Parameters:
build - the AbstractBuild.
Throws:
Exception - if something in the KnowledgeBase handling goes wrong.


Copyright © 2004-2014. All Rights Reserved.