use of org.jboss.hal.dmr.Property in project console by hal.
the class DataSourceView method update.
@Override
public void update(DataSource dataSource) {
// TODO Add a suggestion handler for the DRIVER_NAME field
showHide(dataSource.isXa());
// noinspection HardCodedStringLiteral
header.innerHTML = new SafeHtmlBuilder().appendEscaped(dataSource.getName()).appendHtmlConstant("<small>").appendEscaped(" (").appendEscaped(dataSource.isEnabled() ? resources.constants().enabled() : resources.constants().disabled()).appendEscaped(")").appendHtmlConstant("</small>").toSafeHtml().asString();
if (dataSource.isXa()) {
xaForm.view(dataSource);
Map<String, String> p = failSafePropertyList(dataSource, XA_DATASOURCE_PROPERTIES).stream().collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
originalConnectionProperties = p;
xaForm.getFormItem(XA_DATASOURCE_PROPERTIES).setValue(p);
String dsClassname = dataSource.hasDefined(XA_DATASOURCE_CLASS) ? dataSource.get(XA_DATASOURCE_CLASS).asString() : null;
String driverName = dataSource.get(DRIVER_NAME).asString();
presenter.readJdbcDriverProperties(true, dsClassname, driverName, dsProperties -> xaAutoCompleteValues.update(dsProperties));
if (xaCrForm != null) {
xaCrForm.view(failSafeGet(dataSource, CREDENTIAL_REFERENCE));
}
} else {
nonXaForm.view(dataSource);
Map<String, String> p = failSafePropertyList(dataSource, CONNECTION_PROPERTIES).stream().collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
originalConnectionProperties = p;
nonXaForm.getFormItem(CONNECTION_PROPERTIES).setValue(p);
String dsClassname = dataSource.hasDefined(DATASOURCE_CLASS) ? dataSource.get(DATASOURCE_CLASS).asString() : null;
String driverName = dataSource.get(DRIVER_NAME).asString();
presenter.readJdbcDriverProperties(false, dsClassname, driverName, dsProperties -> nonXaAutoCompleteValues.update(dsProperties));
if (nonXaCrForm != null) {
nonXaCrForm.view(failSafeGet(dataSource, CREDENTIAL_REFERENCE));
}
}
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class DriverStep method adjustMetadata.
private Metadata adjustMetadata(Metadata metadata) {
ModelNode newAttributes = new ModelNode();
for (Property property : metadata.getDescription().get(ATTRIBUTES).asPropertyList()) {
ModelNode value = property.getValue().clone();
value.get(ACCESS_TYPE).set(READ_WRITE);
value.get(NILLABLE).set(!DRIVER_NAME.equals(property.getName()) && !DRIVER_XA_DATASOURCE_CLASS_NAME.equals(property.getName()));
newAttributes.get(property.getName()).set(value);
}
metadata.getDescription().remove(ATTRIBUTES);
metadata.getDescription().get(ATTRIBUTES).set(newAttributes);
return metadata;
}
use of org.jboss.hal.dmr.Property 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);
}
});
}
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class PatchWizard method checkServersState.
/**
* Checks if each servers of a host is stopped, if the server is started, asks the user to stop them. It is a good practice
* to apply/rollback a patch to a stopped server to prevent application and internal services from failing.
*/
void checkServersState(Consumer<List<Property>> callback) {
if (environment.isStandalone()) {
callback.accept(null);
} else {
String host = statementContext.selectedHost();
ResourceAddress address = new ResourceAddress().add(HOST, host);
Operation operation = new Operation.Builder(address, READ_CHILDREN_RESOURCES_OPERATION).param(INCLUDE_RUNTIME, true).param(CHILD_TYPE, SERVER_CONFIG).build();
dispatcher.execute(operation, result -> {
List<Property> servers = result.asPropertyList();
boolean anyServerStarted = false;
for (Iterator<Property> iter = servers.iterator(); iter.hasNext(); ) {
Property serverProp = iter.next();
Server server = new Server(host, serverProp);
if (!server.isStopped()) {
anyServerStarted = true;
} else {
iter.remove();
}
}
if (anyServerStarted) {
callback.accept(servers);
} else {
callback.accept(null);
}
});
}
}
use of org.jboss.hal.dmr.Property in project console by hal.
the class CompositeRrdParser method makeFqAddress.
@SuppressWarnings("DuplicateStringLiteralInspection")
private ResourceAddress makeFqAddress(ResourceAddress operationAddress, ResourceAddress resultAddress) {
ResourceAddress resolved = resultAddress;
List<Property> operationSegments = operationAddress.asPropertyList();
List<Property> resultSegments = resultAddress.asPropertyList();
// this method fixes this corner case.
if (operationSegments.size() > 2 && operationSegments.size() == resultSegments.size() + 2 && HOST.equals(operationSegments.get(0).getName()) && SERVER.equals(operationSegments.get(1).getName())) {
resolved = new ResourceAddress().add(HOST, operationSegments.get(0).getValue().asString()).add(SERVER, operationSegments.get(1).getValue().asString()).add(resultAddress);
logger.debug("Adjust result address '{}' -> '{}'", resultAddress, resolved);
}
return resolved;
}
Aggregations