diff --git a/src/main/java/org/assimbly/gateway/web/rest/broker/HealthBrokerResource.java b/src/main/java/org/assimbly/gateway/web/rest/broker/HealthBrokerResource.java new file mode 100644 index 00000000..2cd65b7a --- /dev/null +++ b/src/main/java/org/assimbly/gateway/web/rest/broker/HealthBrokerResource.java @@ -0,0 +1,62 @@ +package org.assimbly.gateway.web.rest.broker; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Parameter; +import org.assimbly.brokerrest.ManagedBrokerRuntime; +import org.assimbly.gateway.service.HealthService; +import org.assimbly.util.rest.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.audit.AuditEvent; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +/** + * REST controller for getting the {@link AuditEvent}s. + */ +@RestController +@RequestMapping("/health") +public class HealthBrokerResource { + + protected Logger log = LoggerFactory.getLogger(getClass()); + + public HealthBrokerResource(HealthService healthService) { } + + @Autowired + private ManagedBrokerRuntime managedBroker; + + private boolean plainResponse; + + @GetMapping( + path = "/broker", + produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE} + ) + public ResponseEntity getBrokerStats(@Parameter(hidden = true) @RequestHeader("Accept") String mediaType) throws Exception { + + plainResponse = true; + long connectorId = 1; + + try { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + final ObjectMapper mapper = new ObjectMapper(); + + Map statsMap = managedBroker.getStats("classic"); + + mapper.writeValue(out, statsMap); + + return ResponseUtil.createSuccessResponse(connectorId, mediaType, "/health/broker", out.toString(StandardCharsets.UTF_8), plainResponse); + } catch (Exception e) { + log.error("Get broker failed",e); + return ResponseUtil.createFailureResponse(connectorId, mediaType,"/health/broker",e.getMessage()); + } + } +} diff --git a/src/main/java/org/assimbly/gateway/web/rest/gateway/HealthResource.java b/src/main/java/org/assimbly/gateway/web/rest/integration/HealthIntegrationResource.java similarity index 77% rename from src/main/java/org/assimbly/gateway/web/rest/gateway/HealthResource.java rename to src/main/java/org/assimbly/gateway/web/rest/integration/HealthIntegrationResource.java index f3efc2a2..5578b2f4 100644 --- a/src/main/java/org/assimbly/gateway/web/rest/gateway/HealthResource.java +++ b/src/main/java/org/assimbly/gateway/web/rest/integration/HealthIntegrationResource.java @@ -1,8 +1,7 @@ -package org.assimbly.gateway.web.rest.gateway; +package org.assimbly.gateway.web.rest.integration; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Parameter; -import org.assimbly.brokerrest.ManagedBrokerRuntime; import org.assimbly.gateway.service.HealthService; import org.assimbly.gateway.service.response.BackendResponse; import org.assimbly.integration.Integration; @@ -21,29 +20,25 @@ import java.lang.management.MemoryUsage; import java.lang.management.ThreadMXBean; import java.nio.charset.StandardCharsets; -import java.util.Map; /** * REST controller for getting the {@link AuditEvent}s. */ @RestController @RequestMapping("/health") -public class HealthResource { +public class HealthIntegrationResource { protected Logger log = LoggerFactory.getLogger(getClass()); private final HealthService healthService; - public HealthResource(HealthService healthService) { + public HealthIntegrationResource(HealthService healthService) { this.healthService = healthService; } @Autowired private IntegrationRuntime integrationRuntime; - @Autowired - private ManagedBrokerRuntime managedBroker; - private Integration integration; private boolean plainResponse; @@ -104,29 +99,4 @@ public ResponseEntity getFlowStats(@Parameter(hidden = true) @RequestHea return ResponseUtil.createFailureResponse(connectorId, mediaType,"/health/flow",e.getMessage()); } } - - - @GetMapping( - path = "/broker", - produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE} - ) - public ResponseEntity getBrokerStats(@Parameter(hidden = true) @RequestHeader("Accept") String mediaType) throws Exception { - - plainResponse = true; - long connectorId = 1; - - try { - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - final ObjectMapper mapper = new ObjectMapper(); - - Map statsMap = managedBroker.getStats("classic"); - - mapper.writeValue(out, statsMap); - - return org.assimbly.util.rest.ResponseUtil.createSuccessResponse(connectorId, mediaType, "/health/broker", out.toString(StandardCharsets.UTF_8), plainResponse); - } catch (Exception e) { - log.error("Get broker failed",e); - return ResponseUtil.createFailureResponse(connectorId, mediaType,"/health/broker",e.getMessage()); - } - } }