Skip to content

Commit

Permalink
separate Broker and Integration endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
brunovg committed Jul 11, 2023
1 parent 9f08ca6 commit 774c4d4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> 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<String, Object> 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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -104,29 +99,4 @@ public ResponseEntity<String> 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<String> 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<String, Object> 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());
}
}
}

0 comments on commit 774c4d4

Please sign in to comment.