Search in sources :

Example 6 with DataNodeId

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);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) DataNodeId(com.github.ambry.clustermap.DataNodeId)

Example 7 with DataNodeId

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;
}
Also used : RestServiceException(com.github.ambry.rest.RestServiceException) DataNodeId(com.github.ambry.clustermap.DataNodeId)

Example 8 with 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();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) NetworkConfig(com.github.ambry.config.NetworkConfig) ArrayList(java.util.ArrayList) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ReplicaId(com.github.ambry.clustermap.ReplicaId) DataNodeId(com.github.ambry.clustermap.DataNodeId) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Test(org.junit.Test)

Example 9 with DataNodeId

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);
}
Also used : MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) DataNodeId(com.github.ambry.clustermap.DataNodeId) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Test(org.junit.Test)

Example 10 with DataNodeId

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;
}
Also used : DataNodeId(com.github.ambry.clustermap.DataNodeId)

Aggregations

DataNodeId (com.github.ambry.clustermap.DataNodeId)92 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)45 HashMap (java.util.HashMap)29 PartitionId (com.github.ambry.clustermap.PartitionId)28 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)27 ReplicaId (com.github.ambry.clustermap.ReplicaId)25 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)23 VerifiableProperties (com.github.ambry.config.VerifiableProperties)23 MetricRegistry (com.codahale.metrics.MetricRegistry)22 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)22 List (java.util.List)22 Map (java.util.Map)22 Port (com.github.ambry.network.Port)21 ClusterMap (com.github.ambry.clustermap.ClusterMap)20 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)19 StoreKeyFactory (com.github.ambry.store.StoreKeyFactory)18 BlobIdFactory (com.github.ambry.commons.BlobIdFactory)17 HashSet (java.util.HashSet)16 Properties (java.util.Properties)16