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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations