use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.
the class NfsSecondaryStorageResource method s3ListVolume.
Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
String bucket = s3.getBucketName();
// List the objects in the source directory on S3
final List<S3ObjectSummary> objectSummaries = S3Utils.listDirectory(s3, bucket, VOLUME_ROOT_DIR);
if (objectSummaries == null) {
return null;
}
Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
for (S3ObjectSummary objectSummary : objectSummaries) {
String key = objectSummary.getKey();
// String installPath = StringUtils.substringBeforeLast(key,
// S3Utils.SEPARATOR);
Long id = determineS3VolumeIdFromKey(key);
// TODO: how to get volume template name
TemplateProp tInfo = new TemplateProp(id.toString(), key, objectSummary.getSize(), objectSummary.getSize(), true, false);
tmpltInfos.put(id, tInfo);
}
return tmpltInfos;
}
use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.
the class NfsSecondaryStorageResource method execute.
private Answer execute(ListVolumeCommand cmd) {
if (!_inSystemVM) {
return new ListVolumeAnswer(cmd.getSecUrl(), null);
}
DataStoreTO store = cmd.getDataStore();
if (store instanceof NfsTO) {
String root = getRootDir(cmd.getSecUrl(), _nfsVersion);
Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
} else if (store instanceof S3TO) {
S3TO s3 = (S3TO) store;
Map<Long, TemplateProp> templateInfos = s3ListVolume(s3);
return new ListVolumeAnswer(s3.getBucketName(), templateInfos);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + store);
}
}
use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.
the class DownloadManagerImpl method gatherTemplateInfo.
@Override
public Map<String, TemplateProp> gatherTemplateInfo(String rootDir) {
Map<String, TemplateProp> result = new HashMap<String, TemplateProp>();
String templateDir = rootDir + File.separator + _templateDir;
if (!_storage.exists(templateDir)) {
_storage.mkdirs(templateDir);
}
List<String> publicTmplts = listTemplates(templateDir);
for (String tmplt : publicTmplts) {
String path = tmplt.substring(0, tmplt.lastIndexOf(File.separator));
TemplateLocation loc = new TemplateLocation(_storage, path);
try {
if (!loc.load()) {
s_logger.warn("Post download installation was not completed for " + path);
// loc.purge();
_storage.cleanup(path, templateDir);
continue;
}
} catch (IOException e) {
s_logger.warn("Unable to load template location " + path, e);
continue;
}
TemplateProp tInfo = loc.getTemplateInfo();
if ((tInfo.getSize() == tInfo.getPhysicalSize()) && (tInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) {
try {
Processor processor = _processors.get("OVA Processor");
OVAProcessor vmdkProcessor = (OVAProcessor) processor;
long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.getInstallPath().substring(tInfo.getInstallPath().lastIndexOf(File.separator) + 1));
tInfo.setSize(vSize);
loc.updateVirtualSize(vSize);
loc.save();
} catch (Exception e) {
s_logger.error("Unable to get the virtual size of the template: " + tInfo.getInstallPath() + " due to " + e.getMessage());
}
}
result.put(tInfo.getTemplateName(), tInfo);
s_logger.debug("Added template name: " + tInfo.getTemplateName() + ", path: " + tmplt);
}
/*
for (String tmplt : isoTmplts) {
String tmp[];
tmp = tmplt.split("/");
String tmpltName = tmp[tmp.length - 2];
tmplt = tmplt.substring(tmplt.lastIndexOf("iso/"));
TemplateInfo tInfo = new TemplateInfo(tmpltName, tmplt, false);
s_logger.debug("Added iso template name: " + tmpltName + ", path: " + tmplt);
result.put(tmpltName, tInfo);
}
*/
return result;
}
use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.
the class NfsSecondaryStorageResource method execute.
private Answer execute(ListTemplateCommand cmd) {
if (!_inSystemVM) {
return new ListTemplateAnswer(null, null);
}
DataStoreTO store = cmd.getDataStore();
if (store instanceof NfsTO) {
NfsTO nfs = (NfsTO) store;
String secUrl = nfs.getUrl();
String root = getRootDir(secUrl, cmd.getNfsVersion());
Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
return new ListTemplateAnswer(secUrl, templateInfos);
} else if (store instanceof SwiftTO) {
SwiftTO swift = (SwiftTO) store;
Map<String, TemplateProp> templateInfos = swiftListTemplate(swift);
return new ListTemplateAnswer(swift.toString(), templateInfos);
} else if (store instanceof S3TO) {
S3TO s3 = (S3TO) store;
Map<String, TemplateProp> templateInfos = s3ListTemplate(s3);
return new ListTemplateAnswer(s3.getBucketName(), templateInfos);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + store);
}
}
use of com.cloud.storage.template.TemplateProp in project cloudstack by apache.
the class NfsSecondaryStorageResource method swiftListTemplate.
Map<String, TemplateProp> swiftListTemplate(SwiftTO swift) {
String[] containers = SwiftUtil.list(swift, "", null);
if (containers == null) {
return null;
}
Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>();
for (String container : containers) {
if (container.startsWith("T-")) {
String[] files = SwiftUtil.list(swift, container, _tmpltpp);
if (files.length != 1) {
continue;
}
try {
File tempFile = File.createTempFile("template", ".tmp");
File tmpFile = SwiftUtil.getObject(swift, tempFile, container + File.separator + _tmpltpp);
if (tmpFile == null) {
continue;
}
try (FileReader fr = new FileReader(tmpFile);
BufferedReader brf = new BufferedReader(fr)) {
String line = null;
String uniqName = null;
Long size = null;
Long physicalSize = null;
String name = null;
while ((line = brf.readLine()) != null) {
if (line.startsWith("uniquename=")) {
uniqName = line.split("=")[1];
} else if (line.startsWith("size=")) {
physicalSize = Long.parseLong(line.split("=")[1]);
} else if (line.startsWith("virtualsize=")) {
size = Long.parseLong(line.split("=")[1]);
} else if (line.startsWith("filename=")) {
name = line.split("=")[1];
}
}
//fallback
if (size == null) {
size = physicalSize;
}
tempFile.delete();
if (uniqName != null) {
TemplateProp prop = new TemplateProp(uniqName, container + File.separator + name, size, physicalSize, true, false);
tmpltInfos.put(uniqName, prop);
}
} catch (IOException ex) {
s_logger.debug("swiftListTemplate:Exception:" + ex.getMessage());
continue;
}
} catch (IOException e) {
s_logger.debug("Failed to create templ file:" + e.toString());
continue;
} catch (Exception e) {
s_logger.debug("Failed to get properties: " + e.toString());
continue;
}
}
}
return tmpltInfos;
}
Aggregations