Search in sources :

Example 26 with Service

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

the class ResourceDuplicateNodeSelector method getResource.

private DuplicateNode[] getResource(int storageId, int nums, List<Pair<String, Integer>> servers) {
    List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (serviceList.isEmpty()) {
        LOG.error("[{}] resource select serviceList is empty !!!", Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
        return new DuplicateNode[0];
    }
    Map<String, Service> map = new HashMap<String, Service>();
    for (Service server : serviceList) {
        map.put(server.getServiceId(), server);
    }
    String group = serviceList.get(0).getServiceGroup();
    List<DuplicateNode> nodes = new ArrayList<DuplicateNode>();
    List<String> uNeeds = new ArrayList<String>();
    long start = System.currentTimeMillis();
    while (!serviceList.isEmpty() && nodes.size() < nums) {
        String serverId = WeightRandomPattern.getWeightRandom(servers, rand, uNeeds);
        Service service = null;
        if (BrStringUtils.isEmpty(serverId) && !serviceList.isEmpty()) {
            service = serviceList.remove(rand.nextInt(serviceList.size()));
        } else {
            uNeeds.add(serverId);
            service = map.get(serverId);
        }
        if (service == null) {
            continue;
        }
        DuplicateNode node = new DuplicateNode(service.getServiceGroup(), service.getServiceId());
        DiskNodeConnection conn = connectionPool.getConnection(node.getGroup(), node.getId());
        if (conn == null || conn.getClient() == null) {
            continue;
        }
        serviceList.remove(service);
        nodes.add(node);
    }
    DuplicateNode[] result = new DuplicateNode[nodes.size()];
    long end = System.currentTimeMillis();
    LOG.info("select time {} ms, select services :{}", (end - start), uNeeds);
    return nodes.toArray(result);
}
Also used : HashMap(java.util.HashMap) 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 27 with Service

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

the class MinimalDuplicateNodeSelector method getDuplicationNodes.

@Override
public DuplicateNode[] getDuplicationNodes(int storageId, int nums) {
    List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (serviceList.isEmpty()) {
        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 || !conn.getClient().ping()) {
            continue;
        }
        nodes.add(node);
    }
    DuplicateNode[] result = new DuplicateNode[nodes.size()];
    return nodes.toArray(result);
}
Also used : ArrayList(java.util.ArrayList) Service(com.bonree.brfs.common.service.Service) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)

Example 28 with Service

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

the class FileNodeDistributor method getServiceWithStorageRegionName.

// 获取可以接受属于特定数据库的文件的服务列表
private List<Service> getServiceWithStorageRegionName(String storageRegionName) {
    List<Service> result = new ArrayList<Service>();
    List<Service> activeServices = serviceManager.getServiceListByGroup(DUPLICATE_SERVICE_GROUP);
    for (Service s : activeServices) {
        try {
            List<String> storageRegionNodes = client.getChildren().forPath(ZkFileCoordinatorPaths.buildServiceSinkPath(s));
            if (storageRegionNodes.contains(storageRegionName)) {
                result.add(s);
            }
        } catch (NoNodeException e) {
            LOG.info("no sink node for service[{}], region[{}] error", s.getServiceId(), storageRegionName);
        } catch (Exception e) {
            LOG.error("get sink for service[{}], region[{}] error", s.getServiceId(), storageRegionName, e);
        }
    }
    return result;
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ExecutorService(java.util.concurrent.ExecutorService) Service(com.bonree.brfs.common.service.Service) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 29 with Service

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

the class FileNodeDistributor method handleFileNode.

private boolean handleFileNode(FileNode fileNode) {
    LOG.info("handling wild FileNode[{}]", JsonUtils.toJsonStringQuietly(fileNode));
    List<Service> serviceList = getServiceWithStorageRegionName(fileNode.getStorageName());
    Service target = serviceSelector.selectWith(fileNode, serviceList);
    if (target == null) {
        LOG.info("no service to accept filenode[{}], add it to wild list", fileNode.getName());
        return false;
    }
    LOG.info("transfer fileNode[{}] to service[{}]", fileNode.getName(), target.getServiceId());
    FileNode newFileNode = FileNode.newBuilder(fileNode).setServiceId(target.getServiceId()).setServiceTime(target.getRegisterTime()).build();
    try {
        fileStorer.update(newFileNode);
    } catch (Exception e) {
        LOG.error("update file node[{}] info error", fileNode.getName(), e);
        return false;
    }
    try {
        // 在Sink中放入分配的文件名
        String path = client.create().forPath(ZkFileCoordinatorPaths.buildSinkFileNodePath(newFileNode), JsonUtils.toJsonBytes(newFileNode));
        LOG.info("filenode[{}] add to sink[{}]", newFileNode.getName(), path);
        return true;
    } catch (Exception e) {
        LOG.error("add filenode[{}] to sink error", newFileNode.getName(), e);
        try {
            fileStorer.update(fileNode);
        } catch (Exception e1) {
            LOG.error("roll back to original info of filenode[{}] error", fileNode.getName(), e1);
        }
        return false;
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Service(com.bonree.brfs.common.service.Service) FileNode(com.bonree.brfs.duplication.filenode.FileNode) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 30 with Service

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

the class DeleteDataMessageHandler method handle.

@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    List<String> deleteInfo = Splitter.on("/").omitEmptyStrings().trimResults().splitToList(msg.getPath());
    if (deleteInfo.size() != 2) {
        result.setSuccess(false);
        result.setCause(new IllegalArgumentException(msg.getPath()));
        callback.completed(result);
        return;
    }
    int storageId = Integer.parseInt(deleteInfo.get(0));
    LOG.info("DELETE data for storage[{}]", storageId);
    StorageRegion sn = storageNameManager.findStorageRegionById(storageId);
    if (sn == null) {
        result.setSuccess(false);
        result.setCause(new StorageNameNonexistentException(storageId));
        callback.completed(result);
        LOG.info("storage[{}] is null", storageId);
        return;
    }
    List<String> times = Splitter.on("_").omitEmptyStrings().trimResults().splitToList(deleteInfo.get(1));
    ReturnCode code = checkTime(times.get(0), times.get(1), sn.getCreateTime(), Duration.parse(sn.getFilePartitionDuration()).toMillis());
    if (!ReturnCode.SUCCESS.equals(code)) {
        result.setSuccess(false);
        result.setData(BrStringUtils.toUtf8Bytes(code.name()));
        callback.completed(result);
        LOG.info("DELETE DATE Fail storage[{}] reason : {}", storageId, code.name());
        return;
    }
    long startTime = DateTime.parse(times.get(0)).getMillis();
    long endTime = DateTime.parse(times.get(1)).getMillis();
    LOG.info("DELETE DATA [{}-->{}]", times.get(0), times.get(1));
    List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    code = TasksUtils.createUserDeleteTask(serviceList, zkPaths, sn, startTime, endTime, false);
    result.setSuccess(ReturnCode.SUCCESS.equals(code));
    result.setData(BrStringUtils.toUtf8Bytes(code.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)

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