use of org.platformlayer.ops.helpers.CurlResult in project platformlayer by platformlayer.
the class SolrCoreHelpers method execute.
private CurlResult execute(String action) throws OpsException {
String url = "http://127.0.0.1:8080/solr/admin/cores?core=" + coreKey;
url += "&action=" + action;
CurlRequest request = new CurlRequest(url);
CurlResult result = request.executeRequest(target);
log.info("result: " + result);
return result;
}
use of org.platformlayer.ops.helpers.CurlResult in project platformlayer by platformlayer.
the class ShellBackupClient method uploadStream.
public void uploadStream(Backup request, Command dataSourceCommand) throws OpsException {
ObjectProperties openstackProperties = new ObjectProperties();
if (request.objectName == null) {
throw new IllegalArgumentException("objectName is required");
}
String objectPath = context.toPath(request.objectName);
openstackProperties.setName(objectPath);
for (Map.Entry<String, String> entry : request.objectProperties.entrySet()) {
String key = entry.getKey();
openstackProperties.getCustomProperties().put(key, entry.getValue());
}
log.info("Uploading to " + getContainerName() + "/" + objectPath);
RequestBuilder requestBuilder = getStorageClient(request.target).root().containers().id(getContainerName()).objects().buildPutRequest(openstackProperties);
CurlRequest curlRequest = ((RemoteCurlOpenstackRequest) requestBuilder).toCurlRequest();
curlRequest.bodyFromStdin = true;
Command curlCommand = curlRequest.toCommand();
Command pipedCommand = dataSourceCommand.pipeTo(curlCommand);
ProcessExecution execution = request.target.executeCommand(pipedCommand);
CurlResult curlResult = curlRequest.parseResponse(execution);
int httpResult = curlResult.getHttpResult();
switch(httpResult) {
case 200:
break;
case 201:
break;
default:
throw new OpsException("Unexpected result code while uploading backup: " + httpResult + " Result=" + curlResult);
}
}
use of org.platformlayer.ops.helpers.CurlResult in project platformlayer by platformlayer.
the class SolrCoreHelpers method getStatus.
public SolrCoreStatus getStatus() throws OpsException {
CurlResult result = execute("STATUS");
String xml = result.getBody();
boolean namespaceAware = false;
Document dom;
try {
dom = XmlHelper.parseXmlDocument(xml, namespaceAware);
} catch (ParserConfigurationException e) {
throw new OpsException("Error parsing XML output", e);
} catch (SAXException e) {
throw new OpsException("Error parsing XML output", e);
} catch (IOException e) {
throw new OpsException("Error parsing XML output", e);
}
return new SolrCoreStatus(dom);
}
use of org.platformlayer.ops.helpers.CurlResult in project platformlayer by platformlayer.
the class HttpProxyHelper method chooseProxy.
private String chooseProxy(OpsTarget target, List<String> proxies) {
String bestProxy = null;
TimeSpan bestTime = null;
for (String proxy : proxies) {
// {
// // We choose the fastest proxy that gives us a 200 response
// String url = proxy + "acng-report.html";
// CurlRequest request = new CurlRequest(url);
// request.setTimeout(5);
// try {
// CurlResult result = request.executeRequest(target);
// if (result.getHttpResult() != 200) {
// log.info("Unexpected response code while testing proxy: " + proxy + ". Code=" + result.getHttpResult());
// continue;
// }
// TimeSpan timeTotal = result.getTimeTotal();
// if (bestTime == null || timeTotal.isLessThan(bestTime)) {
// bestProxy = proxy;
// bestTime = timeTotal;
// }
// } catch (ProcessExecutionException e) {
// log.info("Error while testing proxy: " + proxy, e);
// }
// }
{
// We choose the fastest proxy that gives us a 200 response
String url = "http://ftp.debian.org/debian/dists/stable/Release.gpg";
CurlRequest request = new CurlRequest(url);
request.proxy = proxy;
request.timeout = TimeSpan.FIVE_SECONDS;
try {
CurlResult result = request.executeRequest(target);
if (result.getHttpResult() != 200) {
log.info("Unexpected response code while testing proxy: " + proxy + ". Code=" + result.getHttpResult());
continue;
}
TimeSpan timeTotal = result.getTimeTotal();
if (bestTime == null || timeTotal.isLessThan(bestTime)) {
bestProxy = proxy;
bestTime = timeTotal;
}
} catch (OpsException e) {
log.info("Error while testing proxy: " + proxy, e);
}
}
}
return bestProxy;
}
Aggregations