Search in sources :

Example 1 with CurlResult

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;
}
Also used : CurlResult(org.platformlayer.ops.helpers.CurlResult) CurlRequest(org.platformlayer.ops.helpers.CurlRequest)

Example 2 with CurlResult

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);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) RequestBuilder(org.openstack.client.common.RequestBuilder) CurlRequest(org.platformlayer.ops.helpers.CurlRequest) RemoteCurlOpenstackRequest(org.platformlayer.service.cloud.openstack.ops.RemoteCurlOpenstackSession.RemoteCurlOpenstackRequest) ObjectProperties(org.openstack.model.storage.ObjectProperties) CurlResult(org.platformlayer.ops.helpers.CurlResult) Command(org.platformlayer.ops.Command) ProcessExecution(org.platformlayer.ops.process.ProcessExecution) Map(java.util.Map)

Example 3 with 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);
}
Also used : CurlResult(org.platformlayer.ops.helpers.CurlResult) OpsException(org.platformlayer.ops.OpsException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 4 with CurlResult

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;
}
Also used : TimeSpan(com.fathomdb.TimeSpan) CurlResult(org.platformlayer.ops.helpers.CurlResult) OpsException(org.platformlayer.ops.OpsException) CurlRequest(org.platformlayer.ops.helpers.CurlRequest)

Aggregations

CurlResult (org.platformlayer.ops.helpers.CurlResult)4 OpsException (org.platformlayer.ops.OpsException)3 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)3 TimeSpan (com.fathomdb.TimeSpan)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 RequestBuilder (org.openstack.client.common.RequestBuilder)1 ObjectProperties (org.openstack.model.storage.ObjectProperties)1 Command (org.platformlayer.ops.Command)1 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)1 RemoteCurlOpenstackRequest (org.platformlayer.service.cloud.openstack.ops.RemoteCurlOpenstackSession.RemoteCurlOpenstackRequest)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1