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

io.camunda.zeebe.broker.system.management.BrokerAdminServiceEndpoint Maven / Gradle / Ivy

There is a newer version: 8.7.0-alpha1
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.zeebe.broker.system.management;

import io.camunda.zeebe.broker.SpringBrokerBridge;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

@Component
@Endpoint(id = "partitions")
public class BrokerAdminServiceEndpoint {

  @Autowired private SpringBrokerBridge springBrokerBridge;

  private final Map operations = new HashMap<>();

  public BrokerAdminServiceEndpoint() {
    operations.put("pauseProcessing", this::pauseProcessing);
    operations.put("resumeProcessing", this::resumeProcessing);
    operations.put("takeSnapshot", this::takeSnapshot);
    operations.put("prepareUpgrade", this::prepareUpgrade);
    operations.put("pauseExporting", this::pauseExporting);
    operations.put("softPauseExporting", this::softPauseExporting);
    operations.put("resumeExporting", this::resumeExporting);
  }

  @WriteOperation
  public Map trigger(@Selector final String operation) {
    final var runnable = operations.get(operation);
    if (runnable != null) {
      runnable.run();
      return partitionStatus();
    }
    // Not a valid operation
    return null;
  }

  private Map pauseProcessing() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::pauseStreamProcessing);
    return partitionStatus();
  }

  private Map resumeProcessing() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::resumeStreamProcessing);
    return partitionStatus();
  }

  private Map pauseExporting() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::pauseExporting);
    return partitionStatus();
  }

  private Map softPauseExporting() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::softPauseExporting);
    return partitionStatus();
  }

  private Map resumeExporting() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::resumeExporting);
    return partitionStatus();
  }

  private Map takeSnapshot() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::takeSnapshot);
    return partitionStatus();
  }

  private Map prepareUpgrade() {
    springBrokerBridge.getAdminService().ifPresent(BrokerAdminService::prepareForUpgrade);
    return partitionStatus();
  }

  @ReadOperation
  public Map partitionStatus() {
    return springBrokerBridge
        .getAdminService()
        .map(BrokerAdminService::getPartitionStatus)
        .orElse(Map.of());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy