use of org.apache.geode.management.internal.cli.CommandRequest in project geode by apache.
the class CLIMultiStepHelper method executeStep.
private static Result executeStep(final LogWrapper logWrapper, final Gfsh shell, final CLIStep nextStep, final ParseResult parseResult, final SectionResultData nextStepArgs) {
try {
if (nextStep instanceof CLIRemoteStep) {
if (shell.isConnectedAndReady()) {
if (GfshParseResult.class.isInstance(parseResult)) {
GfshParseResult gfshParseResult = (GfshParseResult) parseResult;
// stepArgs
if (nextStepArgs != null) {
GfJsonObject argsJSon = nextStepArgs.getSectionGfJsonObject();
shell.setEnvProperty(CLIMultiStepHelper.STEP_ARGS, argsJSon.toString());
}
CommandRequest commandRequest = new CommandRequest(gfshParseResult, shell.getEnv());
commandRequest.setCustomInput(changeStepName(gfshParseResult.getUserInput(), nextStep.getName()));
commandRequest.getCustomParameters().put(CliStrings.QUERY__STEPNAME, nextStep.getName());
String json = (String) shell.getOperationInvoker().processCommand(commandRequest);
return ResultBuilder.fromJson(json);
} else {
throw new IllegalArgumentException("Command Configuration/Definition error.");
}
} else {
try {
throw new Exception();
} catch (Exception ex) {
ex.printStackTrace();
}
throw new IllegalStateException("Can't execute a remote command without connection. Use 'connect' first to connect.");
}
} else {
Map<String, String> args = CommandExecutionContext.getShellEnv();
if (args == null) {
args = new HashMap<String, String>();
CommandExecutionContext.setShellEnv(args);
}
if (nextStepArgs != null) {
GfJsonObject argsJSon = nextStepArgs.getSectionGfJsonObject();
Gfsh.getCurrentInstance().setEnvProperty(CLIMultiStepHelper.STEP_ARGS, argsJSon.toString());
}
return nextStep.exec();
}
} catch (CLIStepExecption e) {
logWrapper.severe("CLIStep " + nextStep.getName() + " failed aborting command");
throw e;
}
}
use of org.apache.geode.management.internal.cli.CommandRequest in project geode by apache.
the class RestHttpOperationInvokerJUnitTest method testCreateHttpRequest.
@Test
public void testCreateHttpRequest() {
final Map<String, String> commandOptions = new HashMap<>();
commandOptions.put("author", "Adams");
commandOptions.put("blankOption", " ");
commandOptions.put("category", "sci-fi");
commandOptions.put("emptyOption", StringUtils.EMPTY);
commandOptions.put("isbn", "0-123456789");
commandOptions.put("nullOption", null);
commandOptions.put("title", "Hitch Hiker's Guide to the Galaxy");
commandOptions.put("year", "1983");
final CommandRequest command = createCommandRequest("add-book", commandOptions);
final ClientHttpRequest request = getOperationInvoker().createHttpRequest(command);
assertNotNull(request);
assertEquals("POST http://host.domain.com/service/v1/libraries/{name}/books", request.getLink().toHttpRequestLine());
assertEquals("Adams", request.getParameterValue("author"));
assertEquals("sci-fi", request.getParameterValue("category"));
assertEquals("0-123456789", request.getParameterValue("isbn"));
assertEquals("Hitch Hiker's Guide to the Galaxy", request.getParameterValue("title"));
assertEquals("1983", request.getParameterValue("year"));
assertTrue(request.getParameters().containsKey("blankOption"));
assertTrue(request.getParameters().containsKey("emptyOption"));
assertFalse(request.getParameters().containsKey("nullOption"));
for (String requestParameter : request.getParameters().keySet()) {
assertFalse(requestParameter.startsWith(RestHttpOperationInvoker.ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX));
}
assertNull(request.getParameterValue(RestHttpOperationInvoker.RESOURCES_REQUEST_PARAMETER));
}
use of org.apache.geode.management.internal.cli.CommandRequest in project geode by apache.
the class RestHttpOperationInvokerJUnitTest method testCreateHttpRequestWithEnvironmentVariables.
@Test
public void testCreateHttpRequestWithEnvironmentVariables() {
final Map<String, String> commandOptions = new HashMap<>(2);
commandOptions.put("name", "ElLibreDeCongress");
commandOptions.put("isbn", "${ISBN}");
final Map<String, String> environment = new HashMap<>(2);
environment.put("ISBN", "0-987654321");
environment.put("VAR", "test");
final CommandRequest command = createCommandRequest("get-book", commandOptions, environment);
final ClientHttpRequest request = getOperationInvoker().createHttpRequest(command);
assertNotNull(request);
assertEquals("GET http://host.domain.com/service/v1/libraries/{name}/books/{isbn}", request.getLink().toHttpRequestLine());
assertEquals("${ISBN}", request.getParameterValue("isbn"));
assertFalse(request.getParameters().containsKey("ISBN"));
assertEquals("0-987654321", request.getParameterValue(RestHttpOperationInvoker.ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX + "ISBN"));
assertFalse(request.getParameters().containsKey("VAR"));
assertEquals("test", request.getParameterValue(RestHttpOperationInvoker.ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX + "VAR"));
}
use of org.apache.geode.management.internal.cli.CommandRequest in project geode by apache.
the class RestHttpOperationInvokerJUnitTest method testCreateHttpRequestWithFileData.
@Test
public void testCreateHttpRequestWithFileData() {
final Map<String, String> commandOptions = Collections.singletonMap("isbn", "0-123456789");
final byte[][] fileData = { "/path/to/book/content.txt".getBytes(), "Once upon a time in a galaxy far, far away...".getBytes() };
final CommandRequest command = createCommandRequest("add-book", commandOptions, fileData);
final ClientHttpRequest request = getOperationInvoker().createHttpRequest(command);
assertNotNull(request);
assertEquals("POST http://host.domain.com/service/v1/libraries/{name}/books", request.getLink().toHttpRequestLine());
assertEquals("0-123456789", request.getParameterValue("isbn"));
assertTrue(request.getParameters().containsKey(RestHttpOperationInvoker.RESOURCES_REQUEST_PARAMETER));
assertTrue(request.getParameterValue(RestHttpOperationInvoker.RESOURCES_REQUEST_PARAMETER) instanceof Resource);
final List<Object> resources = request.getParameterValues(RestHttpOperationInvoker.RESOURCES_REQUEST_PARAMETER);
assertNotNull(resources);
assertFalse(resources.isEmpty());
assertEquals(1, resources.size());
}
use of org.apache.geode.management.internal.cli.CommandRequest in project geode by apache.
the class SimpleHttpOperationInvokerJUnitTest method testCreateLink.
@Test
public void testCreateLink() throws Exception {
final CommandRequest command = createCommandRequest("delete resource --id=1");
final Link actualLink = getOperationInvoker().createLink(command);
assertNotNull(actualLink);
assertEquals(SimpleHttpOperationInvoker.LINK_RELATION, actualLink.getRelation());
assertEquals(HttpMethod.POST, actualLink.getMethod());
assertTrue(toString(actualLink.getHref()).endsWith(command.getInput()));
}
Aggregations