Search in sources :

Example 1 with Service

use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.

the class ResourceDuplicateNodeSelector method getRandom.

/**
 * 概述:随机返回数据节点
 * @param storageId
 * @param nums
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
private DuplicateNode[] getRandom(int storageId, int nums) {
    List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (serviceList.isEmpty()) {
        LOG.info("[DUP] seviceList is empty");
        return new DuplicateNode[0];
    }
    List<DuplicateNode> nodes = new ArrayList<DuplicateNode>();
    while (!serviceList.isEmpty() && nodes.size() < nums) {
        Service service = serviceList.remove(rand.nextInt(serviceList.size()));
        DuplicateNode node = new DuplicateNode(service.getServiceGroup(), service.getServiceId());
        DiskNodeConnection conn = connectionPool.getConnection(node.getGroup(), node.getId());
        if (conn == null || conn.getClient() == null) {
            continue;
        }
        nodes.add(node);
    }
    DuplicateNode[] result = new DuplicateNode[nodes.size()];
    return nodes.toArray(result);
}
Also used : ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Service(com.bonree.brfs.common.service.Service) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)

Example 2 with Service

use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.

the class MultiRecover3 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();
                            Service service = serviceManager.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), fileRecover.getFirstServerID());
                            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;
                                }
                                // if (!diskClient.isExistFile(service.getHost(), service.getPort(), logicPath)) {
                                success = secureCopyTo(service, fileRecover.getFilePath(), 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 3 with Service

use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.

the class VirtualRecover3 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();
                        Service service = serviceManager.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), firstID);
                        while (true) {
                            // 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 4 with Service

use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.

the class DeleteStorageRegionMessageHandler method handleMessage.

@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
    StorageRegion region = storageRegionManager.findStorageRegionByName(msg.getName());
    if (region == null) {
        callback.completed(new HandleResult(false));
        return;
    }
    boolean deleted;
    HandleResult result = new HandleResult();
    try {
        List<Service> services = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
        if (region.isEnable()) {
            result.setSuccess(false);
            result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
            callback.completed(result);
            return;
        }
        ReturnCode code = TasksUtils.createUserDeleteTask(services, zkPaths, region, region.getCreateTime(), System.currentTimeMillis(), true);
        if (!ReturnCode.SUCCESS.equals(code)) {
            result.setSuccess(false);
            result.setData(BrStringUtils.toUtf8Bytes(code.name()));
        } else {
            deleted = storageRegionManager.removeStorageRegion(msg.getName());
            result.setSuccess(deleted);
            if (deleted) {
                LOG.info("clean all data for " + msg.getName());
            } else {
                result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
            }
        }
    } catch (StorageNameNonexistentException e) {
        result.setSuccess(false);
        result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_NONEXIST_ERROR.name()));
    } catch (Exception e) {
        result.setSuccess(false);
        result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
    }
    callback.completed(result);
}
Also used : ReturnCode(com.bonree.brfs.common.ReturnCode) Service(com.bonree.brfs.common.service.Service) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)

Example 5 with Service

use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.

the class DefaultServiceManager method updateService.

@Override
public void updateService(String group, String serviceId, String payload) throws Exception {
    LOG.info("update service payload for service[{}, {}, {}]", group, serviceId, payload);
    Service service = getServiceById(group, serviceId);
    if (service == null) {
        throw new Exception("No service{group=" + group + ", id=" + serviceId + "} is found!");
    }
    service.setPayload(payload);
    serviceDiscovery.updateService(buildFrom(service));
}
Also used : Service(com.bonree.brfs.common.service.Service) ExecutorService(java.util.concurrent.ExecutorService)

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