use of org.jboss.hal.dmr.Operation in project console by hal.
the class MailSessionPresenter method launchAddServer.
void launchAddServer() {
SortedSet<String> availableServers = new TreeSet<>(asList(SMTP.toUpperCase(), IMAP.toUpperCase(), POP3.toUpperCase()));
ResourceAddress selectedSessionAddress = SELECTED_MAIL_SESSION_TEMPLATE.resolve(statementContext);
Operation serverNamesOp = new Operation.Builder(selectedSessionAddress, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SERVER).build();
dispatcher.execute(serverNamesOp, serversResult -> {
Set<String> existingServers = serversResult.asList().stream().map(node -> node.asString().toUpperCase()).collect(toSet());
availableServers.removeAll(existingServers);
if (availableServers.isEmpty()) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().allMailServersExist()));
} else {
FormItem<String> serverTypeItem;
if (availableServers.size() == 1) {
serverTypeItem = new TextBoxItem(ModelDescriptionConstants.SERVER_TYPE, resources.constants().type());
serverTypeItem.setValue(availableServers.first());
serverTypeItem.setEnabled(false);
} else {
serverTypeItem = new SingleSelectBoxItem(ModelDescriptionConstants.SERVER_TYPE, resources.constants().type(), new ArrayList<>(availableServers), false);
serverTypeItem.setRequired(true);
}
Metadata metadata = metadataRegistry.lookup(AddressTemplates.SERVER_TEMPLATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.MAIL_SERVER_DIALOG, metadata).unboundFormItem(serverTypeItem, 0).include(OUTBOUND_SOCKET_BINDING_REF, USERNAME, PASSWORD, "ssl", "tls").fromRequestProperties().requiredOnly().unsorted().build();
form.getFormItem(OUTBOUND_SOCKET_BINDING_REF).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, AddressTemplates.SOCKET_BINDING_TEMPLATE));
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(Names.SERVER), form, (name, modelNode) -> {
String serverType = serverTypeItem.getValue().toLowerCase();
ResourceAddress address = SELECTED_MAIL_SESSION_TEMPLATE.append(SERVER + EQUALS + serverType).resolve(statementContext);
Operation operation = new Operation.Builder(address, ModelDescriptionConstants.ADD).payload(modelNode).build();
dispatcher.execute(operation, result -> {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().addResourceSuccess(Names.SERVER, serverType)));
reload();
});
});
dialog.show();
}
});
}
use of org.jboss.hal.dmr.Operation in project console by hal.
the class JcaPresenter method launchAddThreadPool.
// ------------------------------------------------------ thread pools (for normal and distributed work managers)
/**
* Used to bring up the dialog to add thread pools for the normal and the distributed work managers.
* <p>
* Only one long and one short running thread pool is allowed per (distributed) work manager. This method takes care of
* showing the right attributes in the dialog. If there are already long and short running thread pools attached to the work
* manager an error message is shown.
*/
void launchAddThreadPool(AddressTemplate workmanagerTemplate, String workmanager) {
dispatcher.execute(threadPoolsOperation(workmanagerTemplate, workmanager), (CompositeResult cr) -> {
boolean lrtPresent = !cr.step(0).get(RESULT).asPropertyList().isEmpty();
boolean srtPresent = !cr.step(1).get(RESULT).asPropertyList().isEmpty();
if (lrtPresent && srtPresent) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().allThreadPoolsExist()));
} else {
FormItem<String> typeItem;
if (!lrtPresent && !srtPresent) {
typeItem = new SingleSelectBoxItem(TYPE, resources.constants().type(), asList(Names.LONG_RUNNING, Names.SHORT_RUNNING), false);
typeItem.setRequired(true);
} else {
typeItem = new TextBoxItem(TYPE, resources.constants().type());
typeItem.setValue(lrtPresent ? Names.SHORT_RUNNING : Names.LONG_RUNNING);
typeItem.setEnabled(false);
}
// for the metadata it doesn't matter whether we use the LRT or SRT template nor
// whether we use the normal or distributed workmanager version
Metadata metadata = metadataRegistry.lookup(WORKMANAGER_LRT_TEMPLATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.JCA_THREAD_POOL_ADD, metadata).fromRequestProperties().unboundFormItem(typeItem, 0).include(MAX_THREADS, QUEUE_LENGTH, THREAD_FACTORY).unsorted().build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(THREAD_POOL), form, (name, modelNode) -> {
String type = typeItem.getValue();
AddressTemplate tpTemplate = Names.LONG_RUNNING.equals(type) ? workmanagerTemplate.append(WORKMANAGER_LRT_TEMPLATE.lastName() + EQUALS + workmanager) : workmanagerTemplate.append(WORKMANAGER_SRT_TEMPLATE.lastName() + EQUALS + workmanager);
ResourceAddress address = tpTemplate.resolve(statementContext, workmanager);
Operation operation = new Operation.Builder(address, ADD).payload(modelNode).build();
dispatcher.execute(operation, result -> {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().addResourceSuccess(THREAD_POOL, name)));
loadThreadPools(workmanagerTemplate, workmanager);
});
});
dialog.show();
}
});
}
use of org.jboss.hal.dmr.Operation in project console by hal.
the class JGroupsPresenter method addStack.
// stack resources
@SuppressWarnings("ConstantConditions")
void addStack() {
Metadata metadata = metadataRegistry.lookup(STACK_TEMPLATE);
Metadata transportMetadata = metadataRegistry.lookup(TRANSPORT_TEMPLATE).forOperation(ADD);
transportMetadata.copyAttribute(SOCKET_BINDING, metadata);
metadata.makeWritable(SOCKET_BINDING);
NameItem nameItem = new NameItem();
String transportLabel = new LabelBuilder().label(TRANSPORT);
TextBoxItem transportItem = new TextBoxItem(TRANSPORT, transportLabel);
transportItem.setRequired(true);
String id = Ids.build(Ids.JGROUPS_STACK_CONFIG, Ids.ADD);
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).unboundFormItem(transportItem, 2).unsorted().requiredOnly().build();
AddResourceDialog dialog = new AddResourceDialog(Names.STACK, form, (name, model) -> {
ResourceAddress stackAddress = STACK_TEMPLATE.resolve(filterStatementContext, name);
String transport = transportItem.getValue();
ResourceAddress transportAddress = TRANSPORT_TEMPLATE.resolve(filterStatementContext, name, transport);
Operation addStackOperation = new Operation.Builder(stackAddress, ADD).build();
Operation addTransportOperation = new Operation.Builder(transportAddress, ADD).payload(model).build();
Composite composite = new Composite(addStackOperation, addTransportOperation);
dispatcher.execute(composite, (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.STACK, name)));
reload();
});
});
dialog.show();
}
use of org.jboss.hal.dmr.Operation in project console by hal.
the class RemoteCacheContainerPresenter method switchNearCache.
// ------------------------------------------------------ near cache
void switchNearCache(NearCache newMode) {
Operation operation = new Operation.Builder(nearCacheAddress(newMode), ADD).build();
dispatcher.execute(operation, result -> {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().addSingleResourceSuccess(newMode.type)));
reload();
});
}
use of org.jboss.hal.dmr.Operation in project console by hal.
the class ServerActions method copyServer.
// ------------------------------------------------------ server operations
public void copyServer(Server server, Callback callback) {
Operation operation = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
dispatcher.execute(operation, result -> {
List<String> hosts = new ArrayList<>();
result.asList().forEach(m -> hosts.add(m.asString()));
// get the first host only to retrieve the r-r-d for server-config
// as /host=*/server-config=*:read-operation-description(name=add) does not work
AddressTemplate template = AddressTemplate.of("/host=" + hosts.get(0) + "/server-config=*");
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
String id = Ids.build(SERVER_GROUP, statementContext.selectedServerGroup(), SERVER, FORM);
SingleSelectBoxItem hostFormItem = new SingleSelectBoxItem(HOST, Names.HOST, hosts, false);
hostFormItem.setRequired(true);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).fromRequestProperties().unboundFormItem(nameItem, 0).unboundFormItem(hostFormItem, 1, resources.messages().addServerHostHelp()).exclude(AUTO_START, SOCKET_BINDING_DEFAULT_INTERFACE, SOCKET_BINDING_GROUP, UPDATE_AUTO_START_WITH_SERVER_STATUS).build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().copyServerTitle(), form, (resource, payload) -> {
// read server-config recursively to retrieve nested resources
ModelNode serverConfigModel = new ModelNode();
serverConfigModel.get(HOST).set(server.getHost());
serverConfigModel.get(SERVER_CONFIG).set(server.getName());
ResourceAddress serverAddress = new ResourceAddress(serverConfigModel);
Operation opReadServer = new Operation.Builder(serverAddress, READ_RESOURCE_OPERATION).param(RECURSIVE, true).build();
dispatcher.execute(opReadServer, new Consumer<ModelNode>() {
@Override
public void accept(ModelNode newServerModel) {
String newServerName = nameItem.getValue();
// set the chosen group in the model
newServerModel.get(GROUP).set(payload.get(GROUP).asString());
if (payload.hasDefined(SOCKET_BINDING_PORT_OFFSET)) {
newServerModel.get(SOCKET_BINDING_PORT_OFFSET).set(payload.get(SOCKET_BINDING_PORT_OFFSET).asLong());
}
newServerModel.get(NAME).set(newServerName);
ModelNode newServerModelAddress = new ModelNode();
newServerModelAddress.get(HOST).set(hostFormItem.getValue());
newServerModelAddress.get(SERVER_CONFIG).set(newServerName);
Operation opAddServer = new Operation.Builder(new ResourceAddress(newServerModelAddress), ADD).payload(newServerModel).build();
Composite comp = new Composite();
comp.add(opAddServer);
// create operation for each nested resource of the source server
createOperation(comp, JVM, newServerModel, newServerModelAddress);
createOperation(comp, INTERFACE, newServerModel, newServerModelAddress);
createOperation(comp, PATH, newServerModel, newServerModelAddress);
createOperation(comp, SYSTEM_PROPERTY, newServerModel, newServerModelAddress);
createOperation(comp, SSL, newServerModel, newServerModelAddress);
dispatcher.execute(comp, (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.SERVER, newServerName)));
callback.execute();
}, (operation1, failure) -> {
MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, failure)));
callback.execute();
}, (operation1, exception) -> {
MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, exception.getMessage())));
callback.execute();
});
}
private void createOperation(Composite composite, String resource, ModelNode model, ModelNode baseAddress) {
if (model.hasDefined(resource)) {
List<Property> props = model.get(resource).asPropertyList();
props.forEach(p -> {
String propname = p.getName();
ModelNode _address = baseAddress.clone();
_address.get(resource).set(propname);
Operation operation = new Operation.Builder(new ResourceAddress(_address), ADD).payload(p.getValue()).build();
composite.add(operation);
});
}
}
});
});
dialog.show();
}
});
});
}
Aggregations