All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openremote.manager.system.StatusResourceImpl Maven / Gradle / Ivy

/*
 * Copyright 2017, OpenRemote Inc.
 *
 * See the CONTRIBUTORS.txt file in the distribution for a
 * full listing of individual contributors.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see .
 */
package org.openremote.manager.system;

import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.model.Container;
import org.openremote.model.system.HealthStatusProvider;
import org.openremote.model.system.StatusResource;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class StatusResourceImpl implements StatusResource {

    private static final Logger LOG = Logger.getLogger(StatusResourceImpl.class.getName());
    protected List healthStatusProviderList;
    protected Map serverInfo;

    public StatusResourceImpl(Container container, List healthStatusProviderList) {
        this.healthStatusProviderList = healthStatusProviderList;
        Properties versionProps = new Properties();
        String authServerUrl = "";
        String version = null;

        ManagerIdentityService identityService = container.getService(ManagerIdentityService.class);
        if (identityService != null && identityService.getIdentityProvider().getFrontendURI() != null) {
            authServerUrl = identityService.getIdentityProvider().getFrontendURI();
        }

        try (InputStream resourceStream = StatusResourceImpl.class.getClassLoader().getResourceAsStream("version.properties")) {
            if (resourceStream != null) {
                versionProps.load(resourceStream);
                version = versionProps.getProperty("version");
            }
        } catch (IOException ignored) {
        }

        if (version == null) {
            LOG.log(Level.WARNING, "Failed to load manager version properties file: version.properties");
            version = "0.0.0";
        }

        serverInfo = Map.of(
            "version", version,
            "authServerUrl", authServerUrl
        );
    }

    @Override
    public Map getHealthStatus() {
        Map objectValue = new HashMap<>();

        healthStatusProviderList.forEach(healthStatusProvider -> {
            Map providerValue = Map.of("data", healthStatusProvider.getHealthStatus());
                objectValue.put(healthStatusProvider.getHealthStatusName(), providerValue);
            }
        );

        return objectValue;
    }

    @Override
    public Map getInfo() {
        return serverInfo;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy