simulator: resurrect simulator hypervisor as plugin

Multiple fixes:
1. changes to the mvn configuration
    a. include simulator to client.war
    b. activate simulator by profile
2. templates for simulator
3. developer prefill for simulator
    a. Use deplydb-simulator to setup simulator db
4. Inherit components-simulator.xml from components.xml
5. ListVolumesCommand missed for MockStorageManager
6. Include simulator properties into utils/db.properties

TODO:
 Secondary storage VMs don't come up because ComponentLocator doesn't
retain a unique set of adapaters by name. Fix this in subsequent
checkin.


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

Branch: refs/heads/ui-plugins
Commit: 1f1a13448f2a5fcdf45e44a5a8ba8f5af66e37d5
Parents: 8f6fdc3
Author: Prasanna Santhanam <[email protected]>
Authored: Sun Dec 23 19:22:54 2012 -0800
Committer: Prasanna Santhanam <[email protected]>
Committed: Sun Dec 23 19:28:57 2012 -0800

----------------------------------------------------------------------
 client/pom.xml                                     |   25 +-
 client/tomcatconf/simulator.properties.in          |   31 -
 client/tomcatconf/simulator_commands.properties.in |   19 +
 developer/developer-prefill.sql                    |    2 +
 developer/pom.xml                                  |  134 +++++-
 .../simulator/resources/components-simulator.xml   |   38 +--
 .../cloud/agent/manager/MockStorageManager.java    |   13 +-
 .../agent/manager/MockStorageManagerImpl.java      |   66 ++-
 .../cloud/agent/manager/SimulatorManagerImpl.java  |   47 +-
 .../resource/SimulatorSecondaryDiscoverer.java     |   27 +
 plugins/pom.xml                                    |    2 +-
 pom.xml                                            |    2 -
 setup/db/create-schema-simulator.sql               |    1 +
 setup/db/templates.simulator.sql                   |  437 +--------------
 utils/conf/db.properties                           |   11 +
 15 files changed, 286 insertions(+), 569 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 1673429..7707706 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -44,7 +44,7 @@
       <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-plugin-user-authenticator-sha256salted</artifactId>
       <version>${project.version}</version>
-    </dependency>    
+    </dependency>
     <dependency>
       <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-plugin-network-nvp</artifactId>
@@ -66,9 +66,9 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.cloudstack</groupId>
-      <artifactId>cloud-plugin-hypervisor-ovm</artifactId>
-      <version>${project.version}</version>
+       <groupId>org.apache.cloudstack</groupId>
+       <artifactId>cloud-plugin-hypervisor-ovm</artifactId>
+       <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.cloudstack</groupId>
@@ -290,7 +290,7 @@
     </plugins>
     <pluginManagement>
       <plugins>
-        <!--This plugin's configuration is used to store Eclipse m2e settings 
+        <!--This plugin's configuration is used to store Eclipse m2e settings
           only. It has no influence on the Maven build itself. -->
         <plugin>
           <groupId>org.eclipse.m2e</groupId>
@@ -325,6 +325,21 @@
   </build>
   <profiles>
     <profile>
+        <id>simulator</id>
+        <activation>
+            <property>
+                <name>simulator</name>
+            </property>
+        </activation>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.cloudstack</groupId>
+                <artifactId>cloud-plugin-hypervisor-simulator</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+        </dependencies>
+    </profile>
+    <profile>
       <id>netapp</id>
       <activation>
         <property>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/client/tomcatconf/simulator.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/simulator.properties.in 
b/client/tomcatconf/simulator.properties.in
deleted file mode 100644
index 24e5e62..0000000
--- a/client/tomcatconf/simulator.properties.in
+++ /dev/null
@@ -1,31 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-# 
-#   http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-host=127.0.0.1
-port=8250
-workers=3
-zone=1
-pod=1
-run=13
-sequence=r
-agent.save.path=/tmp/agents
-latency=2
-latency.start.range=2
-latency.end.range=2
-delay.distribution={(5,10); (5,10); (5,10); (5,10); (5,10); (5,10); (5,10); 
(5,10); (5,10); (10,120)}
-property.scan.enabled=1
-property.scan.interval=300

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/client/tomcatconf/simulator_commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/simulator_commands.properties.in 
b/client/tomcatconf/simulator_commands.properties.in
new file mode 100644
index 0000000..d2a4699
--- /dev/null
+++ b/client/tomcatconf/simulator_commands.properties.in
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+configureSimulator=com.cloud.api.commands.ConfigureSimulator;1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/developer/developer-prefill.sql
----------------------------------------------------------------------
diff --git a/developer/developer-prefill.sql b/developer/developer-prefill.sql
index 8e215ba..e14ac37 100644
--- a/developer/developer-prefill.sql
+++ b/developer/developer-prefill.sql
@@ -16,6 +16,8 @@
 -- under the License.
 
 -- Add a default ROOT domain
+use cloud;
+
 INSERT INTO `cloud`.`domain` (id, name, parent, path, owner) VALUES
             (1, 'ROOT', NULL, '/', 2);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/developer/pom.xml
----------------------------------------------------------------------
diff --git a/developer/pom.xml b/developer/pom.xml
index 61cb110..b782a59 100644
--- a/developer/pom.xml
+++ b/developer/pom.xml
@@ -1,4 +1,4 @@
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more 
contributor 
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
   license agreements. See the NOTICE file distributed with this work for 
additional 
   information regarding copyright ownership. The ASF licenses this file to 
   you under the Apache License, Version 2.0 (the "License"); you may not use 
@@ -9,6 +9,7 @@
   OF ANY KIND, either express or implied. See the License for the specific 
   language governing permissions and limitations under the License. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>cloud-developer</artifactId>
@@ -101,6 +102,7 @@
               </dependency>
             </dependencies>
             <configuration>
+
               <driver>org.gjt.mm.mysql.Driver</driver>
               <url>jdbc:mysql://${db.cloud.host}:${db.cloud.port}/cloud</url>
               <username>${db.cloud.username}</username>
@@ -109,7 +111,6 @@
               <skip>${maven.test.skip}</skip>
               <forceMojoExecution>true</forceMojoExecution>
             </configuration>
-
             <executions>
               <execution>
                 <id>drop-database</id>
@@ -310,9 +311,9 @@
                 </goals>
                 <configuration>
                   <autocommit>true</autocommit>
-                  <srcFiles>
-                    <srcFile>${basedir}/developer-prefill.sql</srcFile>
-                  </srcFiles>
+                    <srcFiles>
+                        <srcFile>${basedir}/developer-prefill.sql</srcFile>
+                    </srcFiles>
                 </configuration>
               </execution>
             </executions>
@@ -320,5 +321,128 @@
         </plugins>
       </build>
     </profile>
+
+      <!-- Simulator profile -->
+      <profile>
+          <id>simulator</id>
+          <activation>
+              <property><name>deploydb-simulator</name></property>
+          </activation>
+          <build>
+              <plugins>
+                  <plugin>
+                      <groupId>org.codehaus.mojo</groupId>
+                      <artifactId>properties-maven-plugin</artifactId>
+                      <version>1.0-alpha-2</version>
+                      <executions>
+                          <execution>
+                              <phase>initialize</phase>
+                              <goals>
+                                  <goal>read-project-properties</goal>
+                              </goals>
+                              <configuration>
+                                  <files>
+                                      
<file>${project.parent.basedir}/utils/conf/db.properties</file>
+                                      
<file>${project.parent.basedir}/utils/conf/db.properties.override</file>
+                                  </files>
+                                  <quiet>true</quiet>
+                              </configuration>
+                          </execution>
+                      </executions>
+                  </plugin>
+                  <plugin>
+                      <groupId>org.codehaus.mojo</groupId>
+                      <artifactId>sql-maven-plugin</artifactId>
+                      <version>1.5</version>
+                      <dependencies>
+                          <dependency>
+                              <groupId>mysql</groupId>
+                              <artifactId>mysql-connector-java</artifactId>
+                              <version>${cs.mysql.version}</version>
+                          </dependency>
+                      </dependencies>
+                      <configuration>
+                          <driver>org.gjt.mm.mysql.Driver</driver>
+                          
<url>jdbc:mysql://${db.simulator.host}:3306/simulator</url>
+                          <username>${db.simulator.username}</username>
+                          <password>${db.simulator.password}</password>
+                          <skip>${maven.test.skip}</skip>
+                          <forceMojoExecution>true</forceMojoExecution>
+                      </configuration>
+                      <executions>
+                          <execution>
+                              <id>drop-database</id>
+                              <phase>process-test-resources</phase>
+                              <goals>
+                                  <goal>execute</goal>
+                              </goals>
+                              <configuration>
+                                  <username>root</username>
+                                  <password>${db.root.password}</password>
+                                  
<url>jdbc:mysql://${db.simulator.host}:3306</url>
+                                  <sqlCommand>drop database if exists 
`simulator`</sqlCommand>
+                              </configuration>
+                          </execution>
+                          <execution>
+                              <id>create-database</id>
+                              <phase>process-test-resources</phase>
+                              <goals>
+                                  <goal>execute</goal>
+                              </goals>
+                              <configuration>
+                                  <username>root</username>
+                                  <password>${db.root.password}</password>
+                                  
<url>jdbc:mysql://${db.simulator.host}:3306</url>
+                                  <sqlCommand>create database 
`simulator`</sqlCommand>
+                              </configuration>
+                          </execution>
+                          <execution>
+                              <id>grant-user-cloud</id>
+                              <phase>process-test-resources</phase>
+                              <goals>
+                                  <goal>execute</goal>
+                              </goals>
+                              <configuration>
+                                  <username>root</username>
+                                  <password>${db.root.password}</password>
+                                  
<url>jdbc:mysql://${db.simulator.host}:3306</url>
+                                  <sqlCommand>GRANT ALL ON simulator.* to
+                                      ${db.simulator.username}@`localhost` 
identified by
+                                      '${db.simulator.password}';</sqlCommand>
+                              </configuration>
+                          </execution>
+                          <execution>
+                              <id>grant-user-cloud-all</id>
+                              <phase>process-test-resources</phase>
+                              <goals>
+                                  <goal>execute</goal>
+                              </goals>
+                              <configuration>
+                                  <username>root</username>
+                                  <password>${db.root.password}</password>
+                                  
<url>jdbc:mysql://${db.simulator.host}:3306</url>
+                                  <sqlCommand>GRANT ALL ON simulator.* to
+                                      ${db.simulator.username}@`%` identified 
by
+                                      '${db.simulator.password}';</sqlCommand>
+                              </configuration>
+                          </execution>
+                          <execution>
+                              <id>create-schema</id>
+                              <phase>process-test-resources</phase>
+                              <goals>
+                                  <goal>execute</goal>
+                              </goals>
+                              <configuration>
+                                  <srcFiles>
+                                      
<srcFile>${basedir}/target/db/create-schema-simulator.sql</srcFile>
+                                      
<srcFile>${basedir}/target/db/templates.simulator.sql</srcFile>
+                                  </srcFiles>
+                              </configuration>
+                          </execution>
+                      </executions>
+                  </plugin>
+              </plugins>
+          </build>
+    </profile>
   </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/plugins/hypervisors/simulator/resources/components-simulator.xml
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/resources/components-simulator.xml 
b/plugins/hypervisors/simulator/resources/components-simulator.xml
index 4629acc..2658e4d 100644
--- a/plugins/hypervisors/simulator/resources/components-simulator.xml
+++ b/plugins/hypervisors/simulator/resources/components-simulator.xml
@@ -18,7 +18,7 @@ specific language governing permissions and limitations
 under the License.
 -->
 <components-simulator.xml>
-        <system-integrity-checker 
class="com.cloud.upgrade.DatabaseUpgradeChecker">
+    <system-integrity-checker class="com.cloud.upgrade.DatabaseUpgradeChecker">
         <checker name="ManagementServerNode" 
class="com.cloud.cluster.ManagementServerNode"/>
         <checker name="EncryptionSecretKeyChecker" 
class="com.cloud.utils.crypt.EncryptionSecretKeyChecker"/>
         <checker name="DatabaseIntegrityChecker" 
class="com.cloud.upgrade.DatabaseIntegrityChecker"/>
@@ -30,44 +30,12 @@ under the License.
         <dao name="Configuration configuration server" 
class="com.cloud.configuration.dao.ConfigurationDaoImpl">
             <param name="premium">true</param>
         </dao>
-        <adapters key="com.cloud.agent.manager.allocator.HostAllocator">
-            <adapter name="FirstFitRouting" 
class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator"/>
-        </adapters>
-        <adapters key="com.cloud.storage.allocator.StoragePoolAllocator">
-            <adapter name="LocalStorage" 
class="com.cloud.storage.allocator.LocalStoragePoolAllocator"/>
-            <adapter name="Storage" 
class="com.cloud.storage.allocator.FirstFitStoragePoolAllocator"/>
-        </adapters>
-        <adapters key="com.cloud.agent.manager.allocator.PodAllocator">
-            <adapter name="User First" 
class="com.cloud.agent.manager.allocator.impl.UserConcentratedAllocator"/>
-        </adapters>
-        <adapters key="com.cloud.consoleproxy.ConsoleProxyAllocator">
-            <adapter name="Balance" 
class="com.cloud.consoleproxy.ConsoleProxyBalanceAllocator"/>
-        </adapters>
-        <adapters key="com.cloud.ha.Investigator">
-            <adapter name="SimpleInvestigator" 
class="com.cloud.ha.CheckOnAgentInvestigator"/>
-            <adapter name="PingInvestigator" 
class="com.cloud.ha.UserVmDomRInvestigator"/>
-            <adapter name="ManagementIPSysVMInvestigator" 
class="com.cloud.ha.ManagementIPSystemVMInvestigator"/>
-        </adapters>
         <adapters key="com.cloud.resource.Discoverer">
             <adapter name="Simulator Agent" 
class="com.cloud.resource.SimulatorDiscoverer"/>
-            <adapter name="SecondaryStorage" 
class="com.cloud.resource.SimulatorSecondaryDiscoverer"/>
-            <adapter name="XCP Agent" 
class="com.cloud.hypervisor.xen.discoverer.XcpServerDiscoverer"/>
-            <adapter name="SecondaryStorage" 
class="com.cloud.storage.secondary.SecondaryStorageDiscoverer"/>
-            <adapter name="KVM Agent" 
class="com.cloud.hypervisor.kvm.discoverer.KvmServerDiscoverer"/>
+            <adapter name="SimulatorSecondaryStorage" 
class="com.cloud.resource.SimulatorSecondaryDiscoverer"/>
         </adapters>
         <adapters key="com.cloud.hypervisor.HypervisorGuru">
             <adapter name="SimulatorGuru" 
class="com.cloud.simulator.SimulatorGuru"/>
-            <adapter name="XenServerGuru" 
class="com.cloud.hypervisor.XenServerGuru"/>
-            <adapter name="KVMGuru" class="com.cloud.hypervisor.KVMGuru"/>
-        </adapters>
-        <adapters key="com.cloud.deploy.DeploymentPlanner">
-            <adapter name="First Fit" 
class="com.cloud.deploy.FirstFitPlanner"/>
-            <adapter name="UserDispersing" 
class="com.cloud.deploy.UserDispersingPlanner"/>
-            <adapter name="UserConcentratedPod" 
class="com.cloud.deploy.UserConcentratedPodPlanner"/>
-            <adapter name="BareMetal Fit" 
class="com.cloud.deploy.BareMetalPlanner"/>
-        </adapters>
-        <adapters key="com.cloud.agent.StartupCommandProcessor">
-            <adapter name="BasicAgentAuthorizer" 
class="com.cloud.agent.manager.authn.impl.BasicAgentAuthManager"/>
         </adapters>
     </management-server>
     <configuration-server class="com.cloud.server.ConfigurationServerImpl" 
extends="components.xml:configuration-server">
@@ -95,4 +63,4 @@ under the License.
         <dao name="Site2SiteVpnGatewayDao" 
class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" singleton="false"/>
         <dao name="Site2SiteVpnConnectionDao" 
class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" singleton="false"/>
     </configuration-server>
-</components-simulator.xml>
\ No newline at end of file
+</components-simulator.xml>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java
 
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java
index fc8aacc..ff26d18 100644
--- 
a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java
+++ 
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java
@@ -35,17 +35,7 @@ import com.cloud.agent.api.ModifyStoragePoolCommand;
 import com.cloud.agent.api.SecStorageSetupCommand;
 import com.cloud.agent.api.SecStorageVMSetupCommand;
 import com.cloud.agent.api.StoragePoolInfo;
-import com.cloud.agent.api.storage.CopyVolumeAnswer;
-import com.cloud.agent.api.storage.CopyVolumeCommand;
-import com.cloud.agent.api.storage.CreateAnswer;
-import com.cloud.agent.api.storage.CreateCommand;
-import com.cloud.agent.api.storage.DeleteTemplateCommand;
-import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.DownloadCommand;
-import com.cloud.agent.api.storage.DownloadProgressCommand;
-import com.cloud.agent.api.storage.ListTemplateCommand;
-import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
-import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.*;
 import com.cloud.utils.component.Manager;
 
 public interface MockStorageManager extends Manager {
@@ -64,6 +54,7 @@ public interface MockStorageManager extends Manager {
 
        public Answer SecStorageSetup(SecStorageSetupCommand cmd);
        public Answer ListTemplates(ListTemplateCommand cmd);
+    public Answer ListVolumes(ListVolumeCommand cmd);
        public Answer Destroy(DestroyCommand cmd);
        public Answer Download(DownloadCommand cmd);
        public Answer DownloadProcess(DownloadProgressCommand cmd);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/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 9bf4192..a950926 100644
--- 
a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
+++ 
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
@@ -30,6 +30,7 @@ import java.util.UUID;
 import javax.ejb.Local;
 import javax.naming.ConfigurationException;
 
+import com.cloud.agent.api.storage.*;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
@@ -56,20 +57,6 @@ import com.cloud.agent.api.SecStorageSetupAnswer;
 import com.cloud.agent.api.SecStorageSetupCommand;
 import com.cloud.agent.api.SecStorageVMSetupCommand;
 import com.cloud.agent.api.StoragePoolInfo;
-import com.cloud.agent.api.storage.CopyVolumeAnswer;
-import com.cloud.agent.api.storage.CopyVolumeCommand;
-import com.cloud.agent.api.storage.CreateAnswer;
-import com.cloud.agent.api.storage.CreateCommand;
-import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
-import com.cloud.agent.api.storage.DeleteTemplateCommand;
-import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.DownloadAnswer;
-import com.cloud.agent.api.storage.DownloadCommand;
-import com.cloud.agent.api.storage.DownloadProgressCommand;
-import com.cloud.agent.api.storage.ListTemplateAnswer;
-import com.cloud.agent.api.storage.ListTemplateCommand;
-import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
-import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.agent.api.to.VolumeTO;
 import com.cloud.simulator.MockHost;
@@ -139,8 +126,8 @@ public class MockStorageManagerImpl implements 
MockStorageManager {
 
        @Override
        public PrimaryStorageDownloadAnswer 
primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
-               MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), 
cmd.getSecondaryStorageUrl(),
-                               MockVolumeType.TEMPLATE);
+        MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), 
cmd.getSecondaryStorageUrl(),
+                MockVolumeType.TEMPLATE);
                if (template == null) {
                        return new PrimaryStorageDownloadAnswer("Can't find 
primary storage");
                }
@@ -421,6 +408,49 @@ public class MockStorageManagerImpl implements 
MockStorageManager {
                return new SecStorageSetupAnswer(storage.getMountPoint());
        }
 
+    @Override
+       public Answer ListVolumes(ListVolumeCommand cmd) {
+               Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+               MockSecStorageVO storage = null;
+               try {
+                       txn.start();
+                       storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
+                       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 " + cmd.getSecUrl(), ex);
+               } finally {
+                       txn.close();
+            txn = Transaction.open(Transaction.CLOUD_DB);
+            txn.close();
+               }
+
+               txn = Transaction.open(Transaction.SIMULATOR_DB);
+               try {
+                       txn.start();
+                       List<MockVolumeVO> volumes = 
_mockVolumeDao.findByStorageIdAndType(storage.getId(),
+                                       MockVolumeType.VOLUME);
+
+                       Map<String, TemplateInfo> templateInfos = new 
HashMap<String, TemplateInfo>();
+                       for (MockVolumeVO volume : volumes) {
+                               templateInfos.put(volume.getName(), new 
TemplateInfo(volume.getName(), volume.getPath()
+                                               
.replaceAll(storage.getMountPoint(), ""), volume.getSize(), volume.getSize(), 
true, false));
+                       }
+                       txn.commit();
+                       return new ListTemplateAnswer(cmd.getSecUrl(), 
templateInfos);
+               } catch (Exception ex) {
+                       txn.rollback();
+                       throw new CloudRuntimeException("Error when finding 
template on sec storage " + storage.getId(), ex);
+               } finally {
+                       txn.close();
+            txn = Transaction.open(Transaction.CLOUD_DB);
+            txn.close();
+               }
+       }
+
        @Override
        public Answer ListTemplates(ListTemplateCommand cmd) {
                Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
@@ -907,7 +937,7 @@ public class MockStorageManagerImpl implements 
MockStorageManager {
                        long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
                        MockVolumeVO template = new MockVolumeVO();
                        template.setName("simulator-domR");
-                       template.setPath(storage.getMountPoint() + 
"template/tmpl/1/9/" + UUID.randomUUID().toString());
+                       template.setPath(storage.getMountPoint() + 
"template/tmpl/1/10/" + UUID.randomUUID().toString());
                        template.setPoolId(storage.getId());
                        template.setSize(defaultTemplateSize);
                        template.setType(MockVolumeType.TEMPLATE);
@@ -928,7 +958,7 @@ public class MockStorageManagerImpl implements 
MockStorageManager {
 
                        template = new MockVolumeVO();
                        template.setName("simulator-Centos");
-                       template.setPath(storage.getMountPoint() + 
"template/tmpl/1/10/" + UUID.randomUUID().toString());
+                       template.setPath(storage.getMountPoint() + 
"template/tmpl/1/11/" + UUID.randomUUID().toString());
                        template.setPoolId(storage.getId());
                        template.setSize(defaultTemplateSize);
                        template.setType(MockVolumeType.TEMPLATE);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
 
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
index 3d572ff..4f70ee5 100644
--- 
a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ 
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -23,6 +23,7 @@ import javax.ejb.Local;
 import javax.naming.ConfigurationException;
 
 import com.cloud.agent.api.*;
+import com.cloud.agent.api.storage.*;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.check.CheckSshCommand;
@@ -36,14 +37,6 @@ import com.cloud.agent.api.routing.SetFirewallRulesCommand;
 import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
 import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
 import com.cloud.agent.api.routing.VmDataCommand;
-import com.cloud.agent.api.storage.CopyVolumeCommand;
-import com.cloud.agent.api.storage.CreateCommand;
-import com.cloud.agent.api.storage.DeleteTemplateCommand;
-import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.DownloadCommand;
-import com.cloud.agent.api.storage.DownloadProgressCommand;
-import com.cloud.agent.api.storage.ListTemplateCommand;
-import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.simulator.MockConfigurationVO;
 import com.cloud.simulator.MockHost;
 import com.cloud.simulator.MockVMVO;
@@ -158,45 +151,45 @@ public class SimulatorManagerImpl implements 
SimulatorManager {
             }
 
             if (cmd instanceof GetHostStatsCommand) {
-                return 
_mockAgentMgr.getHostStatistic((GetHostStatsCommand)cmd);
+                return _mockAgentMgr.getHostStatistic((GetHostStatsCommand) 
cmd);
             } else if (cmd instanceof CheckHealthCommand) {
-                return _mockAgentMgr.checkHealth((CheckHealthCommand)cmd);
+                return _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
             } else if (cmd instanceof PingTestCommand) {
-                return _mockAgentMgr.pingTest((PingTestCommand)cmd);
+                return _mockAgentMgr.pingTest((PingTestCommand) cmd);
             } else if (cmd instanceof PrepareForMigrationCommand) {
-                       return 
_mockVmMgr.prepareForMigrate((PrepareForMigrationCommand)cmd);
+                       return 
_mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
             } else if (cmd instanceof MigrateCommand) {
-                return _mockVmMgr.Migrate((MigrateCommand)cmd, info);
+                return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
             } else if (cmd instanceof StartCommand) {
-                return _mockVmMgr.startVM((StartCommand)cmd, info);
+                return _mockVmMgr.startVM((StartCommand) cmd, info);
             } else if (cmd instanceof CheckSshCommand) {
-                return _mockVmMgr.checkSshCommand((CheckSshCommand)cmd);
+                return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
             } else if (cmd instanceof CheckVirtualMachineCommand) {
-                       return 
_mockVmMgr.checkVmState((CheckVirtualMachineCommand)cmd);
+                       return 
_mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
             } else if (cmd instanceof SetStaticNatRulesCommand) {
-                return 
_mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand)cmd);
+                return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand) 
cmd);
             } else if (cmd instanceof SetFirewallRulesCommand) {
-                       return 
_mockVmMgr.SetFirewallRules((SetFirewallRulesCommand)cmd);
+                       return 
_mockVmMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
             } else if (cmd instanceof SetPortForwardingRulesCommand) {
-                return 
_mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand)cmd);
+                return 
_mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
             } else if (cmd instanceof NetworkUsageCommand) {
-                return _mockVmMgr.getNetworkUsage((NetworkUsageCommand)cmd);
+                return _mockVmMgr.getNetworkUsage((NetworkUsageCommand) cmd);
             } else if (cmd instanceof IpAssocCommand) {
-                return _mockVmMgr.IpAssoc((IpAssocCommand)cmd);
+                return _mockVmMgr.IpAssoc((IpAssocCommand) cmd);
             } else if (cmd instanceof LoadBalancerConfigCommand) {
-                return 
_mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand)cmd);
+                return 
_mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
             } else if (cmd instanceof DhcpEntryCommand) {
-                return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand)cmd);
+                return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
             } else if (cmd instanceof VmDataCommand) {
-                return _mockVmMgr.setVmData((VmDataCommand)cmd);
+                return _mockVmMgr.setVmData((VmDataCommand) cmd);
             } else if (cmd instanceof CleanupNetworkRulesCmd) {
-                return 
_mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd)cmd, info);
+                return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) 
cmd, info);
             } else if (cmd instanceof CheckNetworkCommand) {
                        return 
_mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
             }else if (cmd instanceof StopCommand) {
                 return _mockVmMgr.stopVM((StopCommand)cmd);
             } else if (cmd instanceof RebootCommand) {
-                return _mockVmMgr.rebootVM((RebootCommand)cmd);
+                return _mockVmMgr.rebootVM((RebootCommand) cmd);
             } else if (cmd instanceof GetVncPortCommand) {
                 return _mockVmMgr.getVncPort((GetVncPortCommand)cmd);
             } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
@@ -225,6 +218,8 @@ public class SimulatorManagerImpl implements 
SimulatorManager {
                 return 
_mockStorageMgr.SecStorageSetup((SecStorageSetupCommand)cmd);
             } else if (cmd instanceof ListTemplateCommand) {
                 return _mockStorageMgr.ListTemplates((ListTemplateCommand)cmd);
+            } else if (cmd instanceof ListVolumeCommand) {
+                return _mockStorageMgr.ListVolumes((ListVolumeCommand)cmd);
             } else if (cmd instanceof DestroyCommand) {
                 return _mockStorageMgr.Destroy((DestroyCommand)cmd);
             } else if (cmd instanceof DownloadProgressCommand) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/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 5d4d5b9..3f7cea5 100644
--- 
a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
+++ 
b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorSecondaryDiscoverer.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.resource;
 
+import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
@@ -39,8 +40,11 @@ import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.secondary.SecondaryStorageDiscoverer;
 import com.cloud.utils.component.Inject;
 import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.log4j.Logger;
+
 @Local(value=Discoverer.class)
 public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer 
implements ResourceStateAdapter, Listener {
+    private static final Logger s_logger = 
Logger.getLogger(SimulatorSecondaryDiscoverer.class);
     @Inject MockStorageManager _mockStorageMgr = null;
     @Inject AgentManager _agentMgr;
     @Inject ResourceManager _resourceMgr;
@@ -54,9 +58,32 @@ public class SimulatorSecondaryDiscoverer extends 
SecondaryStorageDiscoverer imp
     }
 
     @Override
+    public Map<? extends ServerResource, Map<String, String>> find(long dcId, 
Long podId, Long clusterId, URI uri, String username, String password, 
List<String> hostTags) {
+        if (!uri.getScheme().equalsIgnoreCase("nfs") && 
!uri.getScheme().equalsIgnoreCase("file")
+                && !uri.getScheme().equalsIgnoreCase("iso") && 
!uri.getScheme().equalsIgnoreCase("dummy")) {
+            s_logger.debug("It's not NFS or file or ISO, so not a secondary 
storage server: " + uri.toString());
+            return null;
+        }
+
+        if (uri.getScheme().equalsIgnoreCase("nfs") || 
uri.getScheme().equalsIgnoreCase("iso")) {
+            return createNfsSecondaryStorageResource(dcId, podId, uri);
+        } else if (uri.getScheme().equalsIgnoreCase("file")) {
+            return createLocalSecondaryStorageResource(dcId, podId, uri);
+        } else if (uri.getScheme().equalsIgnoreCase("dummy")) {
+            return createDummySecondaryStorageResource(dcId, podId, uri);
+        } else {
+            return null;
+        }
+    }
+
+
+    @Override
     public void postDiscovery(List<HostVO> hosts, long msId) {
         super.postDiscovery(hosts, msId);
         for (HostVO host: hosts) {
+            if(s_logger.isDebugEnabled()) {
+                s_logger.debug("Preinstalling simulator templates");
+            }
             _mockStorageMgr.preinstallTemplates(host.getStorageUrl(), 
host.getDataCenterId());
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/plugins/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/pom.xml b/plugins/pom.xml
index af86210..820e76f 100644
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -129,7 +129,7 @@
       <id>simulator</id>
       <activation>
         <property>
-          <name>nonoss</name>
+          <name>simulator</name>
         </property>
       </activation>
       <modules>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4d31cde..f374032 100644
--- a/pom.xml
+++ b/pom.xml
@@ -384,7 +384,5 @@
         <module>vmware-base</module>
       </modules>
     </profile>
-
   </profiles>
-
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1f1a1344/setup/db/create-schema-simulator.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema-simulator.sql 
b/setup/db/create-schema-simulator.sql
index 6d4a130..facfefc 100644
--- a/setup/db/create-schema-simulator.sql
+++ b/setup/db/create-schema-simulator.sql
@@ -14,6 +14,7 @@
 -- KIND, either express or implied.  See the License for the
 -- specific language governing permissions and limitations
 -- under the License.
+use simulator;
 
 DROP TABLE IF EXISTS `simulator`.`mockhost`;
 DROP TABLE IF EXISTS `simulator`.`mocksecstorage`;

Reply via email to