Search in sources :

Example 1 with AddServerPopup

use of org.terasology.rendering.nui.layers.mainMenu.AddServerPopup in project Terasology by MovingBlocks.

the class TelemetryScreen method pushAddServerPopupAndStartLogBackAppender.

private void pushAddServerPopupAndStartLogBackAppender() {
    AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
    addServerPopup.removeTip();
    ServerInfo serverInfo;
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    if (telemetryConfig.getErrorReportingDestination() != null) {
        try {
            URL url = new URL("http://" + telemetryConfig.getErrorReportingDestination());
            serverInfo = new ServerInfo(telemetryConfig.getErrorReportingServerName(), url.getHost(), url.getPort());
            serverInfo.setOwner(telemetryConfig.getErrorReportingServerOwner());
        } catch (Exception e) {
            logger.error("Exception when get telemetry server information", e);
            serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
            serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
        }
    } else {
        serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
        serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
    }
    addServerPopup.setServerInfo(serverInfo);
    addServerPopup.onSuccess((item) -> {
        String destinationLogstash = item.getAddress() + ":" + item.getPort();
        TelemetryLogstashAppender telemetryLogstashAppender = TelemetryUtils.fetchTelemetryLogstashAppender();
        if (telemetryLogstashAppender != null) {
            telemetryLogstashAppender.addDestination(destinationLogstash);
            telemetryLogstashAppender.start();
        }
        // Save the destination
        telemetryConfig.setErrorReportingDestination(destinationLogstash);
        telemetryConfig.setErrorReportingServerName(item.getName());
        telemetryConfig.setErrorReportingServerOwner(item.getOwner());
    });
    addServerPopup.onCancel((button) -> telemetryConfig.setErrorReportingEnabled(false));
}
Also used : ServerInfo(org.terasology.config.ServerInfo) TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) AddServerPopup(org.terasology.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.config.TelemetryConfig)

Example 2 with AddServerPopup

use of org.terasology.rendering.nui.layers.mainMenu.AddServerPopup in project Terasology by MovingBlocks.

the class TelemetryScreen method pushAddServerPopupAndStartEmitter.

private void pushAddServerPopupAndStartEmitter() {
    AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
    addServerPopup.removeTip();
    ServerInfo serverInfo;
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    String telemetryDestination = telemetryConfig.getTelemetryDestination();
    if (telemetryDestination != null) {
        try {
            URL url = new URL(telemetryDestination);
            String address = url.getHost();
            int port = url.getPort();
            serverInfo = new ServerInfo(telemetryConfig.getTelemetryServerName(), address, port);
            serverInfo.setOwner(telemetryConfig.getTelemetryServerOwner());
        } catch (Exception e) {
            logger.error("Exception when get telemetry server information", e);
            serverInfo = new ServerInfo(TelemetryEmitter.DEFAULT_COLLECTOR_NAME, TelemetryEmitter.DEFAULT_COLLECTOR_HOST, TelemetryEmitter.DEFAULT_COLLECTOR_PORT);
            serverInfo.setOwner(TelemetryEmitter.DEFAULT_COLLECTOR_OWNER);
        }
    } else {
        serverInfo = new ServerInfo(TelemetryEmitter.DEFAULT_COLLECTOR_NAME, TelemetryEmitter.DEFAULT_COLLECTOR_HOST, TelemetryEmitter.DEFAULT_COLLECTOR_PORT);
        serverInfo.setOwner(TelemetryEmitter.DEFAULT_COLLECTOR_OWNER);
    }
    addServerPopup.setServerInfo(serverInfo);
    addServerPopup.onSuccess((item) -> {
        TelemetryEmitter telemetryEmitter = (TelemetryEmitter) emitter;
        Optional<URL> optionalURL = item.getURL("http");
        if (optionalURL.isPresent()) {
            telemetryEmitter.changeUrl(optionalURL.get());
            // Save the telemetry destination
            telemetryConfig.setTelemetryDestination(optionalURL.get().toString());
            telemetryConfig.setTelemetryServerName(item.getName());
            telemetryConfig.setTelemetryServerOwner(item.getOwner());
        }
    });
    addServerPopup.onCancel((button) -> config.getTelemetryConfig().setTelemetryEnabled(false));
}
Also used : ServerInfo(org.terasology.config.ServerInfo) AddServerPopup(org.terasology.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.config.TelemetryConfig)

Aggregations

URL (java.net.URL)2 ServerInfo (org.terasology.config.ServerInfo)2 TelemetryConfig (org.terasology.config.TelemetryConfig)2 AddServerPopup (org.terasology.rendering.nui.layers.mainMenu.AddServerPopup)2 TelemetryLogstashAppender (org.terasology.telemetry.logstash.TelemetryLogstashAppender)1