Skip to content

Commit

Permalink
Add API endpoint that returns the local datacenter
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard Tudenhoefner committed Jul 6, 2020
1 parent 2d289d8 commit b82d6e0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,10 @@ public void createKeyspace(@RpcParam(name="keyspaceName") String keyspaceName, @
.asCql(),
ConsistencyLevel.ONE);
}

@Rpc(name = "getLocalDataCenter")
public String getLocalDataCenter()
{
return ShimLoader.instance.get().getLocalDataCenter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import org.apache.cassandra.auth.IRoleManager;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.db.ConsistencyLevel;
Expand Down Expand Up @@ -63,4 +64,6 @@ default Object handleRpcResult(Callable<Object> rpcResult) throws Exception
{
return rpcResult.call();
}

String getLocalDataCenter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public Response getEndpointStates()
return executeWithJSONResponse("CALL NodeOps.getEndpointStates()");
}

@GET
@Path("/localdc")
@Operation(summary = "Returns the DataCenter the local node belongs to")
@Produces(MediaType.TEXT_PLAIN)
public Response getLocalDataCenter()
{
return executeWithStringResponse("CALL NodeOps.getLocalDataCenter()");
}

/**
* Executes a CQL query with the expectation that there will be a single row returned with type String
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,10 @@ public Gossiper getGossiper()
{
return Gossiper.instance;
}

@Override
public String getLocalDataCenter()
{
return DatabaseDescriptor.getLocalDataCenter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,10 @@ public Gossiper getGossiper()
{
return Gossiper.instance;
}

@Override
public String getLocalDataCenter()
{
return DatabaseDescriptor.getLocalDataCenter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,10 @@ public Object handleRpcResult(Callable<Object> rpcResult)
{
return RxThreads.subscribeOnIo(Single.defer(() -> Single.fromCallable(rpcResult)), TPCTaskType.UNKNOWN);
}

@Override
public String getLocalDataCenter()
{
return DatabaseDescriptor.getLocalDataCenter();
}
}

0 comments on commit b82d6e0

Please sign in to comment.