use of com.bonree.brfs.common.net.http.client.HttpResponse 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.net.http.client.HttpResponse 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.net.http.client.HttpResponse in project BRFS by zhangnianli.
the class HttpDiskNodeClient method getFileLength.
@Override
public long getFileLength(String path) {
URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_LENGTH_NODE_ROOT + path).build();
try {
LOG.info("get length from file[{}] to {}:{}", path, host, port);
HttpResponse response = client.executeGet(uri);
LOG.debug("get length from file[{}] response[{}]", path, response.getStatusCode());
if (response.isReponseOK()) {
return Longs.fromByteArray(response.getResponseBody());
}
} catch (Exception e) {
LOG.error("get sequences of file[{}] at {}:{} error", path, host, port, e);
}
return -1;
}
use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.
the class HttpDiskNodeClient method readData.
@Override
public void readData(String path, long offset, int size, ByteConsumer consumer) throws IOException {
URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_DISK_NODE_ROOT + path).addParameter("offset", String.valueOf(offset)).addParameter("size", String.valueOf(size)).build();
try {
LOG.info("read file[{}] with offset[{}], size[{}] to {}:{}", path, offset, size, host, port);
HttpResponse response = client.executeGet(uri);
LOG.debug("read file[{}] response[{}]", path, response.getStatusCode());
if (response.isReponseOK()) {
consumer.consume(response.getResponseBody(), true);
}
} catch (Exception e) {
LOG.error("read file[{}] with[offset={},size={}] at {}:{} error", path, offset, size, host, port, e);
}
}
use of com.bonree.brfs.common.net.http.client.HttpResponse in project BRFS by zhangnianli.
the class HttpDiskNodeClient method closeFile.
@Override
public long closeFile(String path) {
URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_DISK_NODE_ROOT + path).build();
try {
LOG.info("close file[{}] to {}:{}", path, host, port);
HttpResponse response = client.executeClose(uri);
LOG.debug("close file[{}] response[{}]", path, response.getStatusCode());
if (response.isReponseOK()) {
return Longs.fromByteArray(response.getResponseBody());
}
} catch (Exception e) {
LOG.error("close file[{}] at {}:{} error", path, host, port, e);
}
return -1;
}
Aggregations