cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [1/2] git commit: updated refs/heads/4.2 to 9a9720c
Date Tue, 09 Jul 2013 01:43:55 GMT
Updated Branches:
  refs/heads/4.2 40cac192f -> 9a9720cee


fix simulator


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9a9720ce
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9a9720ce
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9a9720ce

Branch: refs/heads/4.2
Commit: 9a9720cee79b9a0bd3421c334b7f18c1fb05c726
Parents: ba4192d
Author: Edison Su <sudison@gmail.com>
Authored: Mon Jul 8 18:43:00 2013 -0700
Committer: Edison Su <sudison@gmail.com>
Committed: Mon Jul 8 18:43:20 2013 -0700

----------------------------------------------------------------------
 .../agent/manager/MockAgentManagerImpl.java     |  27 +++-
 .../agent/manager/MockStorageManagerImpl.java   | 141 +++++++------------
 .../cloud/resource/AgentStorageResource.java    |   2 +-
 .../resource/SimulatorSecondaryDiscoverer.java  |  17 ++-
 4 files changed, 88 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9720ce/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
index 9654b74..fcc1b4f 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
@@ -29,6 +29,8 @@ import com.cloud.agent.api.PingTestCommand;
 import com.cloud.api.commands.SimulatorAddSecondaryAgent;
 import com.cloud.dc.dao.HostPodDao;
 import com.cloud.exception.DiscoveryException;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
 import com.cloud.resource.*;
 import com.cloud.simulator.MockHost;
 import com.cloud.simulator.MockHostVO;
@@ -81,6 +83,8 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
     ResourceManager _resourceMgr;
     @Inject
     SimulatorSecondaryDiscoverer discoverer;
+    @Inject
+    HostDao hostDao;
     private SecureRandom random;
     private final Map<String, AgentResourceBase> _resources = new ConcurrentHashMap<String,
AgentResourceBase>();
     private ThreadPoolExecutor _executor;
@@ -250,10 +254,8 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
             this.mode = "Stop";
         }
 
-        @Override
-        @DB
-        public void run() {
 
+        private void handleSystemVMStop() {
             Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
             try {
                 if (this.mode.equalsIgnoreCase("Stop")) {
@@ -281,6 +283,25 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
                 txn.close();
             }
 
+            //stop ssvm agent
+            HostVO host = hostDao.findByGuid(this.guid);
+            if (host != null) {
+                try {
+                    _resourceMgr.deleteHost(host.getId(), true, true);
+                } catch (Exception e) {
+                    s_logger.debug("Failed to delete host: ", e);
+                }
+            }
+        }
+
+        @Override
+        @DB
+        public void run() {
+            if (this.mode.equalsIgnoreCase("Stop")) {
+                handleSystemVMStop();
+                return;
+            }
+
             String resource = null;
             if (vmType.equalsIgnoreCase("secstorage")) {
                 resource = "com.cloud.agent.AgentStorageResource";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9720ce/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
index c81f079..d23575b 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
@@ -71,7 +71,10 @@ import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.template.TemplateProp;
+import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -113,6 +116,8 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
     MockVMDao _mockVMDao = null;
     @Inject
     MockHostDao _mockHostDao = null;
+    @Inject
+    VMTemplateDao templateDao;
 
     private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType
type) {
         Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
@@ -474,26 +479,12 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
         if ( !(store instanceof NfsTO )){
             return new Answer(cmd, false, "Unsupported image data store: " + store);
         }
-        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+
         MockSecStorageVO storage = null;
         String nfsUrl = ((NfsTO) store).getUrl();
-        try {
-            txn.start();
-            storage = _mockSecStorageDao.findByUrl(nfsUrl);
-            if (storage == null) {
-                return new Answer(cmd, false, "Failed to get secondary storage");
-            }
-            txn.commit();
-        } catch (Exception ex) {
-            txn.rollback();
-            throw new CloudRuntimeException("Error when finding sec storage " + nfsUrl, ex);
-        } finally {
-            txn.close();
-            txn = Transaction.open(Transaction.CLOUD_DB);
-            txn.close();
-        }
 
-        txn = Transaction.open(Transaction.SIMULATOR_DB);
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+        storage = _mockSecStorageDao.findByUrl(nfsUrl);
         try {
             txn.start();
             List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(),
@@ -504,7 +495,6 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
                 templateInfos.put(template.getName(), new TemplateProp(template.getName(),
template.getPath()
                         .replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(),
true, false));
             }
-            txn.commit();
             return new ListTemplateAnswer(nfsUrl, templateInfos);
         } catch (Exception ex) {
             txn.rollback();
@@ -889,89 +879,62 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
     @Override
     public void preinstallTemplates(String url, long zoneId) {
         MockSecStorageVO storage = null;
+        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
         try {
+            txn.start();
             storage = _mockSecStorageDao.findByUrl(url);
-        } catch (Exception ex) {
-            throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
-        } finally {
-            Transaction txn = Transaction.open(Transaction.CLOUD_DB);
-            txn.close();
-        }
-        if (storage == null) {
-            storage = new MockSecStorageVO();
-            URI uri;
-            try {
-                uri = new URI(url);
-            } catch (URISyntaxException e) {
-                return;
-            }
 
-            String nfsHost = uri.getHost();
-            String nfsPath = uri.getPath();
-            String path = nfsHost + ":" + nfsPath;
-            String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString() + File.separator;
+            if (storage == null) {
+                storage = new MockSecStorageVO();
+                URI uri;
+                try {
+                    uri = new URI(url);
+                } catch (URISyntaxException e) {
+                    return;
+                }
+
+                String nfsHost = uri.getHost();
+                String nfsPath = uri.getPath();
+                String path = nfsHost + ":" + nfsPath;
+                String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString()
+ File.separator;
+
+                storage.setUrl(url);
+                storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
+
+                storage.setMountPoint(dir);
 
-            storage.setUrl(url);
-            storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
 
-            storage.setMountPoint(dir);
-            Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
-            try {
-                txn.start();
                 storage = _mockSecStorageDao.persist(storage);
-                txn.commit();
-            } catch (Exception ex) {
-                txn.rollback();
-                throw new CloudRuntimeException("Error when saving storage " + storage, ex);
-            } finally {
-                txn.close();
-                txn = Transaction.open(Transaction.CLOUD_DB);
-                txn.close();
-            }
 
-            // preinstall default templates into secondary storage
-            long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
-            MockVolumeVO template = new MockVolumeVO();
-            template.setName("simulator-domR");
-            template.setPath(storage.getMountPoint() + "template/tmpl/1/100/" + UUID.randomUUID().toString());
-            template.setPoolId(storage.getId());
-            template.setSize(defaultTemplateSize);
-            template.setType(MockVolumeType.TEMPLATE);
-            template.setStatus(Status.DOWNLOADED);
-            txn = Transaction.open(Transaction.SIMULATOR_DB);
-            try {
-                txn.start();
+                // preinstall default templates into secondary storage
+                long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
+                MockVolumeVO template = new MockVolumeVO();
+                template.setName("simulator-domR");
+                template.setPath(storage.getMountPoint() + "template/tmpl/1/100/" + UUID.randomUUID().toString());
+                template.setPoolId(storage.getId());
+                template.setSize(defaultTemplateSize);
+                template.setType(MockVolumeType.TEMPLATE);
+                template.setStatus(Status.DOWNLOADED);
                 template = _mockVolumeDao.persist(template);
-                txn.commit();
-            } catch (Exception ex) {
-                txn.rollback();
-                throw new CloudRuntimeException("Error when saving template " + template,
ex);
-            } finally {
-                txn.close();
-                txn = Transaction.open(Transaction.CLOUD_DB);
-                txn.close();
-            }
 
-            template = new MockVolumeVO();
-            template.setName("simulator-Centos");
-            template.setPath(storage.getMountPoint() + "template/tmpl/1/111/" + UUID.randomUUID().toString());
-            template.setPoolId(storage.getId());
-            template.setSize(defaultTemplateSize);
-            template.setType(MockVolumeType.TEMPLATE);
-            template.setStatus(Status.DOWNLOADED);
-            txn = Transaction.open(Transaction.SIMULATOR_DB);
-            try {
-                txn.start();
+
+                template = new MockVolumeVO();
+                template.setName("simulator-Centos");
+                template.setPath(storage.getMountPoint() + "template/tmpl/1/111/" + UUID.randomUUID().toString());
+                template.setPoolId(storage.getId());
+                template.setSize(defaultTemplateSize);
+                template.setType(MockVolumeType.TEMPLATE);
+                template.setStatus(Status.DOWNLOADED);
+
                 template = _mockVolumeDao.persist(template);
+
                 txn.commit();
-            } catch (Exception ex) {
-                txn.rollback();
-                throw new CloudRuntimeException("Error when saving template " + template,
ex);
-            } finally {
-                txn.close();
-                txn = Transaction.open(Transaction.CLOUD_DB);
-                txn.close();
             }
+        } catch (Exception ex) {
+            throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
+        } finally {
+            txn = Transaction.open(Transaction.CLOUD_DB);
+            txn.close();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9720ce/plugins/hypervisors/simulator/src/com/cloud/resource/AgentStorageResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentStorageResource.java
b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentStorageResource.java
index 3e479ae..d93b20d 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentStorageResource.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentStorageResource.java
@@ -50,7 +50,7 @@ public class AgentStorageResource extends AgentResourceBase implements Secondary
     }
 
     public AgentStorageResource() {
-        setType(Host.Type.SecondaryStorage);
+        setType(Type.SecondaryStorageVM);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9a9720ce/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
index 30926e3..e9052eb 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
@@ -25,6 +25,10 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.resource.SecondaryStorageDiscoverer;
 import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
 import org.apache.log4j.Logger;
@@ -54,6 +58,8 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer
imp
     @Inject AgentManager _agentMgr;
     @Inject ResourceManager _resourceMgr;
     @Inject SnapshotDao _snapshotDao;
+    @Inject
+    ImageStoreDao imageStoreDao;
     protected SecondaryStorageResource resource;
 
     public void setResource(SecondaryStorageResource resource) {
@@ -73,6 +79,10 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer
imp
             s_logger.debug("It's not NFS or file or ISO, so not a secondary storage server:
" + uri.toString());
             return null;
         }
+        List<ImageStoreVO> stores = imageStoreDao.listImageStores();
+        for (ImageStoreVO store : stores) {
+            _mockStorageMgr.preinstallTemplates(store.getUrl(), dcId);
+        }
         Map<SecondaryStorageResource, Map<String, String>> resources = new HashMap<SecondaryStorageResource,
Map<String, String>>();
         resources.put(this.resource, new HashMap<String, String>());
         return resources;
@@ -81,12 +91,7 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer
imp
 
     @Override
     public void postDiscovery(List<HostVO> hosts, long msId) {
-        for (HostVO host: hosts) {
-            if(s_logger.isDebugEnabled()) {
-                s_logger.debug("Preinstalling simulator templates");
-            }
-            _mockStorageMgr.preinstallTemplates(host.getStorageUrl(), host.getDataCenterId());
-        }
+
     }
 
     @Override


Mime
View raw message