use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.
the class HeaderView method updateBreadcrumb.
@Override
public void updateBreadcrumb(ModelBrowserPath path) {
clearBreadcrumb();
if (path == null || path.isEmpty()) {
// deselection
breadcrumb.insertBefore(li().textContent(resources.constants().nothingSelected()).element(), breadcrumbToolsItem);
} else {
ModelBrowser modelBrowser = path.getModelBrowser();
for (Iterator<Segment[]> iterator = path.iterator(); iterator.hasNext(); ) {
Segment[] segments = iterator.next();
Segment key = segments[0];
Segment value = segments[1];
boolean link = value != ModelBrowserPath.WILDCARD && iterator.hasNext();
HTMLElement valueContainer;
HTMLElement li = li().add(span().css(CSS.key).add(a().css(clickable).on(click, event -> modelBrowser.select(key.id, true)).textContent(key.text))).add(span().css(arrow).innerHtml(SafeHtmlUtils.fromSafeConstant("⇒"))).add(valueContainer = span().css(CSS.value).element()).element();
if (link) {
valueContainer.appendChild(valueContainer = a().css(clickable).on(click, event -> modelBrowser.select(value.id, true)).element());
}
valueContainer.textContent = value.text;
breadcrumb.insertBefore(li, breadcrumbToolsItem);
}
}
}
use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.
the class OperationFactory method fromChangeSet.
/**
* Turns a change-set into a composite operation containing
* {@linkplain org.jboss.hal.dmr.ModelDescriptionConstants#WRITE_ATTRIBUTE_OPERATION write-attribute} and
* {@linkplain org.jboss.hal.dmr.ModelDescriptionConstants#UNDEFINE_ATTRIBUTE_OPERATION undefine-attribute} operations.
* <p>
* The composite operation will contain {@linkplain org.jboss.hal.dmr.ModelDescriptionConstants#UNDEFINE_ATTRIBUTE_OPERATION
* undefine-attribute} operations which reflect the alternative attributes as defined in the specified metadata.
*
* @param address the fq address used for the operations
* @param changeSet the changed values
* @param metadata the metadata which should contain the attribute definitions of the change-set
*/
public Composite fromChangeSet(ResourceAddress address, Map<String, Object> changeSet, Metadata metadata) {
// TODO Is it safe to always use ATTRIBUTES as path when calling ResourceDescription methods?
Map<String, Operation> operations = new HashMap<>();
HashMap<String, Object> localChanges = new HashMap<>(changeSet);
ResourceDescription resourceDescription = metadata.getDescription();
// look for alternatives
Set<String> conflicts = new HashSet<>();
Map<String, List<String>> allAlternatives = localChanges.keySet().stream().filter(name -> {
Object value = changeSet.get(name);
return !isNullOrEmpty(value);
}).collect(toMap(identity(), name -> resourceDescription.findAlternatives(ATTRIBUTES, name)));
allAlternatives.forEach((attribute, alternatives) -> {
logger.debug("Alternatives resolution for {} -> [{}]", attribute, String.join(", ", alternatives));
HashSet<String> intersection = new HashSet<>(alternatives);
intersection.retainAll(changeSet.keySet());
if (intersection.isEmpty()) {
// the easy part: no conflicts
alternatives.forEach(alternative -> {
boolean alternativeDoesntExist = resourceDescription.findAttribute(ATTRIBUTES, alternative) == null;
if (resourceDescription.isDeprecated(ATTRIBUTES, alternative) || alternativeDoesntExist) {
logger.debug("Skip undefine operations for deprecated or non-existent alternative {}", alternative);
} else {
logger.debug("Add undefine operations for alternative {}", alternative);
operations.putIfAbsent(alternative, undefineAttribute(address, alternative));
List<String> requires = resourceDescription.findRequires(ATTRIBUTES, alternative);
if (!requires.isEmpty()) {
logger.debug("Add undefine operations for attributes which require {}: [{}]", alternative, String.join(", ", requires));
requires.forEach(r -> operations.putIfAbsent(r, undefineAttribute(address, r)));
}
}
});
} else {
// possible conflicts: one or more alternatives are also in the change-set
// just collect for now and resolve later
conflicts.add(attribute);
conflicts.addAll(intersection);
logger.debug("Record conflict {} <-> [{}]", attribute, String.join(", ", intersection));
}
alternatives.forEach(localChanges::remove);
});
if (!conflicts.isEmpty()) {
// try to resolve conflicts: only one of the conflicting attributes must have a value other than
// null, empty or default
logger.debug("Try to resolve conflicts between alternatives [{}]", String.join(", ", conflicts));
Map<Boolean, List<String>> resolution = conflicts.stream().collect(groupingBy(conflict -> {
Object value = changeSet.get(conflict);
return isNullOrEmpty(value) || resourceDescription.isDefaultValue(ATTRIBUTES, conflict, value);
}));
List<String> undefine = resolution.getOrDefault(true, Collections.emptyList());
List<String> write = resolution.getOrDefault(false, Collections.emptyList());
if (write.size() > 1) {
logger.error("More than one conflicting alternative attribute which is not null, empty or default: [{}]. This should have been caught by a form validation. Adding the write operations anyway to get an appropriate error message from the server.", String.join(", ", write));
}
logger.debug("Add undefine operations for [{}], write operation for [{}]", String.join(", ", undefine), String.join(", ", write));
undefine.forEach(u -> {
operations.putIfAbsent(u, undefineAttribute(address, u));
localChanges.remove(u);
// process requires of the current undefine attribute
List<String> requires = resourceDescription.findRequires(ATTRIBUTES, u);
requires.forEach(ur -> {
operations.putIfAbsent(ur, undefineAttribute(address, ur));
localChanges.remove(ur);
});
});
write.forEach(w -> {
operations.putIfAbsent(w, writeAttribute(address, w, changeSet.get(w), resourceDescription, true));
localChanges.remove(w);
List<String> writeAlternatives = resourceDescription.findAlternatives(ATTRIBUTES, w);
// process alternatives of the current write attribute
writeAlternatives.forEach(wa -> {
operations.putIfAbsent(wa, undefineAttribute(address, wa));
localChanges.remove(wa);
});
});
}
// handle the remaining attributes
logger.debug("Process remaining attributes [{}]", String.join(", ", localChanges.keySet()));
localChanges.forEach((name, value) -> operations.putIfAbsent(name, writeAttribute(address, name, value, resourceDescription, false)));
return new Composite(operations.values().stream().filter(Objects::nonNull).collect(toList()));
}
use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.
the class StandaloneServerPresenter method disableSslForManagementInterface.
@Override
@SuppressWarnings("DuplicatedCode")
public void disableSslForManagementInterface() {
Constants constants = resources.constants();
String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
String label = constants.reload() + " " + serverName;
SwitchItem reload = new SwitchItem(RELOAD, label);
reload.setExpressionAllowed(false);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(RELOAD, FORM), Metadata.empty()).unboundFormItem(reload).build();
form.attach();
HTMLElement formElement = form.element();
ModelNode model = new ModelNode();
model.setEmptyObject();
form.edit(model);
ResourceAddress httpAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
DialogFactory.buildConfirmation(constants.disableSSL(), resources.messages().disableSSLManagementQuestion(serverName), formElement, Dialog.Size.MEDIUM, () -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
// load the http-interface resource to get the port, there are differente attributes for
// standalone and domain mode.
Task<FlowContext> loadHttpInterface = flowContext -> {
Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
if (value.hasDefined(SOCKET_BINDING)) {
// standalone mode uses a socket-binding for port
// store the socket-binding name in the flow context and on a later call
// read the socket-binding-group=<s-b-g>/socket-binding=<http-binding> to
// retrieve the port number
flowContext.set(SOCKET_BINDING, value.get(SOCKET_BINDING).asString());
}
}).toCompletable();
};
tasks.add(loadHttpInterface);
// if standalone mode, read the socket-binding-group=<s-b-g>/socket-binding=<http-binding>
// to retrieve the port number
Task<FlowContext> readHttpPortTask = flowContext -> {
Operation op = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
return dispatcher.execute(op).doOnSuccess(result -> {
String sbg = result.asList().get(0).asString();
String httpBinding = flowContext.get(SOCKET_BINDING);
ResourceAddress address = SOCKET_BINDING_GROUP_TEMPLATE.resolve(statementContext, sbg, httpBinding);
Operation readPort = new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, PORT).param(RESOLVE_EXPRESSIONS, true).build();
dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
}).toCompletable();
};
tasks.add(readHttpPortTask);
// as part of the disable ssl task, undefine the secure-socket-binding
// the attribute only exists in standalone mode
Task<FlowContext> undefSslTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefSslTask);
// as part of the disable ssl task, undefine the ssl-context
Task<FlowContext> undefineSslContextTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSslContextTask);
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
if (reload.getValue() != null && reload.getValue()) {
String port = flowContext.get(PORT).toString();
// extracts the url search path, so the reload shows the same view the use is on
String urlSuffix = window.location.getHref();
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
// the location to redirect the browser to the unsecure URL
// TODO Replace hardcoded scheme
String location = "http://" + window.location.getHostname() + ":" + port + urlSuffix;
reloadServer(null, location);
} else {
reload();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLManagementSuccess()));
}
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLManagementError(throwable.getMessage())));
}
});
}).show();
}
use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.
the class RemotingView method updateGenericConnector.
@SuppressWarnings("HardCodedStringLiteral")
private void updateGenericConnector(NamedNode node, Form<NamedNode> form, Form<ModelNode> securityForm, Form<ModelNode> policyForm) {
FormItem<Object> properties = form.getFormItem(PROPERTY);
FormItem<Object> securityProperties = securityForm.getFormItem(PROPERTY);
if (node != null) {
Map<String, String> p = failSafePropertyList(node, PROPERTY).stream().collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
ModelNode security = failSafeGet(node, "security/sasl");
Map<String, String> sp = failSafePropertyList(node, "security/sasl/" + PROPERTY).stream().collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
ModelNode policy = failSafeGet(node, "security/sasl/sasl-policy/policy");
form.view(node);
properties.setValue(p);
securityForm.view(security);
securityProperties.setValue(sp);
policyForm.view(policy);
} else {
form.clear();
properties.clearValue();
securityForm.clear();
securityProperties.clearValue();
policyForm.clear();
}
}
use of org.jboss.hal.dmr.ModelDescriptionConstants.VALUE in project console by hal.
the class HostPresenter method disableSslForManagementInterface.
@Override
@SuppressWarnings("DuplicatedCode")
public void disableSslForManagementInterface() {
Constants constants = resources.constants();
String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
String label = constants.reload() + " " + serverName;
SwitchItem reload = new SwitchItem(RELOAD, label);
reload.setExpressionAllowed(false);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(RELOAD, FORM), Metadata.empty()).unboundFormItem(reload).build();
form.attach();
HTMLElement formElement = form.element();
ModelNode model = new ModelNode();
model.setEmptyObject();
form.edit(model);
ResourceAddress httpAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
DialogFactory.buildConfirmation(constants.disableSSL(), resources.messages().disableSSLManagementQuestion(serverName), formElement, Dialog.Size.MEDIUM, () -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
// load the http-interface resource to get the port
Task<FlowContext> loadHttpInterface = flowContext -> {
Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
if (value.hasDefined(PORT)) {
// only domain mode contains "port" attribute
String port = value.get(PORT).asString();
if (port.contains("$")) {
// if it contains an expression value, resolve it at host level
ResourceAddress address = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
Operation readPort = new Operation.Builder(address, RESOLVE_EXPRESSION).param(EXPRESSION, port).build();
dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
} else {
flowContext.set(PORT, port);
}
}
}).toCompletable();
};
tasks.add(loadHttpInterface);
// in domain-mode read the /host=<dc> domain controller
// it is important for later use if user wants to reload dc if in admin-mode
Task<FlowContext> loadDc = flowContext -> {
ResourceAddress dcAddress = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
Operation readDcOp = new Operation.Builder(dcAddress, READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).build();
return dispatcher.execute(readDcOp).doOnSuccess(value -> flowContext.set(HOST, new Host(value))).toCompletable();
};
tasks.add(loadDc);
// as part of the disable ssl task, undefine the secure-port, it only exists in domain mode
Task<FlowContext> undefineSecurePortTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSecurePortTask);
// as part of the disable ssl task, undefine the ssl-context
Task<FlowContext> undefineSslContextTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSslContextTask);
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
if (reload.getValue() != null && reload.getValue()) {
String port = flowContext.get(PORT).toString();
// extracts the url search path, so the reload shows the same view the use is on
String urlSuffix = window.location.getHref();
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
// the location to redirect the browser to the unsecure URL
// TODO Replace hardcoded scheme
String location = "http://" + window.location.getHostname() + ":" + port + urlSuffix;
Host host = flowContext.get(HOST);
reloadServer(host, location);
} else {
reloadView();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLManagementSuccess()));
}
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLManagementError(throwable.getMessage())));
}
});
}).show();
}
Aggregations