Skip to content

Commit 90de46c

Browse files
committed
get vmware works
1 parent dfd6a29 commit 90de46c

7 files changed

Lines changed: 66 additions & 18 deletions

File tree

engine/api/src/org/apache/cloudstack/storage/to/VolumeObjectTO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public VolumeObjectTO(VolumeInfo volume) {
5757
this.setVolumeId(volume.getId());
5858
this.chainInfo = volume.getChainInfo();
5959
this.volumeType = volume.getVolumeType();
60+
this.name = volume.getName();
6061
this.setId(volume.getId());
6162
}
6263

engine/storage/integration-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
<artifactId>cloud-plugin-hypervisor-xen</artifactId>
6262
<version>${project.version}</version>
6363
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.apache.cloudstack</groupId>
67+
<artifactId>cloud-plugin-hypervisor-vmware</artifactId>
68+
<version>${project.version}</version>
69+
<scope>test</scope>
6470
</dependency>
6571
<dependency>
6672
<groupId>org.apache.cloudstack</groupId>

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.cloudstack.storage.test;
2020

21+
import java.net.URI;
22+
import java.net.URISyntaxException;
2123
import java.util.HashMap;
2224
import java.util.Map;
2325

@@ -36,23 +38,33 @@
3638
import com.cloud.agent.api.StartupCommand;
3739
import com.cloud.agent.manager.AgentAttache;
3840
import com.cloud.agent.manager.Commands;
41+
import com.cloud.dc.ClusterDetailsDao;
42+
import com.cloud.dc.ClusterVO;
43+
import com.cloud.dc.dao.ClusterDao;
3944
import com.cloud.exception.AgentUnavailableException;
4045
import com.cloud.exception.ConnectionException;
46+
import com.cloud.exception.DiscoveryException;
4147
import com.cloud.exception.OperationTimedoutException;
4248
import com.cloud.host.HostEnvironment;
4349
import com.cloud.host.HostVO;
4450
import com.cloud.host.Status.Event;
4551
import com.cloud.host.dao.HostDao;
4652
import com.cloud.hypervisor.Hypervisor.HypervisorType;
53+
import com.cloud.hypervisor.vmware.VmwareServerDiscoverer;
4754
import com.cloud.hypervisor.xen.resource.XcpOssResource;
4855
import com.cloud.resource.ServerResource;
4956
import com.cloud.utils.component.ManagerBase;
57+
import com.cloud.utils.exception.CloudRuntimeException;
5058

5159
public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager {
5260
private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class);
5361
private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
5462
@Inject
5563
HostDao hostDao;
64+
@Inject
65+
ClusterDao clusterDao;
66+
@Inject
67+
ClusterDetailsDao clusterDetailsDao;
5668
@Override
5769
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
5870
// TODO Auto-generated method stub
@@ -104,14 +116,39 @@ protected void loadResource(Long hostId) {
104116
ServerResource resource = null;
105117
if (host.getHypervisorType() == HypervisorType.XenServer) {
106118
resource = new XcpOssResource();
119+
try {
120+
resource.configure(host.getName(), params);
121+
122+
} catch (ConfigurationException e) {
123+
logger.debug("Failed to load resource:" + e.toString());
124+
}
125+
} else if (host.getHypervisorType() == HypervisorType.VMware) {
126+
ClusterVO cluster = clusterDao.findById(host.getClusterId());
127+
String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();
128+
URI uri;
129+
try {
130+
uri = new URI(url);
131+
String userName = clusterDetailsDao.findDetail(cluster.getId(), "username").getValue();
132+
String password = clusterDetailsDao.findDetail(cluster.getId(), "password").getValue();
133+
VmwareServerDiscoverer discover = new VmwareServerDiscoverer();
134+
135+
Map<? extends ServerResource, Map<String, String>> resources = discover.find(host.getDataCenterId(), host.getPodId(), host.getClusterId(), uri, userName, password, null);
136+
for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
137+
resource = entry.getKey();
138+
}
139+
if (resource == null) {
140+
throw new CloudRuntimeException("can't find resource");
141+
}
142+
} catch (DiscoveryException e) {
143+
// TODO Auto-generated catch block
144+
e.printStackTrace();
145+
} catch (URISyntaxException e) {
146+
// TODO Auto-generated catch block
147+
e.printStackTrace();
148+
}
107149
}
108150

109-
try {
110-
resource.configure(host.getName(), params);
111-
hostResourcesMap.put(hostId, resource);
112-
} catch (ConfigurationException e) {
113-
logger.debug("Failed to load resource:" + e.toString());
114-
}
151+
hostResourcesMap.put(hostId, resource);
115152
HostEnvironment env = new HostEnvironment();
116153
SetupCommand cmd = new SetupCommand(env);
117154
cmd.setNeedSetup(true);

engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.cloud.exception.OperationTimedoutException;
4242
import com.cloud.host.Host;
4343
import com.cloud.host.Status;
44+
import com.cloud.hypervisor.HypervisorGuruManager;
4445
import com.cloud.utils.component.ComponentContext;
4546
import com.cloud.utils.exception.CloudRuntimeException;
4647

@@ -52,6 +53,8 @@ public class RemoteHostEndPoint implements EndPoint {
5253
AgentManager agentMgr;
5354
@Inject
5455
HostEndpointRpcServer rpcServer;
56+
@Inject
57+
protected HypervisorGuruManager _hvGuruMgr;
5558
private ScheduledExecutorService executor;
5659

5760
public RemoteHostEndPoint() {
@@ -83,7 +86,8 @@ public long getId() {
8386
public Answer sendMessage(Command cmd) {
8487
String errMsg = null;
8588
try {
86-
return agentMgr.send(getId(), cmd);
89+
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
90+
return agentMgr.send(newHostId, cmd);
8791
} catch (AgentUnavailableException e) {
8892
errMsg = e.toString();
8993
s_logger.debug("Failed to send command, due to Agent:" + getId() + ", " + e.toString());
@@ -160,7 +164,8 @@ public void run() {
160164
@Override
161165
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
162166
try {
163-
agentMgr.send(this.hostId, new Commands(cmd), new CmdRunner(callback));
167+
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(this.hostId, cmd);
168+
agentMgr.send(newHostId, new Commands(cmd), new CmdRunner(callback));
164169
} catch (AgentUnavailableException e) {
165170
throw new CloudRuntimeException("Unable to send message", e);
166171
}

engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class DefaultEndPointSelector implements EndPointSelector {
5858
@Inject
5959
HostDao hostDao;
6060
private String findOneHostInaScope = "select id from host where "
61-
+ " status = 'Up' and hypervisor_type != 'VMware' and type in ('Routing', 'SecondaryStorageVM') ";
61+
+ " status = 'Up' and type in ('Routing', 'SecondaryStorageVM') ";
6262
private String findOneHostOnPrimaryStorage = "select id from host where "
6363
+ "status = 'Up' and type = 'Routing' ";
6464

plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.inject.Inject;
2929

3030
import org.apache.cloudstack.api.ApiConstants.VMDetails;
31+
import org.apache.cloudstack.storage.command.CopyCommand;
3132
import org.apache.log4j.Logger;
3233
import org.springframework.stereotype.Component;
3334

@@ -286,7 +287,8 @@ public long getCommandHostDelegation(long hostId, Command cmd) {
286287
cmd instanceof CopyVolumeCommand ||
287288
cmd instanceof CreateVolumeOVACommand ||
288289
cmd instanceof PrepareOVAPackingCommand ||
289-
cmd instanceof CreateVolumeFromSnapshotCommand) {
290+
cmd instanceof CreateVolumeFromSnapshotCommand ||
291+
cmd instanceof CopyCommand) {
290292
needDelegation = true;
291293
}
292294
/* Fang: remove this before checking in */

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,11 @@ private boolean createVMFullClone(VirtualMachineMO vmTemplate, DatacenterMO dcMo
328328
public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
329329
DataTO srcData = cmd.getSrcTO();
330330
TemplateObjectTO template = (TemplateObjectTO)srcData;
331-
DataStoreTO imageStore = template.getDataStore();
332331
DataTO destData = cmd.getDestTO();
333332
VolumeObjectTO volume = (VolumeObjectTO)destData;
334333
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
335-
if (imageStore != null && !(imageStore instanceof NfsTO)) {
336-
return new CopyCmdAnswer("unsupported protocol");
337-
}
338-
NfsTO nfsImageStore = (NfsTO)imageStore;
334+
PrimaryDataStoreTO srcStore = (PrimaryDataStoreTO)template.getDataStore();
335+
339336

340337
try {
341338
VmwareContext context = this.hostService.getServiceContext(null);
@@ -351,7 +348,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
351348

352349
// attach volume id to make the name unique
353350
String vmdkName = volume.getName() + "-" + volume.getId();
354-
if (nfsImageStore == null) {
351+
if (srcStore == null) {
355352
// create a root volume for blank VM
356353
String dummyVmName = this.hostService.getWorkerName(context, cmd, 0);
357354

@@ -379,8 +376,8 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
379376
vmMo.destroy();
380377
}
381378
} else {
382-
String templateUrl = nfsImageStore.getUrl() + File.separator + template.getPath();
383-
VirtualMachineMO vmTemplate = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUrl), true);
379+
String templatePath = template.getPath();
380+
VirtualMachineMO vmTemplate = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templatePath), true);
384381
if (vmTemplate == null) {
385382
s_logger.warn("Template host in vSphere is not in connected state, request template reload");
386383
return new CopyCmdAnswer("Template host in vSphere is not in connected state, request template reload");

0 commit comments

Comments
 (0)