List of usage examples for javax.naming ConfigurationException toString
public String toString()
From source file:org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource.java
protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) { String srcMountPoint = getRootDir(srcDataStore.getUrl(), _nfsVersion); String snapshotPath = srcData.getPath(); int index = snapshotPath.lastIndexOf("/"); String snapshotName = snapshotPath.substring(index + 1); if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) { snapshotName = snapshotName + ".vhd"; }/* w w w .j a v a 2s . c o m*/ snapshotPath = snapshotPath.substring(0, index); snapshotPath = srcMountPoint + File.separator + snapshotPath; String destMountPoint = getRootDir(destDataStore.getUrl(), _nfsVersion); String destPath = destMountPoint + File.separator + destData.getPath(); String errMsg = null; try { _storage.mkdir(destPath); String templateUuid = UUID.randomUUID().toString(); String templateName = templateUuid + ".vhd"; Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger); command.add("-p", snapshotPath); command.add("-s", snapshotName); command.add("-n", templateName); command.add("-t", destPath); String result = command.execute(); if (result != null && !result.equalsIgnoreCase("")) { return new CopyCmdAnswer(result); } Map<String, Object> params = new HashMap<String, Object>(); params.put(StorageLayer.InstanceConfigKey, _storage); Processor processor = new VhdProcessor(); processor.configure("Vhd Processor", params); FormatInfo info = processor.process(destPath, null, templateUuid); TemplateLocation loc = new TemplateLocation(_storage, destPath); loc.create(1, true, templateUuid); loc.addFormat(info); loc.save(); TemplateProp prop = loc.getTemplateInfo(); 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 (ConfigurationException e) { s_logger.debug("Failed to create template from snapshot: " + e.toString()); errMsg = e.toString(); } catch (InternalErrorException e) { s_logger.debug("Failed to create template from snapshot: " + e.toString()); errMsg = e.toString(); } catch (IOException e) { s_logger.debug("Failed to create template from snapshot: " + e.toString()); errMsg = e.toString(); } return new CopyCmdAnswer(errMsg); }
From source file:org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource.java
protected Answer copySnapshotToTemplateFromNfsToNfs(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) { if (srcData.getHypervisorType() == HypervisorType.XenServer) { return copySnapshotToTemplateFromNfsToNfsXenserver(cmd, srcData, srcDataStore, destData, destDataStore); } else if (srcData.getHypervisorType() == HypervisorType.KVM) { File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl(), _nfsVersion); File destFile = getFile(destData.getPath(), destDataStore.getUrl(), _nfsVersion); VolumeObjectTO volumeObjectTO = srcData.getVolume(); ImageFormat srcFormat = null;//w w w . j a va2 s . c om //TODO: the image format should be stored in snapshot table, instead of getting from volume if (volumeObjectTO != null) { srcFormat = volumeObjectTO.getFormat(); } else { srcFormat = ImageFormat.QCOW2; } // get snapshot file name String templateName = srcFile.getName(); // add kvm file extension for copied template name String fileName = templateName + "." + srcFormat.getFileExtension(); String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName; s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template " + destFileFullPath); Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath); String metaFileName = destFile.getAbsolutePath() + File.separator + _tmpltpp; File metaFile = new File(metaFileName); try { _storage.create(destFile.getAbsolutePath(), _tmpltpp); try ( // generate template.properties file FileWriter writer = new FileWriter(metaFile); BufferedWriter bufferWriter = new BufferedWriter(writer);) { // KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need // to send template name back. bufferWriter.write("uniquename=" + destData.getName()); bufferWriter.write("\n"); bufferWriter.write("filename=" + fileName); bufferWriter.write("\n"); long size = _storage.getSize(destFileFullPath); bufferWriter.write("size=" + size); /** * Snapshots might be in either QCOW2 or RAW image format * * For example RBD snapshots are in RAW format */ Processor processor = null; if (srcFormat == ImageFormat.QCOW2) { processor = new QCOW2Processor(); } else if (srcFormat == ImageFormat.RAW) { processor = new RawImageProcessor(); } else { throw new ConfigurationException("Unknown image format " + srcFormat.toString()); } Map<String, Object> params = new HashMap<String, Object>(); params.put(StorageLayer.InstanceConfigKey, _storage); processor.configure("template processor", params); String destPath = destFile.getAbsolutePath(); FormatInfo info = processor.process(destPath, null, templateName); TemplateLocation loc = new TemplateLocation(_storage, destPath); loc.create(1, true, destData.getName()); loc.addFormat(info); loc.save(); TemplateProp prop = loc.getTemplateInfo(); TemplateObjectTO newTemplate = new TemplateObjectTO(); newTemplate.setPath(destData.getPath() + File.separator + fileName); newTemplate.setFormat(srcFormat); newTemplate.setSize(prop.getSize()); newTemplate.setPhysicalSize(prop.getPhysicalSize()); return new CopyCmdAnswer(newTemplate); } catch (ConfigurationException e) { s_logger.debug("Failed to create template:" + e.toString()); return new CopyCmdAnswer(e.toString()); } catch (InternalErrorException e) { s_logger.debug("Failed to create template:" + e.toString()); return new CopyCmdAnswer(e.toString()); } } catch (IOException e) { s_logger.debug("Failed to create template:" + e.toString()); return new CopyCmdAnswer(e.toString()); } } return new CopyCmdAnswer(""); }