use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.
the class GetPeersHandler method getResponseBody.
/**
* Constructs the response body as a JSON that contains the details of all the {@code dataNodeIds}.
* @param dataNodeIds the {@link DataNodeId}s that need to be packaged as peers.
* @return a {@link ReadableStreamChannel} containing the response.
* @throws JSONException if there is any problem with JSON construction or manipulation.
*/
private static ReadableStreamChannel getResponseBody(Set<DataNodeId> dataNodeIds) throws JSONException, RestServiceException {
JSONObject peers = new JSONObject();
peers.put(PEERS_FIELD_NAME, new JSONArray());
for (DataNodeId dataNodeId : dataNodeIds) {
JSONObject peer = new JSONObject();
peer.put(NAME_QUERY_PARAM, dataNodeId.getHostname());
peer.put(PORT_QUERY_PARAM, dataNodeId.getPort());
peers.append(PEERS_FIELD_NAME, peer);
}
return FrontendUtils.serializeJsonToChannel(peers);
}
use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.
the class GetPeersHandler method getDataNodeId.
/**
* Gets the {@link DataNodeId} based on query parameters in the {@code restRequest}. Return is always non-null.
* @param restRequest the {@link RestRequest} containing the parameters of the request.
* @return the {@link DataNodeId} based on query parameters in the {@code restRequest}. Return is always non-null.
* @throws RestServiceException if either {@link #NAME_QUERY_PARAM} or {@link #PORT_QUERY_PARAM} is missing, if
* {@link #PORT_QUERY_PARAM} is not an {@link Integer} or if there is no datanode that corresponds to the given
* parameters.
*/
private DataNodeId getDataNodeId(RestRequest restRequest) throws RestServiceException {
String name = (String) restRequest.getArgs().get(NAME_QUERY_PARAM);
String portStr = (String) restRequest.getArgs().get(PORT_QUERY_PARAM);
if (name == null || portStr == null) {
throw new RestServiceException("Missing name and/or port of data node", RestServiceErrorCode.MissingArgs);
}
int port;
try {
port = Integer.parseInt(portStr);
} catch (NumberFormatException e) {
throw new RestServiceException("Port " + "[" + portStr + "] could not parsed into a number", RestServiceErrorCode.InvalidArgs);
}
DataNodeId dataNodeId = clusterMap.getDataNodeId(name, port);
if (dataNodeId == null) {
metrics.unknownDatanodeError.inc();
throw new RestServiceException("No datanode found for parameters " + name + ":" + port, RestServiceErrorCode.NotFound);
}
return dataNodeId;
}
use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.
the class MockSelector method testCloseWithDanglingRequest.
/**
* Test when close the router, the dangling requests will be correctly released.
*/
@Test
public void testCloseWithDanglingRequest() throws Exception {
Properties props = new Properties();
props.setProperty(NetworkConfig.NETWORK_CLIENT_ENABLE_CONNECTION_REPLENISHMENT, "true");
VerifiableProperties vprops = new VerifiableProperties(props);
NetworkConfig networkConfig = new NetworkConfig(vprops);
MockSelector mockSelector = new MockSelector(networkConfig);
NetworkMetrics localNetworkMetrics = new NetworkMetrics(new MetricRegistry());
SocketNetworkClient localNetworkClient = new SocketNetworkClient(mockSelector, networkConfig, localNetworkMetrics, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, time);
DataNodeId dataNodeId = localPlainTextDataNodes.get(0);
ReplicaId replicaId = sslDisabledClusterMap.getReplicaIds(dataNodeId).get(0);
List<RequestInfo> requestInfoList = new ArrayList<>();
List<ResponseInfo> responseInfoList;
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(1), replicaId, null));
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(2), replicaId, null));
// This call would create two connection and not send any requests out
localNetworkClient.sendAndPoll(requestInfoList, Collections.EMPTY_SET, POLL_TIMEOUT_MS);
requestInfoList.clear();
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(3), replicaId, null));
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(4), replicaId, null));
mockSelector.setState(MockSelectorState.IdlePoll);
// This call would send first two requests out. At the same time, keep last two requests in the pendingRequests queue.
localNetworkClient.sendAndPoll(requestInfoList, Collections.EMPTY_SET, POLL_TIMEOUT_MS);
localNetworkClient.close();
}
use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.
the class MockSelector method testWarmUpConnectionsSslAndPlainText.
/**
* Test {@link SocketNetworkClient#warmUpConnections(List, int, long, List)}
*/
@Test
public void testWarmUpConnectionsSslAndPlainText() {
// warm up plain-text connections with SSL enabled nodes.
doTestWarmUpConnections(localSslDataNodes, MAX_PORTS_PLAIN_TEXT, PortType.PLAINTEXT);
// enable SSL to local DC.
for (DataNodeId dataNodeId : localSslDataNodes) {
((MockDataNodeId) dataNodeId).setSslEnabledDataCenters(Collections.singletonList(sslEnabledClusterMap.getDatacenterName(sslEnabledClusterMap.getLocalDatacenterId())));
}
// warm up SSL connections.`
doTestWarmUpConnections(localSslDataNodes, MAX_PORTS_SSL, PortType.SSL);
}
use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.
the class ConnectionTracker method removeConnection.
/**
* Remove and stop tracking the given connection id.
* @param connectionId connection to remove.
* @throws {@link IllegalArgumentException} if the passed in connection id is invalid.
* @return {@link DataNodeId} associated with this connection.
*/
DataNodeId removeConnection(String connectionId) {
HostPortPoolManager hostPortPoolManager = connectionIdToPoolManager.remove(connectionId);
if (hostPortPoolManager == null) {
throw new IllegalArgumentException("Invalid connection id passed in");
}
DataNodeId dataNodeId = hostPortPoolManager.removeConnection(connectionId);
totalManagedConnectionsCount--;
if (!hostPortPoolManager.hasMinActiveConnections()) {
poolManagersBelowMinActiveConnections.add(hostPortPoolManager);
}
return dataNodeId;
}
Aggregations