http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/KVMHAMonitor.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/KVMHAMonitor.java 
b/agent/src/com/cloud/agent/resource/computing/KVMHAMonitor.java
index 42f1a6b..09d5c83 100644
--- a/agent/src/com/cloud/agent/resource/computing/KVMHAMonitor.java
+++ b/agent/src/com/cloud/agent/resource/computing/KVMHAMonitor.java
@@ -24,96 +24,96 @@ import org.apache.log4j.Logger;
 import com.cloud.utils.script.Script;
 
 public class KVMHAMonitor extends KVMHABase implements Runnable {
-       private static final Logger s_logger = 
Logger.getLogger(KVMHAMonitor.class);
-       private Map<String, NfsStoragePool> _storagePool = new 
ConcurrentHashMap<String, NfsStoragePool>();
-
-       private String _hostIP; /* private ip address */
-
-       public KVMHAMonitor(NfsStoragePool pool, String host, String 
scriptPath) {
-               if (pool != null) {
-                       this._storagePool.put(pool._poolUUID, pool);
-               }
-               this._hostIP = host;
-               this._heartBeatPath = scriptPath;
-       }
-
-       public void addStoragePool(NfsStoragePool pool) {
-               synchronized (_storagePool) {
-                       this._storagePool.put(pool._poolUUID, pool);
-               }
-       }
-
-       public void removeStoragePool(String uuid) {
-               synchronized (_storagePool) {
-                       this._storagePool.remove(uuid);
-               }
-       }
-
-       public List<NfsStoragePool> getStoragePools() {
-               synchronized (_storagePool) {
-                       return new 
ArrayList<NfsStoragePool>(_storagePool.values());
-               }
-       }
-
-       private class Monitor implements Runnable {
-
-               @Override
-               public void run() {
-                       synchronized (_storagePool) {
-                               for (NfsStoragePool primaryStoragePool : 
_storagePool.values()) {
-                                       String result = null;
-                                       for (int i = 0; i < 5; i++) {
-                                               Script cmd = new 
Script(_heartBeatPath,
-                                                               
_heartBeatUpdateTimeout, s_logger);
-                                               cmd.add("-i", 
primaryStoragePool._poolIp);
-                                               cmd.add("-p", 
primaryStoragePool._poolMountSourcePath);
-                                               cmd.add("-m", 
primaryStoragePool._mountDestPath);
-                                               cmd.add("-h", _hostIP);
-                                               result = cmd.execute();
-                                               if (result != null) {
-                                                       s_logger.warn("write 
heartbeat failed: " + result
-                                                                       + ", 
retry: " + i);
-                                               } else {
-                                                       break;
-                                               }
-                                       }
-
-                                       if (result != null) {
-                                               s_logger.warn("write heartbeat 
failed: " + result
-                                                               + "; reboot the 
host");
-                                               Script cmd = new 
Script(_heartBeatPath,
-                                                               
_heartBeatUpdateTimeout, s_logger);
-                                               cmd.add("-i", 
primaryStoragePool._poolIp);
-                                               cmd.add("-p", 
primaryStoragePool._poolMountSourcePath);
-                                               cmd.add("-m", 
primaryStoragePool._mountDestPath);
-                                               cmd.add("-c");
-                                               result = cmd.execute();
-                                       }
-                               }
-                       }
-
-               }
-       }
-
-       @Override
-       public void run() {
-               // s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
-               // org.apache.log4j.PatternLayout(), "System.out"));
-               while (true) {
-                       Thread monitorThread = new Thread(new Monitor());
-                       monitorThread.start();
-                       try {
-                               monitorThread.join();
-                       } catch (InterruptedException e) {
-
-                       }
-
-                       try {
-                               Thread.sleep(_heartBeatUpdateFreq);
-                       } catch (InterruptedException e) {
-
-                       }
-               }
-       }
+    private static final Logger s_logger = 
Logger.getLogger(KVMHAMonitor.class);
+    private Map<String, NfsStoragePool> _storagePool = new 
ConcurrentHashMap<String, NfsStoragePool>();
+
+    private String _hostIP; /* private ip address */
+
+    public KVMHAMonitor(NfsStoragePool pool, String host, String scriptPath) {
+        if (pool != null) {
+            this._storagePool.put(pool._poolUUID, pool);
+        }
+        this._hostIP = host;
+        this._heartBeatPath = scriptPath;
+    }
+
+    public void addStoragePool(NfsStoragePool pool) {
+        synchronized (_storagePool) {
+            this._storagePool.put(pool._poolUUID, pool);
+        }
+    }
+
+    public void removeStoragePool(String uuid) {
+        synchronized (_storagePool) {
+            this._storagePool.remove(uuid);
+        }
+    }
+
+    public List<NfsStoragePool> getStoragePools() {
+        synchronized (_storagePool) {
+            return new ArrayList<NfsStoragePool>(_storagePool.values());
+        }
+    }
+
+    private class Monitor implements Runnable {
+
+        @Override
+        public void run() {
+            synchronized (_storagePool) {
+                for (NfsStoragePool primaryStoragePool : 
_storagePool.values()) {
+                    String result = null;
+                    for (int i = 0; i < 5; i++) {
+                        Script cmd = new Script(_heartBeatPath,
+                                _heartBeatUpdateTimeout, s_logger);
+                        cmd.add("-i", primaryStoragePool._poolIp);
+                        cmd.add("-p", primaryStoragePool._poolMountSourcePath);
+                        cmd.add("-m", primaryStoragePool._mountDestPath);
+                        cmd.add("-h", _hostIP);
+                        result = cmd.execute();
+                        if (result != null) {
+                            s_logger.warn("write heartbeat failed: " + result
+                                    + ", retry: " + i);
+                        } else {
+                            break;
+                        }
+                    }
+
+                    if (result != null) {
+                        s_logger.warn("write heartbeat failed: " + result
+                                + "; reboot the host");
+                        Script cmd = new Script(_heartBeatPath,
+                                _heartBeatUpdateTimeout, s_logger);
+                        cmd.add("-i", primaryStoragePool._poolIp);
+                        cmd.add("-p", primaryStoragePool._poolMountSourcePath);
+                        cmd.add("-m", primaryStoragePool._mountDestPath);
+                        cmd.add("-c");
+                        result = cmd.execute();
+                    }
+                }
+            }
+
+        }
+    }
+
+    @Override
+    public void run() {
+        // s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new
+        // org.apache.log4j.PatternLayout(), "System.out"));
+        while (true) {
+            Thread monitorThread = new Thread(new Monitor());
+            monitorThread.start();
+            try {
+                monitorThread.join();
+            } catch (InterruptedException e) {
+
+            }
+
+            try {
+                Thread.sleep(_heartBeatUpdateFreq);
+            } catch (InterruptedException e) {
+
+            }
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtCapXMLParser.java
----------------------------------------------------------------------
diff --git 
a/agent/src/com/cloud/agent/resource/computing/LibvirtCapXMLParser.java 
b/agent/src/com/cloud/agent/resource/computing/LibvirtCapXMLParser.java
index 9e2e496..4c5fa29 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtCapXMLParser.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtCapXMLParser.java
@@ -30,165 +30,165 @@ import org.xml.sax.SAXException;
  * 
  */
 public class LibvirtCapXMLParser extends LibvirtXMLParser {
-       private boolean _host = false;
-       private boolean _guest = false;
-       private boolean _osType = false;
-       private boolean _domainTypeKVM = false;
-       private boolean _emulatorFlag = false;
-       private final StringBuffer _emulator = new StringBuffer();
-       private final StringBuffer _capXML = new StringBuffer();
-       private static final Logger s_logger = Logger
-                       .getLogger(LibvirtCapXMLParser.class);
-       private final ArrayList<String> guestOsTypes = new ArrayList<String>();
+    private boolean _host = false;
+    private boolean _guest = false;
+    private boolean _osType = false;
+    private boolean _domainTypeKVM = false;
+    private boolean _emulatorFlag = false;
+    private final StringBuffer _emulator = new StringBuffer();
+    private final StringBuffer _capXML = new StringBuffer();
+    private static final Logger s_logger = Logger
+            .getLogger(LibvirtCapXMLParser.class);
+    private final ArrayList<String> guestOsTypes = new ArrayList<String>();
 
-       @Override
-       public void endElement(String uri, String localName, String qName)
-                       throws SAXException {
-               if (qName.equalsIgnoreCase("host")) {
-                       _host = false;
-               } else if (qName.equalsIgnoreCase("os_type")) {
-                       _osType = false;
-               } else if (qName.equalsIgnoreCase("guest")) {
-                       _guest = false;
-               } else if (qName.equalsIgnoreCase("domain")) {
-                       _domainTypeKVM = false;
-               } else if (qName.equalsIgnoreCase("emulator")) {
-                       _emulatorFlag = false;
+    @Override
+    public void endElement(String uri, String localName, String qName)
+            throws SAXException {
+        if (qName.equalsIgnoreCase("host")) {
+            _host = false;
+        } else if (qName.equalsIgnoreCase("os_type")) {
+            _osType = false;
+        } else if (qName.equalsIgnoreCase("guest")) {
+            _guest = false;
+        } else if (qName.equalsIgnoreCase("domain")) {
+            _domainTypeKVM = false;
+        } else if (qName.equalsIgnoreCase("emulator")) {
+            _emulatorFlag = false;
 
-               } else if (_host) {
-                       
_capXML.append("<").append("/").append(qName).append(">");
-               }
-       }
+        } else if (_host) {
+            _capXML.append("<").append("/").append(qName).append(">");
+        }
+    }
 
-       @Override
-       public void characters(char[] ch, int start, int length)
-                       throws SAXException {
-               if (_host) {
-                       _capXML.append(ch, start, length);
-               } else if (_osType) {
-                       guestOsTypes.add(new String(ch, start, length));
-               } else if (_emulatorFlag) {
-                       _emulator.append(ch, start, length);
-               }
-       }
+    @Override
+    public void characters(char[] ch, int start, int length)
+            throws SAXException {
+        if (_host) {
+            _capXML.append(ch, start, length);
+        } else if (_osType) {
+            guestOsTypes.add(new String(ch, start, length));
+        } else if (_emulatorFlag) {
+            _emulator.append(ch, start, length);
+        }
+    }
 
-       @Override
-       public void startElement(String uri, String localName, String qName,
-                       Attributes attributes) throws SAXException {
-               if (qName.equalsIgnoreCase("host")) {
-                       _host = true;
-               } else if (qName.equalsIgnoreCase("guest")) {
-                       _guest = true;
-               } else if (qName.equalsIgnoreCase("os_type")) {
-                       if (_guest) {
-                               _osType = true;
-                       }
-               } else if (qName.equalsIgnoreCase("domain")) {
-                       for (int i = 0; i < attributes.getLength(); i++) {
-                               if 
(attributes.getQName(i).equalsIgnoreCase("type")
-                                               && 
attributes.getValue(i).equalsIgnoreCase("kvm")) {
-                                       _domainTypeKVM = true;
-                               }
-                       }
-               } else if (qName.equalsIgnoreCase("emulator") && 
_domainTypeKVM) {
-                       _emulatorFlag = true;
-                       _emulator.delete(0, _emulator.length());
-               } else if (_host) {
-                       _capXML.append("<").append(qName);
-                       for (int i = 0; i < attributes.getLength(); i++) {
-                               _capXML.append(" 
").append(attributes.getQName(i)).append("=")
-                                               .append(attributes.getValue(i));
-                       }
-                       _capXML.append(">");
-               }
+    @Override
+    public void startElement(String uri, String localName, String qName,
+            Attributes attributes) throws SAXException {
+        if (qName.equalsIgnoreCase("host")) {
+            _host = true;
+        } else if (qName.equalsIgnoreCase("guest")) {
+            _guest = true;
+        } else if (qName.equalsIgnoreCase("os_type")) {
+            if (_guest) {
+                _osType = true;
+            }
+        } else if (qName.equalsIgnoreCase("domain")) {
+            for (int i = 0; i < attributes.getLength(); i++) {
+                if (attributes.getQName(i).equalsIgnoreCase("type")
+                        && attributes.getValue(i).equalsIgnoreCase("kvm")) {
+                    _domainTypeKVM = true;
+                }
+            }
+        } else if (qName.equalsIgnoreCase("emulator") && _domainTypeKVM) {
+            _emulatorFlag = true;
+            _emulator.delete(0, _emulator.length());
+        } else if (_host) {
+            _capXML.append("<").append(qName);
+            for (int i = 0; i < attributes.getLength(); i++) {
+                _capXML.append(" ").append(attributes.getQName(i)).append("=")
+                        .append(attributes.getValue(i));
+            }
+            _capXML.append(">");
+        }
 
-       }
+    }
 
-       public String parseCapabilitiesXML(String capXML) {
-               if (!_initialized) {
-                       return null;
-               }
-               try {
-                       _sp.parse(new InputSource(new StringReader(capXML)), 
this);
-                       return _capXML.toString();
-               } catch (SAXException se) {
-                       s_logger.warn(se.getMessage());
-               } catch (IOException ie) {
-                       s_logger.error(ie.getMessage());
-               }
-               return null;
-       }
+    public String parseCapabilitiesXML(String capXML) {
+        if (!_initialized) {
+            return null;
+        }
+        try {
+            _sp.parse(new InputSource(new StringReader(capXML)), this);
+            return _capXML.toString();
+        } catch (SAXException se) {
+            s_logger.warn(se.getMessage());
+        } catch (IOException ie) {
+            s_logger.error(ie.getMessage());
+        }
+        return null;
+    }
 
-       public ArrayList<String> getGuestOsType() {
-               return guestOsTypes;
-       }
+    public ArrayList<String> getGuestOsType() {
+        return guestOsTypes;
+    }
 
-       public String getEmulator() {
-               return _emulator.toString();
-       }
+    public String getEmulator() {
+        return _emulator.toString();
+    }
 
-       public static void main(String[] args) {
-               String capXML = "<capabilities>" + "  <host>" + "    <cpu>"
-                               + "      <arch>x86_64</arch>" + "      
<model>core2duo</model>"
-                               + "      <topology sockets='1' cores='2' 
threads='1'/>"
-                               + "      <feature name='lahf_lm'/>"
-                               + "      <feature name='xtpr'/>"
-                               + "      <feature name='cx16'/>"
-                               + "      <feature name='tm2'/>" + "      
<feature name='est'/>"
-                               + "      <feature name='vmx'/>"
-                               + "      <feature name='ds_cpl'/>"
-                               + "      <feature name='pbe'/>" + "      
<feature name='tm'/>"
-                               + "      <feature name='ht'/>" + "      
<feature name='ss'/>"
-                               + "      <feature name='acpi'/>" + "      
<feature name='ds'/>"
-                               + "    </cpu>" + "    <migration_features>" + " 
     <live/>"
-                               + "      <uri_transports>"
-                               + "        <uri_transport>tcp</uri_transport>"
-                               + "      </uri_transports>" + "    
</migration_features>"
-                               + "    <topology>" + "      <cells num='1'>"
-                               + "        <cell id='0'>" + "          <cpus 
num='2'>"
-                               + "            <cpu id='0'/>" + "            
<cpu id='1'/>"
-                               + "          </cpus>" + "        </cell>" + "   
   </cells>"
-                               + "    </topology>" + "  </host>" + "" + "  
<guest>"
-                               + "    <os_type>hvm</os_type>" + "    <arch 
name='i686'>"
-                               + "      <wordsize>32</wordsize>"
-                               + "      <emulator>/usr/bin/qemu</emulator>"
-                               + "      <machine>pc-0.11</machine>"
-                               + "      <machine 
canonical='pc-0.11'>pc</machine>"
-                               + "      <machine>pc-0.10</machine>"
-                               + "      <machine>isapc</machine>"
-                               + "      <domain type='qemu'>" + "      
</domain>"
-                               + "      <domain type='kvm'>"
-                               + "        
<emulator>/usr/bin/qemu-kvm</emulator>"
-                               + "        <machine>pc-0.11</machine>"
-                               + "        <machine 
canonical='pc-0.11'>pc</machine>"
-                               + "        <machine>pc-0.10</machine>"
-                               + "        <machine>isapc</machine>" + "      
</domain>"
-                               + "    </arch>" + "    <features>" + "      
<cpuselection/>"
-                               + "      <pae/>" + "      <nonpae/>"
-                               + "      <acpi default='on' toggle='yes'/>"
-                               + "      <apic default='on' toggle='no'/>" + "  
  </features>"
-                               + "  </guest>" + "  <guest>" + "    
<os_type>hvm</os_type>"
-                               + "    <arch name='x86_64'>" + "      
<wordsize>64</wordsize>"
-                               + "      
<emulator>/usr/bin/qemu-system-x86_64</emulator>"
-                               + "      <machine>pc-0.11</machine>"
-                               + "      <machine 
canonical='pc-0.11'>pc</machine>"
-                               + "      <machine>pc-0.10</machine>"
-                               + "      <machine>isapc</machine>"
-                               + "      <domain type='qemu'>" + "      
</domain>"
-                               + "      <domain type='kvm'>"
-                               + "        
<emulator>/usr/bin/qemu-kvm</emulator>"
-                               + "        <machine>pc-0.11</machine>"
-                               + "        <machine 
canonical='pc-0.11'>pc</machine>"
-                               + "        <machine>pc-0.10</machine>"
-                               + "        <machine>isapc</machine>" + "      
</domain>"
-                               + "    </arch>" + "    <features>" + "      
<cpuselection/>"
-                               + "      <acpi default='on' toggle='yes'/>"
-                               + "      <apic default='on' toggle='no'/>" + "  
  </features>"
-                               + "  </guest>" + "</capabilities>";
+    public static void main(String[] args) {
+        String capXML = "<capabilities>" + "  <host>" + "    <cpu>"
+                + "      <arch>x86_64</arch>" + "      <model>core2duo</model>"
+                + "      <topology sockets='1' cores='2' threads='1'/>"
+                + "      <feature name='lahf_lm'/>"
+                + "      <feature name='xtpr'/>"
+                + "      <feature name='cx16'/>"
+                + "      <feature name='tm2'/>" + "      <feature name='est'/>"
+                + "      <feature name='vmx'/>"
+                + "      <feature name='ds_cpl'/>"
+                + "      <feature name='pbe'/>" + "      <feature name='tm'/>"
+                + "      <feature name='ht'/>" + "      <feature name='ss'/>"
+                + "      <feature name='acpi'/>" + "      <feature name='ds'/>"
+                + "    </cpu>" + "    <migration_features>" + "      <live/>"
+                + "      <uri_transports>"
+                + "        <uri_transport>tcp</uri_transport>"
+                + "      </uri_transports>" + "    </migration_features>"
+                + "    <topology>" + "      <cells num='1'>"
+                + "        <cell id='0'>" + "          <cpus num='2'>"
+                + "            <cpu id='0'/>" + "            <cpu id='1'/>"
+                + "          </cpus>" + "        </cell>" + "      </cells>"
+                + "    </topology>" + "  </host>" + "" + "  <guest>"
+                + "    <os_type>hvm</os_type>" + "    <arch name='i686'>"
+                + "      <wordsize>32</wordsize>"
+                + "      <emulator>/usr/bin/qemu</emulator>"
+                + "      <machine>pc-0.11</machine>"
+                + "      <machine canonical='pc-0.11'>pc</machine>"
+                + "      <machine>pc-0.10</machine>"
+                + "      <machine>isapc</machine>"
+                + "      <domain type='qemu'>" + "      </domain>"
+                + "      <domain type='kvm'>"
+                + "        <emulator>/usr/bin/qemu-kvm</emulator>"
+                + "        <machine>pc-0.11</machine>"
+                + "        <machine canonical='pc-0.11'>pc</machine>"
+                + "        <machine>pc-0.10</machine>"
+                + "        <machine>isapc</machine>" + "      </domain>"
+                + "    </arch>" + "    <features>" + "      <cpuselection/>"
+                + "      <pae/>" + "      <nonpae/>"
+                + "      <acpi default='on' toggle='yes'/>"
+                + "      <apic default='on' toggle='no'/>" + "    </features>"
+                + "  </guest>" + "  <guest>" + "    <os_type>hvm</os_type>"
+                + "    <arch name='x86_64'>" + "      <wordsize>64</wordsize>"
+                + "      <emulator>/usr/bin/qemu-system-x86_64</emulator>"
+                + "      <machine>pc-0.11</machine>"
+                + "      <machine canonical='pc-0.11'>pc</machine>"
+                + "      <machine>pc-0.10</machine>"
+                + "      <machine>isapc</machine>"
+                + "      <domain type='qemu'>" + "      </domain>"
+                + "      <domain type='kvm'>"
+                + "        <emulator>/usr/bin/qemu-kvm</emulator>"
+                + "        <machine>pc-0.11</machine>"
+                + "        <machine canonical='pc-0.11'>pc</machine>"
+                + "        <machine>pc-0.10</machine>"
+                + "        <machine>isapc</machine>" + "      </domain>"
+                + "    </arch>" + "    <features>" + "      <cpuselection/>"
+                + "      <acpi default='on' toggle='yes'/>"
+                + "      <apic default='on' toggle='no'/>" + "    </features>"
+                + "  </guest>" + "</capabilities>";
 
-               LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
-               String cap = parser.parseCapabilitiesXML(capXML);
-               System.out.println(parser.getGuestOsType());
-               System.out.println(parser.getEmulator());
-       }
+        LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
+        String cap = parser.parseCapabilitiesXML(capXML);
+        System.out.println(parser.getGuestOsType());
+        System.out.println(parser.getEmulator());
+    }
 }

Reply via email to