use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback 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.meta.processing.SuccessfulMetadataCallback in project console by hal.
the class PropertiesOperations method saveWithProperties.
// ------------------------------------------------------ save methods
// please add additional save() or saveSingleton() methods from CrudOperations if necessary
/**
* Saves the changed values and its properties (if modified) to the specified resource. After the resource has been saved a
* standard success message is fired and the specified callback is executed.
* <p>
* This is the properties-extended version of {@link CrudOperations#save(String, String, AddressTemplate, Map, Callback)}:
* <ol>
* <li>New properties are added as children of the PSR</li>
* <li>Modified properties are modified in the PSRs</li>
* <li>Removed properties are removed from the PSR</li>
* </ol>
*
* @param type the human readable resource type used in the success message
* @param name the resource name
* @param template the address template which is resolved against the current statement context and the resource name to get
* the resource address for the operation
* @param changedValues the changed values / payload for the operation
* @param psr the name of the properties sub resource (PSR) - most often this is "property"
* @param properties the properties to save
* @param callback the callback executed after saving the resource
*/
public void saveWithProperties(String type, String name, AddressTemplate template, Map<String, Object> changedValues, String psr, Map<String, String> properties, Callback callback) {
changedValues.remove(psr);
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
ResourceAddress address = template.resolve(statementContext, name);
Composite operations = operationFactory.fromChangeSet(address, changedValues, metadata);
saveInternal(type, name, address, operations, psr, properties, callback);
}
});
}
use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback 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.meta.processing.SuccessfulMetadataCallback in project console by hal.
the class PatchesColumn method applyPatch.
private void applyPatch() {
// check the host controller for restart-required
checkHostState(() -> metadataProcessor.lookup(PATCHING_TEMPLATE, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
Metadata metadataOp = metadata.forOperation(PATCH);
new ApplyPatchWizard(resources, environment, metadataOp, statementContext, dispatcher, progress, serverActions, () -> refresh(RESTORE_SELECTION)).show();
}
}));
}
use of org.jboss.hal.meta.processing.SuccessfulMetadataCallback in project console by hal.
the class ModelBrowser method showResourceView.
private void showResourceView(Node<Context> node, ResourceAddress address) {
Node<Context> parent = tree.getNode(node.parent);
AddressTemplate template = asGenericTemplate(parent, address);
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
resourcePanel.update(node, node.data.getAddress(), metadata);
resourcePanel.show();
}
});
}
Aggregations