use of org.jboss.hal.meta.StatementContext in project console by hal.
the class DefaultFormItemProvider method checkCapabilityReference.
private void checkCapabilityReference(ModelNode attributeDescription, FormItem<?> formItem) {
SuggestHandler suggestHandler = null;
if (attributeDescription.hasDefined(CAPABILITY_REFERENCE)) {
Dispatcher dispatcher = Core.INSTANCE.dispatcher();
StatementContext statementContext = Core.INSTANCE.statementContext();
String reference = attributeDescription.get(CAPABILITY_REFERENCE).asString();
Capabilities capabilities = metadata.getCapabilities();
if (capabilities.supportsSuggestions()) {
suggestHandler = new SuggestCapabilitiesAutoComplete(dispatcher, statementContext, reference, metadata.getTemplate());
} else if (capabilities.contains(reference)) {
suggestHandler = new ReadChildrenAutoComplete(dispatcher, statementContext, capabilities.lookup(reference));
}
}
if (suggestHandler != null) {
formItem.registerSuggestHandler(suggestHandler);
}
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class RoleColumn method addScopedRole.
// ------------------------------------------------------ add roles
@SuppressWarnings("ConstantConditions")
private void addScopedRole(Role.Type type, String typeName, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).addOnly().unboundFormItem(new NameItem(), 0).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 3, resources.messages().includeAllHelpText()).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
item.setRequired(true);
return item;
}).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(typeName), form, (name, model) -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(new AddScopedRole(dispatcher, type, name, model));
Boolean includeAll = form.<Boolean>getFormItem(INCLUDE_ALL).getValue();
Role transientRole = new Role(name, null, type, null);
// We only need the role name in the functions,
// so it's ok to setup a transient role w/o the other attributes.
tasks.add(new CheckRoleMapping(dispatcher, transientRole));
tasks.add(new AddRoleMapping(dispatcher, transientRole, status -> status == 404));
if (includeAll != null && includeAll) {
tasks.add(new ModifyIncludeAll(dispatcher, transientRole, includeAll));
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(typeName, name)));
accessControl.reload(() -> {
refresh(Ids.role(name));
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class TestStep method testConnection.
private void testConnection() {
Context context = wizard().getContext();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!context.isCreated()) {
// add data source
tasks.add(flowContext -> dispatcher.execute(addOperation(context, statementContext)).doOnSuccess((CompositeResult result) -> context.setCreated(true)).doOnError(throwable -> {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, resources.messages().dataSourceAddError());
}).toCompletable());
}
// check running server(s)
tasks.addAll(runningServers(environment, dispatcher, properties(PROFILE_NAME, statementContext.selectedProfile())));
// test connection
tasks.add(flowContext -> {
List<Server> servers = flowContext.get(TopologyTasks.SERVERS);
ResourceAddress address;
if (!servers.isEmpty()) {
Server server = servers.get(0);
address = server.getServerAddress();
} else if (environment.isStandalone()) {
address = ResourceAddress.root();
} else {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, SafeHtmlUtils.fromString(resources.constants().noRunningServers()));
return Completable.error(new FlowException(resources.messages().testConnectionErrorDomain(), flowContext));
}
address.add(SUBSYSTEM, DATASOURCES).add(context.dataSource.isXa() ? XA_DATA_SOURCE : DATA_SOURCE, context.dataSource.getName());
Operation operation = new Operation.Builder(address, TEST_CONNECTION_IN_POOL).build();
return dispatcher.execute(operation).doOnError(throwable -> {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, resources.messages().testConnectionError(context.dataSource.getName()));
}).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext flowContext, Throwable error) {
String title;
SafeHtml text;
if (flowContext == null) {
title = resources.constants().unknownError();
text = resources.messages().unknownError();
} else {
title = flowContext.get(WIZARD_TITLE);
text = flowContext.get(WIZARD_TEXT);
}
wizard().showError(title, text, error.getMessage(), false);
}
@Override
public void onSuccess(FlowContext flowContext) {
wizard().showSuccess(resources.constants().testConnectionSuccess(), resources.messages().testConnectionSuccess(context.dataSource.getName()), false);
}
});
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class EjbView method init.
@PostConstruct
void init() {
StatementContext statementContext = mbuiContext.statementContext();
if (ManagementModel.supportsEjbApplicationSecurityDomain(environment().getManagementVersion())) {
AddressTemplate template = AddressTemplate.of("/{selected.profile}/subsystem=ejb3/application-security-domain=*");
Metadata metadata = mbuiContext.metadataRegistry().lookup(template);
appSecurityDomainTable = new ModelNodeTable.Builder<NamedNode>(Ids.EJB3_APPLICATION_SECURITY_DOMAIN_TABLE, metadata).button(mbuiContext.tableButtonFactory().add(Ids.EJB3_APPLICATION_SECURITY_DOMAIN_ADD, Names.APPLICATION_SECURITY_DOMAIN, template, (name, address) -> presenter.reload())).button(mbuiContext.tableButtonFactory().remove(Names.APPLICATION_SECURITY_DOMAIN, template, (api) -> api.selectedRow().getName(), () -> presenter.reload())).column(NAME, (cell, type, row, meta) -> row.getName()).build();
appSecurityDomainForm = new ModelNodeForm.Builder<NamedNode>(Ids.EJB3_APPLICATION_SECURITY_DOMAIN_FORM, metadata).onSave((form, changedValues) -> {
String name = form.getModel().getName();
saveForm(Names.APPLICATION_SECURITY_DOMAIN, name, template.resolve(statementContext, name), changedValues, metadata);
}).prepareReset(form -> {
String name = form.getModel().getName();
resetForm(Names.APPLICATION_SECURITY_DOMAIN, name, template.resolve(statementContext, name), form, metadata);
}).build();
HTMLElement section = section().add(h(1).textContent(Names.APPLICATION_SECURITY_DOMAIN)).add(p().textContent(metadata.getDescription().getDescription())).add(appSecurityDomainTable).add(appSecurityDomainForm).element();
navigation.insertPrimary(Ids.EJB3_APPLICATION_SECURITY_DOMAIN_ITEM, null, Names.SECURITY_DOMAIN, fontAwesome("link"), section);
}
Dispatcher dispatcher = mbuiContext.dispatcher();
configurationForm.getFormItem(DEFAULT_SFSB_CACHE).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, CACHE_TEMPLATE));
configurationForm.getFormItem(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, CACHE_TEMPLATE));
configurationForm.getFormItem(DEFAULT_SLSB_INSTANCE_POOL).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, BEAN_POOL_TEMPLATE));
configurationForm.getFormItem(DEFAULT_SECURITY_DOMAIN).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, SECURITY_DOMAIN_TEMPLATE));
cacheForm.getFormItem(PASSIVATION_STORE).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, PASSIVATION_TEMPLATE));
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class ManagementOperationsPresenter method reload.
@Override
protected void reload() {
if (environment.isStandalone()) {
ResourceAddress addressFindNP = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operationFindNP = new Operation.Builder(addressFindNP, FIND_NON_PROGRESSING_OPERATION).build();
ResourceAddress addressMO = MANAGEMENT_OPERATIONS_TEMPLATE.resolve(statementContext);
Operation operationMO = new Operation.Builder(addressMO, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACTIVE_OPERATION).build();
dispatcher.execute(new Composite(operationFindNP, operationMO), (CompositeResult result) -> {
ModelNode resultNP = result.step(0).get(RESULT);
ModelNode resultOperations = result.step(1).get(RESULT);
final String nonProgressingId = resultNP.isDefined() ? resultNP.asString() : null;
List<ManagementOperations> activeOps = asNamedNodes(resultOperations.asPropertyList()).stream().map(ManagementOperations::new).peek(activeOp -> {
if (nonProgressingId != null && nonProgressingId.equals(activeOp.getName())) {
activeOp.setAsNonProgressing();
}
}).collect(toList());
getView().update(activeOps);
});
} else {
// return available hosts, to later call a find-non-progressing-operation on each host
Task<FlowContext> hostsTask = context -> {
ResourceAddress address = new ResourceAddress();
Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
List<String> hosts = result.asList().stream().map(ModelNode::asString).collect(toList());
context.set(HOSTS, hosts);
}).toCompletable();
};
// return running servers, to later call a find-non-progressing-operation on each runtime server
Task<FlowContext> serversTask = context -> {
// /host=*/server=*:query(select=[host,name],where={server-state=running})
ResourceAddress address = new ResourceAddress().add(HOST, WILDCARD).add(SERVER, WILDCARD);
Operation operation = new Operation.Builder(address, QUERY).param(SELECT, new ModelNode().add(HOST).add(NAME)).param(WHERE, new ModelNode().set(SERVER_STATE, "running")).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
List<String> servers = Collections.emptyList();
if (result != null && result.isDefined()) {
servers = result.asList().stream().map(r -> hostServerAddress(r.get(RESULT))).collect(toList());
}
context.set("servers", servers);
}).toCompletable();
};
// call find-non-progressing-operation and read-resource of active operations
// on each host and server
Task<FlowContext> findNonProgressingTask = context -> {
List<String> hosts = context.get(HOSTS);
List<String> servers = context.get("servers");
Composite composite = new Composite();
for (String host : hosts) {
ResourceAddress address = new ResourceAddress().add(HOST, host).add(CORE_SERVICE, MANAGEMENT).add(SERVICE, MANAGEMENT_OPERATIONS);
Operation operation = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(operation);
ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
Operation operationMO = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
composite.add(operationMO);
}
if (!servers.isEmpty()) {
for (String server : servers) {
ResourceAddress address = AddressTemplate.of(server).append(MANAGEMENT_OPERATIONS_TEMPLATE).resolve(statementContext);
Operation findOp = new Operation.Builder(address, FIND_NON_PROGRESSING_OPERATION).build();
composite.add(findOp);
ResourceAddress ad = new ResourceAddress(address.clone()).add(ACTIVE_OPERATION, WILDCARD);
Operation operation = new Operation.Builder(ad, READ_RESOURCE_OPERATION).build();
composite.add(operation);
}
}
return dispatcher.execute(composite).doOnSuccess(response -> {
List<String> nonProgressingOps = new ArrayList<>();
List<ManagementOperations> ops = new ArrayList<>();
for (ModelNode r : response) {
ModelNode result = r.get(RESULT);
if (result != null && result.isDefined()) {
ModelType type = result.getType();
// if model is LIST it is the list of active operations
if (ModelType.LIST.equals(type)) {
for (ModelNode op : result.asList()) {
ModelNode opResult = op.get(RESULT);
// the result has two addresses
// 1) the active-operation address itself, example
// /host=master/server=server-three/core-service=management/service=management-operations/active-operation=1940701884
// 2) the resource address
// /host=master/server=server-three/subsystem=elytron/filesystem-realm=file1
// the active-operation address should be store to later use it to cancel, if needed
// the resource address is displayed to the user
ModelNode activeOpAddress = op.get(ADDRESS);
opResult.get(HAL_ACTIVE_OP_ADDRESS).set(activeOpAddress);
String opId = null;
List<Property> activeOperationAddressList = activeOpAddress.asPropertyList();
for (Property p : activeOperationAddressList) {
if (p.getName().equals(ACTIVE_OPERATION)) {
opId = p.getValue().asString();
}
// store the host and server to later show in the view
if (p.getName().equals(HOST)) {
opResult.get(HAL_ACTIVE_ADDRESS_HOST).set(p.getValue().asString());
}
if (p.getName().equals(SERVER)) {
opResult.get(HAL_ACTIVE_ADDRESS_SERVER).set(p.getValue().asString());
}
}
NamedNode node = new NamedNode(opId, opResult);
ManagementOperations activeOp = new ManagementOperations(node);
ops.add(activeOp);
}
} else {
nonProgressingOps.add(result.asString());
}
}
}
// if there are non progressing operations, mark them in the list
if (!nonProgressingOps.isEmpty()) {
Collections.sort(nonProgressingOps);
for (ManagementOperations mop : ops) {
if (nonProgressingOps.indexOf(mop.getName()) > -1) {
mop.setAsNonProgressing();
}
}
}
context.set("active-operations", ops);
}).toCompletable();
};
series(new FlowContext(progress.get()), hostsTask, serversTask, findNonProgressingTask).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
MessageEvent.fire(getEventBus(), Message.error(SafeHtmlUtils.fromString("Error loading management operations: " + error.getMessage())));
}
@Override
public void onSuccess(FlowContext context) {
List<ManagementOperations> ops = context.get("active-operations");
getView().update(ops);
}
});
}
}
Aggregations