package com.github.secondbase.all;

import java.io.IOException;
import com.github.secondbase.consul.ConsulModule;
import com.github.secondbase.core.SecondBaseException;
import com.github.secondbase.core.config.SecondBaseModule;
import com.github.secondbase.flags.Flags;
import com.github.secondbase.logging.JsonLoggerModule;
import com.github.secondbase.secrets.SecretHandler;
import com.github.secondbase.secrets.s3.S3SecretHandler;
import com.github.secondbase.secrets.vault.VaultSecretHandler;
import com.github.secondbase.webconsole.HttpWebConsole;
import com.github.secondbase.webconsole.PrometheusWebConsole;
import com.github.secondbase.webconsole.widget.Widget;

/**
 * SecondBase implementation which will set up all submodules
 */
public class SecondBase {
    /**
     * Initiates {@link com.github.secondbase.core.SecondBase} with all {@link SecondBaseModule}
     * available.
     * @param args command line arguments to be parsed
     * @throws IOException if WebConsole fails to start
     * @throws SecondBaseException if {@link com.github.secondbase.core.SecondBase} fails to start
     */
    public SecondBase(final String[] args) throws IOException, SecondBaseException {
        new SecondBase(
                args,
                new Flags(
                        new SecretHandler[]{
                                new S3SecretHandler(),
                                new VaultSecretHandler()}));
    }

    /**
     * Initiates {@link com.github.secondbase.core.SecondBase} with all {@link SecondBaseModule}
     * available.
     * @param args command line arguments to be parsed
     * @param flags custom {@link Flags}. NB! Needs custom setup of {@link SecretHandler}
     * @throws IOException if WebConsole fails to start
     * @throws SecondBaseException if {@link com.github.secondbase.core.SecondBase} fails to start
     */
    public SecondBase(
            final String[] args,
            final Flags flags)
            throws IOException, SecondBaseException {
        final SecondBaseModule jsonLogger = new JsonLoggerModule();

        final Widget prometheusWidget = new PrometheusWebConsole();
        final Widget[] widgets = {prometheusWidget};

        final ConsulModule consul = new ConsulModule();
        final SecondBaseModule webconsole = new HttpWebConsole(widgets);
        final SecondBaseModule[] modules = {consul, webconsole, jsonLogger};

        new com.github.secondbase.core.SecondBase(args, modules, flags);

        //TODO: Register webconsole in consul.
    }
}

@@ -29,16 +29,102 @@
 e.all;%0A%0A
+import com.github.secondbase.consul.registration.ConsulRegistrationMetricsWebConsole;%0A
 import j
@@ -2077,32 +2077,33 @@
 BaseException %7B%0A
+%0A
         final Se
@@ -2169,22 +2169,36 @@
   final 
-Widget
+PrometheusWebConsole
  prometh
@@ -2289,16 +2289,87 @@
 Widget%7D;
+%0A        final HttpWebConsole webConsole = new HttpWebConsole(widgets);
 %0A%0A      
@@ -2436,67 +2436,140 @@
 nal 
-SecondBaseModule webc
+ConsulRegistrationMetricsWebC
 onsole 
-= new HttpWebConsole(widgets
+registerMetrics%0A                = new ConsulRegistrationMetricsWebConsole(webConsole, consul
 );%0A
+%0A
     
@@ -2612,38 +2612,226 @@
  = %7B
-consul,
+%0A                jsonLogger, // Put jsonLogger first, since it can define how the other modules log.%0A                consul,%0A                prometheusWidget,%0A               
  web
-c
+C
 onsole,
- jsonLogger
+%0A                registerMetrics
 %7D;%0A%0A

Add consul reg for webconsole in SecondBase all (#61)