Skip to content
Permalink
Browse files

[JENKINS-24380] Stop relying on the format of Run.id.

  • Loading branch information
jglick committed Dec 15, 2014
1 parent f9c0ef9 commit 19e500d2a168a1dfedf8987c618b4a4d0c9be8a0
@@ -70,7 +70,7 @@ public void setDiskUsage(Long size) throws IOException{
information.setSize(size);
}
else{
property.getDiskUsageOfBuilds().add(new DiskUsageBuildInformation(build.getId(), build.getNumber(), size));
property.getDiskUsageOfBuilds().add(new DiskUsageBuildInformation(build.getId(), build.getTimeInMillis(), build.getNumber(), size));
}
property.saveDiskUsage();
}
@@ -5,28 +5,49 @@
package hudson.plugins.disk_usage;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
*
* @author Lucie Votypkova
*/
public class DiskUsageBuildInformation implements Serializable, Comparable{

private static final DateFormat LEGACY_ID_FORMATTER = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");

private String id;

private long timestamp;
private int number;

private Long size;

public DiskUsageBuildInformation(String id, int number, Long size){
public DiskUsageBuildInformation(String id, long timestamp, int number, Long size){
this.id = id;
this.timestamp = timestamp;
this.number = number;
this.size = size;
}

private Object readResolve() {
if (timestamp == 0) {
try {
timestamp = LEGACY_ID_FORMATTER.parse(id).getTime();
} catch (ParseException x) {
// never mind
}
}
return this;
}

public String getId(){
return id;
}

public long getTimestamp() {
return timestamp;
}

public int getNumber(){
return number;
@@ -12,17 +12,11 @@
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Node;
import hudson.model.Run;
import hudson.model.TopLevelItem;
import hudson.remoting.Callable;
import hudson.tasks.Mailer;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@@ -400,13 +394,13 @@ public static void calculateDiskUsageForBuild(String buildId, AbstractProject pr
}
else{
if(build!=null){
information = new DiskUsageBuildInformation(buildId, build.getNumber(), buildSize);
information = new DiskUsageBuildInformation(buildId, build.getTimeInMillis(), build.getNumber(), buildSize);
property.getDiskUsageOfBuilds().add(information);
}
else{
//should not happen
AbstractBuild newLoadedBuild = (AbstractBuild) project._getRuns().getById(buildId);
information = new DiskUsageBuildInformation(buildId, newLoadedBuild.getNumber(), buildSize);
information = new DiskUsageBuildInformation(buildId, newLoadedBuild.getTimeInMillis(), newLoadedBuild.getNumber(), buildSize);
property.getDiskUsageOfBuilds().add(information);
}
}
@@ -536,29 +530,5 @@ public Long call() throws IOException {

}


public static FilenameFilter getBuildDirectoryFilter(){
final DateFormat formatter = Run.getIDFormatter();
return new FilenameFilter() {
@Override public boolean accept(File dir, String name) {
if (name.startsWith("0000")) {
// JENKINS-1461 sometimes create bogus data directories with impossible dates, such as year 0, April 31st,
// or August 0th. Date object doesn't roundtrip those, so we eventually fail to load this data.
// Don't even bother trying.
return false;
}
try {
if (formatter.format(formatter.parse(name)).equals(name)) {
return true;
}
} catch (ParseException e) {
// fall through
}
LOGGER.log(Level.FINE, "Skipping {0} in {1}", new Object[] {name, dir});
return false;
}
};
}

public static final Logger LOGGER = Logger.getLogger(DiskUsageUtil.class.getName());
}
@@ -82,7 +82,7 @@ public synchronized void loadFirstTime(){
if(run instanceof AbstractBuild){
AbstractBuild build = (AbstractBuild) run;
BuildDiskUsageAction usage = run.getAction(BuildDiskUsageAction.class);
DiskUsageBuildInformation information = new DiskUsageBuildInformation(build.getId(), build.number, 0l);
DiskUsageBuildInformation information = new DiskUsageBuildInformation(build.getId(), build.getTimeInMillis(), build.number, 0l);
buildDiskUsage.add(information);
if(usage==null){
run.getActions().add(new BuildDiskUsageAction(build));
@@ -134,7 +134,7 @@ public void loadOldData(){
if(run instanceof AbstractBuild){
AbstractBuild build = (AbstractBuild) run;
BuildDiskUsageAction usage = run.getAction(BuildDiskUsageAction.class);
DiskUsageBuildInformation information = new DiskUsageBuildInformation(build.getId(), build.number, 0l);
DiskUsageBuildInformation information = new DiskUsageBuildInformation(build.getId(), build.getTimeInMillis(), build.number, 0l);
buildDiskUsage.add(information);
if(usage!=null){
information.setSize(usage.buildDiskUsage);
@@ -7,7 +7,6 @@
import hudson.model.ProminentProjectAction;
import hudson.util.Graph;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -160,13 +159,7 @@ public Long getJobRootDirDiskUsage() {
}
Set<DiskUsageBuildInformation> informations = property.getDiskUsageOfBuilds();
for(DiskUsageBuildInformation information: informations){
Date date = null;
try {
date = Run.getIDFormatter().parse(information.getId());
} catch (ParseException ex) {
Logger.getLogger(ProjectDiskUsageAction.class.getName()).log(Level.SEVERE, null, ex);
continue;
}
Date date = new Date(information.getTimestamp());
if(older!=null && !date.before(older))
continue;
if(yonger!=null && !date.after(yonger))
@@ -230,13 +223,7 @@ public Long getAllBuildsDiskUsage() throws IOException{
}
Set<DiskUsageBuildInformation> informations = property.getDiskUsageOfBuilds();
for(DiskUsageBuildInformation information: informations){
Date date = null;
try {
date = Run.getIDFormatter().parse(information.getId());
} catch (ParseException ex) {
Logger.getLogger(ProjectDiskUsageAction.class.getName()).log(Level.SEVERE, null, ex);
continue;
}
Date date = new Date(information.getTimestamp());
if(older!=null && !date.before(older))
continue;
if(yonger!=null && !date.after(yonger))

0 comments on commit 19e500d

Please sign in to comment.
You can’t perform that action at this time.