Skip to content
Permalink
Browse files
[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 3, 2017
1 parent 2f95712 commit dc6f1d1ac0481de9447eb8ce0f5446a225ae7f23
Showing 11 changed files with 121 additions and 19 deletions.
@@ -8,3 +8,5 @@ jenkins.war
*.iml
*.ipr
*.iws
.DS_Store

@@ -31,13 +31,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 {

@@ -47,6 +52,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();
@@ -81,8 +95,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());
@@ -95,8 +109,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());
@@ -116,19 +130,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;
@@ -18,6 +21,7 @@ public AbstractCheck() {
this.setName(this.getClass().getSimpleName());
}

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

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

@Exported
public String getSeverity() {
return severity;
}
@@ -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;
@@ -18,6 +21,7 @@ public AbstractSlaveCheck() {
this.setName(this.getClass().getSimpleName());
}

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

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

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

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

public String getName();
boolean executeCheck(Node item);
boolean isIgnored(String jobDescription);
}
@@ -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;
@@ -19,6 +22,7 @@ public Job(final String name, final String url) {
this.url = url;
}

@Exported
public String getName() {
return name;
}
@@ -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);
}
@@ -75,6 +90,7 @@ public String toString() {
append(", ").append(lintList).toString();
}

@Exported
public HealthReport getLintHealthReport() {
if (lintList != null && lintList.size() > 0) {
int ok = 0;
@@ -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;
@@ -16,6 +20,7 @@ public Lint(final String name, final boolean found, final boolean ignored) {
this.setIgnored(ignored);
}

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

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

@Exported
public boolean isIgnored() {
return ignored;
}
@@ -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;
@@ -20,6 +24,7 @@ public Slave(final String name, final String url) {
this.url = url;
}

@Exported
public String getName() {
return name;
}
@@ -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);
}
@@ -76,6 +92,7 @@ public String toString() {
append(", ").append(lintList).toString();
}

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

0 comments on commit dc6f1d1

Please sign in to comment.