Search in sources :

Example 1 with Version

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();
}
Also used : OperationMode(org.jboss.hal.config.OperationMode) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Version(org.jboss.hal.config.Version) Logger(org.slf4j.Logger) CompositeResult(org.jboss.hal.dmr.CompositeResult) Environment(org.jboss.hal.config.Environment) Operation(org.jboss.hal.dmr.Operation) LoggerFactory(org.slf4j.LoggerFactory) KeycloakHolder(org.jboss.hal.config.keycloak.KeycloakHolder) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ManagementModel(org.jboss.hal.meta.ManagementModel) FlowContext(org.jboss.hal.flow.FlowContext) ModelNodeHelper.asEnumValue(org.jboss.hal.dmr.ModelNodeHelper.asEnumValue) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Role(org.jboss.hal.config.Role) Keycloak(org.jboss.hal.config.keycloak.Keycloak) User(org.jboss.hal.config.User) Server(org.jboss.hal.core.runtime.server.Server) Composite(org.jboss.hal.dmr.Composite) CompositeResult(org.jboss.hal.dmr.CompositeResult) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) Role(org.jboss.hal.config.Role) Version(org.jboss.hal.config.Version) ArrayList(java.util.ArrayList) List(java.util.List) Keycloak(org.jboss.hal.config.keycloak.Keycloak) ModelNode(org.jboss.hal.dmr.ModelNode) OperationMode(org.jboss.hal.config.OperationMode)

Example 2 with Version

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();
    }
}
Also used : Version(org.jboss.hal.config.Version) XMLHttpRequest(elemental2.dom.XMLHttpRequest)

Aggregations

Version (org.jboss.hal.config.Version)2 XMLHttpRequest (elemental2.dom.XMLHttpRequest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Inject (javax.inject.Inject)1 Environment (org.jboss.hal.config.Environment)1 OperationMode (org.jboss.hal.config.OperationMode)1 Role (org.jboss.hal.config.Role)1 User (org.jboss.hal.config.User)1 Keycloak (org.jboss.hal.config.keycloak.Keycloak)1 KeycloakHolder (org.jboss.hal.config.keycloak.KeycloakHolder)1 Server (org.jboss.hal.core.runtime.server.Server)1 Composite (org.jboss.hal.dmr.Composite)1 CompositeResult (org.jboss.hal.dmr.CompositeResult)1 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)1 ModelNode (org.jboss.hal.dmr.ModelNode)1 ModelNodeHelper.asEnumValue (org.jboss.hal.dmr.ModelNodeHelper.asEnumValue)1 Operation (org.jboss.hal.dmr.Operation)1 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)1 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)1