use of org.jboss.hal.config.Version in project console by hal.
the class ReadEnvironment method call.
@Override
public Completable call(FlowContext context) {
logger.debug("Read environment");
Keycloak keycloak = keycloakHolder.getKeycloak();
environment.setSingleSignOn(keycloak != null);
if (keycloak != null) {
logger.debug("Keycloak token: {}", keycloak.token);
}
List<Operation> ops = new ArrayList<>();
ops.add(new Operation.Builder(ResourceAddress.root(), READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).param(INCLUDE_RUNTIME, true).build());
ops.add(new Operation.Builder(ResourceAddress.root(), WHOAMI).param(VERBOSE, true).build());
ops.add(new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, CORE_SERVICE).param(RECURSIVE, false).build());
return dispatcher.execute(new Composite(ops)).doOnSuccess((CompositeResult result) -> {
ModelNode node = result.step(0).get(RESULT);
// operation mode
OperationMode operationMode = asEnumValue(node, LAUNCH_TYPE, (name) -> OperationMode.valueOf(name), OperationMode.UNDEFINED);
environment.setOperationMode(operationMode);
logger.debug("Operation mode: {}", operationMode);
// name and org
if (node.get(NAME).isDefined()) {
String name = node.get(NAME).asString();
environment.setName(name);
}
String orgAttribute = environment.isStandalone() ? ORGANIZATION : DOMAIN_ORGANIZATION;
if (node.get(orgAttribute).isDefined()) {
String org = node.get(orgAttribute).asString();
environment.setOrganization(org);
}
// server info
environment.setInstanceInfo(node.get(PRODUCT_NAME).asString(), node.get(PRODUCT_VERSION).asString(), node.get(RELEASE_CODENAME).asString(), node.get(RELEASE_VERSION).asString());
// management version
Version version = ManagementModel.parseVersion(node);
environment.setManagementVersion(version);
logger.debug("Management model version: {}", version);
if (environment.isStandalone()) {
Server.STANDALONE.addServerAttributes(node);
}
// user info
if (environment.isSingleSignOn()) {
user.setName(keycloak.userProfile.username);
// are not supported on the javascript side when run in the browser.
if (keycloak.realmAccess != null && keycloak.realmAccess.roles != null) {
for (int i = 0; i < keycloak.realmAccess.roles.length; i++) {
String role = keycloak.realmAccess.roles[i];
user.addRole(new Role(role));
}
}
} else {
ModelNode whoami = result.step(1).get(RESULT);
String username = whoami.get("identity").get("username").asString();
user.setName(username);
if (whoami.hasDefined("mapped-roles")) {
List<ModelNode> roles = whoami.get("mapped-roles").asList();
for (ModelNode role : roles) {
String roleName = role.asString();
user.addRole(new Role(roleName));
}
}
}
user.setAuthenticated(true);
logger.debug("User info: {} {}", user.getName(), user.getRoles());
ModelNode step = result.step(2).get(RESULT);
environment.setPatchingEnabled(!environment.isStandalone() || step.get(PATCHING).isDefined());
}).toCompletable();
}
use of org.jboss.hal.config.Version in project console by hal.
the class CheckForUpdate method run.
@Override
public void run() {
// only check for community updates
if (environment.getHalBuild() == Build.PRODUCT) {
logger.debug("Version update check skipped for EAP");
} else {
logger.debug("Check for update");
XMLHttpRequest xhr = new XMLHttpRequest();
xhr.onload = event -> {
String versionText = xhr.responseText;
try {
logger.debug("Online version {}", versionText);
Version version = Version.parseVersion(versionText);
eventBus.fireEvent(new VersionUpdateEvent(version));
} catch (Throwable t) {
logger.warn("Cannot parse version from {}: {}", versionText, t.getMessage());
}
};
xhr.addEventListener("error", event -> logger.warn("Cannot read version from {}: Status {} {}", METADATA_URL, xhr.status, xhr.statusText));
xhr.open(GET.name(), METADATA_URL, true);
xhr.send();
}
}
Aggregations