use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testStartCommandFailedConnect.
@Test
public void testStartCommandFailedConnect() {
final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
final Host host = Mockito.mock(Host.class);
final boolean executeInSequence = false;
final StartCommand command = new StartCommand(vmSpec, host, executeInSequence);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final LibvirtVmDef vmDef = Mockito.mock(LibvirtVmDef.class);
final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[] { nic };
final String vmName = "Test";
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachineType.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
when(this.libvirtComputingResource.createVmFromSpec(vmSpec)).thenReturn(vmDef);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
doNothing().when(this.libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
fail(e.getMessage());
} catch (final URISyntaxException e) {
fail(e.getMessage());
}
when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.
protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(final CopyCommand cmd, final SnapshotObjectTO srcData, final NfsTO srcDataStore, final TemplateObjectTO destData, final NfsTO destDataStore) {
final String srcMountPoint = getRootDir(srcDataStore.getUrl());
String snapshotPath = srcData.getPath();
final int index = snapshotPath.lastIndexOf("/");
String snapshotName = snapshotPath.substring(index + 1);
if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
snapshotName = snapshotName + ".vhd";
}
snapshotPath = snapshotPath.substring(0, index);
snapshotPath = srcMountPoint + File.separator + snapshotPath;
final String destMountPoint = getRootDir(destDataStore.getUrl());
final String destPath = destMountPoint + File.separator + destData.getPath();
String errMsg = null;
try {
this._storage.mkdir(destPath);
final String templateUuid = UUID.randomUUID().toString();
final String templateName = templateUuid + ".vhd";
final Script command = new Script(this.createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
command.add("-p", snapshotPath);
command.add("-s", snapshotName);
command.add("-n", templateName);
command.add("-t", destPath);
final String result = command.execute();
if (result != null && !result.equalsIgnoreCase("")) {
return new CopyCmdAnswer(result);
}
final Map<String, Object> params = new HashMap<>();
params.put(StorageLayer.InstanceConfigKey, this._storage);
final Processor processor = new VhdProcessor();
processor.configure("Vhd Processor", params);
final TemplateFormatInfo info = processor.process(destPath, null, templateUuid);
final TemplateLocation loc = new TemplateLocation(this._storage, destPath);
loc.create(1, true, templateUuid);
loc.addFormat(info);
loc.save();
final TemplateProp prop = loc.getTemplateInfo();
final TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(destData.getPath() + File.separator + templateName);
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(prop.getSize());
newTemplate.setPhysicalSize(prop.getPhysicalSize());
newTemplate.setName(templateUuid);
return new CopyCmdAnswer(newTemplate);
} catch (final ConfigurationException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
} catch (final InternalErrorException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
} catch (final IOException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
}
return new CopyCmdAnswer(errMsg);
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class VhdProcessor method process.
@Override
public TemplateFormatInfo process(final String templatePath, final ImageFormat format, final String templateName) throws InternalErrorException {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to VHD.");
return null;
}
final String vhdPath = templatePath + File.separator + templateName + "." + ImageFormat.VHD.toString().toLowerCase();
if (!this._storage.exists(vhdPath)) {
s_logger.debug("Unable to find the vhd file: " + vhdPath);
return null;
}
final File vhdFile = this._storage.getFile(vhdPath);
final TemplateFormatInfo info = new TemplateFormatInfo();
info.format = ImageFormat.VHD;
info.filename = templateName + "." + ImageFormat.VHD.toString().toLowerCase();
info.size = this._storage.getSize(vhdPath);
try {
info.virtualSize = getTemplateVirtualSize(vhdFile);
} catch (final IOException e) {
s_logger.error("Unable to get the virtual size for " + vhdPath);
throw new InternalErrorException("unable to get virtual size from vhd file");
}
return info;
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class QCOW2Processor method process.
@Override
public TemplateFormatInfo process(final String templatePath, final ImageFormat format, final String templateName) throws InternalErrorException {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to QCOW2.");
return null;
}
final String qcow2Path = templatePath + File.separator + templateName + "." + ImageFormat.QCOW2.toString().toLowerCase();
if (!this._storage.exists(qcow2Path)) {
s_logger.debug("Unable to find the qcow2 file: " + qcow2Path);
return null;
}
final TemplateFormatInfo info = new TemplateFormatInfo();
info.format = ImageFormat.QCOW2;
info.filename = templateName + "." + ImageFormat.QCOW2.toString().toLowerCase();
final File qcow2File = this._storage.getFile(qcow2Path);
info.size = this._storage.getSize(qcow2Path);
try {
info.virtualSize = getTemplateVirtualSize(qcow2File);
} catch (final IOException e) {
s_logger.error("Unable to get virtual size from " + qcow2File.getName());
throw new InternalErrorException("unable to get virtual size from qcow2 file");
}
return info;
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method attachOrDetachDisk.
private synchronized String attachOrDetachDisk(final Connect conn, final boolean attach, final String vmName, final KvmPhysicalDisk attachingDisk, final int devId, final DiskControllerType diskControllerType, final ImageFormat diskFormat, final String serial, final VolumeObjectTO volumeObjectTO) throws LibvirtException, InternalErrorException {
final List<LibvirtDiskDef> disks;
Domain dm = null;
LibvirtDiskDef diskdef = null;
final KvmStoragePool attachingPool = attachingDisk.getPool();
try {
dm = conn.domainLookupByName(vmName);
final LibvirtDomainXmlParser parser = new LibvirtDomainXmlParser();
final String domXml = dm.getXMLDesc(0);
parser.parseDomainXml(domXml);
disks = parser.getDisks();
if (!attach) {
for (final LibvirtDiskDef disk : disks) {
final String file = disk.getDiskPath();
if (file != null && file.equalsIgnoreCase(attachingDisk.getPath())) {
diskdef = disk;
break;
}
}
if (diskdef == null) {
throw new InternalErrorException("disk: " + attachingDisk.getPath() + " is not attached before");
}
} else {
diskdef = new LibvirtDiskDef();
if (diskControllerType == DiskControllerType.SCSI) {
diskdef.setQemuDriver(true);
diskdef.setDiscard(LibvirtDiskDef.DiscardType.UNMAP);
}
diskdef.setSerial(serial);
diskdef.setDeviceId(devId);
Optional.ofNullable(volumeObjectTO.getBytesReadRate()).filter(bps -> bps > 0).ifPresent(diskdef::setBytesReadRate);
Optional.ofNullable(volumeObjectTO.getBytesWriteRate()).filter(bps -> bps > 0).ifPresent(diskdef::setBytesWriteRate);
if (volumeObjectTO.getIopsTotalRate() == null) {
Optional.ofNullable(volumeObjectTO.getIopsReadRate()).filter(iops -> iops > 0).ifPresent(diskdef::setIopsReadRate);
Optional.ofNullable(volumeObjectTO.getIopsWriteRate()).filter(iops -> iops > 0).ifPresent(diskdef::setIopsWriteRate);
} else {
Optional.ofNullable(volumeObjectTO.getIopsTotalRate()).filter(iops -> iops > 0).ifPresent(diskdef::setIopsTotalRate);
}
if (attachingPool.getType() == StoragePoolType.RBD) {
diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), attachingPool.getUuid(), devId, diskControllerType, LibvirtDiskDef.DiskProtocol.RBD, ImageFormat.RAW);
} else if (attachingPool.getType() == StoragePoolType.Gluster) {
final String mountpoint = attachingPool.getLocalPath();
final String path = attachingDisk.getPath();
final String glusterVolume = attachingPool.getSourceDir().replace("/", "");
diskdef.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), attachingPool.getSourceHost(), attachingPool.getSourcePort(), null, null, devId, diskControllerType, LibvirtDiskDef.DiskProtocol.GLUSTER, ImageFormat.QCOW2);
} else if (attachingPool.getType() == StoragePoolType.NetworkFilesystem) {
diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, diskControllerType, diskFormat);
} else if (attachingPool.getType() == StoragePoolType.LVM) {
diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, diskControllerType);
}
}
final String xml = diskdef.toString();
return attachOrDetachDevice(conn, attach, vmName, xml);
} finally {
if (dm != null) {
dm.free();
}
}
}
Aggregations