use of org.jboss.hal.dmr.Property 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();
}
});
});
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class ServerGroupActions method addChildOperations.
private static void addChildOperations(Composite composite, ModelNode rootModel, ModelNode baseAddress, int depth) {
if (depth <= 0) {
return;
}
for (Property property : rootModel.asPropertyList()) {
if (ModelType.OBJECT.equals(property.getValue().getType())) {
for (Property resource : property.getValue().asPropertyList()) {
if (ModelType.OBJECT.equals(resource.getValue().getType())) {
ModelNode resourceAddress = baseAddress.clone().add(property.getName(), resource.getName());
Operation operation = new Operation.Builder(new ResourceAddress(resourceAddress), ADD).payload(resource.getValue()).build();
composite.add(operation);
addChildOperations(composite, resource.getValue(), resourceAddress, depth - 1);
}
}
}
}
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class SingleRrdParser method parseSingle.
private void parseSingle(ResourceAddress address, ModelNode modelNode) {
// resource description
// to reduce the payload we only use the flat model node w/o children
ModelNode childrenNode = modelNode.hasDefined(CHILDREN) ? modelNode.remove(CHILDREN) : new ModelNode();
if (!rrdResult.containsResourceDescription(address) && modelNode.hasDefined(DESCRIPTION)) {
rrdResult.addResourceDescription(addressProcessor.apply(address), new ResourceDescription(modelNode));
}
// security context
ModelNode accessControl = modelNode.get(ACCESS_CONTROL);
if (accessControl.isDefined()) {
if (!rrdResult.containsSecurityContext(address) && accessControl.hasDefined(DEFAULT)) {
rrdResult.addSecurityContext(address, new SecurityContext(accessControl.get(DEFAULT)));
}
// exceptions
if (accessControl.hasDefined(EXCEPTIONS)) {
List<Property> exceptions = accessControl.get(EXCEPTIONS).asPropertyList();
for (Property property : exceptions) {
ModelNode exception = property.getValue();
ResourceAddress exceptionAddress = new ResourceAddress(exception.get(ADDRESS));
if (!rrdResult.containsSecurityContext(exceptionAddress)) {
rrdResult.addSecurityContext(exceptionAddress, new SecurityContext(exception));
}
}
}
}
// children
if (childrenNode.isDefined()) {
List<Property> children = childrenNode.asPropertyList();
for (Property child : children) {
String addressKey = child.getName();
if (child.getValue().hasDefined(MODEL_DESCRIPTION)) {
List<Property> modelDescriptions = child.getValue().get(MODEL_DESCRIPTION).asPropertyList();
for (Property modelDescription : modelDescriptions) {
String addressValue = modelDescription.getName();
ModelNode childNode = modelDescription.getValue();
ResourceAddress childAddress = new ResourceAddress(address).add(addressKey, addressValue);
parseSingle(childAddress, childNode);
}
}
}
}
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class Metadata method forComplexAttribute.
/**
* Creates a new metadata instance based on this metadata with the attributes taken from the specified complex attribute.
* The resource description will only include the attributes but no operations!
*
* @param prefixLabel if {@code true} the labels of the attributes of the complex attribute are prefixed with name of the
* complex attribute.
*/
@JsIgnore
public Metadata forComplexAttribute(String name, boolean prefixLabel) {
ModelNode payload = new ModelNode();
payload.get(DESCRIPTION).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + DESCRIPTION));
payload.get(REQUIRED).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + REQUIRED));
payload.get(NILLABLE).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + NILLABLE));
Property complexAttribute = description.findAttribute(ATTRIBUTES, name);
if (complexAttribute != null && complexAttribute.getValue().hasDefined(VALUE_TYPE)) {
complexAttribute.getValue().get(VALUE_TYPE).asPropertyList().forEach(nestedProperty -> {
// The nested name is *always* just the nested property name,
// since it's used when building the DMR operations
String nestedName = nestedProperty.getName();
ModelNode nestedDescription = nestedProperty.getValue();
// up by LabelBuilder.label(Property)
if (prefixLabel) {
nestedDescription.get(HAL_LABEL).set(name + "-" + nestedProperty.getName());
}
payload.get(ATTRIBUTES).get(nestedName).set(nestedDescription);
});
}
SecurityContext parentContext = this.securityContext.get();
SecurityContext attributeContext = new SecurityContext(new ModelNode()) {
@Override
public boolean isReadable() {
return parentContext.isReadable(name);
}
@Override
public boolean isWritable() {
return parentContext.isWritable(name);
}
@Override
public boolean isReadable(String attribute) {
// if the complex attribute is readable all nested attributes are readable as well
return isReadable();
}
@Override
public boolean isWritable(String attribute) {
// if the complex attribute is writable all nested attributes are writable as well
return isWritable();
}
@Override
public boolean isExecutable(String operation) {
return parentContext.isExecutable(operation);
}
};
return new Metadata(template, () -> attributeContext, new ResourceDescription(payload), capabilities);
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class ResetServerDialog method reset.
void reset(String messagingServer) {
LabelBuilder labelBuilder = new LabelBuilder();
String l1 = labelBuilder.label(RESET_ALL_MESSAGE_COUNTERS);
Property p1 = metadata.getDescription().findOperation(RESET_ALL_MESSAGE_COUNTERS);
if (p1 != null && p1.getValue().hasDefined(DESCRIPTION)) {
l1 = p1.getValue().get(DESCRIPTION).asString();
l1 = Strings.sanitize(l1);
}
String l2 = labelBuilder.label(RESET_ALL_MESSAGE_COUNTER_HISTORIES);
Property p2 = metadata.getDescription().findOperation(RESET_ALL_MESSAGE_COUNTER_HISTORIES);
if (p2 != null && p2.getValue().hasDefined(DESCRIPTION)) {
l2 = p2.getValue().get(DESCRIPTION).asString();
l2 = Strings.sanitize(l2);
}
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.RESET_MESSAGE_COUNTERS, Metadata.empty()).unboundFormItem(new SwitchItem(RESET_ALL_MESSAGE_COUNTERS, l1)).unboundFormItem(new SwitchItem(RESET_ALL_MESSAGE_COUNTER_HISTORIES, l2)).onSave((f, changedValues) -> column.resetServer(messagingServer, !f.getFormItem(RESET_ALL_MESSAGE_COUNTERS).isEmpty(), !f.getFormItem(RESET_ALL_MESSAGE_COUNTER_HISTORIES).isEmpty())).build();
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(RESET_ALL_MESSAGE_COUNTERS, RESET_ALL_MESSAGE_COUNTER_HISTORIES), resources));
// Make the long labels more readable
stream(form.element().querySelectorAll("." + halFormLabel + ", ." + halFormInput)).filter(htmlElements()).map(asHtmlElement()).forEach(element -> element.style.width = WidthUnionType.of("50%"));
Dialog dialog = new Dialog.Builder(resources.constants().reset()).add(form.element()).primary(resources.constants().reset(), form::save).size(Size.MEDIUM).closeIcon(true).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
form.edit(new ModelNode());
dialog.show();
}
Aggregations