merlimat closed pull request #1464: Fix broker stats to work with v2 namespace
format.
URL: https://github.com/apache/incubator-pulsar/pull/1464
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
index 9da3fc6fc..03fc9a258 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokerStatsBase.java
@@ -158,20 +158,11 @@ public LoadManagerReport getLoadReport() throws Exception
{
}
}
- @GET
- @Path("/broker-resource-availability/{property}/{cluster}/{namespace}")
- @ApiOperation(value = "Broker availability report", notes = "This API
gives the current broker availability in percent, each resource percentage
usage is calculated and then"
- + "sum of all of the resource usage percent is called
broker-resource-availability"
- + "<br/><br/>THIS API IS ONLY FOR USE BY TESTING FOR CONFIRMING
NAMESPACE ALLOCATION ALGORITHM", response = ResourceUnit.class,
responseContainer = "Map")
- @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have
admin permission"),
- @ApiResponse(code = 409, message = "Load-manager doesn't support
operation") })
- public Map<Long, Collection<ResourceUnit>>
getBrokerResourceAvailability(@PathParam("property") String property,
- @PathParam("cluster") String cluster, @PathParam("namespace")
String namespace) throws Exception {
+ protected Map<Long, Collection<ResourceUnit>>
internalBrokerResourceAvailability(NamespaceName namespace) {
try {
- NamespaceName ns = NamespaceName.get(property, cluster, namespace);
LoadManager lm = pulsar().getLoadManager().get();
if (lm instanceof SimpleLoadManagerImpl) {
- return ((SimpleLoadManagerImpl)
lm).getResourceAvailabilityFor(ns).asMap();
+ return ((SimpleLoadManagerImpl)
lm).getResourceAvailabilityFor(namespace).asMap();
} else {
throw new RestException(Status.CONFLICT,
lm.getClass().getName() + " does not support this operation");
}
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/BrokerStats.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/BrokerStats.java
index 97ebbd9a7..76aea674b 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/BrokerStats.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/BrokerStats.java
@@ -19,14 +19,38 @@
package org.apache.pulsar.broker.admin.v1;
import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.apache.pulsar.broker.admin.impl.BrokerStatsBase;
+import org.apache.pulsar.broker.loadbalance.ResourceUnit;
+import org.apache.pulsar.common.naming.NamespaceName;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import java.util.Collection;
+import java.util.Map;
@Path("/broker-stats")
@Api(value = "/broker-stats", description = "Stats for broker", tags =
"broker-stats")
@Produces(MediaType.APPLICATION_JSON)
public class BrokerStats extends BrokerStatsBase {
+
+ @GET
+ @Path("/broker-resource-availability/{property}/{cluster}/{namespace}")
+ @ApiOperation(value = "Broker availability report", notes = "This API
gives the current broker availability in "
+ + "percent, each resource percentage usage is calculated and then"
+ + "sum of all of the resource usage percent is called
broker-resource-availability"
+ + "<br/><br/>THIS API IS ONLY FOR USE BY TESTING FOR CONFIRMING
NAMESPACE ALLOCATION ALGORITHM",
+ response = ResourceUnit.class, responseContainer = "Map")
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have
admin permission"),
+ @ApiResponse(code = 409, message = "Load-manager doesn't support
operation") })
+ public Map<Long, Collection<ResourceUnit>>
getBrokerResourceAvailability(@PathParam("property") String property,
+ @PathParam("cluster") String cluster, @PathParam("namespace") String
namespace) {
+ validateNamespaceName(property, cluster, namespace);
+ return internalBrokerResourceAvailability(namespaceName);
+ }
}
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/BrokerStats.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/BrokerStats.java
index f0318d7e9..fd0d83992 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/BrokerStats.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/BrokerStats.java
@@ -19,14 +19,37 @@
package org.apache.pulsar.broker.admin.v2;
import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.apache.pulsar.broker.admin.impl.BrokerStatsBase;
+import org.apache.pulsar.broker.loadbalance.ResourceUnit;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import java.util.Collection;
+import java.util.Map;
@Path("/broker-stats")
@Api(value = "/broker-stats", description = "Stats for broker", tags =
"broker-stats")
@Produces(MediaType.APPLICATION_JSON)
public class BrokerStats extends BrokerStatsBase {
+
+ @GET
+ @Path("/broker-resource-availability/{property}/{namespace}")
+ @ApiOperation(value = "Broker availability report", notes = "This API
gives the current broker availability in "
+ + "percent, each resource percentage usage is calculated and then"
+ + "sum of all of the resource usage percent is called
broker-resource-availability"
+ + "<br/><br/>THIS API IS ONLY FOR USE BY TESTING FOR CONFIRMING
NAMESPACE ALLOCATION ALGORITHM",
+ response = ResourceUnit.class, responseContainer = "Map")
+ @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have
admin permission"),
+ @ApiResponse(code = 409, message = "Load-manager doesn't support
operation") })
+ public Map<Long, Collection<ResourceUnit>>
getBrokerResourceAvailability(@PathParam("property") String property,
+ @PathParam("namespace") String namespace) {
+ validateNamespaceName(property, namespace);
+ return internalBrokerResourceAvailability(namespaceName);
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services