use of com.cloud.storage.template.Processor.FormatInfo in project cloudstack by apache.
the class DownloadManagerImpl method postProcessAfterDownloadComplete.
private String postProcessAfterDownloadComplete(DownloadJob dnld, String resourcePath, String templateName, TemplateLocation loc) {
Iterator<Processor> en = _processors.values().iterator();
while (en.hasNext()) {
Processor processor = en.next();
FormatInfo info;
try {
info = processor.process(resourcePath, null, templateName, this._processTimeout);
} catch (InternalErrorException e) {
LOGGER.error("Template process exception ", e);
return e.toString();
}
if (info != null) {
if (!loc.addFormat(info)) {
loc.purge();
return "Unable to install due to invalid file format";
}
dnld.setTemplatesize(info.virtualSize);
dnld.setTemplatePhysicalSize(info.size);
if (info.ovfInformationTO != null) {
dnld.setOvfInformationTO(info.ovfInformationTO);
}
break;
}
}
if (!loc.save()) {
LOGGER.warn("Cleaning up because we're unable to save the formats");
loc.purge();
}
return null;
}
use of com.cloud.storage.template.Processor.FormatInfo in project cosmic by MissionCriticalCloud.
the class TemplateLocation method load.
public boolean load() throws IOException {
try (FileInputStream strm = new FileInputStream(_file)) {
_props.load(strm);
} catch (final IOException e) {
s_logger.warn("Unable to load the template properties", e);
}
for (final ImageFormat format : ImageFormat.values()) {
final String ext = _props.getProperty(format.getFileExtension());
if (ext != null) {
final FormatInfo info = new FormatInfo();
info.format = format;
info.filename = _props.getProperty(format.getFileExtension() + ".filename");
if (info.filename == null) {
continue;
}
info.size = NumbersUtil.parseLong(_props.getProperty(format.getFileExtension() + ".size"), -1);
_props.setProperty("physicalSize", Long.toString(info.size));
info.virtualSize = NumbersUtil.parseLong(_props.getProperty(format.getFileExtension() + ".virtualsize"), -1);
_formats.add(info);
if (!checkFormatValidity(info)) {
_isCorrupted = true;
s_logger.warn("Cleaning up inconsistent information for " + format);
}
}
}
if (_props.getProperty("uniquename") == null || _props.getProperty("virtualsize") == null) {
return false;
}
return (_formats.size() > 0);
}
use of com.cloud.storage.template.Processor.FormatInfo in project cosmic by MissionCriticalCloud.
the class TemplateLocation method save.
public boolean save() {
for (final FormatInfo info : _formats) {
_props.setProperty(info.format.getFileExtension(), "true");
_props.setProperty(info.format.getFileExtension() + ".filename", info.filename);
_props.setProperty(info.format.getFileExtension() + ".size", Long.toString(info.size));
_props.setProperty(info.format.getFileExtension() + ".virtualsize", Long.toString(info.virtualSize));
}
try (FileOutputStream strm = new FileOutputStream(_file)) {
_props.store(strm, "");
} catch (final IOException e) {
s_logger.warn("Unable to save the template properties ", e);
return false;
}
return true;
}
use of com.cloud.storage.template.Processor.FormatInfo in project cosmic by MissionCriticalCloud.
the class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper method execute.
@Override
public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplName = libvirtUtilitiesHelper.generateUuidName();
final String tmplFileName = tmplName + ".qcow2";
KvmStoragePool secondaryPool = null;
KvmStoragePool snapshotPool = null;
final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
try {
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
snapshotPool = storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
secondaryPool = storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl());
final KvmPhysicalDisk snapshot = snapshotPool.getPhysicalDisk(command.getSnapshotName());
final String templatePath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
final StorageLayer storage = libvirtComputingResource.getStorage();
storage.mkdirs(templatePath);
final String tmplPath = templateInstallFolder + File.separator + tmplFileName;
final String createTmplPath = libvirtComputingResource.createTmplPath();
final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout();
final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger);
scriptCommand.add("-t", templatePath);
scriptCommand.add("-n", tmplFileName);
scriptCommand.add("-f", snapshot.getPath());
scriptCommand.execute();
final Processor qcow2Processor = libvirtUtilitiesHelper.buildQcow2Processor(storage);
final FormatInfo info = qcow2Processor.process(templatePath, null, tmplName);
final TemplateLocation loc = libvirtUtilitiesHelper.buildTemplateLocation(storage, templatePath);
loc.create(1, true, tmplName);
loc.addFormat(info);
loc.save();
return new CreatePrivateTemplateAnswer(command, true, "", tmplPath, info.virtualSize, info.size, tmplName, info.format);
} catch (final ConfigurationException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final InternalErrorException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final IOException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final CloudRuntimeException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} finally {
if (secondaryPool != null) {
storagePoolMgr.deleteStoragePool(secondaryPool.getType(), secondaryPool.getUuid());
}
if (snapshotPool != null) {
storagePoolMgr.deleteStoragePool(snapshotPool.getType(), snapshotPool.getUuid());
}
}
}
use of com.cloud.storage.template.Processor.FormatInfo in project cloudstack by apache.
the class TemplateLocation method load.
public boolean load() throws IOException {
try (FileInputStream strm = new FileInputStream(_file)) {
_props.load(strm);
} catch (IOException e) {
s_logger.warn("Unable to load the template properties for '" + _file + "': ", e);
}
for (ImageFormat format : ImageFormat.values()) {
String currentExtension = format.getFileExtension();
String ext = _props.getProperty(currentExtension);
if (ext != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("File extension '" + currentExtension + "' was found in '" + _file + "'.");
}
FormatInfo info = new FormatInfo();
info.format = format;
info.filename = _props.getProperty(currentExtension + ".filename");
if (info.filename == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Property '" + currentExtension + ".filename' was not found in '" + _file + "'. Current format is ignored.");
}
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Property '" + currentExtension + ".filename' was found in '" + _file + "'. Current format will be parsed.");
}
info.size = NumbersUtil.parseLong(_props.getProperty(currentExtension + ".size"), -1);
_props.setProperty("physicalSize", Long.toString(info.size));
info.virtualSize = NumbersUtil.parseLong(_props.getProperty(currentExtension + ".virtualsize"), -1);
_formats.add(info);
if (!checkFormatValidity(info)) {
_isCorrupted = true;
s_logger.warn("Cleaning up inconsistent information for " + format);
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Format extension '" + currentExtension + "' wasn't found in '" + _file + "'.");
}
}
}
if (_props.getProperty("uniquename") == null || _props.getProperty("virtualsize") == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Property 'uniquename' or 'virtualsize' weren't found in '" + _file + "'. Loading failed.");
}
return false;
}
return (_formats.size() > 0);
}
Aggregations