use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.
the class IsilonApiFactory method init.
/**
* Initialize HTTP client
*/
public void init() {
_clientMap = new ConcurrentHashMap<String, IsilonApi>();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
params.setMaxTotalConnections(_maxConn);
params.setTcpNoDelay(true);
params.setConnectionTimeout(_connTimeout);
params.setSoTimeout(_socketConnTimeout);
_connectionManager = new MultiThreadedHttpConnectionManager();
_connectionManager.setParams(params);
// close idle connections immediately
_connectionManager.closeIdleConnections(0);
HttpClient client = new HttpClient(_connectionManager);
client.getParams().setConnectionManagerTimeout(connManagerTimeout);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
return false;
}
});
_clientHandler = new ApacheHttpClientHandler(client);
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.
the class RestClientFactory method init.
/**
* Initialize HTTP client
*/
public void init() {
_clientMap = new ConcurrentHashMap<String, RestClientItf>();
_log.info("Init");
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
params.setMaxTotalConnections(_maxConn);
params.setTcpNoDelay(true);
params.setConnectionTimeout(_connTimeout);
params.setSoTimeout(_socketConnTimeout);
_connectionManager = new MultiThreadedHttpConnectionManager();
_connectionManager.setParams(params);
// close idle connections immediately
_connectionManager.closeIdleConnections(0);
HttpClient client = new HttpClient(_connectionManager);
client.getParams().setConnectionManagerTimeout(connManagerTimeout);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
return false;
}
});
if (_needCertificateManager) {
// TMP CODE to create dummy security certificate manager
ClientConfig clientConfig = null;
try {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// Install the all-trusting trust manager
SSLContext sslContext;
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
javax.net.ssl.HostnameVerifier hostVerifier = new javax.net.ssl.HostnameVerifier() {
@Override
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
return true;
}
};
clientConfig = new com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig();
clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostVerifier, sslContext));
} catch (GeneralSecurityException ex) {
throw new RuntimeException("Failed to obtain ApacheHTTPClient Config");
}
_clientHandler = new ApacheHttpClientHandler(client, clientConfig);
} else {
_clientHandler = new ApacheHttpClientHandler(client);
}
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project pinot by linkedin.
the class ControllerStarter method start.
public void start() {
LOGGER.info("Starting Pinot controller");
Utils.logVersions();
component.getServers().add(Protocol.HTTP, Integer.parseInt(config.getControllerPort()));
component.getClients().add(Protocol.FILE);
component.getClients().add(Protocol.JAR);
final Context applicationContext = component.getContext().createChildContext();
LOGGER.info("Controller download url base: {}", config.generateVipUrl());
LOGGER.info("Injecting configuration and resource manager to the API context");
applicationContext.getAttributes().put(ControllerConf.class.toString(), config);
applicationContext.getAttributes().put(PinotHelixResourceManager.class.toString(), helixResourceManager);
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setConnectionTimeout(config.getServerAdminRequestTimeoutSeconds());
applicationContext.getAttributes().put(HttpConnectionManager.class.toString(), connectionManager);
applicationContext.getAttributes().put(Executor.class.toString(), executorService);
controllerRestApp.setContext(applicationContext);
component.getDefaultHost().attach(controllerRestApp);
MetricsHelper.initializeMetrics(config.subset("pinot.controller.metrics"));
MetricsHelper.registerMetricsRegistry(_metricsRegistry);
final ControllerMetrics controllerMetrics = new ControllerMetrics(_metricsRegistry);
try {
LOGGER.info("Starting Pinot Helix resource manager and connecting to Zookeeper");
helixResourceManager.start();
// Helix resource manager must be started in order to create PinotLLCRealtimeSegmentManager
PinotLLCRealtimeSegmentManager.create(helixResourceManager, config, controllerMetrics);
ValidationMetrics validationMetrics = new ValidationMetrics(_metricsRegistry);
validationManager = new ValidationManager(validationMetrics, helixResourceManager, config, PinotLLCRealtimeSegmentManager.getInstance());
LOGGER.info("Starting Pinot REST API component");
component.start();
LOGGER.info("Starting retention manager");
retentionManager.start();
LOGGER.info("Starting validation manager");
validationManager.start();
LOGGER.info("Starting realtime segment manager");
realtimeSegmentsManager.start(controllerMetrics);
PinotLLCRealtimeSegmentManager.getInstance().start();
LOGGER.info("Starting segment status manager");
segmentStatusChecker.start(controllerMetrics);
LOGGER.info("Pinot controller ready and listening on port {} for API requests", config.getControllerPort());
LOGGER.info("Controller services available at http://{}:{}/", config.getControllerHost(), config.getControllerPort());
} catch (final Exception e) {
LOGGER.error("Caught exception while starting controller", e);
Utils.rethrowException(e);
throw new AssertionError("Should not reach this");
}
controllerMetrics.addCallbackGauge("helix.connected", new Callable<Long>() {
@Override
public Long call() throws Exception {
return helixResourceManager.getHelixZkManager().isConnected() ? 1L : 0L;
}
});
controllerMetrics.addCallbackGauge("helix.leader", new Callable<Long>() {
@Override
public Long call() throws Exception {
return helixResourceManager.getHelixZkManager().isLeader() ? 1L : 0L;
}
});
controllerMetrics.addCallbackGauge("dataDir.exists", new Callable<Long>() {
@Override
public Long call() throws Exception {
return new File(config.getDataDir()).exists() ? 1L : 0L;
}
});
controllerMetrics.addCallbackGauge("dataDir.fileOpLatencyMs", new Callable<Long>() {
@Override
public Long call() throws Exception {
File dataDir = new File(config.getDataDir());
if (dataDir.exists()) {
try {
long startTime = System.currentTimeMillis();
final File testFile = new File(dataDir, config.getControllerHost());
FileOutputStream outputStream = new FileOutputStream(testFile, false);
outputStream.write(Longs.toByteArray(System.currentTimeMillis()));
outputStream.flush();
outputStream.close();
FileUtils.deleteQuietly(testFile);
long endTime = System.currentTimeMillis();
return endTime - startTime;
} catch (IOException e) {
LOGGER.warn("Caught exception while checking the data directory operation latency", e);
return DATA_DIRECTORY_EXCEPTION_VALUE;
}
} else {
return DATA_DIRECTORY_MISSING_VALUE;
}
}
});
ServiceStatus.setServiceStatusCallback(new ServiceStatus.ServiceStatusCallback() {
private boolean _isStarted = false;
@Override
public ServiceStatus.Status getServiceStatus() {
if (_isStarted) {
// If we've connected to Helix at some point, the instance status depends on being connected to ZK
if (helixResourceManager.getHelixZkManager().isConnected()) {
return ServiceStatus.Status.GOOD;
} else {
return ServiceStatus.Status.BAD;
}
}
// Return starting until zk is connected
if (!helixResourceManager.getHelixZkManager().isConnected()) {
return ServiceStatus.Status.STARTING;
} else {
_isStarted = true;
return ServiceStatus.Status.GOOD;
}
}
});
helixResourceManager.getHelixZkManager().addPreConnectCallback(new PreConnectCallback() {
@Override
public void onPreConnect() {
controllerMetrics.addMeteredGlobalValue(ControllerMeter.HELIX_ZOOKEEPER_RECONNECTS, 1L);
}
});
controllerMetrics.initializeGlobalMeters();
ControllerRestApplication.setControllerMetrics(controllerMetrics);
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project kotlin by JetBrains.
the class ResolveDescriptorsFromExternalLibraries method getFileFromUrl.
private static File getFileFromUrl(@NotNull String lib, @NotNull File file, @NotNull String uri) throws IOException {
if (file.exists()) {
return file;
}
KotlinTestUtils.mkdirs(file.getParentFile());
File tmp = new File(file.getPath() + "~");
GetMethod method = new GetMethod(uri);
FileOutputStream os = null;
System.out.println("Downloading library " + lib + " to " + file);
MultiThreadedHttpConnectionManager connectionManager = null;
try {
connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);
os = new FileOutputStream(tmp);
String userAgent = ResolveDescriptorsFromExternalLibraries.class.getName() + "/commons-httpclient";
method.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
int code = httpClient.executeMethod(method);
if (code != 200) {
throw new RuntimeException("failed to execute GET " + uri + ", code is " + code);
}
InputStream responseBodyAsStream = method.getResponseBodyAsStream();
if (responseBodyAsStream == null) {
throw new RuntimeException("method is executed fine, but response is null");
}
ByteStreams.copy(responseBodyAsStream, os);
os.close();
if (!tmp.renameTo(file)) {
throw new RuntimeException("failed to rename file: " + tmp + " to " + file);
}
return file;
} finally {
try {
method.releaseConnection();
} catch (Throwable e) {
}
if (connectionManager != null) {
try {
connectionManager.shutdown();
} catch (Throwable e) {
}
}
if (os != null) {
try {
os.close();
} catch (Throwable e) {
}
}
tmp.delete();
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project sling by apache.
the class JsonPipe method configureHttpClient.
/**
* Configure http client
*/
private void configureHttpClient() {
HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
manager.setParams(params);
client = new HttpClient(manager);
client.getParams().setAuthenticationPreemptive(false);
}
Aggregations