use of org.jboss.hal.resources.Resources in project console by hal.
the class StoresPresenter method importCertificate.
void importCertificate(Metadata metadata, String name) {
AddressTemplate template = metadata.getTemplate();
String resource = Names.KEY_STORE + SPACE + name;
metadata = metadata.forOperation(IMPORT_CERTIFICATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), IMPORT_CERTIFICATE), metadata).build();
form.setSaveCallback((form1, changedValues) -> {
ModelNode payload = form.getModel();
String path = payload.get(PATH).asString();
if (!payload.hasDefined(VALIDATE)) {
payload.get(VALIDATE).set(false);
}
ResourceAddress address = template.resolve(statementContext, name);
String alias = payload.get(ALIAS).asString();
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, IMPORT_CERTIFICATE).payload(payload).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().importCertificateError(alias, path, resource, ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().storeError(resource, ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resource, ex.getMessage())))).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().importCertificateSuccess(alias, path, resource)));
}
@Override
public void onError(FlowContext context, Throwable ex) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().removeAliasError(alias, resource, ex.getMessage())));
}
});
});
Dialog dialog = new Dialog.Builder(resources.constants().importCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().importt(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
dialog.show();
form.edit(new ModelNode());
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class PasswordWizard method show.
public void show() {
Constants constants = resources.constants();
Wizard.Builder<PasswordContext, PasswordState> wb = new Wizard.Builder<>(constants.setIdentityPasswordTitle(), new PasswordContext());
wb.addStep(PasswordState.CHOOSE_PASSWORD_TYPE, new ChoosePasswordTypeStep(resources)).addStep(PasswordState.CONFIGURATION, new ConfigurePasswordStep(resources, metadata)).addStep(PasswordState.REVIEW, new ReviewPasswordStep(resources, metadata)).onBack((context, currentState) -> {
PasswordState previous = null;
switch(currentState) {
case CHOOSE_PASSWORD_TYPE:
break;
case CONFIGURATION:
previous = PasswordState.CHOOSE_PASSWORD_TYPE;
break;
case REVIEW:
previous = PasswordState.CONFIGURATION;
break;
default:
break;
}
return previous;
}).onNext((context, currentState) -> {
PasswordState next = null;
switch(currentState) {
case CHOOSE_PASSWORD_TYPE:
next = PasswordState.CONFIGURATION;
break;
case CONFIGURATION:
next = PasswordState.REVIEW;
break;
case REVIEW:
break;
default:
break;
}
return next;
}).onFinish((wizard, context) -> {
ResourceAddress address = metadata.getTemplate().resolve(statementContext, selectedRealm);
Operation operation = new Operation.Builder(address, SET_PASSWORD).param(IDENTITY, selectedIdentity).param(context.type.name, context.model).build();
LabelBuilder labelBuilder = new LabelBuilder();
String type = labelBuilder.label(metadata.getTemplate().lastName());
String resourceName = type + "" + selectedRealm;
dispatcher.execute(operation, result -> MessageEvent.fire(eventBus, Message.success(resources.messages().setIdentityPasswordSuccess(selectedIdentity, resourceName))), (operation1, failure) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, failure))), (operation1, exception) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, exception.getMessage()))));
});
Wizard<PasswordContext, PasswordState> wizard = wb.build();
wizard.show();
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class RealmsPresenter method addIdentity.
void addIdentity(AddressTemplate template, Metadata metadata, String name) {
Metadata opMetadata = metadata.forOperation(ADD_IDENTITY);
SafeHtml identityAttributeHelp = resources.messages().identityAttributeHelp();
IdentityAttributeItem identityAttribute = new IdentityAttributeItem(Ids.asId(IDENTITY_ATTRIBUTE_MAPPING), IDENTITY_ATTRIBUTE_MAPPING);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), ADD_IDENTITY), opMetadata).unboundFormItem(identityAttribute, 1, identityAttributeHelp).build();
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.constants().addIdentity(), form, (name1, model) -> {
LabelBuilder labelBuilder = new LabelBuilder();
String resourceName = labelBuilder.label(template.lastName()) + SPACE + name;
String identity = model.get(IDENTITY).asString();
ResourceAddress address = template.resolve(statementContext, name);
List<Task<FlowContext>> tasks = new ArrayList<>();
Task<FlowContext> addTask = flowContext -> {
Operation addOp = new Operation.Builder(address, ADD_IDENTITY).param(IDENTITY, identity).build();
return dispatcher.execute(addOp).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().addError(resources.constants().identity(), identity, resourceName, ex.getMessage())))).toCompletable();
};
tasks.add(addTask);
if (identityAttribute.getValue() != null) {
identityAttribute.getValue().forEach((key, values) -> {
Task<FlowContext> addAttribute = flowContext -> {
ModelNode modelValues = new ModelNode();
values.forEach(modelValues::add);
Operation addIdentAttributeOp = new Operation.Builder(address, ADD_IDENTITY_ATTRIBUTE).param(IDENTITY, identity).param(NAME, key).param(VALUE, modelValues).build();
return dispatcher.execute(addIdentAttributeOp).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().addError(resources.constants().identity(), identity, resourceName, ex.getMessage())))).toCompletable();
};
tasks.add(addAttribute);
});
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().addSuccess(resources.constants().identity(), identity, resourceName)));
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().addError(resources.constants().identity(), identity, resourceName, throwable.getMessage())));
}
});
});
dialog.show();
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class ConfigurationChangesPresenter method launchAdd.
void launchAdd() {
AddressTemplate template;
if (environment.isStandalone()) {
template = HOST_CONFIGURATION_CHANGES_TEMPLATE;
} else {
if (hostOnly) {
template = HOST_CONFIGURATION_CHANGES_TEMPLATE;
} else {
template = PROFILE_CONFIGURATION_CHANGES_TEMPLATE.replaceWildcards(profile);
}
}
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(getEventBus(), resources) {
@Override
public void onMetadata(Metadata metadata) {
String id = Ids.build(Ids.CONFIGURATION_CHANGES, Ids.ADD);
Form<ModelNode> form = new OperationFormBuilder<>(id, metadata, ADD).build();
ModelNode changeModel = new ModelNode();
Dialog dialog = new Dialog.Builder(resources.constants().configurationChanges()).add(form.element()).primary(resources.constants().yes(), () -> {
boolean valid = form.save();
// if the form contains validation error, don't close the dialog
if (valid) {
crud.addSingleton(Names.CONFIGURATION_CHANGES, template, form.getModel(), address -> reload());
}
return valid;
}).secondary(resources.constants().cancel(), () -> true).closeIcon(true).closeOnEsc(true).build();
dialog.registerAttachable(form);
dialog.show();
form.edit(changeModel);
}
});
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class ServerPreview method update.
@Override
public void update(Server server) {
ServerStatusSwitch sss = new ServerStatusSwitch(serverActions) {
@Override
protected void onPending(Server server) {
pending(resources.messages().serverPending(server.getName()));
disableAllLinks();
}
@Override
protected void onBootErrors(Server server) {
error(resources.messages().serverBootErrors(server.getName()));
disableAllLinksBut(bootErrorsLink);
}
@Override
protected void onFailed(Server server) {
error(resources.messages().serverFailed(server.getName()));
if (server.isStandalone()) {
disableAllLinks();
} else {
disableAllLinksBut(startLink);
}
}
@Override
protected void onAdminMode(Server server) {
adminOnly(resources.messages().serverAdminMode(server.getName()));
disableAllLinks();
}
@Override
protected void onStarting(Server server) {
adminOnly(resources.messages().serverAdminMode(server.getName()));
disableAllLinks();
}
@Override
protected void onSuspended(Server server) {
suspended(resources.messages().serverSuspended(server.getName()));
disableAllLinksBut(resumeLink);
}
@Override
protected void onNeedsReload(Server server) {
needsReload(resources.messages().serverNeedsReload(server.getName()));
disableAllLinksBut(reloadLink);
}
@Override
protected void onNeedsRestart(Server server) {
needsRestart(resources.messages().serverNeedsRestart(server.getName()));
disableAllLinksBut(restartLink);
}
@Override
protected void onRunning(Server server) {
running(resources.messages().serverRunning(server.getName()));
if (server.isStandalone()) {
disableAllLinks();
} else {
disableAllLinksBut(stopLink);
}
}
@Override
protected void onStopped(Server server) {
alertContainer.className = alert + " " + alertInfo;
alertIcon.className = Icons.STOPPED;
alertText.innerHTML = resources.messages().serverStopped(server.getName()).asString();
if (server.isStandalone()) {
disableAllLinks();
} else {
disableAllLinksBut(startLink);
}
}
@Override
protected void onUnknown(Server server) {
unknown(resources.messages().serverUndefined(server.getName()));
disableAllLinks();
}
};
sss.accept(server);
ServerPreviewAttributes.refresh(server, attributes);
boolean displayOpenPorts = server.isRunning() || server.needsRestart() || server.needsReload();
if (displayOpenPorts) {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
ResourceAddress address = SELECTED_SERVER.resolve(statementContext);
Operation operation = new Operation.Builder(address, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
return dispatcher.execute(operation).doOnSuccess(result -> flowContext.push(result.get(0).asString())).toCompletable();
});
tasks.add(flowContext -> {
String socketBnding = flowContext.pop();
ResourceAddress address = SELECTED_SERVER.resolve(statementContext).add(SOCKET_BINDING_GROUP, socketBnding).add(SOCKET_BINDING, "*");
ModelNode select = new ModelNode();
select.add("bound-port").add(NAME);
ModelNode where = new ModelNode();
where.set("bound", true);
Operation operation = new Operation.Builder(address, QUERY).param(SELECT, select).param(WHERE, where).build();
return dispatcher.execute(operation).doOnSuccess(result -> {
ModelNode openPortsModel = new ModelNode();
result.asList().forEach(m -> {
ModelNode sbModel = m.get(RESULT);
openPortsModel.add(sbModel.get(NAME).asString(), sbModel.get("bound-port").asInt());
flowContext.push(openPortsModel);
});
}).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext flowContext) {
ModelNode openPorts = flowContext.pop();
buildOpenPortsElement(openPorts);
}
});
serverActions.readUrl(server, serverUrl);
}
Elements.setVisible(headerOpenPorts, displayOpenPorts);
Elements.setVisible(ulOpenPorts, displayOpenPorts);
}
Aggregations