Search in sources :

Example 1 with BRFSException

use of com.bonree.brfs.common.exception.BRFSException 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)

Example 2 with BRFSException

use of com.bonree.brfs.common.exception.BRFSException in project BRFS by zhangnianli.

the class DefaultBRFileSystem method updateStorageName.

@Override
public boolean updateStorageName(String storageName, Map<String, Object> attrs) {
    try {
        Service[] serviceList = regionNodeSelector.select(regionNodeSelector.serviceNum());
        if (serviceList.length == 0) {
            throw new BRFSException("none disknode!!!");
        }
        for (Service service : serviceList) {
            URIBuilder uriBuilder = new URIBuilder().setScheme(config.getUrlSchema()).setHost(service.getHost()).setPort(service.getPort()).setPath(config.getStorageUrlRoot() + "/" + storageName);
            for (Entry<String, Object> attr : attrs.entrySet()) {
                uriBuilder.addParameter(attr.getKey(), String.valueOf(attr.getValue()));
            }
            HttpResponse response = null;
            try {
                Map<String, String> headers = new HashMap<String, String>();
                headers.put("username", config.getName());
                headers.put("password", config.getPasswd());
                response = httpClient.executePost(uriBuilder.build(), headers);
            } catch (Exception e) {
                LOG.warn("updateStorageName http request failed", e);
                continue;
            }
            if (response == null) {
                throw new Exception("can not get response for updateStorageName!");
            }
            if (response.isReponseOK()) {
                return true;
            }
        }
    } catch (Exception e) {
        LOG.error("updateStorageName error", e);
    }
    return false;
}
Also used : HashMap(java.util.HashMap) Service(com.bonree.brfs.common.service.Service) HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) BRFSException(com.bonree.brfs.common.exception.BRFSException) BRFSException(com.bonree.brfs.common.exception.BRFSException) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 3 with BRFSException

use of com.bonree.brfs.common.exception.BRFSException in project BRFS by zhangnianli.

the class DefaultStorageNameStick method deleteData.

@Override
public boolean deleteData(DateTime startTime, DateTime endTime) {
    try {
        Service[] serviceList = regionNodeSelector.select(regionNodeSelector.serviceNum());
        if (serviceList.length == 0) {
            throw new BRFSException("none disknode!!!");
        }
        for (Service service : serviceList) {
            StringBuilder pathBuilder = new StringBuilder();
            pathBuilder.append(config.getDuplicateUrlRoot()).append("/").append(storageId).append("/").append(startTime.toString()).append("_").append(endTime.toString());
            URI uri = new URIBuilder().setScheme(config.getUrlSchema()).setHost(service.getHost()).setPort(service.getPort()).setPath(pathBuilder.toString()).build();
            HttpResponse response = null;
            try {
                response = client.executeDelete(uri, defaultHeaders);
            } catch (Exception e) {
                LOG.warn("delete data http request failed", e);
                continue;
            }
            if (response == null) {
                throw new Exception("can not get response for createStorageName!");
            }
            if (response.isReponseOK()) {
                return true;
            }
            String code = new String(response.getResponseBody(), StandardCharsets.UTF_8);
            ReturnCode returnCode = ReturnCode.checkCode(storageName, code);
            LOG.info("returnCode:" + returnCode);
        }
    } catch (Exception e) {
        LOG.error("delete data error", e);
    }
    return false;
}
Also used : ReturnCode(com.bonree.brfs.common.ReturnCode) 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)

Example 4 with BRFSException

use of com.bonree.brfs.common.exception.BRFSException in project BRFS by zhangnianli.

the class DefaultBRFileSystem method createStorageName.

@Override
public boolean createStorageName(String storageName, Map<String, Object> attrs) {
    try {
        Service[] serviceList = regionNodeSelector.select(regionNodeSelector.serviceNum());
        if (serviceList.length == 0) {
            throw new BRFSException("none disknode!!!");
        }
        for (Service service : serviceList) {
            URIBuilder uriBuilder = new URIBuilder().setScheme(config.getUrlSchema()).setHost(service.getHost()).setPort(service.getPort()).setPath(config.getStorageUrlRoot() + "/" + storageName);
            for (Entry<String, Object> attr : attrs.entrySet()) {
                uriBuilder.addParameter(attr.getKey(), String.valueOf(attr.getValue()));
            }
            HttpResponse response = null;
            try {
                response = httpClient.executePut(uriBuilder.build(), defaultHeaders);
            } catch (Exception e) {
                LOG.warn("createStorageName http request failed", e);
                continue;
            }
            if (response == null) {
                throw new Exception("can not get response for createStorageName!");
            }
            if (response.isReponseOK()) {
                return true;
            }
        }
    } catch (Exception e) {
        LOG.error("createStorageName 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) BRFSException(com.bonree.brfs.common.exception.BRFSException) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 5 with BRFSException

use of com.bonree.brfs.common.exception.BRFSException 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

BRFSException (com.bonree.brfs.common.exception.BRFSException)6 HttpResponse (com.bonree.brfs.common.net.http.client.HttpResponse)6 URIBuilder (com.bonree.brfs.common.net.http.client.URIBuilder)6 Service (com.bonree.brfs.common.service.Service)6 IOException (java.io.IOException)6 URI (java.net.URI)4 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 HashMap (java.util.HashMap)1