Search in sources :

Example 31 with Service

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;
}
Also used : Service(com.bonree.brfs.common.service.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)

Example 32 with Service

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;
}
Also used : BaseResponse(com.bonree.brfs.common.net.tcp.BaseResponse) BaseMessage(com.bonree.brfs.common.net.tcp.BaseMessage) TcpClientConfig(com.bonree.brfs.common.net.tcp.client.TcpClientConfig) InetSocketAddress(java.net.InetSocketAddress) Service(com.bonree.brfs.common.service.Service) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 33 with Service

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;
}
Also used : ArrayList(java.util.ArrayList) Service(com.bonree.brfs.common.service.Service)

Example 34 with Service

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();
            }
        }
    };
}
Also used : Service(com.bonree.brfs.common.service.Service)

Example 35 with Service

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();
            }
        }
    };
}
Also used : Service(com.bonree.brfs.common.service.Service)

Aggregations

Service (com.bonree.brfs.common.service.Service)35 IOException (java.io.IOException)10 ExecutorService (java.util.concurrent.ExecutorService)8 BRFSException (com.bonree.brfs.common.exception.BRFSException)7 HttpResponse (com.bonree.brfs.common.net.http.client.HttpResponse)6 URIBuilder (com.bonree.brfs.common.net.http.client.URIBuilder)6 ServiceManager (com.bonree.brfs.common.service.ServiceManager)4 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 ReturnCode (com.bonree.brfs.common.ReturnCode)3 HandleResult (com.bonree.brfs.common.net.http.HandleResult)3 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)3 DiskNodeClient (com.bonree.brfs.disknode.client.DiskNodeClient)3 DiskNodeConnection (com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)3 DuplicateNode (com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)3 SimpleAuthentication (com.bonree.brfs.authentication.SimpleAuthentication)2 UserModel (com.bonree.brfs.authentication.model.UserModel)2 ZookeeperPaths (com.bonree.brfs.common.ZookeeperPaths)2 FileObjectSyncState (com.bonree.brfs.common.filesync.FileObjectSyncState)2