Search in sources :

Example 1 with DescriptorImpl

use of hudson.node_monitors.ArchitectureMonitor.DescriptorImpl in project hudson-2.x by hudson.

the class UsageStatistics method getStatData.

/**
     * Gets the encrypted usage stat data to be sent to the Hudson server.
     */
public String getStatData() throws IOException {
    Hudson h = Hudson.getInstance();
    JSONObject o = new JSONObject();
    o.put("stat", 1);
    o.put("install", Util.getDigestOf(h.getSecretKey()));
    o.put("version", Hudson.VERSION);
    List<JSONObject> nodes = new ArrayList<JSONObject>();
    for (Computer c : h.getComputers()) {
        JSONObject n = new JSONObject();
        if (c.getNode() == h) {
            n.put("master", true);
            n.put("jvm-vendor", System.getProperty("java.vm.vendor"));
            n.put("jvm-version", System.getProperty("java.version"));
        }
        n.put("executors", c.getNumExecutors());
        DescriptorImpl descriptor = h.getDescriptorByType(DescriptorImpl.class);
        n.put("os", descriptor.get(c));
        nodes.add(n);
    }
    o.put("nodes", nodes);
    List<JSONObject> plugins = new ArrayList<JSONObject>();
    for (PluginWrapper pw : h.getPluginManager().getPlugins()) {
        if (!pw.isActive()) {
            // treat disabled plugins as if they are uninstalled
            continue;
        }
        JSONObject p = new JSONObject();
        p.put("name", pw.getShortName());
        p.put("version", pw.getVersion());
        plugins.add(p);
    }
    o.put("plugins", plugins);
    JSONObject jobs = new JSONObject();
    List<TopLevelItem> items = h.getItems();
    for (TopLevelItemDescriptor d : Items.all()) {
        int cnt = 0;
        for (TopLevelItem item : items) {
            if (item.getDescriptor() == d) {
                cnt++;
            }
        }
        jobs.put(d.getJsonSafeClassName(), cnt);
    }
    o.put("jobs", jobs);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // json -> UTF-8 encode -> gzip -> encrypt -> base64 -> string
        OutputStreamWriter w = new OutputStreamWriter(new GZIPOutputStream(new CombinedCipherOutputStream(baos, getCipher(), "AES")), "UTF-8");
        o.write(w);
        w.close();
        return new String(Base64.encode(baos.toByteArray()));
    } catch (GeneralSecurityException e) {
        // impossible
        throw new Error(e);
    }
}
Also used : DescriptorImpl(hudson.node_monitors.ArchitectureMonitor.DescriptorImpl) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) JSONObject(net.sf.json.JSONObject) GZIPOutputStream(java.util.zip.GZIPOutputStream) PluginWrapper(hudson.PluginWrapper) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

PluginWrapper (hudson.PluginWrapper)1 DescriptorImpl (hudson.node_monitors.ArchitectureMonitor.DescriptorImpl)1 OutputStreamWriter (java.io.OutputStreamWriter)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 JSONObject (net.sf.json.JSONObject)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1