Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-41449] RestAPI feature based on hashes
RestAPI feature: creating a list of elements with some hierarchy

RestAPI feature: refreshing data when quering through the api otherwise it will keep the previous run which means null when it hasn't been requested through the UI

RestAPI feature: fixing bug when creating a list of elements with some hierarchy

Deprecated public api and created an alternative one based on Hashes

Added some test api cases

Added Rest API test cases

Excluding evil macosx files

Removed wrong size method

Using the class name rather than the package+class name, then those data structures amp correctly
  • Loading branch information
v1v committed Feb 26, 2017
1 parent 926d570 commit 24925a4
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ jenkins.war
*.iml
*.ipr
*.iws
.DS_Store

Expand Up @@ -33,13 +33,18 @@
import org.jenkins.ci.plugins.jenkinslint.model.Job;
import org.jenkins.ci.plugins.jenkinslint.model.Lint;
import org.jenkins.ci.plugins.jenkinslint.model.Slave;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import hudson.model.Api;

@ExportedBean
@Extension
public final class JenkinsLintAction implements RootAction {

Expand All @@ -49,6 +54,15 @@ public final class JenkinsLintAction implements RootAction {
private Hashtable<String, Slave> slaveSet = new Hashtable<String, Slave>();
private ArrayList<InterfaceSlaveCheck> slaveCheckList = new ArrayList<InterfaceSlaveCheck>();

public Api getApi() {
try {
this.getData();
} catch (IOException ioe) {
LOG.log(Level.INFO, "Failing when getting the JenkinsLint data through the API");
}
return new Api(this);
}

public void getData() throws IOException {
LOG.log(Level.FINE, "getData()");
jobSet.clear();
Expand Down Expand Up @@ -85,8 +99,8 @@ public void getData() throws IOException {
LOG.log(Level.FINER, "queryChecks " + item.getDisplayName());
Job newJob = new Job(item.getName(), item.getUrl());
for (InterfaceCheck checker : checkList) {
LOG.log(Level.FINER, checker.getClass().getName() + " " + item.getName() + " " + checker.executeCheck(item));
newJob.addLint(new Lint(checker.getClass().getName(), checker.executeCheck(item), checker.isIgnored(item.getDescription())));
LOG.log(Level.FINER, checker.getName() + " " + item.getName() + " " + checker.executeCheck(item));
newJob.addLint(new Lint(checker.getName(), checker.executeCheck(item), checker.isIgnored(item.getDescription())));
}
jobSet.put(item.getName(),newJob);
LOG.log(Level.FINER, newJob.toString());
Expand All @@ -99,8 +113,8 @@ public void getData() throws IOException {
Slave newSlave = new Slave(node.getNodeName(), node.getSearchUrl());
for (InterfaceSlaveCheck checker : slaveCheckList) {
boolean status = checker.executeCheck(node);
LOG.log(Level.FINER, checker.getClass().getName() + " " + node.getDisplayName() + " " + status);
newSlave.addLint(new Lint(checker.getClass().getName(), status, checker.isIgnored(node.getNodeDescription())));
LOG.log(Level.FINER, checker.getName() + " " + node.getDisplayName() + " " + status);
newSlave.addLint(new Lint(checker.getName(), status, checker.isIgnored(node.getNodeDescription())));
}
slaveSet.put(newSlave.getName(), newSlave);
LOG.log(Level.FINER, newSlave.toString());
Expand All @@ -120,19 +134,43 @@ public String getUrlName() {
return Messages.UrlName();
}

@Exported
public Hashtable<String, Job> getJobSet() {
return jobSet;
}

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<InterfaceCheck> getCheckList() {
return checkList;
}

@Exported
public Hashtable<String, InterfaceCheck> getCheckSet() {
Hashtable<String, InterfaceCheck> temp = new Hashtable<String, InterfaceCheck>();
for (InterfaceCheck check : checkList) {
temp.put(check.getName(), check);
}
return temp;
}

@Exported
public Hashtable<String, Slave> getSlaveSet() {
return slaveSet;
}

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<InterfaceSlaveCheck> getSlaveCheckList() {
return slaveCheckList;
}

@Exported
public Hashtable<String, InterfaceSlaveCheck> getSlaveCheckSet() {
Hashtable<String, InterfaceSlaveCheck> temp = new Hashtable<String, InterfaceSlaveCheck>();
for (InterfaceSlaveCheck check : slaveCheckList) {
temp.put(check.getName(), check);
}
return temp;
}
}
@@ -1,11 +1,14 @@
package org.jenkins.ci.plugins.jenkinslint.model;

import java.util.logging.Logger;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* AbstractCheck class.
* @author Victor Martinez
*/
@ExportedBean
public abstract class AbstractCheck implements Comparable<AbstractCheck>, InterfaceCheck {
private String name;
private String description;
Expand All @@ -18,6 +21,7 @@ public AbstractCheck() {
this.setName(this.getClass().getSimpleName());
}

@Exported
public String getName() {
return name;
}
Expand All @@ -30,6 +34,7 @@ public String getId() {
return id;
}

@Exported
public String getDescription() {
return description;
}
Expand All @@ -38,6 +43,7 @@ public void setDescription(final String description) {
this.description = description;
}

@Exported
public String getSeverity() {
return severity;
}
Expand Down
@@ -1,11 +1,14 @@
package org.jenkins.ci.plugins.jenkinslint.model;

import java.util.logging.Logger;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* AbstractCheck class.
* @author Victor Martinez
*/
@ExportedBean
public abstract class AbstractSlaveCheck implements Comparable<AbstractSlaveCheck>, InterfaceSlaveCheck {
private String name;
private String description;
Expand All @@ -18,6 +21,7 @@ public AbstractSlaveCheck() {
this.setName(this.getClass().getSimpleName());
}

@Exported
public String getName() {
return name;
}
Expand All @@ -30,6 +34,7 @@ public String getId() {
return id;
}

@Exported
public String getDescription() {
return description;
}
Expand All @@ -38,6 +43,7 @@ public void setDescription(final String description) {
this.description = description;
}

@Exported
public String getSeverity() {
return severity;
}
Expand Down
Expand Up @@ -7,7 +7,7 @@
* @author Victor Martinez
*/
public interface InterfaceCheck {

public String getName();
boolean executeCheck(Item item);
boolean isIgnored(String jobDescription);
}
Expand Up @@ -7,7 +7,7 @@
* @author Victor Martinez
*/
public interface InterfaceSlaveCheck {

public String getName();
boolean executeCheck(Node item);
boolean isIgnored(String jobDescription);
}
18 changes: 17 additions & 1 deletion src/main/java/org/jenkins/ci/plugins/jenkinslint/model/Job.java
Expand Up @@ -3,11 +3,14 @@
import hudson.model.HealthReport;
import org.jenkins.ci.plugins.jenkinslint.Messages;
import java.util.ArrayList;

import java.util.Hashtable;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
/**
* Job class.
* @author Victor Martinez
*/
@ExportedBean
public final class Job implements Comparable<Job> {
private String name;
private String url;
Expand All @@ -19,6 +22,7 @@ public Job(final String name, final String url) {
this.url = url;
}

@Exported
public String getName() {
return name;
}
Expand All @@ -35,10 +39,21 @@ public void setUrl(final String url) {
this.url = url;
}

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<Lint> getLintList() {
return lintList;
}

@Exported
public Hashtable<String, Lint> getLintSet() {
Hashtable<String, Lint> temp = new Hashtable<String, Lint>();
for (Lint lint : lintList) {
temp.put(lint.getName(), lint);
}
return temp;
}

public void addLint(Lint lint) {
lintList.add(lint);
}
Expand Down Expand Up @@ -75,6 +90,7 @@ public String toString() {
append(", ").append(lintList).toString();
}

@Exported
public HealthReport getLintHealthReport() {
if (lintList != null && lintList.size() > 0) {
int ok = 0;
Expand Down
@@ -1,9 +1,13 @@
package org.jenkins.ci.plugins.jenkinslint.model;

import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* Check class.
* @author Victor Martinez
*/
@ExportedBean
public final class Lint implements Comparable<Lint> {
private String name;
private boolean found = false;
Expand All @@ -16,6 +20,7 @@ public Lint(final String name, final boolean found, final boolean ignored) {
this.setIgnored(ignored);
}

@Exported
public String getName() {
return name;
}
Expand All @@ -31,6 +36,7 @@ public int compareTo(final Lint other) {
return getName().compareTo(other.getName());
}

@Exported
public boolean isFound() {
return found;
}
Expand All @@ -39,6 +45,7 @@ public void setFound(boolean found) {
this.found = found;
}

@Exported
public boolean isIgnored() {
return ignored;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/jenkins/ci/plugins/jenkinslint/model/Slave.java
Expand Up @@ -4,11 +4,15 @@
import org.jenkins.ci.plugins.jenkinslint.Messages;

import java.util.ArrayList;
import java.util.Hashtable;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* Slave class.
* @author Victor Martinez
*/
@ExportedBean
public final class Slave implements Comparable<Slave> {
private String name;
private String url;
Expand All @@ -20,6 +24,7 @@ public Slave(final String name, final String url) {
this.url = url;
}

@Exported
public String getName() {
return name;
}
Expand All @@ -36,10 +41,21 @@ public void setUrl(final String url) {
this.url = url;
}

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<Lint> getLintList() {
return lintList;
}

@Exported
public Hashtable<String, Lint> getLintSet() {
Hashtable<String, Lint> temp = new Hashtable<String, Lint>();
for (Lint lint : lintList) {
temp.put(lint.getName(), lint);
}
return temp;
}

public void addLint(Lint lint) {
lintList.add(lint);
}
Expand Down Expand Up @@ -76,6 +92,7 @@ public String toString() {
append(", ").append(lintList).toString();
}

@Exported
public HealthReport getLintHealthReport() {
if (lintList != null && lintList.size() > 0) {
int ok = 0;
Expand Down

0 comments on commit 24925a4

Please sign in to comment.