use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.
the class OperationParsingTestCase method testNoOperation.
@Test
public void testNoOperation() throws Exception {
DefaultCallbackHandler handler = new DefaultCallbackHandler();
try {
parse("./subsystem=logging:", handler);
} catch (OperationFormatException e) {
}
assertTrue(handler.hasAddress());
assertFalse(handler.hasOperationName());
assertFalse(handler.hasProperties());
assertTrue(handler.endsOnAddressOperationNameSeparator());
assertFalse(handler.endsOnPropertyListStart());
assertFalse(handler.endsOnPropertySeparator());
assertFalse(handler.endsOnPropertyValueSeparator());
assertFalse(handler.endsOnNodeSeparator());
assertFalse(handler.endsOnNodeTypeNameSeparator());
assertFalse(handler.isRequestComplete());
OperationRequestAddress address = handler.getAddress();
Iterator<Node> i = address.iterator();
assertTrue(i.hasNext());
Node node = i.next();
assertEquals("subsystem", node.getType());
assertEquals("logging", node.getName());
assertFalse(i.hasNext());
}
use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.
the class OperationParsingTestCase method testOperationEscapedQuotesInArgumentValues.
@Test
public void testOperationEscapedQuotesInArgumentValues() throws Exception {
DefaultCallbackHandler handler = new DefaultCallbackHandler();
parse("/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec, value=\"substituteAll(\\\"JBAS\\\",\\\"DUMMY\\\")\")", handler);
assertTrue(handler.hasAddress());
assertTrue(handler.hasOperationName());
assertTrue(handler.hasProperties());
assertFalse(handler.endsOnAddressOperationNameSeparator());
assertFalse(handler.endsOnPropertyListStart());
assertFalse(handler.endsOnPropertySeparator());
assertFalse(handler.endsOnPropertyValueSeparator());
assertFalse(handler.endsOnNodeSeparator());
assertFalse(handler.endsOnNodeTypeNameSeparator());
assertFalse(handler.isRequestComplete());
assertEquals("write-attribute", handler.getOperationName());
OperationRequestAddress address = handler.getAddress();
Iterator<Node> i = address.iterator();
assertTrue(i.hasNext());
Node node = i.next();
assertEquals("subsystem", node.getType());
assertEquals("logging", node.getName());
assertTrue(i.hasNext());
node = i.next();
assertEquals("console-handler", node.getType());
assertEquals("CONSOLE", node.getName());
assertFalse(i.hasNext());
Set<String> args = handler.getPropertyNames();
assertEquals(2, args.size());
assertTrue(args.contains("name"));
assertEquals("filter-spec", handler.getPropertyValue("name"));
assertTrue(args.contains("value"));
assertEquals("\"substituteAll(\\\"JBAS\\\",\\\"DUMMY\\\")\"", handler.getPropertyValue("value"));
}
use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.
the class OperationParsingTestCase method testOpenQuote.
@Test
public void testOpenQuote() throws Exception {
DefaultCallbackHandler handler = new DefaultCallbackHandler(false);
try {
handler.parse(null, "./subsystem=logging:add(a=\"", null);
} catch (OperationFormatException e) {
}
assertTrue(handler.hasAddress());
assertTrue(handler.hasOperationName());
assertTrue(handler.hasProperties());
assertFalse(handler.endsOnAddressOperationNameSeparator());
assertFalse(handler.endsOnPropertyListStart());
assertFalse(handler.endsOnPropertySeparator());
assertFalse(handler.endsOnPropertyValueSeparator());
assertFalse(handler.endsOnNodeSeparator());
assertFalse(handler.endsOnNodeTypeNameSeparator());
assertFalse(handler.isRequestComplete());
OperationRequestAddress address = handler.getAddress();
Iterator<Node> i = address.iterator();
assertTrue(i.hasNext());
Node node = i.next();
assertEquals("subsystem", node.getType());
assertEquals("logging", node.getName());
assertFalse(i.hasNext());
assertEquals("add", handler.getOperationName());
assertEquals("a", handler.getLastParsedPropertyName());
assertEquals("\"", handler.getLastParsedPropertyValue());
}
use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.
the class BaseOperationCommand method isAvailable.
@Override
public boolean isAvailable(CommandContext ctx) {
if (!super.isAvailable(ctx)) {
return false;
}
if (requiredAddress == null) {
return ctx.getConfig().isAccessControl() ? accessRequirement.isSatisfied(ctx) : true;
}
if (dependsOnProfile && ctx.isDomainMode()) {
// not checking address in all the profiles
return ctx.getConfig().isAccessControl() ? accessRequirement.isSatisfied(ctx) : true;
}
if (available != null) {
return available.booleanValue();
}
final ModelControllerClient client = ctx.getModelControllerClient();
if (client == null) {
return false;
}
// which happens on reconnect/disconnect
if (requiredType == null) {
available = isAddressValid(ctx);
} else {
final ModelNode request = new ModelNode();
final ModelNode address = request.get(Util.ADDRESS);
for (OperationRequestAddress.Node node : requiredAddress) {
address.add(node.getType(), node.getName());
}
request.get(Util.OPERATION).set(Util.READ_CHILDREN_TYPES);
ModelNode result;
try {
result = ctx.getModelControllerClient().execute(request);
} catch (IOException e) {
return false;
}
available = Util.listContains(result, requiredType);
}
if (ctx.getConfig().isAccessControl()) {
available = available && accessRequirement.isSatisfied(ctx);
}
return available;
}
use of org.jboss.as.cli.operation.OperationRequestAddress.Node in project wildfly-core by wildfly.
the class LsHandler method getDynamicOptions.
private Map<String, CommandArgument> getDynamicOptions(CommandContext ctx) throws CommandFormatException {
if (ctx.getModelControllerClient() == null) {
return Collections.emptyMap();
}
final OperationRequestAddress address = getOperationRequestAddress(ctx);
if (address.endsOnType()) {
return Collections.emptyMap();
}
final ModelNode req = new ModelNode();
if (address.isEmpty()) {
req.get(Util.ADDRESS).setEmptyList();
} else {
final ModelNode addrNode = req.get(Util.ADDRESS);
for (OperationRequestAddress.Node node : address) {
addrNode.add(node.getType(), node.getName());
}
}
req.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
Map<String, CommandArgument> options = Collections.emptyMap();
try {
final ModelNode response = ctx.getModelControllerClient().execute(req);
if (Util.isSuccess(response)) {
if (response.hasDefined(Util.RESULT)) {
final ModelNode result = response.get(Util.RESULT);
if (result.hasDefined(Util.ATTRIBUTES)) {
options = new TreeMap<>();
ModelNode attributes = result.get(Util.ATTRIBUTES);
for (String key : attributes.keys()) {
ModelNode attribute = attributes.get(key);
for (String k : attribute.keys()) {
ArgumentWithoutValue wv = new ArgumentWithoutValue(new CommandHandlerWithArguments() {
@Override
public boolean isAvailable(CommandContext ctx) {
return LsHandler.this.isAvailable(ctx);
}
@Override
public boolean isBatchMode(CommandContext ctx) {
return LsHandler.this.isBatchMode(ctx);
}
@Override
public void handle(CommandContext ctx) throws CommandLineException {
LsHandler.this.handle(ctx);
}
@Override
public void addArgument(CommandArgument arg) {
// Noop.
}
}, "--" + k);
wv.addRequiredPreceding(l);
options.put("--" + k, wv);
}
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return options;
}
Aggregations