Étiquette : Coding

  • Socle V004 – Données Partagées

    Socle V004 – Données Partagées

    07 – SharedDataRegistry

    Version : 4.0.0 Date : 2025-12-09

    1. Introduction

    SharedDataRegistry est un registre centralisé pour partager des données entre Workers au sein d’une même instance. Il fournit des opérations atomiques et un système de niveaux de santé.

    Différence avec KvBus

    Aspect SharedDataRegistry KvBus
    Scope Intra-instance Optionnel inter-instances (Redis)
    Performance Ultra rapide (mémoire) Variable (réseau si Redis)
    Types Fortement typés Strings/JSON
    Health levels Oui Non
    Callbacks Oui Non

    2. Interface SharedDataRegistry

    package eu.lmvi.socle.shared;
    
    public interface SharedDataRegistry {
    
        // === Key-Value basique ===
    
        void put(String key, Object value);
        void put(String key, Object value, HealthLevel level);
        Optional<Object> get(String key);
        <T> Optional<T> get(String key, Class<T> type);
        void delete(String key);
        boolean exists(String key);
    
        // === Typed getters ===
    
        Optional<String> getString(String key);
        Optional<Integer> getInt(String key);
        Optional<Long> getLong(String key);
        Optional<Double> getDouble(String key);
        Optional<Boolean> getBoolean(String key);
    
        // === Sequences (compteurs atomiques) ===
    
        void createSequence(String key, long initialValue, HealthLevel level);
        long incrementSequence(String key);
        long incrementSequence(String key, long delta);
        long getSequence(String key);
        void setSequence(String key, long value);
    
        // === Lists ===
    
        <T> void addToList(String key, T item);
        <T> List<T> getList(String key, Class<T> type);
        void clearList(String key);
    
        // === Maps ===
    
        <V> void putInMap(String key, String mapKey, V value);
        <V> Optional<V> getFromMap(String key, String mapKey, Class<V> type);
        <V> Map<String, V> getMap(String key, Class<V> type);
        void removeFromMap(String key, String mapKey);
    
        // === Health ===
    
        HealthLevel getHealthLevel(String key);
        Map<String, HealthLevel> getAllHealthLevels();
        List<String> getUnhealthyKeys();
    
        // === Callbacks ===
    
        void registerCallback(String key, Consumer<Object> callback);
        void unregisterCallback(String key);
    
        // === Introspection ===
    
        Set<String> keys();
        Set<String> keys(String pattern);
        Map<String, Object> getAll();
        int size();
        void clear();
    }
    

    3. Health Levels

    package eu.lmvi.socle.shared;
    
    public enum HealthLevel {
        /**
         * Informatif - pas d'impact sur la santé
         */
        INFO,
    
        /**
         * Normal - contribue à la santé normale
         */
        NORMAL,
    
        /**
         * Important - dégradation si problème
         */
        IMPORTANT,
    
        /**
         * Critique - unhealthy si problème
         */
        CRITICAL
    }
    

    Utilisation dans le Supervisor

    Le Supervisor consulte les HealthLevel pour déterminer l’état de santé global :

    • CRITICAL absent ou invalide → Instance UNHEALTHY
    • IMPORTANT absent ou invalide → Instance DEGRADED
    • NORMAL/INFO → Pas d’impact

    4. Implémentation

    package eu.lmvi.socle.shared;
    
    @Component
    public class InMemorySharedDataRegistry implements SharedDataRegistry {
    
        private final ConcurrentHashMap<String, Entry> store = new ConcurrentHashMap<>();
        private final ConcurrentHashMap<String, Consumer<Object>> callbacks = new ConcurrentHashMap<>();
    
        @Override
        public void put(String key, Object value) {
            put(key, value, HealthLevel.NORMAL);
        }
    
        @Override
        public void put(String key, Object value, HealthLevel level) {
            Entry previous = store.put(key, new Entry(value, level));
            notifyCallback(key, value);
        }
    
        @Override
        public Optional<Object> get(String key) {
            Entry entry = store.get(key);
            return entry != null ? Optional.of(entry.value) : Optional.empty();
        }
    
        @Override
        public <T> Optional<T> get(String key, Class<T> type) {
            return get(key).filter(type::isInstance).map(type::cast);
        }
    
        @Override
        public Optional<String> getString(String key) {
            return get(key).map(Object::toString);
        }
    
        @Override
        public Optional<Integer> getInt(String key) {
            return get(key, Number.class).map(Number::intValue);
        }
    
        @Override
        public Optional<Long> getLong(String key) {
            return get(key, Number.class).map(Number::longValue);
        }
    
        @Override
        public void createSequence(String key, long initialValue, HealthLevel level) {
            store.put(key, new Entry(new AtomicLong(initialValue), level));
        }
    
        @Override
        public long incrementSequence(String key) {
            return incrementSequence(key, 1);
        }
    
        @Override
        public long incrementSequence(String key, long delta) {
            Entry entry = store.get(key);
            if (entry == null || !(entry.value instanceof AtomicLong)) {
                throw new IllegalStateException("Sequence not found: " + key);
            }
            long newValue = ((AtomicLong) entry.value).addAndGet(delta);
            notifyCallback(key, newValue);
            return newValue;
        }
    
        @Override
        public long getSequence(String key) {
            Entry entry = store.get(key);
            if (entry == null || !(entry.value instanceof AtomicLong)) {
                throw new IllegalStateException("Sequence not found: " + key);
            }
            return ((AtomicLong) entry.value).get();
        }
    
        @Override
        public HealthLevel getHealthLevel(String key) {
            Entry entry = store.get(key);
            return entry != null ? entry.level : null;
        }
    
        @Override
        public List<String> getUnhealthyKeys() {
            return store.entrySet().stream()
                .filter(e -> e.getValue().level == HealthLevel.CRITICAL)
                .filter(e -> !isValueHealthy(e.getValue().value))
                .map(Map.Entry::getKey)
                .toList();
        }
    
        @Override
        public void registerCallback(String key, Consumer<Object> callback) {
            callbacks.put(key, callback);
        }
    
        private void notifyCallback(String key, Object value) {
            Consumer<Object> callback = callbacks.get(key);
            if (callback != null) {
                try {
                    callback.accept(value);
                } catch (Exception e) {
                    // Log but don't propagate
                }
            }
        }
    
        private boolean isValueHealthy(Object value) {
            if (value == null) return false;
            if (value instanceof Boolean b) return b;
            if (value instanceof Number n) return n.doubleValue() >= 0;
            return true;
        }
    
        private record Entry(Object value, HealthLevel level) {}
    }
    

    5. Utilisation

    5.1 Injection

    @Service
    public class MonService {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void process() {
            // ...
        }
    }
    

    5.2 Key-Value simple

    // Stocker
    registry.put("config.maxRetries", 3);
    registry.put("status.lastSync", Instant.now().toString());
    
    // Récupérer
    int maxRetries = registry.getInt("config.maxRetries").orElse(5);
    String lastSync = registry.getString("status.lastSync").orElse("never");
    

    5.3 Avec Health Level

    // Donnée critique - instance unhealthy si absente
    registry.put("database.connected", true, HealthLevel.CRITICAL);
    
    // Donnée importante - instance degraded si absente
    registry.put("cache.available", true, HealthLevel.IMPORTANT);
    
    // Donnée normale
    registry.put("stats.requestsTotal", 0, HealthLevel.NORMAL);
    
    // Donnée informative
    registry.put("info.startTime", Instant.now(), HealthLevel.INFO);
    

    5.4 Sequences (Compteurs)

    // Créer une séquence
    registry.createSequence("orders.processed", 0, HealthLevel.NORMAL);
    
    // Incrémenter
    long count = registry.incrementSequence("orders.processed");
    log.info("Processed order #{}", count);
    
    // Incrémenter avec delta
    long bytes = registry.incrementSequence("bytes.transferred", 1024);
    
    // Lire
    long total = registry.getSequence("orders.processed");
    

    5.5 Listes

    // Ajouter à une liste
    registry.addToList("errors.recent", new ErrorRecord("timeout", Instant.now()));
    registry.addToList("errors.recent", new ErrorRecord("connection", Instant.now()));
    
    // Lire la liste
    List<ErrorRecord> errors = registry.getList("errors.recent", ErrorRecord.class);
    
    // Vider
    registry.clearList("errors.recent");
    

    5.6 Maps

    // Stocker dans une map
    registry.putInMap("workers.status", "worker-1", "RUNNING");
    registry.putInMap("workers.status", "worker-2", "STOPPED");
    
    // Lire une entrée
    Optional<String> status = registry.getFromMap("workers.status", "worker-1", String.class);
    
    // Lire toute la map
    Map<String, String> allStatus = registry.getMap("workers.status", String.class);
    

    5.7 Callbacks

    // Enregistrer un callback
    registry.registerCallback("config.maxRetries", newValue -> {
        log.info("maxRetries changed to: {}", newValue);
        reconfigure((Integer) newValue);
    });
    
    // La modification déclenche le callback
    registry.put("config.maxRetries", 5);  // Callback appelé
    

    6. Patterns courants

    6.1 État de connexion

    @Component
    public class DatabaseWorker implements Worker {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @Override
        public void initialize() {
            registry.put("database.connected", false, HealthLevel.CRITICAL);
        }
    
        @Override
        public void start() {
            try {
                connect();
                registry.put("database.connected", true, HealthLevel.CRITICAL);
            } catch (Exception e) {
                registry.put("database.connected", false, HealthLevel.CRITICAL);
                throw e;
            }
        }
    
        @Override
        public void stop() {
            disconnect();
            registry.put("database.connected", false, HealthLevel.CRITICAL);
        }
    }
    

    6.2 Métriques temps réel

    @Component
    public class MetricsCollector {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @PostConstruct
        public void init() {
            registry.createSequence("metrics.requests.total", 0, HealthLevel.INFO);
            registry.createSequence("metrics.requests.errors", 0, HealthLevel.NORMAL);
            registry.createSequence("metrics.bytes.in", 0, HealthLevel.INFO);
            registry.createSequence("metrics.bytes.out", 0, HealthLevel.INFO);
        }
    
        public void recordRequest(long bytesIn, long bytesOut, boolean success) {
            registry.incrementSequence("metrics.requests.total");
            registry.incrementSequence("metrics.bytes.in", bytesIn);
            registry.incrementSequence("metrics.bytes.out", bytesOut);
    
            if (!success) {
                registry.incrementSequence("metrics.requests.errors");
            }
        }
    
        public Map<String, Object> getMetrics() {
            return Map.of(
                "requests.total", registry.getSequence("metrics.requests.total"),
                "requests.errors", registry.getSequence("metrics.requests.errors"),
                "bytes.in", registry.getSequence("metrics.bytes.in"),
                "bytes.out", registry.getSequence("metrics.bytes.out")
            );
        }
    }
    

    6.3 Circuit Breaker state

    @Component
    public class CircuitBreakerStateManager {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void updateState(String circuitName, CircuitState state) {
            String key = "circuit." + circuitName + ".state";
            HealthLevel level = state == CircuitState.OPEN
                ? HealthLevel.IMPORTANT
                : HealthLevel.NORMAL;
            registry.put(key, state.name(), level);
        }
    
        public CircuitState getState(String circuitName) {
            return registry.getString("circuit." + circuitName + ".state")
                .map(CircuitState::valueOf)
                .orElse(CircuitState.CLOSED);
        }
    }
    

    6.4 Progress tracking

    @Component
    public class BatchProcessor {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void processBatch(String batchId, List<Item> items) {
            registry.put("batch." + batchId + ".total", items.size());
            registry.createSequence("batch." + batchId + ".processed", 0, HealthLevel.NORMAL);
    
            for (Item item : items) {
                processItem(item);
                registry.incrementSequence("batch." + batchId + ".processed");
            }
    
            registry.put("batch." + batchId + ".status", "COMPLETED");
        }
    
        public double getProgress(String batchId) {
            int total = registry.getInt("batch." + batchId + ".total").orElse(0);
            if (total == 0) return 0;
    
            long processed = registry.getSequence("batch." + batchId + ".processed");
            return (double) processed / total * 100;
        }
    }
    

    7. Intégration avec Supervisor

    @Component
    public class HealthAggregator {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @Autowired
        private List<Worker> workers;
    
        public HealthStatus aggregateHealth() {
            // Check workers
            boolean allWorkersHealthy = workers.stream().allMatch(Worker::isHealthy);
    
            // Check critical registry entries
            List<String> unhealthyKeys = registry.getUnhealthyKeys();
            boolean hasCriticalFailure = !unhealthyKeys.isEmpty();
    
            if (!allWorkersHealthy || hasCriticalFailure) {
                return HealthStatus.UNHEALTHY;
            }
    
            // Check important entries
            Map<String, HealthLevel> levels = registry.getAllHealthLevels();
            boolean hasImportantFailure = levels.entrySet().stream()
                .filter(e -> e.getValue() == HealthLevel.IMPORTANT)
                .anyMatch(e -> !isHealthy(registry.get(e.getKey())));
    
            if (hasImportantFailure) {
                return HealthStatus.DEGRADED;
            }
    
            return HealthStatus.HEALTHY;
        }
    }
    

    8. Exposition API

    @RestController
    @RequestMapping("/admin/registry")
    public class SharedDataController {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @GetMapping
        public Map<String, Object> getAll() {
            return registry.getAll();
        }
    
        @GetMapping("/{key}")
        public ResponseEntity<?> get(@PathVariable String key) {
            return registry.get(key)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
        }
    
        @GetMapping("/health")
        public Map<String, HealthLevel> getHealthLevels() {
            return registry.getAllHealthLevels();
        }
    
        @GetMapping("/unhealthy")
        public List<String> getUnhealthyKeys() {
            return registry.getUnhealthyKeys();
        }
    }
    

    9. Bonnes pratiques

    Conventions de nommage

    <category>.<subcategory>.<name>
    
    Exemples:
    - database.connected
    - worker.kafka.status
    - metrics.requests.total
    - batch.order-123.progress
    - circuit.external-api.state
    

    DO

    • Utiliser des noms de clés cohérents et hiérarchiques
    • Définir le HealthLevel approprié pour chaque donnée
    • Utiliser les sequences pour les compteurs (thread-safe)
    • Nettoyer les données obsolètes

    DON’T

    • Ne pas stocker de données volumineuses (logs, payloads)
    • Ne pas utiliser pour le stockage persistant (utiliser TechDB)
    • Ne pas créer de nouvelles clés dynamiquement sans contrôle
    • Ne pas oublier que c’est per-instance (pas de sync multi-instances)

    10. Références

  • Socle V004 – TLS/HTTPS

    Socle V004 – TLS/HTTPS

    13 – TLS/HTTPS

    Version : 4.0.0 Date : 2025-12-09

    1. Introduction

    Configuration du TLS/HTTPS pour sécuriser les communications HTTP du Socle V4.

    2. Configuration Spring Boot

    2.1 application.yml

    server:
      port: ${HTTPS_PORT:8443}
      ssl:
        enabled: ${SSL_ENABLED:true}
        key-store: ${SSL_KEYSTORE:classpath:keystore.p12}
        key-store-password: ${SSL_KEYSTORE_PASSWORD:changeit}
        key-store-type: ${SSL_KEYSTORE_TYPE:PKCS12}
        key-alias: ${SSL_KEY_ALIAS:socle}
    

    2.2 Variables d’environnement

    Variable Description Défaut
    SSL_ENABLED Activer SSL false
    SSL_KEYSTORE Chemin du keystore classpath:keystore.p12
    SSL_KEYSTORE_PASSWORD Mot de passe keystore changeit
    SSL_KEYSTORE_TYPE Type de keystore PKCS12
    SSL_KEY_ALIAS Alias de la clé socle

    3. Génération des certificats

    3.1 Certificat auto-signé (développement)

    # Générer un keystore PKCS12 avec certificat auto-signé
    keytool -genkeypair \
      -alias socle \
      -keyalg RSA \
      -keysize 2048 \
      -storetype PKCS12 \
      -keystore keystore.p12 \
      -validity 365 \
      -dname "CN=localhost,OU=Dev,O=MyCompany,L=Paris,C=FR" \
      -storepass changeit \
      -keypass changeit
    
    # Exporter le certificat (pour les clients)
    keytool -exportcert \
      -alias socle \
      -keystore keystore.p12 \
      -storetype PKCS12 \
      -storepass changeit \
      -file socle.crt
    

    3.2 Avec Let’s Encrypt (production)

    # Obtenir le certificat
    certbot certonly --standalone -d myapp.example.com
    
    # Convertir en PKCS12
    openssl pkcs12 -export \
      -in /etc/letsencrypt/live/myapp.example.com/fullchain.pem \
      -inkey /etc/letsencrypt/live/myapp.example.com/privkey.pem \
      -out keystore.p12 \
      -name socle \
      -passout pass:changeit
    

    3.3 Avec CA interne

    # Générer CSR
    keytool -certreq \
      -alias socle \
      -keystore keystore.p12 \
      -file socle.csr \
      -storepass changeit
    
    # Après signature par la CA, importer le certificat
    keytool -importcert \
      -alias socle \
      -keystore keystore.p12 \
      -file signed-cert.crt \
      -storepass changeit
    
    # Importer la chaîne CA
    keytool -importcert \
      -alias ca-root \
      -keystore keystore.p12 \
      -file ca-root.crt \
      -storepass changeit
    

    4. Configuration avancée

    4.1 Mutual TLS (mTLS)

    server:
      ssl:
        enabled: true
        key-store: ${SSL_KEYSTORE:keystore.p12}
        key-store-password: ${SSL_KEYSTORE_PASSWORD}
        key-store-type: PKCS12
        # Trust store pour vérifier les clients
        trust-store: ${SSL_TRUSTSTORE:truststore.p12}
        trust-store-password: ${SSL_TRUSTSTORE_PASSWORD}
        trust-store-type: PKCS12
        # Exiger certificat client
        client-auth: ${SSL_CLIENT_AUTH:need}  # none, want, need
    

    4.2 Protocoles et Ciphers

    server:
      ssl:
        enabled-protocols: TLSv1.3,TLSv1.2
        ciphers:
          - TLS_AES_256_GCM_SHA384
          - TLS_AES_128_GCM_SHA256
          - TLS_CHACHA20_POLY1305_SHA256
          - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
          - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
    

    5. HTTP + HTTPS (dual port)

    5.1 Configuration

    @Configuration
    public class TlsConfiguration {
    
        @Value("${server.http.port:8080}")
        private int httpPort;
    
        @Bean
        public ServletWebServerFactory servletContainer() {
            TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
            tomcat.addAdditionalTomcatConnectors(createHttpConnector());
            return tomcat;
        }
    
        private Connector createHttpConnector() {
            Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
            connector.setScheme("http");
            connector.setPort(httpPort);
            connector.setSecure(false);
            return connector;
        }
    }
    

    5.2 Redirection HTTP → HTTPS

    @Configuration
    public class HttpsRedirectConfiguration {
    
        @Bean
        public TomcatServletWebServerFactory servletContainer() {
            TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
                @Override
                protected void postProcessContext(Context context) {
                    SecurityConstraint securityConstraint = new SecurityConstraint();
                    securityConstraint.setUserConstraint("CONFIDENTIAL");
                    SecurityCollection collection = new SecurityCollection();
                    collection.addPattern("/*");
                    securityConstraint.addCollection(collection);
                    context.addConstraint(securityConstraint);
                }
            };
    
            tomcat.addAdditionalTomcatConnectors(httpToHttpsRedirectConnector());
            return tomcat;
        }
    
        private Connector httpToHttpsRedirectConnector() {
            Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
            connector.setScheme("http");
            connector.setPort(8080);
            connector.setSecure(false);
            connector.setRedirectPort(8443);
            return connector;
        }
    }
    

    6. Client HTTPS

    6.1 OkHttpClient avec TLS

    @Configuration
    public class HttpClientConfiguration {
    
        @Value("${ssl.truststore:#{null}}")
        private Resource trustStore;
    
        @Value("${ssl.truststore-password:changeit}")
        private String trustStorePassword;
    
        @Bean
        public OkHttpClient secureHttpClient() throws Exception {
            OkHttpClient.Builder builder = new OkHttpClient.Builder();
    
            if (trustStore != null && trustStore.exists()) {
                KeyStore ks = KeyStore.getInstance("PKCS12");
                try (InputStream is = trustStore.getInputStream()) {
                    ks.load(is, trustStorePassword.toCharArray());
                }
    
                TrustManagerFactory tmf = TrustManagerFactory.getInstance(
                    TrustManagerFactory.getDefaultAlgorithm());
                tmf.init(ks);
    
                SSLContext sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, tmf.getTrustManagers(), new SecureRandom());
    
                builder.sslSocketFactory(sslContext.getSocketFactory(),
                    (X509TrustManager) tmf.getTrustManagers()[0]);
            }
    
            return builder
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .build();
        }
    }
    

    6.2 Bypass SSL pour développement (NON RECOMMANDÉ)

    // UNIQUEMENT POUR LE DÉVELOPPEMENT - NE PAS UTILISER EN PRODUCTION
    public OkHttpClient insecureClient() throws Exception {
        TrustManager[] trustAllCerts = new TrustManager[]{
            new X509TrustManager() {
                public void checkClientTrusted(X509Certificate[] chain, String authType) {}
                public void checkServerTrusted(X509Certificate[] chain, String authType) {}
                public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
            }
        };
    
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new SecureRandom());
    
        return new OkHttpClient.Builder()
            .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
            .hostnameVerifier((hostname, session) -> true)
            .build();
    }
    

    7. Docker avec TLS

    7.1 Dockerfile

    FROM eclipse-temurin:21-jre
    
    WORKDIR /app
    
    # Copier le certificat
    COPY keystore.p12 /app/certs/keystore.p12
    
    # Copier l'application
    COPY target/socle-v004-4.0.0.jar app.jar
    
    ENV SSL_ENABLED=true
    ENV SSL_KEYSTORE=/app/certs/keystore.p12
    
    EXPOSE 8443
    
    ENTRYPOINT ["java", "-jar", "app.jar"]
    

    7.2 docker-compose.yml

    version: '3.8'
    
    services:
      socle-app:
        image: socle-v4:latest
        environment:
          - SSL_ENABLED=true
          - SSL_KEYSTORE=/app/certs/keystore.p12
          - SSL_KEYSTORE_PASSWORD_FILE=/run/secrets/ssl_password
        ports:
          - "8443:8443"
        volumes:
          - ./certs:/app/certs:ro
        secrets:
          - ssl_password
    
    secrets:
      ssl_password:
        file: ./secrets/ssl_password.txt
    

    8. Kubernetes avec TLS

    8.1 Secret pour le certificat

    apiVersion: v1
    kind: Secret
    metadata:
      name: socle-tls
    type: kubernetes.io/tls
    data:
      tls.crt: <base64-encoded-cert>
      tls.key: <base64-encoded-key>
    

    8.2 Ingress avec TLS

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: socle-ingress
      annotations:
        nginx.ingress.kubernetes.io/ssl-redirect: "true"
    spec:
      tls:
        - hosts:
            - socle.example.com
          secretName: socle-tls
      rules:
        - host: socle.example.com
          http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: socle-service
                    port:
                      number: 8080
    

    8.3 cert-manager

    apiVersion: cert-manager.io/v1
    kind: Certificate
    metadata:
      name: socle-cert
    spec:
      secretName: socle-tls
      issuerRef:
        name: letsencrypt-prod
        kind: ClusterIssuer
      dnsNames:
        - socle.example.com
    

    9. Vérification

    9.1 Test avec curl

    # Test HTTPS
    curl -v https://localhost:8443/admin/health
    
    # Avec certificat client (mTLS)
    curl -v --cert client.crt --key client.key https://localhost:8443/admin/health
    
    # Ignorer la vérification (dev only)
    curl -vk https://localhost:8443/admin/health
    

    9.2 Test avec openssl

    # Vérifier le certificat du serveur
    openssl s_client -connect localhost:8443 -showcerts
    
    # Vérifier les protocoles supportés
    openssl s_client -connect localhost:8443 -tls1_3
    
    # Vérifier les ciphers
    openssl s_client -connect localhost:8443 -cipher 'ECDHE-RSA-AES256-GCM-SHA384'
    

    10. Troubleshooting

    Erreur: PKIX path building failed

    Le certificat du serveur n’est pas trusté.

    # Importer le certificat dans le truststore Java
    keytool -importcert \
      -alias server-cert \
      -file server.crt \
      -keystore $JAVA_HOME/lib/security/cacerts \
      -storepass changeit
    

    Erreur: Handshake failure

    Incompatibilité de protocole ou cipher.

    # Vérifier les protocoles
    openssl s_client -connect host:port -tls1_2
    openssl s_client -connect host:port -tls1_3
    

    Erreur: Certificate expired

    Renouveler le certificat et recréer le keystore.

    11. Bonnes pratiques

    DO

    • Utiliser TLS 1.2 minimum, TLS 1.3 recommandé
    • Renouveler les certificats avant expiration
    • Utiliser des clés RSA 2048 bits minimum ou ECDSA 256 bits
    • Activer HSTS en production
    • Utiliser cert-manager en Kubernetes

    DON’T

    • Ne pas utiliser de certificats auto-signés en production
    • Ne pas désactiver la vérification des certificats
    • Ne pas stocker les mots de passe en clair
    • Ne pas utiliser TLS 1.0 ou 1.1 (dépréciés)

    12. Références

  • Socle V004 – Données Partagées

    Socle V004 – Données Partagées

    07 – SharedDataRegistry

    Version : 4.0.0 Date : 2025-12-09

    1. Introduction

    SharedDataRegistry est un registre centralisé pour partager des données entre Workers au sein d’une même instance. Il fournit des opérations atomiques et un système de niveaux de santé.

    Différence avec KvBus

    Aspect SharedDataRegistry KvBus
    Scope Intra-instance Optionnel inter-instances (Redis)
    Performance Ultra rapide (mémoire) Variable (réseau si Redis)
    Types Fortement typés Strings/JSON
    Health levels Oui Non
    Callbacks Oui Non

    2. Interface SharedDataRegistry

    package eu.lmvi.socle.shared;
    
    public interface SharedDataRegistry {
    
        // === Key-Value basique ===
    
        void put(String key, Object value);
        void put(String key, Object value, HealthLevel level);
        Optional<Object> get(String key);
        <T> Optional<T> get(String key, Class<T> type);
        void delete(String key);
        boolean exists(String key);
    
        // === Typed getters ===
    
        Optional<String> getString(String key);
        Optional<Integer> getInt(String key);
        Optional<Long> getLong(String key);
        Optional<Double> getDouble(String key);
        Optional<Boolean> getBoolean(String key);
    
        // === Sequences (compteurs atomiques) ===
    
        void createSequence(String key, long initialValue, HealthLevel level);
        long incrementSequence(String key);
        long incrementSequence(String key, long delta);
        long getSequence(String key);
        void setSequence(String key, long value);
    
        // === Lists ===
    
        <T> void addToList(String key, T item);
        <T> List<T> getList(String key, Class<T> type);
        void clearList(String key);
    
        // === Maps ===
    
        <V> void putInMap(String key, String mapKey, V value);
        <V> Optional<V> getFromMap(String key, String mapKey, Class<V> type);
        <V> Map<String, V> getMap(String key, Class<V> type);
        void removeFromMap(String key, String mapKey);
    
        // === Health ===
    
        HealthLevel getHealthLevel(String key);
        Map<String, HealthLevel> getAllHealthLevels();
        List<String> getUnhealthyKeys();
    
        // === Callbacks ===
    
        void registerCallback(String key, Consumer<Object> callback);
        void unregisterCallback(String key);
    
        // === Introspection ===
    
        Set<String> keys();
        Set<String> keys(String pattern);
        Map<String, Object> getAll();
        int size();
        void clear();
    }
    

    3. Health Levels

    package eu.lmvi.socle.shared;
    
    public enum HealthLevel {
        /**
         * Informatif - pas d'impact sur la santé
         */
        INFO,
    
        /**
         * Normal - contribue à la santé normale
         */
        NORMAL,
    
        /**
         * Important - dégradation si problème
         */
        IMPORTANT,
    
        /**
         * Critique - unhealthy si problème
         */
        CRITICAL
    }
    

    Utilisation dans le Supervisor

    Le Supervisor consulte les HealthLevel pour déterminer l’état de santé global :

    • CRITICAL absent ou invalide → Instance UNHEALTHY
    • IMPORTANT absent ou invalide → Instance DEGRADED
    • NORMAL/INFO → Pas d’impact

    4. Implémentation

    package eu.lmvi.socle.shared;
    
    @Component
    public class InMemorySharedDataRegistry implements SharedDataRegistry {
    
        private final ConcurrentHashMap<String, Entry> store = new ConcurrentHashMap<>();
        private final ConcurrentHashMap<String, Consumer<Object>> callbacks = new ConcurrentHashMap<>();
    
        @Override
        public void put(String key, Object value) {
            put(key, value, HealthLevel.NORMAL);
        }
    
        @Override
        public void put(String key, Object value, HealthLevel level) {
            Entry previous = store.put(key, new Entry(value, level));
            notifyCallback(key, value);
        }
    
        @Override
        public Optional<Object> get(String key) {
            Entry entry = store.get(key);
            return entry != null ? Optional.of(entry.value) : Optional.empty();
        }
    
        @Override
        public <T> Optional<T> get(String key, Class<T> type) {
            return get(key).filter(type::isInstance).map(type::cast);
        }
    
        @Override
        public Optional<String> getString(String key) {
            return get(key).map(Object::toString);
        }
    
        @Override
        public Optional<Integer> getInt(String key) {
            return get(key, Number.class).map(Number::intValue);
        }
    
        @Override
        public Optional<Long> getLong(String key) {
            return get(key, Number.class).map(Number::longValue);
        }
    
        @Override
        public void createSequence(String key, long initialValue, HealthLevel level) {
            store.put(key, new Entry(new AtomicLong(initialValue), level));
        }
    
        @Override
        public long incrementSequence(String key) {
            return incrementSequence(key, 1);
        }
    
        @Override
        public long incrementSequence(String key, long delta) {
            Entry entry = store.get(key);
            if (entry == null || !(entry.value instanceof AtomicLong)) {
                throw new IllegalStateException("Sequence not found: " + key);
            }
            long newValue = ((AtomicLong) entry.value).addAndGet(delta);
            notifyCallback(key, newValue);
            return newValue;
        }
    
        @Override
        public long getSequence(String key) {
            Entry entry = store.get(key);
            if (entry == null || !(entry.value instanceof AtomicLong)) {
                throw new IllegalStateException("Sequence not found: " + key);
            }
            return ((AtomicLong) entry.value).get();
        }
    
        @Override
        public HealthLevel getHealthLevel(String key) {
            Entry entry = store.get(key);
            return entry != null ? entry.level : null;
        }
    
        @Override
        public List<String> getUnhealthyKeys() {
            return store.entrySet().stream()
                .filter(e -> e.getValue().level == HealthLevel.CRITICAL)
                .filter(e -> !isValueHealthy(e.getValue().value))
                .map(Map.Entry::getKey)
                .toList();
        }
    
        @Override
        public void registerCallback(String key, Consumer<Object> callback) {
            callbacks.put(key, callback);
        }
    
        private void notifyCallback(String key, Object value) {
            Consumer<Object> callback = callbacks.get(key);
            if (callback != null) {
                try {
                    callback.accept(value);
                } catch (Exception e) {
                    // Log but don't propagate
                }
            }
        }
    
        private boolean isValueHealthy(Object value) {
            if (value == null) return false;
            if (value instanceof Boolean b) return b;
            if (value instanceof Number n) return n.doubleValue() >= 0;
            return true;
        }
    
        private record Entry(Object value, HealthLevel level) {}
    }
    

    5. Utilisation

    5.1 Injection

    @Service
    public class MonService {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void process() {
            // ...
        }
    }
    

    5.2 Key-Value simple

    // Stocker
    registry.put("config.maxRetries", 3);
    registry.put("status.lastSync", Instant.now().toString());
    
    // Récupérer
    int maxRetries = registry.getInt("config.maxRetries").orElse(5);
    String lastSync = registry.getString("status.lastSync").orElse("never");
    

    5.3 Avec Health Level

    // Donnée critique - instance unhealthy si absente
    registry.put("database.connected", true, HealthLevel.CRITICAL);
    
    // Donnée importante - instance degraded si absente
    registry.put("cache.available", true, HealthLevel.IMPORTANT);
    
    // Donnée normale
    registry.put("stats.requestsTotal", 0, HealthLevel.NORMAL);
    
    // Donnée informative
    registry.put("info.startTime", Instant.now(), HealthLevel.INFO);
    

    5.4 Sequences (Compteurs)

    // Créer une séquence
    registry.createSequence("orders.processed", 0, HealthLevel.NORMAL);
    
    // Incrémenter
    long count = registry.incrementSequence("orders.processed");
    log.info("Processed order #{}", count);
    
    // Incrémenter avec delta
    long bytes = registry.incrementSequence("bytes.transferred", 1024);
    
    // Lire
    long total = registry.getSequence("orders.processed");
    

    5.5 Listes

    // Ajouter à une liste
    registry.addToList("errors.recent", new ErrorRecord("timeout", Instant.now()));
    registry.addToList("errors.recent", new ErrorRecord("connection", Instant.now()));
    
    // Lire la liste
    List<ErrorRecord> errors = registry.getList("errors.recent", ErrorRecord.class);
    
    // Vider
    registry.clearList("errors.recent");
    

    5.6 Maps

    // Stocker dans une map
    registry.putInMap("workers.status", "worker-1", "RUNNING");
    registry.putInMap("workers.status", "worker-2", "STOPPED");
    
    // Lire une entrée
    Optional<String> status = registry.getFromMap("workers.status", "worker-1", String.class);
    
    // Lire toute la map
    Map<String, String> allStatus = registry.getMap("workers.status", String.class);
    

    5.7 Callbacks

    // Enregistrer un callback
    registry.registerCallback("config.maxRetries", newValue -> {
        log.info("maxRetries changed to: {}", newValue);
        reconfigure((Integer) newValue);
    });
    
    // La modification déclenche le callback
    registry.put("config.maxRetries", 5);  // Callback appelé
    

    6. Patterns courants

    6.1 État de connexion

    @Component
    public class DatabaseWorker implements Worker {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @Override
        public void initialize() {
            registry.put("database.connected", false, HealthLevel.CRITICAL);
        }
    
        @Override
        public void start() {
            try {
                connect();
                registry.put("database.connected", true, HealthLevel.CRITICAL);
            } catch (Exception e) {
                registry.put("database.connected", false, HealthLevel.CRITICAL);
                throw e;
            }
        }
    
        @Override
        public void stop() {
            disconnect();
            registry.put("database.connected", false, HealthLevel.CRITICAL);
        }
    }
    

    6.2 Métriques temps réel

    @Component
    public class MetricsCollector {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @PostConstruct
        public void init() {
            registry.createSequence("metrics.requests.total", 0, HealthLevel.INFO);
            registry.createSequence("metrics.requests.errors", 0, HealthLevel.NORMAL);
            registry.createSequence("metrics.bytes.in", 0, HealthLevel.INFO);
            registry.createSequence("metrics.bytes.out", 0, HealthLevel.INFO);
        }
    
        public void recordRequest(long bytesIn, long bytesOut, boolean success) {
            registry.incrementSequence("metrics.requests.total");
            registry.incrementSequence("metrics.bytes.in", bytesIn);
            registry.incrementSequence("metrics.bytes.out", bytesOut);
    
            if (!success) {
                registry.incrementSequence("metrics.requests.errors");
            }
        }
    
        public Map<String, Object> getMetrics() {
            return Map.of(
                "requests.total", registry.getSequence("metrics.requests.total"),
                "requests.errors", registry.getSequence("metrics.requests.errors"),
                "bytes.in", registry.getSequence("metrics.bytes.in"),
                "bytes.out", registry.getSequence("metrics.bytes.out")
            );
        }
    }
    

    6.3 Circuit Breaker state

    @Component
    public class CircuitBreakerStateManager {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void updateState(String circuitName, CircuitState state) {
            String key = "circuit." + circuitName + ".state";
            HealthLevel level = state == CircuitState.OPEN
                ? HealthLevel.IMPORTANT
                : HealthLevel.NORMAL;
            registry.put(key, state.name(), level);
        }
    
        public CircuitState getState(String circuitName) {
            return registry.getString("circuit." + circuitName + ".state")
                .map(CircuitState::valueOf)
                .orElse(CircuitState.CLOSED);
        }
    }
    

    6.4 Progress tracking

    @Component
    public class BatchProcessor {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void processBatch(String batchId, List<Item> items) {
            registry.put("batch." + batchId + ".total", items.size());
            registry.createSequence("batch." + batchId + ".processed", 0, HealthLevel.NORMAL);
    
            for (Item item : items) {
                processItem(item);
                registry.incrementSequence("batch." + batchId + ".processed");
            }
    
            registry.put("batch." + batchId + ".status", "COMPLETED");
        }
    
        public double getProgress(String batchId) {
            int total = registry.getInt("batch." + batchId + ".total").orElse(0);
            if (total == 0) return 0;
    
            long processed = registry.getSequence("batch." + batchId + ".processed");
            return (double) processed / total * 100;
        }
    }
    

    7. Intégration avec Supervisor

    @Component
    public class HealthAggregator {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @Autowired
        private List<Worker> workers;
    
        public HealthStatus aggregateHealth() {
            // Check workers
            boolean allWorkersHealthy = workers.stream().allMatch(Worker::isHealthy);
    
            // Check critical registry entries
            List<String> unhealthyKeys = registry.getUnhealthyKeys();
            boolean hasCriticalFailure = !unhealthyKeys.isEmpty();
    
            if (!allWorkersHealthy || hasCriticalFailure) {
                return HealthStatus.UNHEALTHY;
            }
    
            // Check important entries
            Map<String, HealthLevel> levels = registry.getAllHealthLevels();
            boolean hasImportantFailure = levels.entrySet().stream()
                .filter(e -> e.getValue() == HealthLevel.IMPORTANT)
                .anyMatch(e -> !isHealthy(registry.get(e.getKey())));
    
            if (hasImportantFailure) {
                return HealthStatus.DEGRADED;
            }
    
            return HealthStatus.HEALTHY;
        }
    }
    

    8. Exposition API

    @RestController
    @RequestMapping("/admin/registry")
    public class SharedDataController {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @GetMapping
        public Map<String, Object> getAll() {
            return registry.getAll();
        }
    
        @GetMapping("/{key}")
        public ResponseEntity<?> get(@PathVariable String key) {
            return registry.get(key)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
        }
    
        @GetMapping("/health")
        public Map<String, HealthLevel> getHealthLevels() {
            return registry.getAllHealthLevels();
        }
    
        @GetMapping("/unhealthy")
        public List<String> getUnhealthyKeys() {
            return registry.getUnhealthyKeys();
        }
    }
    

    9. Bonnes pratiques

    Conventions de nommage

    <category>.<subcategory>.<name>
    
    Exemples:
    - database.connected
    - worker.kafka.status
    - metrics.requests.total
    - batch.order-123.progress
    - circuit.external-api.state
    

    DO

    • Utiliser des noms de clés cohérents et hiérarchiques
    • Définir le HealthLevel approprié pour chaque donnée
    • Utiliser les sequences pour les compteurs (thread-safe)
    • Nettoyer les données obsolètes

    DON’T

    • Ne pas stocker de données volumineuses (logs, payloads)
    • Ne pas utiliser pour le stockage persistant (utiliser TechDB)
    • Ne pas créer de nouvelles clés dynamiquement sans contrôle
    • Ne pas oublier que c’est per-instance (pas de sync multi-instances)

    10. Références

  • Socle V004 – TLS/HTTPS

    Socle V004 – TLS/HTTPS

    13 – TLS/HTTPS

    Version : 4.0.0 Date : 2025-12-09

    1. Introduction

    Configuration du TLS/HTTPS pour sécuriser les communications HTTP du Socle V4.

    2. Configuration Spring Boot

    2.1 application.yml

    server:
      port: ${HTTPS_PORT:8443}
      ssl:
        enabled: ${SSL_ENABLED:true}
        key-store: ${SSL_KEYSTORE:classpath:keystore.p12}
        key-store-password: ${SSL_KEYSTORE_PASSWORD:changeit}
        key-store-type: ${SSL_KEYSTORE_TYPE:PKCS12}
        key-alias: ${SSL_KEY_ALIAS:socle}
    

    2.2 Variables d’environnement

    Variable Description Défaut
    SSL_ENABLED Activer SSL false
    SSL_KEYSTORE Chemin du keystore classpath:keystore.p12
    SSL_KEYSTORE_PASSWORD Mot de passe keystore changeit
    SSL_KEYSTORE_TYPE Type de keystore PKCS12
    SSL_KEY_ALIAS Alias de la clé socle

    3. Génération des certificats

    3.1 Certificat auto-signé (développement)

    # Générer un keystore PKCS12 avec certificat auto-signé
    keytool -genkeypair \
      -alias socle \
      -keyalg RSA \
      -keysize 2048 \
      -storetype PKCS12 \
      -keystore keystore.p12 \
      -validity 365 \
      -dname "CN=localhost,OU=Dev,O=MyCompany,L=Paris,C=FR" \
      -storepass changeit \
      -keypass changeit
    
    # Exporter le certificat (pour les clients)
    keytool -exportcert \
      -alias socle \
      -keystore keystore.p12 \
      -storetype PKCS12 \
      -storepass changeit \
      -file socle.crt
    

    3.2 Avec Let’s Encrypt (production)

    # Obtenir le certificat
    certbot certonly --standalone -d myapp.example.com
    
    # Convertir en PKCS12
    openssl pkcs12 -export \
      -in /etc/letsencrypt/live/myapp.example.com/fullchain.pem \
      -inkey /etc/letsencrypt/live/myapp.example.com/privkey.pem \
      -out keystore.p12 \
      -name socle \
      -passout pass:changeit
    

    3.3 Avec CA interne

    # Générer CSR
    keytool -certreq \
      -alias socle \
      -keystore keystore.p12 \
      -file socle.csr \
      -storepass changeit
    
    # Après signature par la CA, importer le certificat
    keytool -importcert \
      -alias socle \
      -keystore keystore.p12 \
      -file signed-cert.crt \
      -storepass changeit
    
    # Importer la chaîne CA
    keytool -importcert \
      -alias ca-root \
      -keystore keystore.p12 \
      -file ca-root.crt \
      -storepass changeit
    

    4. Configuration avancée

    4.1 Mutual TLS (mTLS)

    server:
      ssl:
        enabled: true
        key-store: ${SSL_KEYSTORE:keystore.p12}
        key-store-password: ${SSL_KEYSTORE_PASSWORD}
        key-store-type: PKCS12
        # Trust store pour vérifier les clients
        trust-store: ${SSL_TRUSTSTORE:truststore.p12}
        trust-store-password: ${SSL_TRUSTSTORE_PASSWORD}
        trust-store-type: PKCS12
        # Exiger certificat client
        client-auth: ${SSL_CLIENT_AUTH:need}  # none, want, need
    

    4.2 Protocoles et Ciphers

    server:
      ssl:
        enabled-protocols: TLSv1.3,TLSv1.2
        ciphers:
          - TLS_AES_256_GCM_SHA384
          - TLS_AES_128_GCM_SHA256
          - TLS_CHACHA20_POLY1305_SHA256
          - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
          - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
    

    5. HTTP + HTTPS (dual port)

    5.1 Configuration

    @Configuration
    public class TlsConfiguration {
    
        @Value("${server.http.port:8080}")
        private int httpPort;
    
        @Bean
        public ServletWebServerFactory servletContainer() {
            TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
            tomcat.addAdditionalTomcatConnectors(createHttpConnector());
            return tomcat;
        }
    
        private Connector createHttpConnector() {
            Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
            connector.setScheme("http");
            connector.setPort(httpPort);
            connector.setSecure(false);
            return connector;
        }
    }
    

    5.2 Redirection HTTP → HTTPS

    @Configuration
    public class HttpsRedirectConfiguration {
    
        @Bean
        public TomcatServletWebServerFactory servletContainer() {
            TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
                @Override
                protected void postProcessContext(Context context) {
                    SecurityConstraint securityConstraint = new SecurityConstraint();
                    securityConstraint.setUserConstraint("CONFIDENTIAL");
                    SecurityCollection collection = new SecurityCollection();
                    collection.addPattern("/*");
                    securityConstraint.addCollection(collection);
                    context.addConstraint(securityConstraint);
                }
            };
    
            tomcat.addAdditionalTomcatConnectors(httpToHttpsRedirectConnector());
            return tomcat;
        }
    
        private Connector httpToHttpsRedirectConnector() {
            Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
            connector.setScheme("http");
            connector.setPort(8080);
            connector.setSecure(false);
            connector.setRedirectPort(8443);
            return connector;
        }
    }
    

    6. Client HTTPS

    6.1 OkHttpClient avec TLS

    @Configuration
    public class HttpClientConfiguration {
    
        @Value("${ssl.truststore:#{null}}")
        private Resource trustStore;
    
        @Value("${ssl.truststore-password:changeit}")
        private String trustStorePassword;
    
        @Bean
        public OkHttpClient secureHttpClient() throws Exception {
            OkHttpClient.Builder builder = new OkHttpClient.Builder();
    
            if (trustStore != null && trustStore.exists()) {
                KeyStore ks = KeyStore.getInstance("PKCS12");
                try (InputStream is = trustStore.getInputStream()) {
                    ks.load(is, trustStorePassword.toCharArray());
                }
    
                TrustManagerFactory tmf = TrustManagerFactory.getInstance(
                    TrustManagerFactory.getDefaultAlgorithm());
                tmf.init(ks);
    
                SSLContext sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, tmf.getTrustManagers(), new SecureRandom());
    
                builder.sslSocketFactory(sslContext.getSocketFactory(),
                    (X509TrustManager) tmf.getTrustManagers()[0]);
            }
    
            return builder
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .build();
        }
    }
    

    6.2 Bypass SSL pour développement (NON RECOMMANDÉ)

    // UNIQUEMENT POUR LE DÉVELOPPEMENT - NE PAS UTILISER EN PRODUCTION
    public OkHttpClient insecureClient() throws Exception {
        TrustManager[] trustAllCerts = new TrustManager[]{
            new X509TrustManager() {
                public void checkClientTrusted(X509Certificate[] chain, String authType) {}
                public void checkServerTrusted(X509Certificate[] chain, String authType) {}
                public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
            }
        };
    
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, new SecureRandom());
    
        return new OkHttpClient.Builder()
            .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
            .hostnameVerifier((hostname, session) -> true)
            .build();
    }
    

    7. Docker avec TLS

    7.1 Dockerfile

    FROM eclipse-temurin:21-jre
    
    WORKDIR /app
    
    # Copier le certificat
    COPY keystore.p12 /app/certs/keystore.p12
    
    # Copier l'application
    COPY target/socle-v004-4.0.0.jar app.jar
    
    ENV SSL_ENABLED=true
    ENV SSL_KEYSTORE=/app/certs/keystore.p12
    
    EXPOSE 8443
    
    ENTRYPOINT ["java", "-jar", "app.jar"]
    

    7.2 docker-compose.yml

    version: '3.8'
    
    services:
      socle-app:
        image: socle-v4:latest
        environment:
          - SSL_ENABLED=true
          - SSL_KEYSTORE=/app/certs/keystore.p12
          - SSL_KEYSTORE_PASSWORD_FILE=/run/secrets/ssl_password
        ports:
          - "8443:8443"
        volumes:
          - ./certs:/app/certs:ro
        secrets:
          - ssl_password
    
    secrets:
      ssl_password:
        file: ./secrets/ssl_password.txt
    

    8. Kubernetes avec TLS

    8.1 Secret pour le certificat

    apiVersion: v1
    kind: Secret
    metadata:
      name: socle-tls
    type: kubernetes.io/tls
    data:
      tls.crt: <base64-encoded-cert>
      tls.key: <base64-encoded-key>
    

    8.2 Ingress avec TLS

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: socle-ingress
      annotations:
        nginx.ingress.kubernetes.io/ssl-redirect: "true"
    spec:
      tls:
        - hosts:
            - socle.example.com
          secretName: socle-tls
      rules:
        - host: socle.example.com
          http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: socle-service
                    port:
                      number: 8080
    

    8.3 cert-manager

    apiVersion: cert-manager.io/v1
    kind: Certificate
    metadata:
      name: socle-cert
    spec:
      secretName: socle-tls
      issuerRef:
        name: letsencrypt-prod
        kind: ClusterIssuer
      dnsNames:
        - socle.example.com
    

    9. Vérification

    9.1 Test avec curl

    # Test HTTPS
    curl -v https://localhost:8443/admin/health
    
    # Avec certificat client (mTLS)
    curl -v --cert client.crt --key client.key https://localhost:8443/admin/health
    
    # Ignorer la vérification (dev only)
    curl -vk https://localhost:8443/admin/health
    

    9.2 Test avec openssl

    # Vérifier le certificat du serveur
    openssl s_client -connect localhost:8443 -showcerts
    
    # Vérifier les protocoles supportés
    openssl s_client -connect localhost:8443 -tls1_3
    
    # Vérifier les ciphers
    openssl s_client -connect localhost:8443 -cipher 'ECDHE-RSA-AES256-GCM-SHA384'
    

    10. Troubleshooting

    Erreur: PKIX path building failed

    Le certificat du serveur n’est pas trusté.

    # Importer le certificat dans le truststore Java
    keytool -importcert \
      -alias server-cert \
      -file server.crt \
      -keystore $JAVA_HOME/lib/security/cacerts \
      -storepass changeit
    

    Erreur: Handshake failure

    Incompatibilité de protocole ou cipher.

    # Vérifier les protocoles
    openssl s_client -connect host:port -tls1_2
    openssl s_client -connect host:port -tls1_3
    

    Erreur: Certificate expired

    Renouveler le certificat et recréer le keystore.

    11. Bonnes pratiques

    DO

    • Utiliser TLS 1.2 minimum, TLS 1.3 recommandé
    • Renouveler les certificats avant expiration
    • Utiliser des clés RSA 2048 bits minimum ou ECDSA 256 bits
    • Activer HSTS en production
    • Utiliser cert-manager en Kubernetes

    DON’T

    • Ne pas utiliser de certificats auto-signés en production
    • Ne pas désactiver la vérification des certificats
    • Ne pas stocker les mots de passe en clair
    • Ne pas utiliser TLS 1.0 ou 1.1 (dépréciés)

    12. Références

  • Socle V004 – Données Partagées

    Socle V004 – Données Partagées

    07 – SharedDataRegistry

    Version : 4.0.0 Date : 2025-12-09

    1. Introduction

    SharedDataRegistry est un registre centralisé pour partager des données entre Workers au sein d’une même instance. Il fournit des opérations atomiques et un système de niveaux de santé.

    Différence avec KvBus

    Aspect SharedDataRegistry KvBus
    Scope Intra-instance Optionnel inter-instances (Redis)
    Performance Ultra rapide (mémoire) Variable (réseau si Redis)
    Types Fortement typés Strings/JSON
    Health levels Oui Non
    Callbacks Oui Non

    2. Interface SharedDataRegistry

    package eu.lmvi.socle.shared;
    
    public interface SharedDataRegistry {
    
        // === Key-Value basique ===
    
        void put(String key, Object value);
        void put(String key, Object value, HealthLevel level);
        Optional<Object> get(String key);
        <T> Optional<T> get(String key, Class<T> type);
        void delete(String key);
        boolean exists(String key);
    
        // === Typed getters ===
    
        Optional<String> getString(String key);
        Optional<Integer> getInt(String key);
        Optional<Long> getLong(String key);
        Optional<Double> getDouble(String key);
        Optional<Boolean> getBoolean(String key);
    
        // === Sequences (compteurs atomiques) ===
    
        void createSequence(String key, long initialValue, HealthLevel level);
        long incrementSequence(String key);
        long incrementSequence(String key, long delta);
        long getSequence(String key);
        void setSequence(String key, long value);
    
        // === Lists ===
    
        <T> void addToList(String key, T item);
        <T> List<T> getList(String key, Class<T> type);
        void clearList(String key);
    
        // === Maps ===
    
        <V> void putInMap(String key, String mapKey, V value);
        <V> Optional<V> getFromMap(String key, String mapKey, Class<V> type);
        <V> Map<String, V> getMap(String key, Class<V> type);
        void removeFromMap(String key, String mapKey);
    
        // === Health ===
    
        HealthLevel getHealthLevel(String key);
        Map<String, HealthLevel> getAllHealthLevels();
        List<String> getUnhealthyKeys();
    
        // === Callbacks ===
    
        void registerCallback(String key, Consumer<Object> callback);
        void unregisterCallback(String key);
    
        // === Introspection ===
    
        Set<String> keys();
        Set<String> keys(String pattern);
        Map<String, Object> getAll();
        int size();
        void clear();
    }
    

    3. Health Levels

    package eu.lmvi.socle.shared;
    
    public enum HealthLevel {
        /**
         * Informatif - pas d'impact sur la santé
         */
        INFO,
    
        /**
         * Normal - contribue à la santé normale
         */
        NORMAL,
    
        /**
         * Important - dégradation si problème
         */
        IMPORTANT,
    
        /**
         * Critique - unhealthy si problème
         */
        CRITICAL
    }
    

    Utilisation dans le Supervisor

    Le Supervisor consulte les HealthLevel pour déterminer l’état de santé global :

    • CRITICAL absent ou invalide → Instance UNHEALTHY
    • IMPORTANT absent ou invalide → Instance DEGRADED
    • NORMAL/INFO → Pas d’impact

    4. Implémentation

    package eu.lmvi.socle.shared;
    
    @Component
    public class InMemorySharedDataRegistry implements SharedDataRegistry {
    
        private final ConcurrentHashMap<String, Entry> store = new ConcurrentHashMap<>();
        private final ConcurrentHashMap<String, Consumer<Object>> callbacks = new ConcurrentHashMap<>();
    
        @Override
        public void put(String key, Object value) {
            put(key, value, HealthLevel.NORMAL);
        }
    
        @Override
        public void put(String key, Object value, HealthLevel level) {
            Entry previous = store.put(key, new Entry(value, level));
            notifyCallback(key, value);
        }
    
        @Override
        public Optional<Object> get(String key) {
            Entry entry = store.get(key);
            return entry != null ? Optional.of(entry.value) : Optional.empty();
        }
    
        @Override
        public <T> Optional<T> get(String key, Class<T> type) {
            return get(key).filter(type::isInstance).map(type::cast);
        }
    
        @Override
        public Optional<String> getString(String key) {
            return get(key).map(Object::toString);
        }
    
        @Override
        public Optional<Integer> getInt(String key) {
            return get(key, Number.class).map(Number::intValue);
        }
    
        @Override
        public Optional<Long> getLong(String key) {
            return get(key, Number.class).map(Number::longValue);
        }
    
        @Override
        public void createSequence(String key, long initialValue, HealthLevel level) {
            store.put(key, new Entry(new AtomicLong(initialValue), level));
        }
    
        @Override
        public long incrementSequence(String key) {
            return incrementSequence(key, 1);
        }
    
        @Override
        public long incrementSequence(String key, long delta) {
            Entry entry = store.get(key);
            if (entry == null || !(entry.value instanceof AtomicLong)) {
                throw new IllegalStateException("Sequence not found: " + key);
            }
            long newValue = ((AtomicLong) entry.value).addAndGet(delta);
            notifyCallback(key, newValue);
            return newValue;
        }
    
        @Override
        public long getSequence(String key) {
            Entry entry = store.get(key);
            if (entry == null || !(entry.value instanceof AtomicLong)) {
                throw new IllegalStateException("Sequence not found: " + key);
            }
            return ((AtomicLong) entry.value).get();
        }
    
        @Override
        public HealthLevel getHealthLevel(String key) {
            Entry entry = store.get(key);
            return entry != null ? entry.level : null;
        }
    
        @Override
        public List<String> getUnhealthyKeys() {
            return store.entrySet().stream()
                .filter(e -> e.getValue().level == HealthLevel.CRITICAL)
                .filter(e -> !isValueHealthy(e.getValue().value))
                .map(Map.Entry::getKey)
                .toList();
        }
    
        @Override
        public void registerCallback(String key, Consumer<Object> callback) {
            callbacks.put(key, callback);
        }
    
        private void notifyCallback(String key, Object value) {
            Consumer<Object> callback = callbacks.get(key);
            if (callback != null) {
                try {
                    callback.accept(value);
                } catch (Exception e) {
                    // Log but don't propagate
                }
            }
        }
    
        private boolean isValueHealthy(Object value) {
            if (value == null) return false;
            if (value instanceof Boolean b) return b;
            if (value instanceof Number n) return n.doubleValue() >= 0;
            return true;
        }
    
        private record Entry(Object value, HealthLevel level) {}
    }
    

    5. Utilisation

    5.1 Injection

    @Service
    public class MonService {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void process() {
            // ...
        }
    }
    

    5.2 Key-Value simple

    // Stocker
    registry.put("config.maxRetries", 3);
    registry.put("status.lastSync", Instant.now().toString());
    
    // Récupérer
    int maxRetries = registry.getInt("config.maxRetries").orElse(5);
    String lastSync = registry.getString("status.lastSync").orElse("never");
    

    5.3 Avec Health Level

    // Donnée critique - instance unhealthy si absente
    registry.put("database.connected", true, HealthLevel.CRITICAL);
    
    // Donnée importante - instance degraded si absente
    registry.put("cache.available", true, HealthLevel.IMPORTANT);
    
    // Donnée normale
    registry.put("stats.requestsTotal", 0, HealthLevel.NORMAL);
    
    // Donnée informative
    registry.put("info.startTime", Instant.now(), HealthLevel.INFO);
    

    5.4 Sequences (Compteurs)

    // Créer une séquence
    registry.createSequence("orders.processed", 0, HealthLevel.NORMAL);
    
    // Incrémenter
    long count = registry.incrementSequence("orders.processed");
    log.info("Processed order #{}", count);
    
    // Incrémenter avec delta
    long bytes = registry.incrementSequence("bytes.transferred", 1024);
    
    // Lire
    long total = registry.getSequence("orders.processed");
    

    5.5 Listes

    // Ajouter à une liste
    registry.addToList("errors.recent", new ErrorRecord("timeout", Instant.now()));
    registry.addToList("errors.recent", new ErrorRecord("connection", Instant.now()));
    
    // Lire la liste
    List<ErrorRecord> errors = registry.getList("errors.recent", ErrorRecord.class);
    
    // Vider
    registry.clearList("errors.recent");
    

    5.6 Maps

    // Stocker dans une map
    registry.putInMap("workers.status", "worker-1", "RUNNING");
    registry.putInMap("workers.status", "worker-2", "STOPPED");
    
    // Lire une entrée
    Optional<String> status = registry.getFromMap("workers.status", "worker-1", String.class);
    
    // Lire toute la map
    Map<String, String> allStatus = registry.getMap("workers.status", String.class);
    

    5.7 Callbacks

    // Enregistrer un callback
    registry.registerCallback("config.maxRetries", newValue -> {
        log.info("maxRetries changed to: {}", newValue);
        reconfigure((Integer) newValue);
    });
    
    // La modification déclenche le callback
    registry.put("config.maxRetries", 5);  // Callback appelé
    

    6. Patterns courants

    6.1 État de connexion

    @Component
    public class DatabaseWorker implements Worker {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @Override
        public void initialize() {
            registry.put("database.connected", false, HealthLevel.CRITICAL);
        }
    
        @Override
        public void start() {
            try {
                connect();
                registry.put("database.connected", true, HealthLevel.CRITICAL);
            } catch (Exception e) {
                registry.put("database.connected", false, HealthLevel.CRITICAL);
                throw e;
            }
        }
    
        @Override
        public void stop() {
            disconnect();
            registry.put("database.connected", false, HealthLevel.CRITICAL);
        }
    }
    

    6.2 Métriques temps réel

    @Component
    public class MetricsCollector {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @PostConstruct
        public void init() {
            registry.createSequence("metrics.requests.total", 0, HealthLevel.INFO);
            registry.createSequence("metrics.requests.errors", 0, HealthLevel.NORMAL);
            registry.createSequence("metrics.bytes.in", 0, HealthLevel.INFO);
            registry.createSequence("metrics.bytes.out", 0, HealthLevel.INFO);
        }
    
        public void recordRequest(long bytesIn, long bytesOut, boolean success) {
            registry.incrementSequence("metrics.requests.total");
            registry.incrementSequence("metrics.bytes.in", bytesIn);
            registry.incrementSequence("metrics.bytes.out", bytesOut);
    
            if (!success) {
                registry.incrementSequence("metrics.requests.errors");
            }
        }
    
        public Map<String, Object> getMetrics() {
            return Map.of(
                "requests.total", registry.getSequence("metrics.requests.total"),
                "requests.errors", registry.getSequence("metrics.requests.errors"),
                "bytes.in", registry.getSequence("metrics.bytes.in"),
                "bytes.out", registry.getSequence("metrics.bytes.out")
            );
        }
    }
    

    6.3 Circuit Breaker state

    @Component
    public class CircuitBreakerStateManager {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void updateState(String circuitName, CircuitState state) {
            String key = "circuit." + circuitName + ".state";
            HealthLevel level = state == CircuitState.OPEN
                ? HealthLevel.IMPORTANT
                : HealthLevel.NORMAL;
            registry.put(key, state.name(), level);
        }
    
        public CircuitState getState(String circuitName) {
            return registry.getString("circuit." + circuitName + ".state")
                .map(CircuitState::valueOf)
                .orElse(CircuitState.CLOSED);
        }
    }
    

    6.4 Progress tracking

    @Component
    public class BatchProcessor {
    
        @Autowired
        private SharedDataRegistry registry;
    
        public void processBatch(String batchId, List<Item> items) {
            registry.put("batch." + batchId + ".total", items.size());
            registry.createSequence("batch." + batchId + ".processed", 0, HealthLevel.NORMAL);
    
            for (Item item : items) {
                processItem(item);
                registry.incrementSequence("batch." + batchId + ".processed");
            }
    
            registry.put("batch." + batchId + ".status", "COMPLETED");
        }
    
        public double getProgress(String batchId) {
            int total = registry.getInt("batch." + batchId + ".total").orElse(0);
            if (total == 0) return 0;
    
            long processed = registry.getSequence("batch." + batchId + ".processed");
            return (double) processed / total * 100;
        }
    }
    

    7. Intégration avec Supervisor

    @Component
    public class HealthAggregator {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @Autowired
        private List<Worker> workers;
    
        public HealthStatus aggregateHealth() {
            // Check workers
            boolean allWorkersHealthy = workers.stream().allMatch(Worker::isHealthy);
    
            // Check critical registry entries
            List<String> unhealthyKeys = registry.getUnhealthyKeys();
            boolean hasCriticalFailure = !unhealthyKeys.isEmpty();
    
            if (!allWorkersHealthy || hasCriticalFailure) {
                return HealthStatus.UNHEALTHY;
            }
    
            // Check important entries
            Map<String, HealthLevel> levels = registry.getAllHealthLevels();
            boolean hasImportantFailure = levels.entrySet().stream()
                .filter(e -> e.getValue() == HealthLevel.IMPORTANT)
                .anyMatch(e -> !isHealthy(registry.get(e.getKey())));
    
            if (hasImportantFailure) {
                return HealthStatus.DEGRADED;
            }
    
            return HealthStatus.HEALTHY;
        }
    }
    

    8. Exposition API

    @RestController
    @RequestMapping("/admin/registry")
    public class SharedDataController {
    
        @Autowired
        private SharedDataRegistry registry;
    
        @GetMapping
        public Map<String, Object> getAll() {
            return registry.getAll();
        }
    
        @GetMapping("/{key}")
        public ResponseEntity<?> get(@PathVariable String key) {
            return registry.get(key)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
        }
    
        @GetMapping("/health")
        public Map<String, HealthLevel> getHealthLevels() {
            return registry.getAllHealthLevels();
        }
    
        @GetMapping("/unhealthy")
        public List<String> getUnhealthyKeys() {
            return registry.getUnhealthyKeys();
        }
    }
    

    9. Bonnes pratiques

    Conventions de nommage

    <category>.<subcategory>.<name>
    
    Exemples:
    - database.connected
    - worker.kafka.status
    - metrics.requests.total
    - batch.order-123.progress
    - circuit.external-api.state
    

    DO

    • Utiliser des noms de clés cohérents et hiérarchiques
    • Définir le HealthLevel approprié pour chaque donnée
    • Utiliser les sequences pour les compteurs (thread-safe)
    • Nettoyer les données obsolètes

    DON’T

    • Ne pas stocker de données volumineuses (logs, payloads)
    • Ne pas utiliser pour le stockage persistant (utiliser TechDB)
    • Ne pas créer de nouvelles clés dynamiquement sans contrôle
    • Ne pas oublier que c’est per-instance (pas de sync multi-instances)

    10. Références

  • Socle V004 – Status Dashboard

    Socle V004 – Status Dashboard

    27 – Status Dashboard

    Version : 4.0.0 Package : eu.lmvi.socle.worker.status

    Introduction

    Le StatusDashboardWorker est un Worker integre au Socle V004 qui expose un dashboard HTML de supervision sur un port dedie. Il permet de visualiser en temps reel l’etat de l’application et de tous les Workers.

    Caracteristiques

    • Automatique : Active par defaut, aucun code a ajouter
    • Port dedie : 9374 (configurable)
    • Dashboard HTML : Interface web avec rafraichissement AJAX partiel
    • API JSON : Endpoints REST pour integration
    • Metriques d’activite : Throughput, duree, charge relative
    • Animation visuelle : Mise en evidence des valeurs modifiees

    Acces au Dashboard

    Une fois l’application demarree, le dashboard est accessible sur :

    http://localhost:9374/
    

    Configuration

    application.yml

    socle:
      status_dashboard:
        # Activer/desactiver le dashboard (defaut: true)
        enabled: true
    
        # Port du serveur HTTP (defaut: 9374)
        port: 9374
    
        # Adresse de bind (vide = toutes les interfaces)
        bind_address: ""
    
        # Intervalle de rafraichissement HTML en secondes (defaut: 5)
        refresh_interval: 5
    
        # Fenetre de calcul des metriques en secondes (defaut: 60)
        metrics_window: 60
    
        # Limite de requetes par seconde (defaut: 10)
        max_requests_per_second: 10
    
        # Activer l'API JSON (defaut: true)
        api_enabled: true
    

    Variables d’environnement

    Variable Description Defaut
    STATUS_DASHBOARD_ENABLED Activer le dashboard true
    STATUS_DASHBOARD_PORT Port HTTP 9374
    STATUS_DASHBOARD_BIND Adresse de bind (vide)
    STATUS_DASHBOARD_REFRESH Refresh interval (sec) 5
    STATUS_DASHBOARD_METRICS_WINDOW Fenetre metriques (sec) 60
    STATUS_DASHBOARD_MAX_RPS Max requetes/sec 10
    STATUS_DASHBOARD_API_ENABLED Activer API JSON true

    Rafraichissement AJAX

    Le dashboard utilise JavaScript pour mettre a jour uniquement les valeurs qui changent, sans recharger la page entiere.

    Fonctionnement

    1. Chargement initial : La page HTML complete est servie
    2. Rafraichissement periodique : JavaScript appelle /api/status et /api/workers
    3. Mise a jour selective : Seuls les elements dont la valeur a change sont modifies
    4. Animation visuelle : Les valeurs modifiees sont brievement mises en surbrillance (effet cyan)

    Avantages

    • Pas de rechargement complet de la page
    • Experience utilisateur fluide
    • Reduction de la bande passante
    • Conservation de l’etat de scroll

    Configuration de l’intervalle

    L’intervalle de rafraichissement AJAX correspond a refresh_interval :

    socle:
      status_dashboard:
        refresh_interval: 3  # Rafraichissement toutes les 3 secondes
    

    Endpoints HTTP

    Dashboard HTML

    Endpoint Methode Description
    / GET Page HTML du dashboard
    /index.html GET Alias pour /

    Health Check

    Endpoint Methode Description
    /health GET Status UP/DOWN en JSON

    Exemple de reponse :

    {"status":"UP"}
    

    API JSON

    Endpoint Methode Description
    /api/status GET Status global de l’application
    /api/workers GET Liste de tous les workers avec metriques
    /api/workers/{name} GET Metriques d’un worker specifique

    Donnees affichees

    Section : Status Global

    Donnee Description
    MOP State Etat du MainOrchestratorProcess (RUNNING, DRAINING, etc.)
    Uptime Temps depuis le demarrage
    Workers Health Nombre de workers healthy / total
    Total Activity Throughput agrege (ops/sec)

    Section : Worker Activity

    Barres visuelles montrant la charge relative de chaque Worker :

    cdc_kafka_worker    ████████████████████░░░░  85%  [HOT]
    http_worker         ██████████████░░░░░░░░░░  58%
    rule_engine         ████████░░░░░░░░░░░░░░░░  32%
    control_worker      ███░░░░░░░░░░░░░░░░░░░░░  12%
    maintenance_worker  █░░░░░░░░░░░░░░░░░░░░░░░   2%  [IDLE]
    

    Tags :

    • [HOT] : Worker avec charge > 80%
    • [IDLE] : Worker inactif
    • [PASSIVE] : Worker event-driven sans activite

    Section : Workers Detail

    Tableau detaille avec :

    Colonne Description
    Name Nom du worker
    State Running / Stopped
    Health OK / FAIL
    Mode PASSIVE / CRON / INTERVAL
    Executions Nombre total d’executions doWork()
    Avg Duration Duree moyenne d’execution
    Throughput Operations par seconde
    Last Activity Temps depuis derniere activite
    Errors Nombre d’erreurs

    Exemples API JSON

    GET /api/status

    {
      "timestamp": "2026-01-12T17:34:56.789Z",
      "application": {
        "name": "my-app",
        "environment": "PROD",
        "version": "4.0.0"
      },
      "mop": {
        "state": "RUNNING",
        "uptime_ms": 9252000,
        "uptime_human": "2h 34m 12s"
      },
      "workers": {
        "total": 6,
        "healthy": 6,
        "running": 6
      },
      "activity": {
        "total_throughput": 847.3,
        "metrics_window_sec": 60
      }
    }
    

    GET /api/workers

    {
      "timestamp": "2026-01-12T17:34:56.789Z",
      "workers": [
        {
          "name": "cdc_kafka_worker",
          "state": "running",
          "healthy": true,
          "schedule": "PASSIVE",
          "metrics": {
            "execution_count": 12847,
            "total_duration_ms": 29548,
            "avg_duration_ms": 2.3,
            "last_execution": "2026-01-12T17:34:55.123Z",
            "throughput_per_sec": 721.4,
            "errors_count": 3,
            "messages_processed": 45230
          },
          "relative_load": 0.85
        }
      ]
    }
    

    Securite

    Bind localhost uniquement (production)

    Pour limiter l’acces au dashboard en production :

    socle:
      status_dashboard:
        bind_address: "127.0.0.1"
    

    Desactiver en production

    socle:
      status_dashboard:
        enabled: false
    

    Ou via variable d’environnement :

    export STATUS_DASHBOARD_ENABLED=false
    

    Architecture

    ┌─────────────────────────────────────────────────────────────┐
    │                  StatusDashboardWorker                      │
    │                                                             │
    │  ┌─────────────────────┐    ┌─────────────────────────┐    │
    │  │ WorkerActivityTracker│    │ DashboardHtmlRenderer   │    │
    │  │ (collecte metriques) │    │ (genere HTML)           │    │
    │  └──────────┬──────────┘    └────────────┬────────────┘    │
    │             │                            │                  │
    │             └──────────┬─────────────────┘                  │
    │                        │                                    │
    │              ┌─────────▼─────────┐                          │
    │              │   MiniHttpServer  │                          │
    │              │   (port 9374)     │                          │
    │              └─────────┬─────────┘                          │
    └────────────────────────┼────────────────────────────────────┘
                             │
                             ▼
                        Browser / curl
    

    Composants

    Composant Responsabilite
    StatusDashboardWorker Worker principal, orchestre le dashboard
    WorkerActivityTracker Collecte et agregation des metriques
    MiniHttpServer Serveur HTTP leger (ServerSocket)
    DashboardHtmlRenderer Generation du HTML avec CSS inline

    Integration avec Monitoring

    Le dashboard peut etre integre avec des outils de monitoring existants :

    Prometheus / Grafana

    Utilisez l’endpoint /api/status pour collecter les metriques :

    # prometheus.yml
    scrape_configs:
      - job_name: 'socle-status'
        metrics_path: /api/status
        static_configs:
          - targets: ['localhost:9374']
    

    Health Checks (Kubernetes)

    # deployment.yaml
    livenessProbe:
      httpGet:
        path: /health
        port: 9374
      initialDelaySeconds: 30
      periodSeconds: 10
    

    Convention des Stats Workers

    Pour que le dashboard affiche correctement les metriques, les workers doivent exposer des cles standardisees dans getStats().

    Cles requises par WorkerActivityTracker

    Cle Type Utilisation
    state String Affichage Running/Stopped
    execution_count long Colonne Executions
    errors_count long Colonne Errors
    last_execution String/long Colonne Last Activity
    schedule String Colonne Mode

    Cles optionnelles

    Cle Type Utilisation
    total_duration_ms long Calcul Avg Duration
    avg_duration_ms double Colonne Avg Duration (prioritaire)
    throughput_per_sec double Colonne Throughput
    messages_processed long Fallback pour execution_count

    Note : Les workers heritant de AbstractEventDrivenWorker exposent automatiquement ces cles depuis la version 4.0.1.

    Voir 05-WORKERS.md section 12 pour les details d’implementation.

    Troubleshooting

    Le dashboard ne demarre pas

    Cause possible : Port deja utilise

    Solution :

    socle:
      status_dashboard:
        port: 9375  # Changer le port
    

    Metriques a zero

    Cause possible : Les workers sont en mode PASSIVE et n’ont pas encore traite d’evenements

    Solution : Normal pour les workers event-driven. Les metriques apparaitront des que des evenements seront traites.

    Dashboard lent

    Cause possible : Trop de workers ou refresh trop frequent

    Solution :

    socle:
      status_dashboard:
        refresh_interval: 10  # Augmenter l'intervalle
    

    Voir aussi

    Socle V004 – Status Dashboard

  • Socle V004 – Dépannage

    Socle V004 – Dépannage

    18 – Troubleshooting

    Version : 4.0.0 Date : 2025-12-09

    1. Problèmes de démarrage

    1.1 Application ne démarre pas

    Symptôme : L’application ne démarre pas ou crashe immédiatement.

    Causes possibles :

    1. Port déjà utilisé

      Error: Address already in use: bind
      

      Solution :

      # Trouver le processus
      lsof -i :8080
      # Changer le port
      export HTTP_PORT=8081
      
    2. Configuration manquante

      Failed to bind properties under 'socle.xxx'
      

      Solution : Vérifier les variables d’environnement et application.yml

    3. Erreur de logging

      ERROR StatusLogger Log4j2 could not find a logging implementation
      

      Solution : Vérifier que log4j2.xml existe dans src/main/resources/

    1.2 Workers ne démarrent pas

    Symptôme : Les workers sont enregistrés mais restent en état REGISTERED.

    Solutions :

    1. Vérifier les logs d’initialisation
    2. Vérifier les dépendances (base de données, Redis, etc.)
    3. Vérifier les priorités de démarrage
    curl http://localhost:8080/admin/workers
    

    2. Problèmes de connectivité

    2.1 Redis non accessible

    Symptôme :

    Cannot get Jedis connection
    

    Solutions :

    1. Vérifier l’hôte et le port Redis
      redis-cli -h localhost -p 6379 ping
      
    2. Vérifier le mot de passe
    3. Vérifier les firewalls

    2.2 Database non accessible

    Symptôme :

    Database may be already in use: "locked by another process"
    

    Solutions :

    1. Arrêter les autres instances
    2. Utiliser AUTO_SERVER=TRUE dans l’URL H2
    3. Supprimer les fichiers de lock
    rm ./data/socle-techdb.lock.db
    

    3. Problèmes de logging (V4)

    3.1 Logs non visibles

    Symptôme : Aucun log n’apparaît.

    Solutions :

    1. Vérifier que log4j2.xml existe
    2. Vérifier le niveau de log
    3. Vérifier logging.config dans application.yml
    logging:
      config: classpath:log4j2.xml
    

    3.2 Conflit Logback/Log4j2

    Symptôme :

    SLF4J: Class path contains multiple SLF4J bindings
    

    Solution : Exclure Logback de toutes les dépendances

    mvn dependency:tree | grep logback
    
    <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
    

    3.3 AsyncLoggers non actifs

    Symptôme : Performance de logging dégradée.

    Solution : Vérifier log4j2.component.properties

    Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
    

    3.4 LogForwarder queue pleine

    Symptôme :

    WARN - Log queue full, storing to fallback
    

    Solutions :

    1. Augmenter queue-capacity
    2. Vérifier la connectivité réseau vers le LogHub
    3. Réduire le volume de logs
    # Vérifier les logs en fallback
    curl http://localhost:8080/admin/logforwarder/status
    

    4. Problèmes de performance

    4.1 Haute consommation CPU

    Solutions :

    1. Vérifier les workers en boucle infinie
    2. Vérifier les logs en DEBUG
    3. Profiler avec JFR
    jcmd <pid> JFR.start duration=60s filename=recording.jfr
    

    4.2 Haute consommation mémoire

    Solutions :

    1. Analyser le heap dump
      jmap -dump:format=b,file=heap.hprof <pid>
      
    2. Vérifier les fuites dans KvBus/SharedDataRegistry
    3. Ajuster la configuration JVM

    4.3 Latence élevée

    Solutions :

    1. Vérifier les circuit breakers
      curl http://localhost:8080/admin/resilience/circuits
      
    2. Vérifier les connexions réseau
    3. Vérifier les métriques
      curl http://localhost:8080/actuator/prometheus | grep latency
      

    5. Problèmes de résilience

    5.1 Circuit Breaker bloqué en OPEN

    Symptôme : Un circuit reste ouvert malgré la récupération du service.

    Solutions :

    1. Reset manuel
      curl -X POST http://localhost:8080/admin/resilience/circuits/my-circuit/reset
      
    2. Vérifier le timeout configuré
    3. Vérifier que le service cible répond

    5.2 Retry infini

    Symptôme : L’application retry sans fin.

    Solutions :

    1. Vérifier max-attempts configuré
    2. Vérifier les exceptions retryables
    3. Ajouter un circuit breaker

    6. Problèmes H2 TechDB (V4)

    6.1 Base corrompue

    Symptôme :

    File corrupted
    

    Solution :

    rm -rf ./data/socle-techdb.*
    # Redémarrer l'application
    

    6.2 H2 Console inaccessible

    Solutions :

    1. Vérifier socle.techdb.console.enabled=true
    2. Vérifier l’URL : http://localhost:8080/h2-console
    3. Utiliser l’URL JDBC correcte : jdbc:h2:file:./data/socle-techdb

    6.3 Offsets perdus

    Solutions :

    1. Vérifier que TechDB est enabled
    2. Vérifier les logs de saveOffset
    3. Requêter directement H2
      SELECT * FROM socle_offsets;
      

    7. Problèmes d’authentification (V4)

    7.1 Login échoue

    Symptôme :

    AuthenticationException: Login failed: 401
    

    Solutions :

    1. Vérifier API_KEY
    2. Vérifier SOURCE_NAME
    3. Vérifier AUTH_SERVER_URL

    7.2 Token expiré

    Symptôme :

    Token expired
    

    Solutions :

    1. Vérifier l’horloge système (NTP)
    2. Augmenter access-token-buffer-seconds

    7.3 Admin API 401

    Solutions :

    1. Vérifier si l’auth est activée
      socle.admin.auth.enabled: true
      
    2. Utiliser les credentials corrects
      curl -u admin:password http://localhost:8080/admin/workers
      

    8. Problèmes Kubernetes

    8.1 Pod en CrashLoopBackOff

    Solutions :

    1. Vérifier les logs
      kubectl logs <pod-name> --previous
      
    2. Vérifier les ressources
    3. Vérifier les probes

    8.2 Probes échouent

    Solutions :

    1. Augmenter initialDelaySeconds
    2. Vérifier que l’endpoint /admin/health répond
    3. Vérifier le port

    8.3 OOMKilled

    Solutions :

    1. Augmenter les limites mémoire
    2. Ajuster les options JVM
      -XX:MaxRAMPercentage=75.0
      

    9. Commandes de diagnostic

    9.1 API Admin

    # Santé globale
    curl http://localhost:8080/admin/health
    
    # État des workers
    curl http://localhost:8080/admin/workers
    
    # Registry
    curl http://localhost:8080/admin/registry
    
    # Circuits breakers
    curl http://localhost:8080/admin/resilience/circuits
    
    # Configuration
    curl http://localhost:8080/admin/config
    
    # Métriques
    curl http://localhost:8080/actuator/prometheus
    

    9.2 JVM

    # Thread dump
    jstack <pid>
    
    # Heap info
    jmap -heap <pid>
    
    # GC stats
    jstat -gcutil <pid> 1000
    
    # JFR recording
    jcmd <pid> JFR.start duration=60s filename=recording.jfr
    

    9.3 Réseau

    # Test Redis
    redis-cli -h localhost ping
    
    # Test HTTP
    curl -v http://localhost:8080/admin/health
    
    # DNS
    nslookup myservice.namespace.svc.cluster.local
    

    10. Logs utiles à activer

    # application.yml ou variables d'environnement
    
    logging:
      level:
        eu.lmvi.socle: DEBUG
        eu.lmvi.socle.mop: DEBUG
        eu.lmvi.socle.supervisor: DEBUG
        eu.lmvi.socle.techdb: DEBUG
        eu.lmvi.socle.resilience: DEBUG
        org.springframework.web: DEBUG
        io.lettuce: DEBUG  # Redis
    

    11. Checklist de diagnostic

    □ L'application démarre-t-elle ?
      □ Logs de démarrage présents ?
      □ Port disponible ?
      □ Configuration valide ?
    
    □ Les workers sont-ils healthy ?
      □ GET /admin/workers
      □ Heartbeats reçus ?
      □ Erreurs dans les logs ?
    
    □ Les connexions externes fonctionnent-elles ?
      □ Redis accessible ?
      □ Base de données accessible ?
      □ APIs externes accessibles ?
    
    □ Les métriques sont-elles normales ?
      □ CPU < 80% ?
      □ Mémoire < 80% ?
      □ Latence acceptable ?
      □ Taux d'erreur bas ?
    
    □ Les logs sont-ils corrects ?
      □ Log4j2 configuré ?
      □ LogForwarder fonctionne ?
      □ Pas de logs en fallback ?
    

    12. Références

  • Socle V004 – Introduction

    Socle V004 – Introduction

    01 – Introduction au Socle V4

    Version : 4.0.0 Date : 2025-01-25

    1. Qu’est-ce que le Socle V4 ?

    Le Socle V4 est un framework Java de grade production construit sur Spring Boot 3.2.1 qui implémente le pattern MOP (Main Orchestrator Process). Il fournit une base solide pour construire des applications d’entreprise robustes et observables.

    Évolution depuis V3

    Le Socle V4 conserve et étend l’architecture V3 en ajoutant :

    Nouveauté V4 Description
    H2 TechDB Base embarquée pour état technique (remplace Nitrite)
    Log4j2 Framework logging haute performance (remplace Logback)
    LogForwarder Centralisation des logs vers LogHub (HTTP/NATS)
    SocleAuthClient Client authentification JWT
    WorkerRegistryClient Auto-enregistrement des workers
    StatusDashboard Dashboard HTML de supervision temps réel (port 9374)
    Pipeline V2 Pipeline asynchrone avec garantie at-least-once (Queue/Claim/Ack)

    2. Philosophie « MOP Pilote Tout »

    Le Main Orchestrator Process est le cœur du framework :

    ┌─────────────────────────────────────────────────────────────────┐
    │                           MOP                                    │
    │  - Orchestre tous les Workers                                   │
    │  - Gère le lifecycle (start/stop)                               │
    │  - Appelle doWork() automatiquement                             │
    │  - Garantit le shutdown gracieux                                │
    └─────────────────────────────────────────────────────────────────┘
                                  │
             ┌────────────────────┼────────────────────┐
             ▼                    ▼                    ▼
        ┌─────────┐         ┌─────────┐         ┌─────────┐
        │ Worker  │         │ Worker  │         │  HTTP   │
        │ Métier  │         │ Métier  │         │ Worker  │
        └─────────┘         └─────────┘         └─────────┘
    

    Principes clés

    1. Orchestration centralisée : Le MOP contrôle tout le lifecycle
    2. Démarrage ordonné : Workers par priorité (petit → grand), HTTP en dernier
    3. Arrêt gracieux : HTTP d’abord (drain), puis Workers
    4. Scheduling automatique : doWork() appelé selon cron ou interval

    3. Les 4 principes fondamentaux V4

    3.1 Portabilité

    • Fonctionne sur ARM/AMD64, Linux/macOS
    • Aucune dépendance serveur externe obligatoire
    • Base H2 embarquée pour l’état technique

    3.2 Sécurité

    • Aucun port entrant sur les NUC/agents
    • Communication sortante uniquement (HTTP/NATS)
    • Authentification JWT pour les services centraux

    3.3 Observabilité

    • Logs centralisés via LogForwarder
    • Corrélation par correlationId / execId
    • Suivi des workers via Registry

    3.4 Standardisation

    • Même authentification partout
    • Même format de logs
    • Même enregistrement des workers

    4. Stack technique

    Composant Version Usage
    Java 21 LTS Runtime
    Spring Boot 3.2.1 Framework
    Log4j2 2.22.1 Logging (nouveau V4)
    LMAX Disruptor 4.0.0 AsyncLoggers
    H2 2.2.x Base technique embarquée (nouveau V4)
    Kafka 3.6.0 Messaging
    NATS 2.17.0 Messaging
    Redisson 3.24.3 Redis client
    OkHttp 4.12.0 HTTP client
    Micrometer 1.12.0 Metrics

    5. Composants du Socle

    Composants V3 (conservés)

    Package Description
    mop Main Orchestrator Process
    worker Interface Worker
    config SocleConfiguration
    kv KvBus (in_memory / Redis)
    shared SharedDataRegistry
    supervisor Supervision heartbeats
    http HttpWorker, TomcatManager
    admin AdminRestApi
    metrics SocleMetrics
    pipeline PipelineEngine
    resilience CircuitBreaker, Retry
    scheduler WorkerScheduler
    security AdminAuthFilter, RateLimit

    Nouveaux composants V4

    Package Description
    techdb H2 TechDB Manager
    logging Log4j2 + LogForwarder
    client/auth SocleAuthClient
    client/registry WorkerRegistryClient

    6. Cas d’usage

    Le Socle V4 est idéal pour :

    • Agents de collecte (DB2 Journal Reader, CDC)
    • Services de synchronisation (ODH-sync)
    • Proxies et bridges (Kafka Proxy)
    • Workers de traitement (ETL, pipelines)
    • Services multi-région (MTQ, GUA, REU, etc.)

    7. Prérequis

    Développement

    • JDK 21+
    • Maven 3.9+
    • IDE (IntelliJ IDEA recommandé)

    Production

    • JRE 21+
    • Docker (optionnel)
    • Accès NATS ou HTTP pour LogForwarder (optionnel)

    8. Premiers pas

    # Cloner le projet
    git clone <repo>/socle-v004.git
    
    # Build
    cd socle-v004
    mvn clean package -DskipTests
    
    # Run
    java -jar target/socle-v004-4.0.0.jar
    
    # Vérifier
    curl http://localhost:8080/health
    

    9. Documentation

    Document Description
    02-ARCHITECTURE Architecture détaillée
    03-QUICKSTART Guide de démarrage
    08-SUPERVISOR Supervision et heartbeats
    09-PIPELINE Pipeline V1 et V2
    21-H2-TECHDB Base H2 (V4)
    22-LOG4J2-LOGFORWARDER Logging V4
    25-MIGRATION-V3-V4 Migration
    27-STATUS-DASHBOARD Dashboard supervision
    GUIDE-METHODOLOGIQUE Bonnes pratiques

    10. Support

    • Issues : GitHub Issues
    • Documentation : Ce dossier docs/Help/
    • Exemples : 20-EXEMPLES
  • Socle V004 – Dépannage

    Socle V004 – Dépannage

    18 – Troubleshooting

    Version : 4.0.0 Date : 2025-12-09

    1. Problèmes de démarrage

    1.1 Application ne démarre pas

    Symptôme : L’application ne démarre pas ou crashe immédiatement.

    Causes possibles :

    1. Port déjà utilisé

      Error: Address already in use: bind
      

      Solution :

      # Trouver le processus
      lsof -i :8080
      # Changer le port
      export HTTP_PORT=8081
      
    2. Configuration manquante

      Failed to bind properties under 'socle.xxx'
      

      Solution : Vérifier les variables d’environnement et application.yml

    3. Erreur de logging

      ERROR StatusLogger Log4j2 could not find a logging implementation
      

      Solution : Vérifier que log4j2.xml existe dans src/main/resources/

    1.2 Workers ne démarrent pas

    Symptôme : Les workers sont enregistrés mais restent en état REGISTERED.

    Solutions :

    1. Vérifier les logs d’initialisation
    2. Vérifier les dépendances (base de données, Redis, etc.)
    3. Vérifier les priorités de démarrage
    curl http://localhost:8080/admin/workers
    

    2. Problèmes de connectivité

    2.1 Redis non accessible

    Symptôme :

    Cannot get Jedis connection
    

    Solutions :

    1. Vérifier l’hôte et le port Redis
      redis-cli -h localhost -p 6379 ping
      
    2. Vérifier le mot de passe
    3. Vérifier les firewalls

    2.2 Database non accessible

    Symptôme :

    Database may be already in use: "locked by another process"
    

    Solutions :

    1. Arrêter les autres instances
    2. Utiliser AUTO_SERVER=TRUE dans l’URL H2
    3. Supprimer les fichiers de lock
    rm ./data/socle-techdb.lock.db
    

    3. Problèmes de logging (V4)

    3.1 Logs non visibles

    Symptôme : Aucun log n’apparaît.

    Solutions :

    1. Vérifier que log4j2.xml existe
    2. Vérifier le niveau de log
    3. Vérifier logging.config dans application.yml
    logging:
      config: classpath:log4j2.xml
    

    3.2 Conflit Logback/Log4j2

    Symptôme :

    SLF4J: Class path contains multiple SLF4J bindings
    

    Solution : Exclure Logback de toutes les dépendances

    mvn dependency:tree | grep logback
    
    <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
    

    3.3 AsyncLoggers non actifs

    Symptôme : Performance de logging dégradée.

    Solution : Vérifier log4j2.component.properties

    Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
    

    3.4 LogForwarder queue pleine

    Symptôme :

    WARN - Log queue full, storing to fallback
    

    Solutions :

    1. Augmenter queue-capacity
    2. Vérifier la connectivité réseau vers le LogHub
    3. Réduire le volume de logs
    # Vérifier les logs en fallback
    curl http://localhost:8080/admin/logforwarder/status
    

    4. Problèmes de performance

    4.1 Haute consommation CPU

    Solutions :

    1. Vérifier les workers en boucle infinie
    2. Vérifier les logs en DEBUG
    3. Profiler avec JFR
    jcmd <pid> JFR.start duration=60s filename=recording.jfr
    

    4.2 Haute consommation mémoire

    Solutions :

    1. Analyser le heap dump
      jmap -dump:format=b,file=heap.hprof <pid>
      
    2. Vérifier les fuites dans KvBus/SharedDataRegistry
    3. Ajuster la configuration JVM

    4.3 Latence élevée

    Solutions :

    1. Vérifier les circuit breakers
      curl http://localhost:8080/admin/resilience/circuits
      
    2. Vérifier les connexions réseau
    3. Vérifier les métriques
      curl http://localhost:8080/actuator/prometheus | grep latency
      

    5. Problèmes de résilience

    5.1 Circuit Breaker bloqué en OPEN

    Symptôme : Un circuit reste ouvert malgré la récupération du service.

    Solutions :

    1. Reset manuel
      curl -X POST http://localhost:8080/admin/resilience/circuits/my-circuit/reset
      
    2. Vérifier le timeout configuré
    3. Vérifier que le service cible répond

    5.2 Retry infini

    Symptôme : L’application retry sans fin.

    Solutions :

    1. Vérifier max-attempts configuré
    2. Vérifier les exceptions retryables
    3. Ajouter un circuit breaker

    6. Problèmes H2 TechDB (V4)

    6.1 Base corrompue

    Symptôme :

    File corrupted
    

    Solution :

    rm -rf ./data/socle-techdb.*
    # Redémarrer l'application
    

    6.2 H2 Console inaccessible

    Solutions :

    1. Vérifier socle.techdb.console.enabled=true
    2. Vérifier l’URL : http://localhost:8080/h2-console
    3. Utiliser l’URL JDBC correcte : jdbc:h2:file:./data/socle-techdb

    6.3 Offsets perdus

    Solutions :

    1. Vérifier que TechDB est enabled
    2. Vérifier les logs de saveOffset
    3. Requêter directement H2
      SELECT * FROM socle_offsets;
      

    7. Problèmes d’authentification (V4)

    7.1 Login échoue

    Symptôme :

    AuthenticationException: Login failed: 401
    

    Solutions :

    1. Vérifier API_KEY
    2. Vérifier SOURCE_NAME
    3. Vérifier AUTH_SERVER_URL

    7.2 Token expiré

    Symptôme :

    Token expired
    

    Solutions :

    1. Vérifier l’horloge système (NTP)
    2. Augmenter access-token-buffer-seconds

    7.3 Admin API 401

    Solutions :

    1. Vérifier si l’auth est activée
      socle.admin.auth.enabled: true
      
    2. Utiliser les credentials corrects
      curl -u admin:password http://localhost:8080/admin/workers
      

    8. Problèmes Kubernetes

    8.1 Pod en CrashLoopBackOff

    Solutions :

    1. Vérifier les logs
      kubectl logs <pod-name> --previous
      
    2. Vérifier les ressources
    3. Vérifier les probes

    8.2 Probes échouent

    Solutions :

    1. Augmenter initialDelaySeconds
    2. Vérifier que l’endpoint /admin/health répond
    3. Vérifier le port

    8.3 OOMKilled

    Solutions :

    1. Augmenter les limites mémoire
    2. Ajuster les options JVM
      -XX:MaxRAMPercentage=75.0
      

    9. Commandes de diagnostic

    9.1 API Admin

    # Santé globale
    curl http://localhost:8080/admin/health
    
    # État des workers
    curl http://localhost:8080/admin/workers
    
    # Registry
    curl http://localhost:8080/admin/registry
    
    # Circuits breakers
    curl http://localhost:8080/admin/resilience/circuits
    
    # Configuration
    curl http://localhost:8080/admin/config
    
    # Métriques
    curl http://localhost:8080/actuator/prometheus
    

    9.2 JVM

    # Thread dump
    jstack <pid>
    
    # Heap info
    jmap -heap <pid>
    
    # GC stats
    jstat -gcutil <pid> 1000
    
    # JFR recording
    jcmd <pid> JFR.start duration=60s filename=recording.jfr
    

    9.3 Réseau

    # Test Redis
    redis-cli -h localhost ping
    
    # Test HTTP
    curl -v http://localhost:8080/admin/health
    
    # DNS
    nslookup myservice.namespace.svc.cluster.local
    

    10. Logs utiles à activer

    # application.yml ou variables d'environnement
    
    logging:
      level:
        eu.lmvi.socle: DEBUG
        eu.lmvi.socle.mop: DEBUG
        eu.lmvi.socle.supervisor: DEBUG
        eu.lmvi.socle.techdb: DEBUG
        eu.lmvi.socle.resilience: DEBUG
        org.springframework.web: DEBUG
        io.lettuce: DEBUG  # Redis
    

    11. Checklist de diagnostic

    □ L'application démarre-t-elle ?
      □ Logs de démarrage présents ?
      □ Port disponible ?
      □ Configuration valide ?
    
    □ Les workers sont-ils healthy ?
      □ GET /admin/workers
      □ Heartbeats reçus ?
      □ Erreurs dans les logs ?
    
    □ Les connexions externes fonctionnent-elles ?
      □ Redis accessible ?
      □ Base de données accessible ?
      □ APIs externes accessibles ?
    
    □ Les métriques sont-elles normales ?
      □ CPU < 80% ?
      □ Mémoire < 80% ?
      □ Latence acceptable ?
      □ Taux d'erreur bas ?
    
    □ Les logs sont-ils corrects ?
      □ Log4j2 configuré ?
      □ LogForwarder fonctionne ?
      □ Pas de logs en fallback ?
    

    12. Références

  • Socle V004 – Introduction

    Socle V004 – Introduction

    01 – Introduction au Socle V4

    Version : 4.0.0 Date : 2025-01-25

    1. Qu’est-ce que le Socle V4 ?

    Le Socle V4 est un framework Java de grade production construit sur Spring Boot 3.2.1 qui implémente le pattern MOP (Main Orchestrator Process). Il fournit une base solide pour construire des applications d’entreprise robustes et observables.

    Évolution depuis V3

    Le Socle V4 conserve et étend l’architecture V3 en ajoutant :

    Nouveauté V4 Description
    H2 TechDB Base embarquée pour état technique (remplace Nitrite)
    Log4j2 Framework logging haute performance (remplace Logback)
    LogForwarder Centralisation des logs vers LogHub (HTTP/NATS)
    SocleAuthClient Client authentification JWT
    WorkerRegistryClient Auto-enregistrement des workers
    StatusDashboard Dashboard HTML de supervision temps réel (port 9374)
    Pipeline V2 Pipeline asynchrone avec garantie at-least-once (Queue/Claim/Ack)

    2. Philosophie « MOP Pilote Tout »

    Le Main Orchestrator Process est le cœur du framework :

    ┌─────────────────────────────────────────────────────────────────┐
    │                           MOP                                    │
    │  - Orchestre tous les Workers                                   │
    │  - Gère le lifecycle (start/stop)                               │
    │  - Appelle doWork() automatiquement                             │
    │  - Garantit le shutdown gracieux                                │
    └─────────────────────────────────────────────────────────────────┘
                                  │
             ┌────────────────────┼────────────────────┐
             ▼                    ▼                    ▼
        ┌─────────┐         ┌─────────┐         ┌─────────┐
        │ Worker  │         │ Worker  │         │  HTTP   │
        │ Métier  │         │ Métier  │         │ Worker  │
        └─────────┘         └─────────┘         └─────────┘
    

    Principes clés

    1. Orchestration centralisée : Le MOP contrôle tout le lifecycle
    2. Démarrage ordonné : Workers par priorité (petit → grand), HTTP en dernier
    3. Arrêt gracieux : HTTP d’abord (drain), puis Workers
    4. Scheduling automatique : doWork() appelé selon cron ou interval

    3. Les 4 principes fondamentaux V4

    3.1 Portabilité

    • Fonctionne sur ARM/AMD64, Linux/macOS
    • Aucune dépendance serveur externe obligatoire
    • Base H2 embarquée pour l’état technique

    3.2 Sécurité

    • Aucun port entrant sur les NUC/agents
    • Communication sortante uniquement (HTTP/NATS)
    • Authentification JWT pour les services centraux

    3.3 Observabilité

    • Logs centralisés via LogForwarder
    • Corrélation par correlationId / execId
    • Suivi des workers via Registry

    3.4 Standardisation

    • Même authentification partout
    • Même format de logs
    • Même enregistrement des workers

    4. Stack technique

    Composant Version Usage
    Java 21 LTS Runtime
    Spring Boot 3.2.1 Framework
    Log4j2 2.22.1 Logging (nouveau V4)
    LMAX Disruptor 4.0.0 AsyncLoggers
    H2 2.2.x Base technique embarquée (nouveau V4)
    Kafka 3.6.0 Messaging
    NATS 2.17.0 Messaging
    Redisson 3.24.3 Redis client
    OkHttp 4.12.0 HTTP client
    Micrometer 1.12.0 Metrics

    5. Composants du Socle

    Composants V3 (conservés)

    Package Description
    mop Main Orchestrator Process
    worker Interface Worker
    config SocleConfiguration
    kv KvBus (in_memory / Redis)
    shared SharedDataRegistry
    supervisor Supervision heartbeats
    http HttpWorker, TomcatManager
    admin AdminRestApi
    metrics SocleMetrics
    pipeline PipelineEngine
    resilience CircuitBreaker, Retry
    scheduler WorkerScheduler
    security AdminAuthFilter, RateLimit

    Nouveaux composants V4

    Package Description
    techdb H2 TechDB Manager
    logging Log4j2 + LogForwarder
    client/auth SocleAuthClient
    client/registry WorkerRegistryClient

    6. Cas d’usage

    Le Socle V4 est idéal pour :

    • Agents de collecte (DB2 Journal Reader, CDC)
    • Services de synchronisation (ODH-sync)
    • Proxies et bridges (Kafka Proxy)
    • Workers de traitement (ETL, pipelines)
    • Services multi-région (MTQ, GUA, REU, etc.)

    7. Prérequis

    Développement

    • JDK 21+
    • Maven 3.9+
    • IDE (IntelliJ IDEA recommandé)

    Production

    • JRE 21+
    • Docker (optionnel)
    • Accès NATS ou HTTP pour LogForwarder (optionnel)

    8. Premiers pas

    # Cloner le projet
    git clone <repo>/socle-v004.git
    
    # Build
    cd socle-v004
    mvn clean package -DskipTests
    
    # Run
    java -jar target/socle-v004-4.0.0.jar
    
    # Vérifier
    curl http://localhost:8080/health
    

    9. Documentation

    Document Description
    02-ARCHITECTURE Architecture détaillée
    03-QUICKSTART Guide de démarrage
    08-SUPERVISOR Supervision et heartbeats
    09-PIPELINE Pipeline V1 et V2
    21-H2-TECHDB Base H2 (V4)
    22-LOG4J2-LOGFORWARDER Logging V4
    25-MIGRATION-V3-V4 Migration
    27-STATUS-DASHBOARD Dashboard supervision
    GUIDE-METHODOLOGIQUE Bonnes pratiques

    10. Support

    • Issues : GitHub Issues
    • Documentation : Ce dossier docs/Help/
    • Exemples : 20-EXEMPLES