public static String putObject(SwiftClientCfg cfg, File srcFile, String container, String fileName) { if (fileName == null) { fileName = srcFile.getName(); } Script command = new Script("/bin/bash", logger); command.add("-c"); command.add(String.format(CD_SRC, srcFile.getParent())+getUploadObjectCommand(cfg, getSwiftCLIPath(), container,fileName, srcFile.length())); OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); String result = command.execute(parser); if (result != null) { throw new CloudRuntimeException("Failed to upload file: " + result); } if (parser.getLines() != null) { String[] lines = parser.getLines().split("\\n"); for (String line : lines) { if (line.contains("Errno") || line.contains("failed") || line.contains("not found")) { throw new CloudRuntimeException("Failed to upload file: " + Arrays.toString(lines)); } } } return container + File.separator + srcFile.getName(); }
public static String[] list(SwiftClientCfg swift, String container, String rFilename) { StringBuilder swiftCmdBuilder = new StringBuilder(); swiftCmdBuilder.append(getSwiftContainerCmd(swift, getSwiftCLIPath(), "list", container)); if (rFilename != null) { swiftCmdBuilder.append(" -p "); swiftCmdBuilder.append(rFilename); } Script command = new Script("/bin/bash", logger); command.add("-c"); command.add(swiftCmdBuilder.toString()); OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); String result = command.execute(parser); if (result == null && parser.getLines() != null && !parser.getLines().equalsIgnoreCase("")) { return parser.getLines().split("\\n"); } else { if (result != null) { String errMsg = "swiftList failed , err=" + result; logger.debug("Failed to list " + errMsg); } else { String errMsg = "swiftList failed, no lines returns"; logger.debug("Failed to list " + errMsg); } } return new String[0]; }
command.add(getSwiftObjectCmd(cfg, getSwiftCLIPath(), "download", container, srcPath)+" -o " + destFilePath);
public static boolean deleteObject(SwiftClientCfg cfg, String path) { Script command = new Script("/bin/bash", logger); command.add("-c"); String[] paths = splitSwiftPath(path); if (paths == null) { return false; } String container = paths[0]; String objectName = paths[1]; command.add(getSwiftObjectCmd(cfg, getSwiftCLIPath(), "delete", container, objectName)); OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); command.execute(parser); return true; }
public static boolean postMeta(SwiftClientCfg cfg, String container, String object, Map<String, String> metas) { Script command = new Script("/bin/bash", logger); command.add("-c"); command.add(getSwiftObjectCmd(cfg, getSwiftCLIPath(),"post", container, object) + getMeta(metas)); OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); String result = command.execute(parser); if (result != null) { throw new CloudRuntimeException("Failed to post meta" + result); } return true; }