get vmware works

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

Branch: refs/heads/object_store
Commit: 90de46c4fe14fbb86a147138b6025018ff274fd8
Parents: dfd6a29
Author: Edison Su <sudi...@gmail.com>
Authored: Fri May 10 17:01:07 2013 -0700
Committer: Edison Su <sudi...@gmail.com>
Committed: Fri May 10 19:26:44 2013 -0700

----------------------------------------------------------------------
 .../cloudstack/storage/to/VolumeObjectTO.java      |    1 +
 engine/storage/integration-test/pom.xml            |    6 ++
 .../storage/test/DirectAgentManagerSimpleImpl.java |   49 +++++++++++++--
 .../cloudstack/storage/RemoteHostEndPoint.java     |    9 ++-
 .../storage/endpoint/DefaultEndPointSelector.java  |    2 +-
 .../src/com/cloud/hypervisor/guru/VMwareGuru.java  |    4 +-
 .../storage/resource/VmwareStorageProcessor.java   |   13 ++---
 7 files changed, 66 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/engine/api/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java
----------------------------------------------------------------------
diff --git 
a/engine/api/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java 
b/engine/api/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java
index 0ae2bc7..e8bc176 100644
--- a/engine/api/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java
+++ b/engine/api/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java
@@ -57,6 +57,7 @@ public class VolumeObjectTO implements DataTO {
         this.setVolumeId(volume.getId());
         this.chainInfo = volume.getChainInfo();
         this.volumeType = volume.getVolumeType();
+        this.name = volume.getName();
         this.setId(volume.getId());
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/engine/storage/integration-test/pom.xml
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/pom.xml 
b/engine/storage/integration-test/pom.xml
index b5aa7ee..56d36ad 100644
--- a/engine/storage/integration-test/pom.xml
+++ b/engine/storage/integration-test/pom.xml
@@ -62,6 +62,12 @@
       <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-plugin-hypervisor-vmware</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
      <dependency>
       <groupId>org.apache.cloudstack</groupId>
       <artifactId>cloud-plugin-storage-volume-default</artifactId>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
 
b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
index 127c0e3..ac5a69d 100644
--- 
a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
+++ 
b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.storage.test;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -36,23 +38,33 @@ import com.cloud.agent.api.SetupCommand;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.manager.AgentAttache;
 import com.cloud.agent.manager.Commands;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.dao.ClusterDao;
 import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConnectionException;
+import com.cloud.exception.DiscoveryException;
 import com.cloud.exception.OperationTimedoutException;
 import com.cloud.host.HostEnvironment;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status.Event;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.vmware.VmwareServerDiscoverer;
 import com.cloud.hypervisor.xen.resource.XcpOssResource;
 import com.cloud.resource.ServerResource;
 import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.exception.CloudRuntimeException;
 
 public class DirectAgentManagerSimpleImpl extends ManagerBase implements 
AgentManager {
     private static final Logger logger = 
Logger.getLogger(DirectAgentManagerSimpleImpl.class);
     private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, 
ServerResource>();
     @Inject
     HostDao hostDao;
+    @Inject
+    ClusterDao clusterDao;
+    @Inject
+    ClusterDetailsDao clusterDetailsDao;
     @Override
     public boolean configure(String name, Map<String, Object> params) throws 
ConfigurationException {
         // TODO Auto-generated method stub
@@ -104,14 +116,39 @@ public class DirectAgentManagerSimpleImpl extends 
ManagerBase implements AgentMa
         ServerResource resource = null;
         if (host.getHypervisorType() == HypervisorType.XenServer) {
              resource = new XcpOssResource();
+             try {
+                 resource.configure(host.getName(), params);
+                
+             } catch (ConfigurationException e) {
+                 logger.debug("Failed to load resource:" + e.toString());
+             }
+        } else if (host.getHypervisorType() == HypervisorType.VMware) {
+            ClusterVO cluster = clusterDao.findById(host.getClusterId());
+            String url = clusterDetailsDao.findDetail(cluster.getId(), 
"url").getValue();
+            URI uri;
+            try {
+                uri = new URI(url);
+                String userName = 
clusterDetailsDao.findDetail(cluster.getId(), "username").getValue();
+                String password = 
clusterDetailsDao.findDetail(cluster.getId(), "password").getValue();
+                VmwareServerDiscoverer discover = new VmwareServerDiscoverer();
+
+                Map<? extends ServerResource, Map<String, String>> resources = 
discover.find(host.getDataCenterId(), host.getPodId(), host.getClusterId(), 
uri, userName, password, null);
+                for (Map.Entry<? extends ServerResource, Map<String, String>> 
entry : resources.entrySet()) {
+                    resource = entry.getKey();
+                }
+                if (resource == null) {
+                    throw new CloudRuntimeException("can't find resource");
+                }
+            } catch (DiscoveryException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (URISyntaxException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
         }
 
-        try {
-            resource.configure(host.getName(), params);
-            hostResourcesMap.put(hostId, resource);
-        } catch (ConfigurationException e) {
-            logger.debug("Failed to load resource:" + e.toString());
-        }
+        hostResourcesMap.put(hostId, resource);
         HostEnvironment env = new HostEnvironment();
         SetupCommand cmd = new SetupCommand(env);
         cmd.setNeedSetup(true);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java 
b/engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java
index 8e96bff..7a651c0 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java
@@ -41,6 +41,7 @@ import com.cloud.exception.ConnectionException;
 import com.cloud.exception.OperationTimedoutException;
 import com.cloud.host.Host;
 import com.cloud.host.Status;
+import com.cloud.hypervisor.HypervisorGuruManager;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -52,6 +53,8 @@ public class RemoteHostEndPoint implements EndPoint {
     AgentManager agentMgr;
     @Inject
     HostEndpointRpcServer rpcServer;
+    @Inject
+    protected HypervisorGuruManager _hvGuruMgr;
     private ScheduledExecutorService executor;
 
     public RemoteHostEndPoint() {
@@ -83,7 +86,8 @@ public class RemoteHostEndPoint implements EndPoint {
     public Answer sendMessage(Command cmd) {
        String errMsg = null;
        try {
-                       return agentMgr.send(getId(), cmd);
+           long newHostId = 
_hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
+                       return agentMgr.send(newHostId, cmd);
                } catch (AgentUnavailableException e) {
                        errMsg = e.toString();
                        s_logger.debug("Failed to send command, due to Agent:" 
+ getId() + ", " + e.toString());
@@ -160,7 +164,8 @@ public class RemoteHostEndPoint implements EndPoint {
     @Override
     public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> 
callback) {
         try {
-            agentMgr.send(this.hostId, new Commands(cmd), new 
CmdRunner(callback));
+           long newHostId = 
_hvGuruMgr.getGuruProcessedCommandTargetHost(this.hostId, cmd);
+            agentMgr.send(newHostId, new Commands(cmd), new 
CmdRunner(callback));
         } catch (AgentUnavailableException e) {
             throw new CloudRuntimeException("Unable to send message", e);
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
 
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
index 54059f2..de57dd7 100644
--- 
a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
+++ 
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
@@ -58,7 +58,7 @@ public class DefaultEndPointSelector implements 
EndPointSelector {
     @Inject
     HostDao hostDao;
     private String findOneHostInaScope = "select id from host where "
-            + " status = 'Up' and hypervisor_type != 'VMware' and type in 
('Routing', 'SecondaryStorageVM') ";
+            + " status = 'Up' and type in ('Routing', 'SecondaryStorageVM') ";
     private String findOneHostOnPrimaryStorage = "select id from host where "
             +  "status = 'Up' and type = 'Routing' ";
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
index 55bb1e9..3388fc7 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -28,6 +28,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.storage.command.CopyCommand;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -286,7 +287,8 @@ public class VMwareGuru extends HypervisorGuruBase 
implements HypervisorGuru {
                 cmd instanceof CopyVolumeCommand ||
                 cmd instanceof CreateVolumeOVACommand ||
                 cmd instanceof PrepareOVAPackingCommand ||
-                cmd instanceof CreateVolumeFromSnapshotCommand) {
+                cmd instanceof CreateVolumeFromSnapshotCommand ||
+                cmd instanceof CopyCommand) {
             needDelegation = true;
         }
         /* Fang: remove this before checking in */

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90de46c4/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
index 92c555a1..240c62f 100644
--- 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
@@ -328,14 +328,11 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
        public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
                DataTO srcData = cmd.getSrcTO();
                TemplateObjectTO template = (TemplateObjectTO)srcData;
-               DataStoreTO imageStore = template.getDataStore();
                DataTO destData = cmd.getDestTO();
                VolumeObjectTO volume = (VolumeObjectTO)destData;
                PrimaryDataStoreTO primaryStore = 
(PrimaryDataStoreTO)volume.getDataStore();
-               if (imageStore != null && !(imageStore instanceof NfsTO)) {
-                       return new CopyCmdAnswer("unsupported protocol");
-               }
-               NfsTO nfsImageStore = (NfsTO)imageStore;
+               PrimaryDataStoreTO srcStore = 
(PrimaryDataStoreTO)template.getDataStore();
+
                
                try {
                        VmwareContext context = 
this.hostService.getServiceContext(null);
@@ -351,7 +348,7 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
 
                        // attach volume id to make the name unique
                        String vmdkName = volume.getName() + "-" + 
volume.getId();
-                       if (nfsImageStore == null) {
+                       if (srcStore == null) {
                                // create a root volume for blank VM
                                String dummyVmName = 
this.hostService.getWorkerName(context, cmd, 0);
 
@@ -379,8 +376,8 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
                                        vmMo.destroy();
                                }
                        } else {
-                               String templateUrl = nfsImageStore.getUrl() + 
File.separator + template.getPath();
-                               VirtualMachineMO vmTemplate = 
VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUrl), 
true);
+                               String templatePath = template.getPath();
+                               VirtualMachineMO vmTemplate = 
VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templatePath), 
true);
                                if (vmTemplate == null) {
                                        s_logger.warn("Template host in vSphere 
is not in connected state, request template reload");
                                        return new CopyCmdAnswer("Template host 
in vSphere is not in connected state, request template reload");

Reply via email to