use of org.javaswift.joss.exception.CommandException in project alluxio by Alluxio.
the class SwiftUnderFileSystem method copyObject.
@Override
protected boolean copyObject(String source, String destination) {
LOG.debug("copy from {} to {}", source, destination);
// Retry copy for a few times, in case some Swift internal errors happened during copy.
for (int i = 0; i < NUM_RETRIES; i++) {
try {
Container container = mAccount.getContainer(mContainerName);
container.getObject(source).copyObject(container, container.getObject(destination));
return true;
} catch (CommandException e) {
LOG.error("Source path {} does not exist", source);
return false;
} catch (Exception e) {
LOG.error("Failed to copy file {} to {}", source, destination, e.getMessage());
if (i != NUM_RETRIES - 1) {
LOG.error("Retrying copying file {} to {}", source, destination);
}
}
}
LOG.error("Failed to copy file {} to {}, after {} retries", source, destination, NUM_RETRIES);
return false;
}
use of org.javaswift.joss.exception.CommandException in project alluxio by Alluxio.
the class SwiftUnderFileSystem method createEmptyObject.
@Override
protected boolean createEmptyObject(String key) {
try {
Container container = mAccount.getContainer(mContainerName);
StoredObject object = container.getObject(key);
object.uploadObject(new byte[0]);
return true;
} catch (CommandException e) {
LOG.error("Failed to create object: {}", key, e);
return false;
}
}
use of org.javaswift.joss.exception.CommandException in project alluxio by Alluxio.
the class SwiftUnderFileSystem method deleteObject.
@Override
protected boolean deleteObject(String path) throws IOException {
try {
Container container = mAccount.getContainer(mContainerName);
StoredObject object = container.getObject(path);
if (object != null) {
object.delete();
return true;
}
} catch (CommandException e) {
LOG.debug("Object {} not found", path);
}
return false;
}
use of org.javaswift.joss.exception.CommandException in project stocator by SparkTC.
the class PasswordScopeAccessProvider method authenticate.
/**
* Authentication logic
*
* @return Access JOSS access object
*/
@Override
public Access authenticate() {
try {
JSONObject user = new JSONObject();
user.put("id", mUserId);
user.put("password", mPassword);
JSONObject password = new JSONObject();
password.put("user", user);
JSONArray methods = new JSONArray();
methods.add("password");
JSONObject identity = new JSONObject();
identity.put("methods", methods);
identity.put("password", password);
JSONObject project = new JSONObject();
project.put("id", mProjectId);
JSONObject scope = new JSONObject();
scope.put("project", project);
JSONObject auth = new JSONObject();
auth.put("identity", identity);
auth.put("scope", scope);
JSONObject requestBody = new JSONObject();
requestBody.put("auth", auth);
HttpURLConnection connection = (HttpURLConnection) new URL(mAuthUrl).openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
OutputStream output = connection.getOutputStream();
output.write(requestBody.toString().getBytes());
HttpStatusChecker.verifyCode(STATUS_CHECKERS, connection.getResponseCode());
final String res;
try (final BufferedReader bufReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
res = bufReader.readLine();
}
JSONParser parser = new JSONParser();
JSONObject jsonResponse = (JSONObject) parser.parse(res);
String token = connection.getHeaderField("X-Subject-Token");
PasswordScopeAccess access = new PasswordScopeAccess(jsonResponse, token, mPrefferedRegion);
connection.disconnect();
return access;
} catch (IOException | ParseException e) {
LOG.error(e.getMessage());
throw new CommandException("Unable to execute the HTTP call or to convert the HTTP Response", e);
}
}
Aggregations