use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class HttpDiskNodeConnectionPool method getConnection.
@Override
public DiskNodeConnection getConnection(String serviceGroup, String serviceId) {
HttpDiskNodeConnection connection = connectionCache.get(serviceGroup, serviceId);
if (connection != null) {
return connection;
}
synchronized (connectionCache) {
Service service = serviceManager.getServiceById(serviceGroup, serviceId);
if (service == null) {
return null;
}
connection = new HttpDiskNodeConnection(service.getHost(), service.getPort());
connection.connect();
connectionCache.put(serviceGroup, serviceId, connection);
}
return connection;
}
use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class TcpDiskNodeConnectionPool method getConnection.
@Override
public DiskNodeConnection getConnection(String serviceGroup, String serviceId) {
TcpDiskNodeConnection connection = connectionCache.get(serviceGroup, serviceId);
if (connection != null) {
if (connection.isValid()) {
return connection;
}
synchronized (connectionCache) {
connectionCache.remove(serviceGroup, serviceId);
}
}
try {
synchronized (connectionCache) {
Service service = serviceManager.getServiceById(serviceGroup, serviceId);
if (service == null) {
return null;
}
TcpClient<BaseMessage, BaseResponse> client = tcpClientGroup.createClient(new TcpClientConfig() {
@Override
public SocketAddress remoteAddress() {
return new InetSocketAddress(service.getHost(), service.getPort());
}
@Override
public int connectTimeoutMillis() {
return 3000;
}
}, executor);
if (client == null) {
return null;
}
connection = new TcpDiskNodeConnection(client);
connectionCache.put(serviceGroup, serviceId, connection);
}
return connection;
} catch (Exception e) {
LOG.error("connect tcp connection to disk node error", e);
}
return null;
}
use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class ManagerMetaTaskJob method getServerIds.
/**
* 概述:获取存活的serverid
* @param sm
* @param groupName
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private List<String> getServerIds(ServiceManager sm, String groupName) {
List<String> sids = new ArrayList<>();
List<Service> sList = sm.getServiceListByGroup(groupName);
if (sList == null || sList.isEmpty()) {
return sids;
}
String sid = null;
for (Service server : sList) {
sid = server.getServiceId();
if (BrStringUtils.isEmpty(sid)) {
continue;
}
sids.add(sid);
}
return sids;
}
use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class VirtualRecover method consumerQueue.
private Runnable consumerQueue() {
return new Runnable() {
@Override
public void run() {
try {
FileRecoverMeta fileRecover = null;
while (fileRecover != null || !overFlag) {
if (status.get().equals(TaskStatus.CANCEL)) {
break;
}
fileRecover = fileRecoverQueue.poll(100, TimeUnit.MILLISECONDS);
if (fileRecover != null) {
String logicPath = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getReplica() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String remoteDir = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getPot() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String localFilePath = dataDir + FileUtils.FILE_SEPARATOR + logicPath + FileUtils.FILE_SEPARATOR + fileRecover.getFileName();
boolean success = false;
LOG.info("transfer :" + fileRecover);
String firstID = fileRecover.getFirstServerID();
while (true) {
Service service = serviceManager.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), firstID);
if (service == null) {
LOG.warn("first id is {},maybe down!", firstID);
Thread.sleep(1000);
continue;
}
// if (!diskClient.isExistFile(service.getHost(), service.getPort(), logicPath)) {
success = sucureCopyTo(service, localFilePath, remoteDir, fileRecover.getFileName());
// }
if (success) {
break;
}
}
currentCount += 1;
detail.setCurentCount(currentCount);
detail.setProcess(detail.getCurentCount() / (double) detail.getTotalDirectories());
updateDetail(selfNode, detail);
if (success) {
// BalanceRecord record = new BalanceRecord(fileRecover.getFileName(), idManager.getSecondServerID(balanceSummary.getStorageIndex()), fileRecover.getFirstServerID());
// fileRecover.getSimpleWriter().writeRecord(record.toString());
}
LOG.info("update:" + selfNode + "-------------" + detail);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}
use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class MultiRecover method consumerQueue.
private Runnable consumerQueue() {
return new Runnable() {
@Override
public void run() {
try {
FileRecoverMeta fileRecover = null;
while (fileRecover != null || !overFlag) {
if (status.get().equals(TaskStatus.CANCEL)) {
break;
} else if (status.get().equals(TaskStatus.PAUSE)) {
LOG.info("task pause!!!");
Thread.sleep(1000);
} else if (status.get().equals(TaskStatus.RUNNING)) {
fileRecover = fileRecoverQueue.poll(1, TimeUnit.SECONDS);
if (fileRecover != null) {
String localDir = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getReplica() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String remoteDir = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getPot() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String localFilePath = dataDir + FileUtils.FILE_SEPARATOR + localDir + FileUtils.FILE_SEPARATOR + fileRecover.getFileName();
boolean success = false;
while (true) {
if (status.get().equals(TaskStatus.PAUSE)) {
LOG.info("task pause!!!");
Thread.sleep(1000);
continue;
}
if (status.get().equals(TaskStatus.CANCEL)) {
break;
}
Service service = serviceManager.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), fileRecover.getFirstServerID());
if (service == null) {
LOG.warn("first id is {},maybe down!", fileRecover.getFirstServerID());
Thread.sleep(1000);
continue;
}
// if (!diskClient.isExistFile(service.getHost(), service.getPort(), logicPath)) {
success = secureCopyTo(service, localFilePath, remoteDir, fileRecover.getFileName());
// }
if (success) {
break;
}
}
currentCount += 1;
detail.setCurentCount(currentCount);
detail.setProcess(detail.getCurentCount() / (double) detail.getTotalDirectories());
updateDetail(selfNode, detail);
if (success) {
// BalanceRecord record = new BalanceRecord(fileRecover.getFileName(), idManager.getSecondServerID(balanceSummary.getStorageIndex()),
// fileRecover.getFirstServerID());
// fileRecover.getSimpleWriter().writeRecord(record.toString());
}
LOG.info("update:" + selfNode + "-------------" + detail);
}
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}
Aggregations