Search in sources :

Example 1 with HttpResponse

use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.

the class HttpDiskNodeClient method recover.

@Override
public boolean recover(String path, long fileLength, List<String> fullSates) {
    URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_RECOVER_NODE_ROOT + path).addParameter("length", String.valueOf(fileLength)).addParameter("fulls", Joiner.on(',').join(fullSates)).build();
    try {
        LOG.info("recover file[{}] response[{}] to {}:{}", path, host, port);
        HttpResponse response = client.executePost(uri);
        LOG.debug("recover file[{}] response[{}]", path, response.getStatusCode());
        return response.isReponseOK();
    } catch (Exception e) {
        LOG.error("recover file[{}] at {}:{} error", path, host, port, e);
    }
    return false;
}
Also used : HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) URI(java.net.URI) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 2 with HttpResponse

use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.

the class HttpDiskNodeClient method flush.

@Override
public boolean flush(String path) {
    URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_FLUSH_NODE_ROOT + path).build();
    try {
        LOG.info("flush file[{}] to {}:{}", path, host, port);
        HttpResponse response = client.executePost(uri);
        LOG.debug("flush file[{}] response[{}]", path, response.getStatusCode());
        return response.isReponseOK();
    } catch (Exception e) {
        LOG.error("write file[{}] to {}:{} error", path, host, port, e);
    }
    return false;
}
Also used : HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) URI(java.net.URI) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 3 with HttpResponse

use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.

the class HttpDiskNodeClient method openFile.

@Override
public long openFile(String path, long capacity) {
    URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_DISK_NODE_ROOT + path).addParameter("capacity", String.valueOf(capacity)).build();
    try {
        LOG.info("open file[{}] @ {}:{}", path, host, port);
        HttpResponse response = client.executePut(uri);
        LOG.debug("open file[{}] response[{}]", path, response.getStatusCode());
        if (response != null && response.isReponseOK()) {
            return Longs.fromByteArray(response.getResponseBody());
        }
    } catch (Exception e) {
        LOG.error("open file[{}] at {}:{} error", path, host, port, e);
    }
    return -1l;
}
Also used : HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) URI(java.net.URI) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 4 with HttpResponse

use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.

the class HttpDiskNodeClient method deleteFile.

@Override
public boolean deleteFile(String path, boolean force) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_DISK_NODE_ROOT + path);
    if (force) {
        builder.addParameter("force");
    }
    try {
        LOG.info("delete file[{}] force[{}] to {}:{}", path, force, host, port);
        HttpResponse response = client.executeDelete(builder.build());
        LOG.debug("delete file[{}] response[{}]", path, response.getStatusCode());
        return response.isReponseOK();
    } catch (Exception e) {
        LOG.error("delete file[{}] at {}:{} error", path, host, port, e);
    }
    return false;
}
Also used : HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 5 with HttpResponse

use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.

the class DefaultBRFileSystem method deleteStorageName.

@Override
public boolean deleteStorageName(String storageName) {
    try {
        Service[] serviceList = regionNodeSelector.select(regionNodeSelector.serviceNum());
        if (serviceList.length == 0) {
            throw new BRFSException("none disknode!!!");
        }
        for (Service service : serviceList) {
            URI uri = new URIBuilder().setScheme(config.getUrlSchema()).setHost(service.getHost()).setPort(service.getPort()).setPath(config.getStorageUrlRoot() + "/" + storageName).build();
            HttpResponse response = null;
            try {
                response = httpClient.executeDelete(uri, defaultHeaders);
            } catch (Exception e) {
                LOG.warn("deleteStorageName http request failed", e);
                continue;
            }
            if (response == null) {
                throw new Exception("can not get response for deleteStorageName!");
            }
            if (response.isReponseOK()) {
                return true;
            }
        }
    } catch (Exception e) {
        LOG.error("deleteStorageName error", e);
    }
    return false;
}
Also used : Service(com.bonree.brfs.common.service.Service) HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) BRFSException(com.bonree.brfs.common.exception.BRFSException) URI(java.net.URI) BRFSException(com.bonree.brfs.common.exception.BRFSException) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Aggregations

HttpResponse (com.bonree.brfs.common.net.http.client.HttpResponse)15 URIBuilder (com.bonree.brfs.common.net.http.client.URIBuilder)15 IOException (java.io.IOException)15 URI (java.net.URI)11 BRFSException (com.bonree.brfs.common.exception.BRFSException)6 Service (com.bonree.brfs.common.service.Service)6 StorageNameStick (com.bonree.brfs.client.StorageNameStick)1 ReturnCode (com.bonree.brfs.common.ReturnCode)1 DataItem (com.bonree.brfs.common.write.data.DataItem)1 WriteDataMessage (com.bonree.brfs.common.write.data.WriteDataMessage)1 WriteData (com.bonree.brfs.disknode.server.handler.data.WriteData)1 WriteDataList (com.bonree.brfs.disknode.server.handler.data.WriteDataList)1 HashMap (java.util.HashMap)1