Search in sources :

Example 26 with StorageRegion

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

the class WatchDogJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.debug("watch dog do it >>>>>>>>>>>>>>");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String zkHosts = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
    String baseRoutPath = data.getString(JobDataMapConstract.BASE_ROUTE_PATH);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    if (BrStringUtils.isEmpty(dataPath) || BrStringUtils.isEmpty(baseRoutPath) || BrStringUtils.isEmpty(zkHosts)) {
        LOG.warn("config is empty !! skip watchdog");
        return;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> sns = snm.getStorageRegionList();
    long preTime = System.currentTimeMillis();
    LOG.info("Scan {} below data !!!", TimeUtils.formatTimeStamp(preTime));
    WatchDog.searchPreys(sim, sns, zkHosts, baseRoutPath, dataPath, preTime);
}
Also used : JobDataMap(org.quartz.JobDataMap) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 27 with StorageRegion

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

the class GatherResourceJob method getStorageNameIdWithName.

/**
 * 概述:获取storageName关系
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
private Map<Integer, String> getStorageNameIdWithName() {
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> sns = snm.getStorageRegionList();
    Map<Integer, String> snToId = new ConcurrentHashMap<>();
    if (sns == null || sns.isEmpty()) {
        return snToId;
    }
    int id;
    String name;
    for (StorageRegion sn : sns) {
        if (sn == null) {
            continue;
        }
        name = sn.getName();
        if (BrStringUtils.isEmpty(name)) {
            continue;
        }
        id = sn.getId();
        if (snToId.containsKey(id)) {
            continue;
        }
        snToId.put(id, name);
    }
    return snToId;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 28 with StorageRegion

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

the class ServerChangeTaskGenetor method genChangeSummary.

private void genChangeSummary(Service service, ChangeType type) {
    String firstID = service.getServiceId();
    List<StorageRegion> snList = snManager.getStorageRegionList();
    List<String> currentServers = getCurrentServers(serverManager);
    LOG.info("fetch all storageRegion:" + snList);
    for (StorageRegion snModel : snList) {
        if (snModel.getReplicateNum() > 1) {
            // TODO 此处需要判断是否配置了sn恢复
            String secondID = idManager.getOtherSecondID(firstID, snModel.getId());
            if (!StringUtils.isEmpty(secondID)) {
                try {
                    ChangeSummary tsm = new ChangeSummary(snModel.getId(), genChangeID(), type, secondID, currentServers);
                    String jsonStr = JsonUtils.toJsonString(tsm);
                    String snTaskNode = ZKPaths.makePath(changesPath, String.valueOf(snModel.getId()), tsm.getChangeID());
                    client.createPersistent(snTaskNode, true, jsonStr.getBytes(StandardCharsets.UTF_8));
                    LOG.info("generator a change record:" + jsonStr + ", for storageRegion:" + snModel);
                    if (ChangeType.REMOVE == type) {
                        EmailPool emailPool = EmailPool.getInstance();
                        emailPool.sendEmail(MailWorker.newBuilder(emailPool.getProgramInfo()).setMessage(jsonStr));
                    }
                } catch (Exception e) {
                    LOG.error("generator a change record failed for storageRegion:" + snModel, e);
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : EmailPool(com.bonree.brfs.email.EmailPool) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 29 with StorageRegion

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

the class OpenStorageRegionMessageHandler method handleMessage.

@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
    LOG.info("open storage region[{}]", msg.getName());
    StorageRegion node = storageRegionManager.findStorageRegionByName(msg.getName());
    if (node == null || !node.isEnable()) {
        callback.completed(new HandleResult(false));
        return;
    }
    HandleResult result = new HandleResult();
    result.setSuccess(true);
    result.setData(Ints.toByteArray(node.getId()));
    callback.completed(result);
}
Also used : HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 30 with StorageRegion

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

the class UpdateStorageRegionMessageHandler method handleMessage.

@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
    LOG.info("update storage region[{}] with attrs {}", msg.getName(), msg.getAttributes());
    StorageRegion region = storageRegionManager.findStorageRegionByName(msg.getName());
    if (region == null) {
        callback.completed(new HandleResult(false));
        return;
    }
    try {
        StorageRegionConfig config = new StorageRegionConfig(region);
        config.update(msg.getAttributes());
        storageRegionManager.updateStorageRegion(msg.getName(), config);
        callback.completed(new HandleResult(true));
    } catch (Exception e) {
        LOG.error("remove nonexist storage region");
        callback.completed(new HandleResult(false));
    }
}
Also used : StorageRegionConfig(com.bonree.brfs.duplication.storageregion.StorageRegionConfig) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Aggregations

StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)30 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)8 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HandleResult (com.bonree.brfs.common.net.http.HandleResult)5 Service (com.bonree.brfs.common.service.Service)5 ServiceManager (com.bonree.brfs.common.service.ServiceManager)5 Pair (com.bonree.brfs.common.utils.Pair)4 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)4 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashedMap (org.apache.commons.collections.map.HashedMap)4 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)3 StorageNameNonexistentException (com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)3 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)3 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)3 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)3 IOException (java.io.IOException)3 JobDataMap (org.quartz.JobDataMap)3