use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method copyVolumeFromImageCacheToPrimary.
@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
final int wait = cmd.getWait();
final VolumeObjectTO srcVolume = (VolumeObjectTO) srcData;
final VolumeObjectTO destVolume = (VolumeObjectTO) destData;
final DataStoreTO srcStore = srcVolume.getDataStore();
if (srcStore instanceof NfsTO) {
final NfsTO nfsStore = (NfsTO) srcStore;
try {
final SR primaryStoragePool = hypervisorResource.getStorageRepository(conn, destVolume.getDataStore().getUuid());
final String srUuid = primaryStoragePool.getUuid(conn);
final URI uri = new URI(nfsStore.getUrl());
final String volumePath = uri.getHost() + ":" + uri.getPath() + nfsStore.getPathSeparator() + srcVolume.getPath();
final String uuid = copy_vhd_from_secondarystorage(conn, volumePath, srUuid, wait);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(uuid);
newVol.setSize(srcVolume.getSize());
return new CopyCmdAnswer(newVol);
} catch (final Exception e) {
final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
s_logger.warn(msg, e);
return new CopyCmdAnswer(e.toString());
}
}
s_logger.debug("unsupported protocol");
return new CopyCmdAnswer("unsupported protocol");
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method forgetObject.
@Override
public Answer forgetObject(final ForgetObjectCommand cmd) {
try {
final Connection conn = hypervisorResource.getConnection();
final DataTO data = cmd.getDataTO();
final VDI vdi = VDI.getByUuid(conn, data.getPath());
vdi.forget(conn);
return new IntroduceObjectAnswer(cmd.getDataTO());
} catch (final Exception e) {
s_logger.debug("Failed to introduce object", e);
return new Answer(cmd, false, e.toString());
}
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class Xenserver625StorageProcessor method createTemplateFromSnapshot.
@Override
public Answer createTemplateFromSnapshot(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof NfsTO) {
return createTemplateFromSnapshot2(cmd);
}
final int wait = cmd.getWait();
final SnapshotObjectTO srcObj = (SnapshotObjectTO) srcData;
final TemplateObjectTO destObj = (TemplateObjectTO) destData;
final NfsTO srcStore = (NfsTO) srcObj.getDataStore();
final NfsTO destStore = (NfsTO) destObj.getDataStore();
URI srcUri = null;
URI destUri = null;
try {
srcUri = new URI(srcStore.getUrl());
destUri = new URI(destStore.getUrl());
} catch (final Exception e) {
s_logger.debug("incorrect url", e);
return new CopyCmdAnswer("incorrect url" + e.toString());
}
final String srcPath = srcObj.getPath();
final int index = srcPath.lastIndexOf("/");
final String srcDir = srcPath.substring(0, index);
final String destDir = destObj.getPath();
SR srcSr = null;
SR destSr = null;
VDI destVdi = null;
boolean result = false;
try {
srcSr = createFileSr(conn, srcUri.getHost() + ":" + srcUri.getPath(), srcDir);
final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes());
mountNfs(conn, destUri.getHost() + ":" + destUri.getPath(), localDir);
makeDirectory(conn, localDir + "/" + destDir);
destSr = createFileSR(conn, localDir + "/" + destDir);
final String nameLabel = "cloud-" + UUID.randomUUID().toString();
final String[] parents = srcObj.getParents();
final List<VDI> snapshotChains = new ArrayList<>();
if (parents != null) {
for (int i = 0; i < parents.length; i++) {
final String snChainPath = parents[i];
final String uuid = getSnapshotUuid(snChainPath);
final VDI chain = VDI.getByUuid(conn, uuid);
snapshotChains.add(chain);
}
}
final String snapshotUuid = getSnapshotUuid(srcPath);
final VDI snapshotVdi = VDI.getByUuid(conn, snapshotUuid);
snapshotChains.add(snapshotVdi);
final long templateVirtualSize = snapshotChains.get(0).getVirtualSize(conn);
destVdi = createVdi(conn, nameLabel, destSr, templateVirtualSize);
final String destVdiUuid = destVdi.getUuid(conn);
for (final VDI snapChain : snapshotChains) {
final Task task = snapChain.copyAsync(conn, null, null, destVdi);
// poll every 1 seconds ,
hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
hypervisorResource.checkForSuccess(conn, task);
task.destroy(conn);
}
destVdi = VDI.getByUuid(conn, destVdiUuid);
// scan makes XenServer pick up VDI physicalSize
destSr.scan(conn);
final String templateUuid = destVdi.getUuid(conn);
final String templateFilename = templateUuid + ".vhd";
final long virtualSize = destVdi.getVirtualSize(conn);
final long physicalSize = destVdi.getPhysicalUtilisation(conn);
String templatePath = destNfsPath + "/" + destDir;
templatePath = templatePath.replaceAll("//", "/");
result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, destObj.getId());
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir");
}
final TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(destDir + "/" + templateFilename);
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(destVdi.getVirtualSize(conn));
newTemplate.setPhysicalSize(destVdi.getPhysicalUtilisation(conn));
newTemplate.setName(destVdiUuid);
result = true;
return new CopyCmdAnswer(newTemplate);
} catch (final Exception e) {
s_logger.error("Failed create template from snapshot", e);
return new CopyCmdAnswer("Failed create template from snapshot " + e.toString());
} finally {
if (!result) {
if (destVdi != null) {
try {
destVdi.destroy(conn);
} catch (final Exception e) {
s_logger.debug("Clean up left over on dest storage failed: ", e);
}
}
}
if (srcSr != null) {
hypervisorResource.removeSR(conn, srcSr);
}
if (destSr != null) {
hypervisorResource.removeSR(conn, destSr);
}
}
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class Xenserver625StorageProcessor method createVolumeFromSnapshot.
@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final DataTO srcData = cmd.getSrcTO();
final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
final DataTO destData = cmd.getDestTO();
final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
final VolumeObjectTO volume = (VolumeObjectTO) destData;
final DataStoreTO imageStore = srcData.getDataStore();
if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof PrimaryDataStoreTO) {
return createVolumeFromSnapshot2(cmd);
}
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
final NfsTO nfsImageStore = (NfsTO) imageStore;
final String primaryStorageNameLabel = pool.getUuid();
final String secondaryStorageUrl = nfsImageStore.getUrl();
final int wait = cmd.getWait();
boolean result = false;
// Generic error message.
String details = null;
String volumeUUID = null;
if (secondaryStorageUrl == null) {
details += " because the URL passed: " + secondaryStorageUrl + " is invalid.";
return new CopyCmdAnswer(details);
}
SR srcSr = null;
VDI destVdi = null;
try {
final SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
if (primaryStorageSR == null) {
throw new InternalErrorException("Could not create volume from snapshot because the primary Storage SR could not be created from the name label: " + primaryStorageNameLabel);
}
final String nameLabel = "cloud-" + UUID.randomUUID().toString();
destVdi = createVdi(conn, nameLabel, primaryStorageSR, volume.getSize());
volumeUUID = destVdi.getUuid(conn);
final String snapshotInstallPath = snapshot.getPath();
final int index = snapshotInstallPath.lastIndexOf(File.separator);
final String snapshotDirectory = snapshotInstallPath.substring(0, index);
final String snapshotUuid = getSnapshotUuid(snapshotInstallPath);
final URI uri = new URI(secondaryStorageUrl);
srcSr = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), snapshotDirectory);
final String[] parents = snapshot.getParents();
final List<VDI> snapshotChains = new ArrayList<>();
if (parents != null) {
for (int i = 0; i < parents.length; i++) {
final String snChainPath = parents[i];
final String uuid = getSnapshotUuid(snChainPath);
final VDI chain = VDI.getByUuid(conn, uuid);
snapshotChains.add(chain);
}
}
final VDI snapshotVdi = VDI.getByUuid(conn, snapshotUuid);
snapshotChains.add(snapshotVdi);
for (final VDI snapChain : snapshotChains) {
final Task task = snapChain.copyAsync(conn, null, null, destVdi);
// poll every 1 seconds ,
hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
hypervisorResource.checkForSuccess(conn, task);
task.destroy(conn);
}
result = true;
destVdi = VDI.getByUuid(conn, volumeUUID);
final VDI.Record vdir = destVdi.getRecord(conn);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(volumeUUID);
newVol.setSize(vdir.virtualSize);
return new CopyCmdAnswer(newVol);
} catch (final Types.XenAPIException e) {
details += " due to " + e.toString();
s_logger.warn(details, e);
} catch (final Exception e) {
details += " due to " + e.getMessage();
s_logger.warn(details, e);
} finally {
if (srcSr != null) {
hypervisorResource.removeSR(conn, srcSr);
}
if (!result && destVdi != null) {
try {
destVdi.destroy(conn);
} catch (final Exception e) {
s_logger.debug("destroy dest vdi failed", e);
}
}
}
if (!result) {
// Is this logged at a higher level?
s_logger.error(details);
}
// In all cases return something.
return new CopyCmdAnswer(details);
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerGuru method getCommandHostDelegation.
@Override
public Pair<Boolean, Long> getCommandHostDelegation(final long hostId, final Command cmd) {
LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
if (cmd instanceof StorageSubSystemCommand) {
final StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(true);
}
if (cmd instanceof CopyCommand) {
final CopyCommand cpyCommand = (CopyCommand) cmd;
final DataTO srcData = cpyCommand.getSrcTO();
final DataTO destData = cpyCommand.getDestTO();
if (srcData.getHypervisorType() == HypervisorType.XenServer && srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
final DataStoreTO srcStore = srcData.getDataStore();
final DataStoreTO destStore = destData.getDataStore();
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
HostVO host = hostDao.findById(hostId);
final EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
host = hostDao.findById(ep.getId());
hostDao.loadDetails(host);
final String hypervisorVersion = host.getHypervisorVersion();
final String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0")) {
if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") && !(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
return new Pair<>(Boolean.TRUE, new Long(ep.getId()));
}
}
}
}
}
return new Pair<>(Boolean.FALSE, new Long(hostId));
}
Aggregations