use of com.bonree.brfs.disknode.boot.DataNodeBootStrap 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);
}
}
Aggregations