Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release-src > by-pkgid > 68c9e78ae1b69f5a01913e2c1ac7acbd > files > 1

jenkins-extras-memory-monitor-1.7-4.mga5.src.rpm

From c4b472998a055c0bc8edea0a13086d0a9f4d4b49 Mon Sep 17 00:00:00 2001
From: Michal Srb <msrb@redhat.com>
Date: Tue, 16 Apr 2013 15:20:52 +0200
Subject: [PATCH] Remove support for windows and solaris

---
 src/main/java/org/jvnet/hudson/MemoryMonitor.java |  11 --
 src/main/java/org/jvnet/hudson/Solaris.java       | 128 ----------------------
 src/main/java/org/jvnet/hudson/Windows.java       |  66 -----------
 3 files changed, 205 deletions(-)
 delete mode 100644 src/main/java/org/jvnet/hudson/Solaris.java
 delete mode 100644 src/main/java/org/jvnet/hudson/Windows.java

diff --git a/src/main/java/org/jvnet/hudson/MemoryMonitor.java b/src/main/java/org/jvnet/hudson/MemoryMonitor.java
index 4951925..2b44827 100644
--- a/src/main/java/org/jvnet/hudson/MemoryMonitor.java
+++ b/src/main/java/org/jvnet/hudson/MemoryMonitor.java
@@ -59,8 +59,6 @@ public abstract class MemoryMonitor {
     }
 
     private static MemoryMonitor obtain() throws IOException {
-        if(File.pathSeparatorChar==';')
-            return new Windows();
 
         if(new File("/proc/meminfo").exists())
             return new ProcMemInfo();   // Linux has this. Exactly since when, I don't know.
@@ -74,15 +72,6 @@ public abstract class MemoryMonitor {
             // fall through next
         }
 
-        // Solaris?
-        try {
-            Solaris solaris = new Solaris();
-            solaris.monitor();
-            return solaris;
-        } catch(Throwable _) {
-            // next
-        }
-
         throw new IOException(String.format("No suitable implementation found: os.name=%s os.arch=%s sun.arch.data.model=%s",
                 System.getProperty("os.name"),System.getProperty("os.arch"),System.getProperty("sun.arch.data.model")));
     }
diff --git a/src/main/java/org/jvnet/hudson/Solaris.java b/src/main/java/org/jvnet/hudson/Solaris.java
deleted file mode 100644
index 6e13062..0000000
--- a/src/main/java/org/jvnet/hudson/Solaris.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * The MIT License
- *
- * Copyright (c) 2008-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi, 
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package org.jvnet.hudson;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * For Solaris, where top(1) is an optional install. 
- *
- * @author Kohsuke Kawaguchi
- */
-public class Solaris extends AbstractMemoryMonitorImpl {
-
-    @Override
-    public MemoryUsage monitor() throws IOException {
-        long[] v = getSwap();
-        return new MemoryUsage(
-            getTotalPhysicalMemory(),
-            getAvailablePhysicalMemory(),
-            v[0],v[1] 
-        );
-    }
-
-    private long getTotalPhysicalMemory() throws IOException {
-        Process proc = startProcess("/usr/sbin/prtdiag");
-        BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
-        try {
-            String line;
-            while ((line=r.readLine())!=null) {
-                if (line.contains("Memory size:")) {
-                    line = line.substring(line.indexOf(':')+1).trim();
-                    return parse(line);
-                }
-            }
-            return -1;
-        } finally {
-            r.close();
-        }
-    }
-
-    private long getAvailablePhysicalMemory() throws IOException {
-        Process proc = startProcess("vmstat");
-        BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
-        try {
-            String line;
-            while ((line=r.readLine())!=null) {
-                if (NUMBER_ONLY.matcher(line).matches()) {
-                    return Long.parseLong(line.trim().split(" +")[4])*1024;
-                }
-            }
-            return -1;
-        } finally {
-            r.close();
-        }
-    }
-
-    /**
-     * Returns total/availablae.
-     */
-    private long[] getSwap() throws IOException {
-        long[] v = new long[]{-1,-1};
-        Process proc = startProcess("/usr/sbin/swap","-s");
-        BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
-        /* output
-
-            $ uname -a; swap -s
-            SunOS kohsuke2 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-2500 Solaris
-            total: 800296k bytes allocated + 181784k reserved = 982080k used, 6014528k available
-          */
-        try {
-            String line = r.readLine().toLowerCase();
-
-            Matcher m = USED_SWAP.matcher(line);
-            if (m.find()) {
-                v[0] = Long.parseLong(m.group(1))*1024;
-            }
-
-            m = AVAILABLE_SWAP.matcher(line);
-            if (m.find()) {
-                v[1] = Long.parseLong(m.group(1))*1024;
-            }
-
-            // we want total/available, not used/available.
-            if (v[0]!=-1 && v[1]!=-1)
-                v[0] += v[1];
-            return v;
-        } finally {
-            r.close();
-        }
-    }
-
-    private Process startProcess(String... cmd) throws IOException {
-        ProcessBuilder pb = new ProcessBuilder(cmd);
-        pb.redirectErrorStream(true);
-        Process proc = pb.start();
-        proc.getOutputStream().close();
-        return proc;
-    }
-
-    private static final Pattern NUMBER_ONLY = Pattern.compile("[0-9 ]+");
-    private static final Pattern USED_SWAP = Pattern.compile(" ([0-9]+)k used");
-    private static final Pattern AVAILABLE_SWAP = Pattern.compile(" ([0-9]+)k available");
-}
diff --git a/src/main/java/org/jvnet/hudson/Windows.java b/src/main/java/org/jvnet/hudson/Windows.java
deleted file mode 100644
index d33ccbf..0000000
--- a/src/main/java/org/jvnet/hudson/Windows.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The MIT License
- *
- * Copyright (c) 2008-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi,
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package org.jvnet.hudson;
-
-import com.sun.jna.Native;
-import com.sun.jna.Structure;
-import com.sun.jna.win32.StdCallLibrary;
-
-/**
- * {@link MemoryMonitor} implementation for Windows.
- *
- * <p>
- * JNA requires that the class and interface be public.
- *
- * @author Kohsuke Kawaguchi
-*/
-public final class Windows extends MemoryMonitor {
-    public MemoryUsage monitor() {
-        MEMORYSTATUSEX mse = new MEMORYSTATUSEX();
-        Kernel32.INSTANCE.GlobalMemoryStatusEx(mse);
-        mse.read();
-
-        return new MemoryUsage(
-                mse.ullTotalPhys, mse.ullAvailPhys,
-                mse.ullTotalPageFile, mse.ullAvailPageFile);
-    }
-
-    public interface Kernel32 extends StdCallLibrary {
-        boolean GlobalMemoryStatusEx(MEMORYSTATUSEX p);
-
-        Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32",Kernel32.class);
-    }
-
-    public static final class MEMORYSTATUSEX extends Structure {
-        public int dwLength = size();
-        public int dwMemoryLoad;
-        public long ullTotalPhys;
-        public long ullAvailPhys;
-        public long ullTotalPageFile;
-        public long ullAvailPageFile;
-        public long ullTotalVirtual;
-        public long ullAvailVirtual;
-        public long ullAvailExtendedVirtual;
-    }
-}
-- 
1.8.1.4