use of com.bonree.brfs.resourceschedule.model.LimitServerResource in project BRFS by zhangnianli.
the class MachineResourceWriterSelectorTest method testFiler01.
@Test
public void testFiler01() {
String groupName = "a";
int centSize = 100;
LimitServerResource limit = new LimitServerResource();
limit.setForceWriteValue(0.9);
limit.setForceDiskRemainRate(0.01);
limit.setDiskWriteValue(0.8);
limit.setDiskRemainRate(0.05);
limit.setRemainForceSize(20000000);
limit.setRemainWarnSize(20000000);
MachineResourceWriterSelector selector = new MachineResourceWriterSelector(null, null, limit, groupName, 5, centSize);
int num = 1;
List<ResourceModel> list = new ArrayList<>();
List<Pair<String, Integer>> numList = new ArrayList<>();
ResourceModel obj;
String mount = "tmp";
Map<String, Double> remainRateMap = new HashMap<>();
remainRateMap.put("tmp", 0.04);
Map<String, Double> writValue = new HashMap<>();
writValue.put("tmp", 0.999);
String sn = "sn";
Map<String, String> snMap = new HashMap<>();
snMap.put(sn, mount);
for (int i = 0; i < num; i++) {
obj = new ResourceModel();
obj.setHost("192.168.3." + i);
obj.setDiskSize(20000000L);
obj.setServerId(String.valueOf(i));
obj.setLocalDiskRemainRate(remainRateMap);
obj.setDiskWriteValue(writValue);
obj.setStorageNameOnPartitionMap(snMap);
list.add(obj);
numList.add(new Pair<>(String.valueOf(i), 100));
}
Collection<ResourceModel> wins = selector.filterService(list, sn);
show(wins);
}
use of com.bonree.brfs.resourceschedule.model.LimitServerResource in project BRFS by zhangnianli.
the class InitTaskManager method initManager.
/**
* 概述:初始化任务服务系统
* @throws ParamsErrorException
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void initManager(ResourceTaskConfig managerConfig, ZookeeperPaths zkPath, ServiceManager sm, StorageRegionManager snm, ServerIDManager sim, CuratorClient client) throws Exception {
managerConfig.printDetail();
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
String serverId = sim.getFirstServerID();
mcf.setServerId(serverId);
mcf.setGroupName(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
double diskRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_AVAILABLE_RATE);
double diskForceRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_AVAILABLE_RATE);
double diskwriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_WRITE_SPEED);
double diskForcewriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_WRITE_SPEED);
long diskRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_REMAIN_SIZE);
long diskForceRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_REMAIN_SIZE);
LimitServerResource lmit = new LimitServerResource();
lmit.setDiskRemainRate(diskRemainRate);
lmit.setDiskWriteValue(diskwriteValue);
lmit.setForceDiskRemainRate(diskForceRemainRate);
lmit.setForceWriteValue(diskForcewriteValue);
lmit.setRemainWarnSize(diskRemainSize);
lmit.setRemainForceSize(diskForceRemainSize);
mcf.setLimitServerResource(lmit);
// 工厂类添加服务管理
mcf.setSm(sm);
// 工厂类添加storageName管理服务
mcf.setSnm(snm);
// 1.工厂类添加调度管理
SchedulerManagerInterface manager = DefaultSchedulersManager.getInstance();
mcf.setStm(manager);
// 工厂类添加发布接口
MetaTaskManagerInterface release = DefaultReleaseTask.getInstance();
if (release == null) {
LOG.error("Meta task is empty");
System.exit(1);
}
String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
release.setPropreties(zkAddresses, zkPath.getBaseTaskPath(), zkPath.getBaseLocksPath());
if (client == null) {
LOG.error("zk client is empty");
System.exit(1);
}
mcf.setClient(client);
mcf.setTm(release);
// 工厂类添加任务可执行接口
RunnableTaskInterface run = DefaultRunnableTask.getInstance();
TaskExecutablePattern limit = TaskExecutablePattern.parse(managerConfig);
run.setLimitParameter(limit);
mcf.setRt(run);
mcf.setZkPath(zkPath);
mcf.setSim(sim);
// 创建任务线程池
if (managerConfig.isTaskFrameWorkSwitch()) {
// 1.创建任务管理服务
createMetaTaskManager(manager, zkPath, managerConfig, serverId);
// 2.启动任务线程池
List<TaskType> tasks = managerConfig.getSwitchOnTaskType();
if (tasks == null || tasks.isEmpty()) {
LOG.warn("switch task on but task type list is empty !!!");
return;
}
createAndStartThreadPool(manager, managerConfig);
if (tasks.contains(TaskType.SYSTEM_COPY_CHECK)) {
SumbitTaskInterface copyJob = createCopySimpleTask(managerConfig.getExecuteTaskIntervalTime(), TaskType.SYSTEM_COPY_CHECK.name(), serverId, CopyRecoveryJob.class.getCanonicalName(), zkAddresses, zkPath.getBaseRoutePath(), Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_DATA_ROOT));
manager.addTask(TaskType.SYSTEM_COPY_CHECK.name(), copyJob);
}
mcf.setTaskOn(tasks);
// 3.创建执行任务线程池
createOperationPool(managerConfig, zkPath, tasks, true);
}
if (managerConfig.isResourceFrameWorkSwitch()) {
// 创建资源调度服务
createResourceManager(manager, zkPath, managerConfig);
}
}
use of com.bonree.brfs.resourceschedule.model.LimitServerResource in project BRFS by zhangnianli.
the class BootStrap method main.
public static void main(String[] args) {
ProcessFinalizer finalizer = new ProcessFinalizer();
try {
// 初始化email发送配置
EmailPool.getInstance();
String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
String host = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_HOST);
int port = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_PORT);
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zkAddresses, 3000, 15000, retryPolicy);
client.start();
client.blockUntilConnected();
finalizer.add(client);
CuratorCacheFactory.init(zkAddresses);
String clusterName = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_CLUSTER_NAME);
ZookeeperPaths zookeeperPaths = ZookeeperPaths.create(clusterName, zkAddresses);
ServerIDManager idManager = new ServerIDManager(client, zookeeperPaths);
SimpleAuthentication simpleAuthentication = SimpleAuthentication.getAuthInstance(zookeeperPaths.getBaseUserPath(), zookeeperPaths.getBaseLocksPath(), client);
UserModel model = simpleAuthentication.getUser("root");
if (model == null) {
LOG.error("please init server!!!");
System.exit(1);
}
Service service = new Service(UUID.randomUUID().toString(), Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_REGION_SERVICE_GROUP_NAME), host, port);
ServiceManager serviceManager = new DefaultServiceManager(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
serviceManager.start();
finalizer.add(serviceManager);
TimeExchangeEventEmitter timeEventEmitter = new TimeExchangeEventEmitter(2);
finalizer.add(timeEventEmitter);
StorageRegionIdBuilder storageIdBuilder = new ZkStorageRegionIdBuilder(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
StorageRegionManager storageNameManager = new DefaultStorageRegionManager(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), storageIdBuilder);
storageNameManager.start();
finalizer.add(storageNameManager);
// HttpDiskNodeConnectionPool connectionPool = new HttpDiskNodeConnectionPool(serviceManager);
// finalizer.add(connectionPool);
AsyncTcpClientGroup tcpClientGroup = new AsyncTcpClientGroup(Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_WRITER_WORKER_NUM));
TcpDiskNodeConnectionPool connectionPool = new TcpDiskNodeConnectionPool(serviceManager, tcpClientGroup);
finalizer.add(tcpClientGroup);
FilePathMaker pathMaker = new IDFilePathMaker(idManager);
int workerThreadNum = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_SERVER_IO_THREAD_NUM);
HttpConfig httpConfig = HttpConfig.newBuilder().setHost(host).setPort(port).setAcceptWorkerNum(1).setRequestHandleWorkerNum(workerThreadNum).setBacklog(Integer.parseInt(System.getProperty(SystemProperties.PROP_NET_BACKLOG, "2048"))).build();
NettyHttpServer httpServer = new NettyHttpServer(httpConfig);
httpServer.addHttpAuthenticator(new HttpAuthenticator() {
@Override
public int check(String userName, String passwd) {
StringBuilder tokenBuilder = new StringBuilder();
tokenBuilder.append(userName).append(":").append(passwd);
return simpleAuthentication.auth(tokenBuilder.toString()) ? 0 : ReturnCode.USER_FORBID.getCode();
}
});
ExecutorService requestHandlerExecutor = Executors.newFixedThreadPool(Math.max(4, Runtime.getRuntime().availableProcessors() / 4), new PooledThreadFactory("request_handler"));
finalizer.add(new Closeable() {
@Override
public void close() throws IOException {
requestHandlerExecutor.shutdown();
}
});
FileObjectSyncProcessor processor = new DefaultFileObjectSyncProcessor(connectionPool, pathMaker);
DefaultFileObjectSynchronier fileSynchronizer = new DefaultFileObjectSynchronier(processor, serviceManager, 10, TimeUnit.SECONDS);
fileSynchronizer.start();
finalizer.add(fileSynchronizer);
FileNodeStorer storer = new ZkFileNodeStorer(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), ZkFileCoordinatorPaths.COORDINATOR_FILESTORE);
// 资源缓存器
String diskGroup = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME);
String rPath = zookeeperPaths.getBaseResourcesPath() + "/" + diskGroup + "/resource";
ClusterResource clusterResource = ClusterResource.newBuilder().setCache(true).setClient(client).setListenPath(rPath).setPool(Executors.newSingleThreadExecutor()).build().start();
// 资源选择策略
// 获取限制值
double diskRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_AVAILABLE_RATE);
double diskForceRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_AVAILABLE_RATE);
double diskwriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_WRITE_SPEED);
double diskForcewriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_WRITE_SPEED);
long diskRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_REMAIN_SIZE);
long diskForceRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_REMAIN_SIZE);
LimitServerResource lmit = new LimitServerResource();
lmit.setDiskRemainRate(diskRemainRate);
lmit.setDiskWriteValue(diskwriteValue);
lmit.setForceDiskRemainRate(diskForceRemainRate);
lmit.setForceWriteValue(diskForcewriteValue);
lmit.setRemainWarnSize(diskRemainSize);
lmit.setRemainForceSize(diskForceRemainSize);
int centSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_RESOURCE_CENT_SIZE);
long fileSize = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_MAX_CAPACITY) / 1024;
MachineResourceWriterSelector serviceSelector = new MachineResourceWriterSelector(connectionPool, storer, lmit, diskGroup, fileSize, centSize);
// 生成备用选择器
DuplicateNodeSelector bakSelect = new MinimalDuplicateNodeSelector(serviceManager, connectionPool);
// 选择
DuplicateNodeSelector nodeSelector = ResourceWriteSelector.newBuilder().setBakSelector(bakSelect).setDaemon(clusterResource).setGroupName(diskGroup).setStorageRegionManager(storageNameManager).setResourceSelector(serviceSelector).build();
FileObjectFactory fileFactory = new DefaultFileObjectFactory(service, storer, nodeSelector, idManager, connectionPool);
int closerThreadNum = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_CLOSER_THREAD_NUM);
DefaultFileObjectCloser fileCloser = new DefaultFileObjectCloser(closerThreadNum, fileSynchronizer, storer, connectionPool, pathMaker);
finalizer.add(fileCloser);
FileNodeSinkManager sinkManager = new ZkFileNodeSinkManager(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), service, serviceManager, timeEventEmitter, storer, new RandomFileNodeSinkSelector(), fileCloser);
sinkManager.start();
finalizer.add(sinkManager);
DataPoolFactory dataPoolFactory = new BlockingQueueDataPoolFactory(Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_DATA_POOL_CAPACITY));
FileObjectSupplierFactory fileSupplierFactory = new DefaultFileObjectSupplierFactory(fileFactory, fileCloser, fileSynchronizer, sinkManager, timeEventEmitter);
DiskWriter diskWriter = new DiskWriter(Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_WRITER_WORKER_NUM), connectionPool, pathMaker);
finalizer.add(diskWriter);
DataEngineFactory engineFactory = new DefaultDataEngineFactory(dataPoolFactory, fileSupplierFactory, diskWriter);
DefaultDataEngineManager engineManager = new DefaultDataEngineManager(storageNameManager, engineFactory);
finalizer.add(engineManager);
DefaultStorageRegionWriter writer = new DefaultStorageRegionWriter(engineManager);
NettyHttpRequestHandler requestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
requestHandler.addMessageHandler("POST", new WriteDataMessageHandler(writer));
requestHandler.addMessageHandler("GET", new ReadDataMessageHandler());
requestHandler.addMessageHandler("DELETE", new DeleteDataMessageHandler(zookeeperPaths, serviceManager, storageNameManager));
httpServer.addContextHandler(URI_DATA_ROOT, requestHandler);
NettyHttpRequestHandler snRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
snRequestHandler.addMessageHandler("PUT", new CreateStorageRegionMessageHandler(storageNameManager));
snRequestHandler.addMessageHandler("POST", new UpdateStorageRegionMessageHandler(storageNameManager));
snRequestHandler.addMessageHandler("GET", new OpenStorageRegionMessageHandler(storageNameManager));
snRequestHandler.addMessageHandler("DELETE", new DeleteStorageRegionMessageHandler(zookeeperPaths, storageNameManager, serviceManager));
httpServer.addContextHandler(URI_STORAGE_REGION_ROOT, snRequestHandler);
httpServer.start();
finalizer.add(httpServer);
serviceManager.registerService(service);
finalizer.add(new Closeable() {
@Override
public void close() throws IOException {
try {
serviceManager.unregisterService(service);
} catch (Exception e) {
LOG.error("unregister service[{}] error", service, e);
}
}
});
} catch (Exception e) {
LOG.error("launch server error!!!", e);
System.exit(1);
} finally {
Runtime.getRuntime().addShutdownHook(finalizer);
}
}
Aggregations