Search in sources :

Example 1 with StorageNameStick

use of com.bonree.brfs.client.StorageNameStick in project BRFS by zhangnianli.

the class DefaultBRFileSystem method openStorageName.

@Override
public StorageNameStick openStorageName(String storageName) {
    StorageNameStick stick = null;
    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.executeGet(uri, defaultHeaders);
            } catch (Exception e) {
                LOG.warn("openStorageName http request failed", e);
                continue;
            }
            if (response == null) {
                throw new Exception("can not get response for deleteStorageName!");
            }
            if (response.isReponseOK()) {
                int storageId = Ints.fromByteArray(response.getResponseBody());
                stick = new DefaultStorageNameStick(storageName, storageId, httpClient, serviceSelectorManager.useDiskSelector(storageId), regionNodeSelector, config);
                return stick;
            }
        }
    } catch (Exception e) {
        LOG.error("openStorageName error", e);
    }
    return stick;
}
Also used : StorageNameStick(com.bonree.brfs.client.StorageNameStick) 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

StorageNameStick (com.bonree.brfs.client.StorageNameStick)1 BRFSException (com.bonree.brfs.common.exception.BRFSException)1 HttpResponse (com.bonree.brfs.common.net.http.client.HttpResponse)1 URIBuilder (com.bonree.brfs.common.net.http.client.URIBuilder)1 Service (com.bonree.brfs.common.service.Service)1 IOException (java.io.IOException)1 URI (java.net.URI)1