use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class Ovm3StorageProcessorTest method copyCommandBogusTest.
/**
* Copy template from secondary to primary template
*
* @throws ConfigurationException
*/
@Test
public void copyCommandBogusTest() throws ConfigurationException {
con = prepare();
VolumeObjectTO src = volume(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
VolumeObjectTO dest = volume(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
CopyCommand copy = new CopyCommand(src, dest, 0, false);
Answer ra = hypervisor.executeRequest(copy);
results.basicBooleanTest(ra.getResult(), false);
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class Ovm3StorageProcessorTest method copyCommandTemplateToVolumeTest.
/**
* Copy template from primary to primary volume
*
* @throws ConfigurationException
*/
@Test
public void copyCommandTemplateToVolumeTest() throws ConfigurationException {
con = prepare();
String voluuid = ovmObject.newUuid();
TemplateObjectTO src = template(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getTemplatesDir());
VolumeObjectTO dest = volume(voluuid, ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
CopyCommand copy = new CopyCommand(src, dest, 0, true);
CopyCmdAnswer ra = (CopyCmdAnswer) hypervisor.executeRequest(copy);
VolumeObjectTO vol = (VolumeObjectTO) ra.getNewData();
results.basicStringTest(vol.getUuid(), voluuid);
results.basicStringTest(vol.getPath(), voluuid);
results.basicBooleanTest(ra.getResult());
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class VMwareGuru method getCommandHostDelegation.
@Override
@DB
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
boolean needDelegation = false;
if (cmd instanceof StorageSubSystemCommand) {
Boolean fullCloneEnabled = VmwareFullClone.value();
StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(fullCloneEnabled);
}
//type is empty, so we need to check the format of volume at first.
if (cmd instanceof CopyCommand) {
CopyCommand cpyCommand = (CopyCommand) cmd;
DataTO srcData = cpyCommand.getSrcTO();
DataStoreTO srcStoreTO = srcData.getDataStore();
DataTO destData = cpyCommand.getDestTO();
DataStoreTO destStoreTO = destData.getDataStore();
boolean inSeq = true;
if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
inSeq = false;
} else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) {
inSeq = false;
} else if (!VmwareFullClone.value()) {
inSeq = false;
}
cpyCommand.setExecuteInSequence(inSeq);
if (srcData.getObjectType() == DataObjectType.VOLUME) {
VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
needDelegation = true;
}
}
if (!needDelegation && !(HypervisorType.VMware == srcData.getHypervisorType() || HypervisorType.VMware == destData.getHypervisorType())) {
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
needDelegation = false;
} else {
needDelegation = true;
}
} else if (cmd instanceof CreateEntityDownloadURLCommand) {
DataTO srcData = ((CreateEntityDownloadURLCommand) cmd).getData();
if ((HypervisorType.VMware == srcData.getHypervisorType())) {
needDelegation = true;
}
if (srcData.getObjectType() == DataObjectType.VOLUME) {
VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
needDelegation = true;
}
}
}
if (!needDelegation) {
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
HostVO host = _hostDao.findById(hostId);
long dcId = host.getDataCenterId();
Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
if (cmdTarget != null) {
// TODO, we need to make sure agent is actually connected too
cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
if (host.getType() == Host.Type.Routing) {
Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
cmd.setContextParam("username", hostDetails.get("username"));
cmd.setContextParam("password", hostDetails.get("password"));
cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
}
CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
_cmdExecLogDao.persist(execLog);
cmd.setContextParam("execid", String.valueOf(execLog.getId()));
cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand || cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand || cmd instanceof CreateVolumeOVACommand || cmd instanceof PrepareOVAPackingCommand || cmd instanceof CreateVolumeFromSnapshotCommand) {
String workerName = _vmwareMgr.composeWorkerName();
long checkPointId = 1;
// FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
cmd.setContextParam("worker", workerName);
cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
// some commands use 2 workers
String workerName2 = _vmwareMgr.composeWorkerName();
long checkPointId2 = 1;
// FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
cmd.setContextParam("worker2", workerName2);
cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
}
return new Pair<Boolean, Long>(Boolean.TRUE, cmdTarget.first().getId());
}
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class NfsSecondaryStorageResource method createTemplateFromSnapshot.
protected Answer createTemplateFromSnapshot(CopyCommand cmd) {
DataTO srcData = cmd.getSrcTO();
DataTO destData = cmd.getDestTO();
DataStoreTO srcDataStore = srcData.getDataStore();
DataStoreTO destDataStore = destData.getDataStore();
if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
if (!(srcDataStore instanceof NfsTO)) {
s_logger.debug("only support nfs storage as src, when create template from snapshot");
return Answer.createUnsupportedCommandAnswer(cmd);
}
if (destDataStore instanceof NfsTO) {
return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) destDataStore);
} else if (destDataStore instanceof SwiftTO) {
//create template on the same data store
CopyCmdAnswer answer = (CopyCmdAnswer) copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) srcDataStore);
if (!answer.getResult()) {
return answer;
}
s_logger.debug("starting copy template to swift");
TemplateObjectTO newTemplate = (TemplateObjectTO) answer.getNewData();
newTemplate.setDataStore(srcDataStore);
CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
Answer result = copyFromNfsToSwift(newCpyCmd);
cleanupStagingNfs(newTemplate);
return result;
} else if (destDataStore instanceof S3TO) {
//create template on the same data store
CopyCmdAnswer answer = (CopyCmdAnswer) copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) srcDataStore);
if (!answer.getResult()) {
return answer;
}
TemplateObjectTO newTemplate = (TemplateObjectTO) answer.getNewData();
newTemplate.setDataStore(srcDataStore);
CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
Answer result = copyFromNfsToS3(newCpyCmd);
cleanupStagingNfs(newTemplate);
return result;
}
}
s_logger.debug("Failed to create template from snapshot");
return new CopyCmdAnswer("Unsupported protocol");
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class LocalNfsSecondaryStorageResourceTest method testExecuteRequest.
@Test
public void testExecuteRequest() throws Exception {
TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
NfsTO cacheStore = Mockito.mock(NfsTO.class);
Mockito.when(cacheStore.getUrl()).thenReturn("nfs://nfs2.lab.vmops.com/export/home/edison/");
SwiftTO swift = Mockito.mock(SwiftTO.class);
Mockito.when(swift.getEndPoint()).thenReturn("https://objects.dreamhost.com/auth");
Mockito.when(swift.getAccount()).thenReturn("cloudstack");
Mockito.when(swift.getUserName()).thenReturn("images");
Mockito.when(swift.getKey()).thenReturn("oxvELQaOD1U5_VyosGfA-wpZ7uBWEff-CUBGCM0u");
Mockito.when(template.getDataStore()).thenReturn(swift);
Mockito.when(template.getPath()).thenReturn("template/1/1/");
Mockito.when(template.isRequiresHvm()).thenReturn(true);
Mockito.when(template.getId()).thenReturn(1L);
Mockito.when(template.getFormat()).thenReturn(Storage.ImageFormat.VHD);
Mockito.when(template.getOrigUrl()).thenReturn("http://nfs1.lab.vmops.com/templates/test.bz2");
Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString());
Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
DownloadCommand cmd = new DownloadCommand(template, 100000L);
cmd.setCacheStore(cacheStore);
DownloadAnswer answer = (DownloadAnswer) resource.executeRequest(cmd);
Assert.assertTrue(answer.getResult());
Mockito.when(template.getPath()).thenReturn(answer.getInstallPath());
Mockito.when(template.getDataStore()).thenReturn(swift);
//download swift:
Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache);
TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class);
Mockito.when(destTemplate.getPath()).thenReturn("template/1/2");
Mockito.when(destTemplate.getDataStore()).thenReturn(cacheStore);
Mockito.when(destTemplate.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
CopyCommand cpyCmd = new CopyCommand(template, destTemplate, 10000, true);
CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) resource.executeRequest(cpyCmd);
Assert.assertTrue(copyCmdAnswer.getResult());
//list template
ListTemplateCommand listCmd = new ListTemplateCommand(swift);
ListTemplateAnswer listAnswer = (ListTemplateAnswer) resource.executeRequest(listCmd);
Assert.assertTrue(listAnswer.getTemplateInfo().size() > 0);
}
Aggregations