Search in sources :

Example 1 with StorageRegionManager

use of com.bonree.brfs.duplication.storageregion.StorageRegionManager in project BRFS by zhangnianli.

the class ServerMain method main.

public static void main(String[] args) {
    ProcessFinalizer finalizer = new ProcessFinalizer();
    try {
        ResourceTaskConfig resourceConfig = ResourceTaskConfig.parse();
        // 初始化email发送配置
        EmailPool.getInstance();
        String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
        CuratorClient leaderClient = CuratorClient.getClientInstance(zkAddresses, 1000, 1000);
        CuratorClient client = CuratorClient.getClientInstance(zkAddresses);
        CuratorCacheFactory.init(zkAddresses);
        ZookeeperPaths zookeeperPaths = ZookeeperPaths.create(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_CLUSTER_NAME), zkAddresses);
        SimpleAuthentication authentication = SimpleAuthentication.getAuthInstance(zookeeperPaths.getBaseUserPath(), zookeeperPaths.getBaseLocksPath(), client.getInnerClient());
        UserModel model = authentication.getUser("root");
        if (model == null) {
            LOG.error("please init server!!!");
            System.exit(1);
        }
        ServerIDManager idManager = new ServerIDManager(client.getInnerClient(), zookeeperPaths);
        idManager.getFirstServerID();
        StorageRegionManager snManager = new DefaultStorageRegionManager(client.getInnerClient().usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), null);
        snManager.addStorageRegionStateListener(new StorageRegionStateListener() {

            @Override
            public void storageRegionAdded(StorageRegion node) {
                LOG.info("-----------StorageNameAdded--[{}]", node);
                idManager.getSecondServerID(node.getId());
            }

            @Override
            public void storageRegionUpdated(StorageRegion node) {
            }

            @Override
            public void storageRegionRemoved(StorageRegion node) {
                LOG.info("-----------StorageNameRemove--[{}]", node);
                idManager.deleteSecondServerID(node.getId());
            }
        });
        snManager.start();
        finalizer.add(snManager);
        ServiceManager sm = new DefaultServiceManager(client.getInnerClient().usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
        sm.start();
        finalizer.add(sm);
        // 磁盘管理模块
        // EmptyMain diskMain = new EmptyMain(sm);
        // diskMain.start();
        // 
        // finalizer.add(diskMain);
        DataNodeBootStrap dataNodeBootStrap = new DataNodeBootStrap(sm);
        dataNodeBootStrap.start();
        finalizer.add(dataNodeBootStrap);
        // 副本平衡模块
        sm.addServiceStateListener(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), new ServerChangeTaskGenetor(leaderClient, client, sm, idManager, zookeeperPaths.getBaseRebalancePath(), 3000, snManager));
        @SuppressWarnings("resource") RebalanceManager rebalanceServer = new RebalanceManager(zookeeperPaths, idManager, snManager, sm);
        rebalanceServer.start();
        String host = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST);
        int port = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_PORT);
        int readPort = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_PORT);
        Service selfService = new Service();
        selfService.setHost(host);
        selfService.setPort(port);
        selfService.setExtraPort(readPort);
        selfService.setServiceGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
        String serviceId = idManager.getFirstServerID();
        selfService.setServiceId(serviceId);
        Service checkService = sm.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), serviceId);
        if (checkService == null) {
            sm.registerService(selfService);
            System.out.println(selfService);
        } else {
            LOG.error("serviceId : {} is exists, system will exit!!!", serviceId);
            System.exit(1);
        }
        finalizer.add(new Closeable() {

            @Override
            public void close() throws IOException {
                try {
                    sm.unregisterService(selfService);
                } catch (Exception e) {
                    LOG.error("unregister service[{}] error", selfService, e);
                }
            }
        });
        // 资源管理模块
        InitTaskManager.initManager(resourceConfig, zookeeperPaths, sm, snManager, idManager, client);
    } catch (Exception e) {
        LOG.error("launch server error!!!", e);
        System.exit(1);
    } finally {
        Runtime.getRuntime().addShutdownHook(finalizer);
    }
}
Also used : Closeable(java.io.Closeable) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Service(com.bonree.brfs.common.service.Service) RebalanceManager(com.bonree.brfs.rebalance.RebalanceManager) IOException(java.io.IOException) ResourceTaskConfig(com.bonree.brfs.configuration.ResourceTaskConfig) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException) UserModel(com.bonree.brfs.authentication.model.UserModel) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) DataNodeBootStrap(com.bonree.brfs.disknode.boot.DataNodeBootStrap) ZookeeperPaths(com.bonree.brfs.common.ZookeeperPaths) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) ServiceManager(com.bonree.brfs.common.service.ServiceManager) ServerChangeTaskGenetor(com.bonree.brfs.rebalance.task.ServerChangeTaskGenetor) SimpleAuthentication(com.bonree.brfs.authentication.SimpleAuthentication) ProcessFinalizer(com.bonree.brfs.common.process.ProcessFinalizer) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) StorageRegionStateListener(com.bonree.brfs.duplication.storageregion.StorageRegionStateListener)

Example 2 with StorageRegionManager

use of com.bonree.brfs.duplication.storageregion.StorageRegionManager in project BRFS by zhangnianli.

the class GatherResourceJob method calcStateServer.

/**
 * 概述:计算队列的状态信息
 * @param inverTime
 * @param dataDir
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
private StatServerModel calcStateServer(long inverTime, String dataDir, int count) {
    StatServerModel sum = null;
    // 0.计算原始状态信息
    List<StatServerModel> lists = GatherResource.calcState(queue, count);
    if (lists == null || lists.isEmpty()) {
        LOG.warn("server state list is null !!");
        return sum;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    // 1-1初始化storagename管理器
    StorageRegionManager snManager = mcf.getSnm();
    // 2.获取storage信息
    List<StorageRegion> storageNames = snManager.getStorageRegionList();
    List<String> storagenameList = getStorageNames(storageNames);
    // 3.计算状态值
    sum = GatherResource.calcStatServerModel(lists, storagenameList, inverTime, dataDir);
    return sum;
}
Also used : ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 3 with StorageRegionManager

use of com.bonree.brfs.duplication.storageregion.StorageRegionManager in project BRFS by zhangnianli.

the class CopyCheckJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.info("createCheck Copy Job working");
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    StorageRegionManager snm = mcf.getSnm();
    ServiceManager sm = mcf.getSm();
    List<String> srs = TaskStateLifeContral.getSRs(snm);
    TaskStateLifeContral.watchSR(release, srs, TaskType.SYSTEM_COPY_CHECK.name());
    // 判断是否有恢复任务,有恢复任务则不进行创建
    if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
        LOG.warn("rebalance task is running !! skip check copy task");
        return;
    }
    String taskType = TaskType.SYSTEM_COPY_CHECK.name();
    List<Service> services = sm.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (services == null || services.isEmpty()) {
        LOG.warn("skip create {} task, because service is empty", taskType);
        return;
    }
    List<StorageRegion> snList = snm.getStorageRegionList();
    if (snList == null || snList.isEmpty()) {
        LOG.warn("storagename list is null");
        return;
    }
    // 1.获取sn创建任务的实际那
    TaskTypeModel tmodel = release.getTaskTypeInfo(taskType);
    if (tmodel == null) {
        tmodel = new TaskTypeModel();
        tmodel.setSwitchFlag(true);
        release.setTaskTypeModel(taskType, tmodel);
    }
    Map<String, Long> sourceTimes = tmodel.getSnTimes();
    LOG.debug("update init sn time :{}", sourceTimes);
    // 2.过滤不符合副本校验的sn信息
    List<StorageRegion> needSns = CopyCountCheck.filterSn(snList, services.size());
    // 3.针对第一次出现的sn补充时间
    sourceTimes = CopyCountCheck.repairTime(sourceTimes, needSns);
    Map<String, List<String>> losers = CopyCountCheck.collectLossFile(needSns, services, sourceTimes);
    LOG.info("update before sn time :{}", sourceTimes);
    Pair<TaskModel, Map<String, Long>> pair = CreateSystemTask.creatTaskWithFiles(sourceTimes, losers, needSns, TaskType.SYSTEM_COPY_CHECK, RECOVERY_NUM, 0);
    if (pair == null) {
        LOG.warn("create pair is empty !!!!");
        return;
    }
    TaskModel task = pair.getFirst();
    String taskName = null;
    if (task != null) {
        List<String> servers = CreateSystemTask.getServerIds(services);
        taskName = CreateSystemTask.updateTask(release, task, servers, TaskType.SYSTEM_COPY_CHECK);
    }
    if (!BrStringUtils.isEmpty(taskName)) {
        LOG.info("create {} {} task successfull !!!", taskType, taskName);
    }
    sourceTimes = pair.getSecond();
    // 更新sn临界信息
    tmodel = release.getTaskTypeInfo(taskType);
    if (tmodel == null) {
        tmodel = new TaskTypeModel();
        tmodel.setSwitchFlag(true);
        LOG.warn("taskType {} metadata loss create against !!", taskType);
    }
    tmodel.putAllSnTimes(sourceTimes);
    release.setTaskTypeModel(taskType, tmodel);
    LOG.debug("update sn time {}", sourceTimes);
    createTransferTasks(release);
}
Also used : Service(com.bonree.brfs.common.service.Service) TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) List(java.util.List) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) Map(java.util.Map) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Example 4 with StorageRegionManager

use of com.bonree.brfs.duplication.storageregion.StorageRegionManager in project BRFS by zhangnianli.

the class CheckCycleJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.info("cycle check job work !!!");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    int day = data.getInt(JobDataMapConstract.CHECK_TIME_RANGE);
    if (day <= 0) {
        LOG.warn("skip cycle job!! because check time range is 0");
        return;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    StorageRegionManager snm = mcf.getSnm();
    ServiceManager sm = mcf.getSm();
    if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
        LOG.warn("rebalance task is running !! skip check copy task ,wait next time to check");
        return;
    }
    List services = sm.getServiceListByGroup(mcf.getGroupName());
    if ((services == null) || (services.isEmpty())) {
        LOG.warn("SKIP create {} task, because service is empty", TaskType.SYSTEM_COPY_CHECK);
        return;
    }
    List<StorageRegion> snList = snm.getStorageRegionList();
    if ((snList == null) || (snList.isEmpty())) {
        LOG.warn("SKIP storagename list is null");
        return;
    }
    long currentTime = System.currentTimeMillis();
    long lGraDay = currentTime - currentTime % 86400000L;
    long sGraDay = lGraDay - day * 86400000L;
    List<StorageRegion> needSns = CopyCountCheck.filterSn(snList, services.size());
    if (needSns == null || needSns.isEmpty()) {
        LOG.warn("no storagename need check copy count ! ");
        return;
    }
    Map<String, List<Long>> snTimes = collectionTimes(needSns, sGraDay, lGraDay);
    if (snTimes == null || snTimes.isEmpty()) {
        LOG.warn("{} - {} time, no data to check copy count", TimeUtils.formatTimeStamp(sGraDay), TimeUtils.formatTimeStamp(lGraDay));
        return;
    }
    List<Map<String, Long>> tTimes = converTimes(snTimes);
    for (Map<String, Long> sourceTimes : tTimes) {
        if (sourceTimes == null || sourceTimes.isEmpty()) {
            continue;
        }
        createSingleTask(release, needSns, services, TaskType.SYSTEM_COPY_CHECK, sourceTimes);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) ArrayList(java.util.ArrayList) List(java.util.List) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) HashMap(java.util.HashMap) Map(java.util.Map) JobDataMap(org.quartz.JobDataMap) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager)

Example 5 with StorageRegionManager

use of com.bonree.brfs.duplication.storageregion.StorageRegionManager in project BRFS by zhangnianli.

the class CreateSystemTaskJob method operation.

@Override
public void operation(JobExecutionContext context) {
    LOG.info("create system task working");
    // 判断是否有恢复任务,有恢复任务则不进行创建
    JobDataMap data = context.getJobDetail().getJobDataMap();
    long checkTtl = data.getLong(JobDataMapConstract.CHECK_TTL);
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    // 获取开启的任务名称
    List<TaskType> switchList = mcf.getTaskOn();
    if (switchList == null || switchList.isEmpty()) {
        LOG.warn("switch on task is empty !!!");
        return;
    }
    // 获取可用服务
    String groupName = mcf.getGroupName();
    ServiceManager sm = mcf.getSm();
    // 2.设置可用服务
    List<String> serverIds = CreateSystemTask.getServerIds(sm, groupName);
    if (serverIds == null || serverIds.isEmpty()) {
        LOG.warn("{} available server list is null", groupName);
        return;
    }
    // 3.获取storageName
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> snList = snm.getStorageRegionList();
    if (snList == null || snList.isEmpty()) {
        LOG.info("skip create system task !!! because storageName is null !!!");
        return;
    }
    TaskModel task;
    String taskName;
    TaskTypeModel tmodel;
    long ttl = 0;
    Pair<TaskModel, TaskTypeModel> result;
    List<String> srs = TaskStateLifeContral.getSRs(snm);
    for (TaskType taskType : switchList) {
        if (TaskType.SYSTEM_COPY_CHECK.equals(taskType) || TaskType.USER_DELETE.equals(taskType)) {
            continue;
        }
        TaskStateLifeContral.watchSR(release, srs, taskType.name());
        if (TaskType.SYSTEM_DELETE.equals(taskType)) {
            ttl = 0;
        } else if (TaskType.SYSTEM_CHECK.equals(taskType)) {
            ttl = checkTtl;
        }
        tmodel = release.getTaskTypeInfo(taskType.name());
        if (tmodel == null) {
            tmodel = new TaskTypeModel();
            tmodel.setSwitchFlag(true);
            LOG.warn("taskType{} is switch but metadata is null");
        }
        result = CreateSystemTask.createSystemTask(tmodel, taskType, snList, ttl);
        if (result == null) {
            LOG.warn("create sys task is empty {}", taskType.name());
            continue;
        }
        task = result.getFirst();
        taskName = CreateSystemTask.updateTask(release, task, serverIds, taskType);
        if (!BrStringUtils.isEmpty(taskName)) {
            LOG.info("create {} {} task successfull !!!", taskType.name(), taskName);
            release.setTaskTypeModel(taskType.name(), tmodel);
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) TaskType(com.bonree.brfs.common.task.TaskType) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Aggregations

StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)9 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)8 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)7 ServiceManager (com.bonree.brfs.common.service.ServiceManager)6 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)4 Service (com.bonree.brfs.common.service.Service)3 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)3 JobDataMap (org.quartz.JobDataMap)3 SimpleAuthentication (com.bonree.brfs.authentication.SimpleAuthentication)2 UserModel (com.bonree.brfs.authentication.model.UserModel)2 ZookeeperPaths (com.bonree.brfs.common.ZookeeperPaths)2 ProcessFinalizer (com.bonree.brfs.common.process.ProcessFinalizer)2 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)2 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)2 HttpConfig (com.bonree.brfs.common.net.http.HttpConfig)1 HttpAuthenticator (com.bonree.brfs.common.net.http.netty.HttpAuthenticator)1 NettyHttpRequestHandler (com.bonree.brfs.common.net.http.netty.NettyHttpRequestHandler)1 NettyHttpServer (com.bonree.brfs.common.net.http.netty.NettyHttpServer)1 AsyncTcpClientGroup (com.bonree.brfs.common.net.tcp.client.AsyncTcpClientGroup)1 TaskType (com.bonree.brfs.common.task.TaskType)1