Skip to content

Commit bfe30cd

Browse files
committed
CLOUDSTACK-3681: fix bunch of bugs related to vmware, regarding to snapshot
1 parent f27ca63 commit bfe30cd

13 files changed

Lines changed: 297 additions & 89 deletions

File tree

api/src/com/cloud/agent/api/to/DataTO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
*/
1919
package com.cloud.agent.api.to;
2020

21+
import com.cloud.hypervisor.Hypervisor;
22+
2123
public interface DataTO {
2224
public DataObjectType getObjectType();
2325
public DataStoreTO getDataStore();
26+
public Hypervisor.HypervisorType getHypervisorType();
2427
/**
2528
* @return
2629
*/

api/src/com/cloud/hypervisor/HypervisorGuru.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.cloud.agent.api.to.NicTO;
2323
import com.cloud.agent.api.to.VirtualMachineTO;
2424
import com.cloud.hypervisor.Hypervisor.HypervisorType;
25+
import com.cloud.utils.Pair;
2526
import com.cloud.utils.component.Adapter;
2627
import com.cloud.vm.NicProfile;
2728
import com.cloud.vm.VirtualMachine;
@@ -40,12 +41,13 @@ public interface HypervisorGuru extends Adapter {
4041

4142
/**
4243
* Give hypervisor guru opportunity to decide if certain command needs to be delegated to other host, mainly to secondary storage VM host
44+
*
4345
* @param hostId original hypervisor host
4446
* @param cmd command that is going to be sent, hypervisor guru usually needs to register various context objects into the command object
4547
*
4648
* @return delegated host id if the command will be delegated
4749
*/
48-
long getCommandHostDelegation(long hostId, Command cmd);
50+
Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd);
4951

5052
/**
5153
* @return true if VM can be migrated independently with CloudStack, and therefore CloudStack needs to track and reflect host change

core/src/com/cloud/storage/resource/StorageProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface StorageProcessor {
3232
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd);
3333
public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd);
3434
public Answer createTemplateFromVolume(CopyCommand cmd);
35+
public Answer createTemplateFromSnapshot(CopyCommand cmd);
3536
public Answer backupSnapshot(CopyCommand cmd);
3637
public Answer attachIso(AttachCommand cmd);
3738
public Answer attachVolume(AttachCommand cmd);

core/src/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ protected Answer execute(CopyCommand cmd) {
8484
return processor.backupSnapshot(cmd);
8585
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.VOLUME) {
8686
return processor.createVolumeFromSnapshot(cmd);
87+
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
88+
return processor.createTemplateFromSnapshot(cmd);
8789
}
8890

8991
return new Answer(cmd, false, "not implemented yet");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public void setName(String name) {
111111
this.name = name;
112112
}
113113

114+
@Override
114115
public HypervisorType getHypervisorType() {
115116
return hypervisorType;
116117
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.to;
1818

19+
import com.cloud.hypervisor.Hypervisor;
1920
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
2021

2122
import com.cloud.agent.api.to.DataObjectType;
@@ -38,6 +39,7 @@ public class TemplateObjectTO implements DataTO {
3839
private String name;
3940
private String guestOsType;
4041
private Long size;
42+
private Hypervisor.HypervisorType hypervisorType;
4143

4244
public TemplateObjectTO() {
4345

@@ -53,6 +55,7 @@ public TemplateObjectTO(VirtualMachineTemplate template) {
5355
this.accountId = template.getAccountId();
5456
this.name = template.getUniqueName();
5557
this.format = template.getFormat();
58+
this.hypervisorType = template.getHypervisorType();
5659
}
5760

5861
public TemplateObjectTO(TemplateInfo template) {
@@ -69,6 +72,7 @@ public TemplateObjectTO(TemplateInfo template) {
6972
if (template.getDataStore() != null) {
7073
this.imageDataStore = template.getDataStore().getTO();
7174
}
75+
this.hypervisorType = template.getHypervisorType();
7276
}
7377

7478
@Override
@@ -128,6 +132,11 @@ public DataStoreTO getDataStore() {
128132
return this.imageDataStore;
129133
}
130134

135+
@Override
136+
public Hypervisor.HypervisorType getHypervisorType() {
137+
return this.hypervisorType;
138+
}
139+
131140
public void setDataStore(DataStoreTO store){
132141
this.imageDataStore = store;
133142
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.to;
1818

19+
import com.cloud.hypervisor.Hypervisor;
1920
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
2021

2122
import com.cloud.agent.api.to.DataObjectType;
@@ -41,6 +42,7 @@ public class VolumeObjectTO implements DataTO {
4142
private Long bytesWriteRate;
4243
private Long iopsReadRate;
4344
private Long iopsWriteRate;
45+
private Hypervisor.HypervisorType hypervisorType;
4446

4547
public VolumeObjectTO() {
4648

@@ -67,6 +69,7 @@ public VolumeObjectTO(VolumeInfo volume) {
6769
this.bytesWriteRate = volume.getBytesWriteRate();
6870
this.iopsReadRate = volume.getIopsReadRate();
6971
this.iopsWriteRate = volume.getIopsWriteRate();
72+
this.hypervisorType = volume.getHypervisorType();
7073
}
7174

7275
public String getUuid() {
@@ -87,6 +90,11 @@ public DataStoreTO getDataStore() {
8790
return this.dataStore;
8891
}
8992

93+
@Override
94+
public Hypervisor.HypervisorType getHypervisorType() {
95+
return this.hypervisorType;
96+
}
97+
9098

9199
public void setDataStore(DataStoreTO store){
92100
this.dataStore = store;

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
403403
}
404404
}
405405

406+
@Override
407+
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
408+
return null; //To change body of implemented methods use File | Settings | File Templates.
409+
}
410+
406411
@Override
407412
public Answer backupSnapshot(CopyCommand cmd) {
408413
DataTO srcData = cmd.getSrcTO();

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

Lines changed: 59 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.ejb.Local;
2929
import javax.inject.Inject;
3030

31+
import com.cloud.host.Host;
3132
import org.apache.log4j.Logger;
3233

3334
import org.apache.cloudstack.storage.command.CopyCommand;
@@ -42,7 +43,6 @@
4243
import com.cloud.agent.api.storage.CopyVolumeCommand;
4344
import com.cloud.agent.api.storage.CreateVolumeOVACommand;
4445
import com.cloud.agent.api.storage.PrepareOVAPackingCommand;
45-
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
4646
import com.cloud.agent.api.to.DataObjectType;
4747
import com.cloud.agent.api.to.DataStoreTO;
4848
import com.cloud.agent.api.to.DataTO;
@@ -294,92 +294,82 @@ public int compare(NicTO arg0, NicTO arg1) {
294294
}
295295

296296
@Override @DB
297-
public long getCommandHostDelegation(long hostId, Command cmd) {
297+
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
298298
boolean needDelegation = false;
299299

300-
if(cmd instanceof PrimaryStorageDownloadCommand ||
301-
cmd instanceof BackupSnapshotCommand ||
302-
cmd instanceof CreatePrivateTemplateFromVolumeCommand ||
303-
cmd instanceof CreatePrivateTemplateFromSnapshotCommand ||
304-
cmd instanceof CopyVolumeCommand ||
305-
cmd instanceof CreateVolumeOVACommand ||
306-
cmd instanceof PrepareOVAPackingCommand ||
307-
cmd instanceof CreateVolumeFromSnapshotCommand ||
308-
cmd instanceof CopyCommand) {
309-
if (cmd instanceof CopyCommand) {
310-
CopyCommand cpyCommand = (CopyCommand)cmd;
311-
DataTO srcData = cpyCommand.getSrcTO();
312-
DataStoreTO srcStoreTO = srcData.getDataStore();
313-
DataTO destData = cpyCommand.getDestTO();
314-
DataStoreTO destStoreTO = destData.getDataStore();
315-
316-
if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary &&
317-
srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
318-
needDelegation = false;
319-
} else {
320-
needDelegation = true;
321-
}
300+
if (cmd instanceof CopyCommand) {
301+
CopyCommand cpyCommand = (CopyCommand)cmd;
302+
DataTO srcData = cpyCommand.getSrcTO();
303+
DataStoreTO srcStoreTO = srcData.getDataStore();
304+
DataTO destData = cpyCommand.getDestTO();
305+
DataStoreTO destStoreTO = destData.getDataStore();
306+
307+
if (!(HypervisorType.VMware == srcData.getHypervisorType() ||
308+
HypervisorType.VMware == destData.getHypervisorType()
309+
)) {
310+
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
311+
}
312+
313+
if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary &&
314+
srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
315+
needDelegation = false;
322316
} else {
323317
needDelegation = true;
324318
}
319+
}
325320

321+
if(!needDelegation) {
322+
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
326323
}
327-
/* Fang: remove this before checking in */
328-
// needDelegation = false;
329324

330-
if (cmd instanceof PrepareOVAPackingCommand ||
331-
cmd instanceof CreateVolumeOVACommand ) {
325+
HostVO host = _hostDao.findById(hostId);
326+
long dcId = host.getDataCenterId();
327+
328+
Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
329+
if(cmdTarget != null) {
330+
// TODO, we need to make sure agent is actually connected too
331+
332332
cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
333-
}
334-
if(needDelegation) {
335-
HostVO host = _hostDao.findById(hostId);
336-
assert(host != null);
337-
assert(host.getHypervisorType() == HypervisorType.VMware);
338-
long dcId = host.getDataCenterId();
339-
340-
Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
341-
if(cmdTarget != null) {
342-
// TODO, we need to make sure agent is actually connected too
343-
cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
333+
if (host.getType() == Host.Type.Routing) {
344334
Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
345335
cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
346336
cmd.setContextParam("username", hostDetails.get("username"));
347337
cmd.setContextParam("password", hostDetails.get("password"));
348338
cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
349339
cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
340+
}
350341

351-
CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
352-
_cmdExecLogDao.persist(execLog);
353-
cmd.setContextParam("execid", String.valueOf(execLog.getId()));
354-
355-
if(cmd instanceof BackupSnapshotCommand ||
356-
cmd instanceof CreatePrivateTemplateFromVolumeCommand ||
357-
cmd instanceof CreatePrivateTemplateFromSnapshotCommand ||
358-
cmd instanceof CopyVolumeCommand ||
359-
cmd instanceof CopyCommand ||
360-
cmd instanceof CreateVolumeOVACommand ||
361-
cmd instanceof PrepareOVAPackingCommand ||
362-
cmd instanceof CreateVolumeFromSnapshotCommand) {
363-
364-
String workerName = _vmwareMgr.composeWorkerName();
365-
long checkPointId = 1;
366-
// FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
367-
cmd.setContextParam("worker", workerName);
368-
cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
369-
370-
// some commands use 2 workers
371-
String workerName2 = _vmwareMgr.composeWorkerName();
372-
long checkPointId2 = 1;
373-
// FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
374-
cmd.setContextParam("worker2", workerName2);
375-
cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
376-
}
377-
378-
return cmdTarget.first().getId();
342+
CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
343+
_cmdExecLogDao.persist(execLog);
344+
cmd.setContextParam("execid", String.valueOf(execLog.getId()));
345+
346+
if(cmd instanceof BackupSnapshotCommand ||
347+
cmd instanceof CreatePrivateTemplateFromVolumeCommand ||
348+
cmd instanceof CreatePrivateTemplateFromSnapshotCommand ||
349+
cmd instanceof CopyVolumeCommand ||
350+
cmd instanceof CopyCommand ||
351+
cmd instanceof CreateVolumeOVACommand ||
352+
cmd instanceof PrepareOVAPackingCommand ||
353+
cmd instanceof CreateVolumeFromSnapshotCommand) {
354+
355+
String workerName = _vmwareMgr.composeWorkerName();
356+
long checkPointId = 1;
357+
// FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
358+
cmd.setContextParam("worker", workerName);
359+
cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
360+
361+
// some commands use 2 workers
362+
String workerName2 = _vmwareMgr.composeWorkerName();
363+
long checkPointId2 = 1;
364+
// FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
365+
cmd.setContextParam("worker2", workerName2);
366+
cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
379367
}
380-
}
381368

382-
return hostId;
369+
return new Pair<Boolean, Long>(Boolean.TRUE,cmdTarget.first().getId());
370+
371+
}
372+
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
383373
}
384374

385375
@Override

0 commit comments

Comments
 (0)