Skip to content

Commit

Permalink
GEODE-5971: Refactor server status/stop commands to return ResultModel (
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeppe-pivotal authored Nov 30, 2018
1 parent 13ee457 commit 8698edc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
import org.apache.geode.management.MemberMXBean;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.ConverterHint;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
import org.apache.geode.management.cli.GfshCommand;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
import org.apache.geode.management.internal.cli.result.model.ResultModel;

public class StatusServerCommand extends InternalGfshCommand {
public class StatusServerCommand extends GfshCommand {

@CliCommand(value = CliStrings.STATUS_SERVER, help = CliStrings.STATUS_SERVER__HELP)
@CliMetaData(shellOnly = true,
relatedTopic = {CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE})
public Result statusServer(
public ResultModel statusServer(
@CliOption(key = CliStrings.STATUS_SERVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME,
help = CliStrings.STATUS_SERVER__MEMBER__HELP) final String member,
@CliOption(key = CliStrings.STATUS_SERVER__PID,
Expand All @@ -51,19 +50,19 @@ public Result statusServer(
final MemberMXBean serverProxy = getMemberMXBean(member);

if (serverProxy != null) {
return ResultBuilder.createInfoResult(
return ResultModel.createInfo(
ServerLauncher.ServerState.fromJson(serverProxy.status()).toString());
} else {
return ResultBuilder.createUserErrorResult(CliStrings
.format(CliStrings.STATUS_SERVER__NO_SERVER_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
return ResultModel.createError((CliStrings
.format(CliStrings.STATUS_SERVER__NO_SERVER_FOUND_FOR_MEMBER_ERROR_MESSAGE, member)));
}
} else {
return ResultBuilder.createUserErrorResult(CliStrings
return ResultModel.createError(CliStrings
.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Cache Server"));
}
} else {
final ServerLauncher serverLauncher = new ServerLauncher.Builder()
.setCommand(ServerLauncher.Command.STATUS).setDebug(isDebugging())
.setCommand(ServerLauncher.Command.STATUS)
// NOTE since we do not know whether the "CacheServer" was enabled or not on the GemFire
// server when it was started,
// set the disableDefaultServer property in the ServerLauncher.Builder to default status
Expand All @@ -75,9 +74,9 @@ public Result statusServer(

if (status.getStatus().equals(AbstractLauncher.Status.NOT_RESPONDING)
|| status.getStatus().equals(AbstractLauncher.Status.STOPPED)) {
return ResultBuilder.createGemFireErrorResult(status.toString());
return ResultModel.createError(status.toString());
}
return ResultBuilder.createInfoResult(status.toString());
return ResultModel.createInfo(status.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
import org.apache.geode.management.MemberMXBean;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.ConverterHint;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
import org.apache.geode.management.internal.cli.result.model.ResultModel;
import org.apache.geode.management.internal.cli.shell.Gfsh;

public class StopServerCommand extends InternalGfshCommand {
Expand All @@ -40,7 +39,7 @@ public class StopServerCommand extends InternalGfshCommand {
@CliCommand(value = CliStrings.STOP_SERVER, help = CliStrings.STOP_SERVER__HELP)
@CliMetaData(shellOnly = true,
relatedTopic = {CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE})
public Result stopServer(
public ResultModel stopServer(
@CliOption(key = CliStrings.STOP_SERVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME,
help = CliStrings.STOP_SERVER__MEMBER__HELP) final String member,
@CliOption(key = CliStrings.STOP_SERVER__PID,
Expand All @@ -52,7 +51,7 @@ public Result stopServer(

if (StringUtils.isNotBlank(member)) {
if (!isConnectedAndReady()) {
return ResultBuilder.createUserErrorResult(CliStrings
return ResultModel.createError(CliStrings
.format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Cache Server"));
}

Expand All @@ -67,14 +66,14 @@ public Result stopServer(
serverState = ServerLauncher.ServerState.fromJson(serverProxy.status());
serverProxy.shutDownMember();
} else {
return ResultBuilder.createUserErrorResult(CliStrings
return ResultModel.createError(CliStrings
.format(CliStrings.STOP_SERVER__NO_SERVER_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
}

} else {
final ServerLauncher serverLauncher =
new ServerLauncher.Builder().setCommand(ServerLauncher.Command.STOP)
.setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
.setPid(pid).setWorkingDirectory(workingDirectory).build();

serverState = serverLauncher.status();
serverLauncher.stop();
Expand All @@ -98,13 +97,10 @@ public Result stopServer(
}
}

return ResultBuilder.createInfoResult(StringUtils.EMPTY);
return ResultModel.createInfo(StringUtils.EMPTY);
} else {
return ResultBuilder.createUserErrorResult(serverState.toString());
return ResultModel.createError(serverState.toString());
}
}

private void stop(String member) {}

private void stop(String pid, String workingDir) {}
}

0 comments on commit 8698edc

Please sign in to comment.