Fail hard if retrieving user/role fails or adding user/role fails

Original commit: elastic/x-pack-elasticsearch@d641dab31c
This commit is contained in:
Lee Hinman 2016-06-29 09:37:59 -06:00
parent 24d7472cea
commit b4c19734ac
1 changed files with 5 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import javax.net.ssl.HttpsURLConnection;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.cli.MultiCommand;
import org.elasticsearch.cli.SettingCommand;
@ -253,9 +254,7 @@ public class ESNativeRealmMigrateTool extends MultiCommand {
try {
existingUsers = getUsersThatExist(terminal, settings, env, options);
} catch (Exception e) {
terminal.println("failed to get users that already exist, skipping user import");
terminal.println(ExceptionsHelper.stackTrace(e));
return;
throw new ElasticsearchException("failed to get users that already exist, skipping user import", e);
}
if (usersToMigrate.length == 0) {
usersToMigrate = userToHashedPW.keySet().toArray(new String[userToHashedPW.size()]);
@ -276,8 +275,7 @@ public class ESNativeRealmMigrateTool extends MultiCommand {
this.url.value(options) + "/_xpack/security/user/" + user, options, reqBody);
terminal.println(resp);
} catch (Exception e) {
terminal.println("failed to migrate user [" + user + "] with body: " + reqBody);
terminal.println(ExceptionsHelper.stackTrace(e));
throw new ElasticsearchException("failed to migrate user [" + user + "] with body: " + reqBody, e);
}
}
}
@ -365,9 +363,7 @@ public class ESNativeRealmMigrateTool extends MultiCommand {
try {
existingRoles = getRolesThatExist(terminal, settings, env, options);
} catch (Exception e) {
terminal.println("failed to get roles that already exist, skipping role import");
terminal.println(ExceptionsHelper.stackTrace(e));
return;
thow new ElasticsearchException("failed to get roles that already exist, skipping role import", e);
}
if (rolesToMigrate.length == 0) {
rolesToMigrate = roles.keySet().toArray(new String[roles.size()]);
@ -388,8 +384,7 @@ public class ESNativeRealmMigrateTool extends MultiCommand {
this.url.value(options) + "/_xpack/security/role/" + roleName, options, reqBody);
terminal.println(resp);
} catch (Exception e) {
terminal.println("failed to migrate role [" + roleName + "] with body: " + reqBody);
terminal.println(ExceptionsHelper.stackTrace(e));
throw new ElasticsearchException("failed to migrate role [" + roleName + "] with body: " + reqBody, e);
}
}
}