/** * Make the job instances node * @param appName the app name * @param jobClass the job class * @return return true if make successfully, or false */ public Boolean mkJobInstances(String appName, String jobClass) { return zk.client().mkdirs(ZkPaths.pathOfJobInstances(appName, jobClass)); }
/** * Update the job fire time info * @param appName the app name * @param jobClass the job class * @param jobFireTime the job fire time * @return return true if update successfully, or false */ public Boolean updateJobFireTime(String appName, String jobClass, JobFireTime jobFireTime) { String jobFireTimeNode = ZkPaths.pathOfJobFireTime(appName, jobClass); zk.client().mkdirs(jobFireTimeNode); return zk.client().update(jobFireTimeNode, JSON.toJSONString(jobFireTime)); }
public AppClientCluster(AntaresZkClient zk, String appName){ this.appName = appName; this.zk = zk; // get alive clients once String appClientsPath = ZkPaths.pathOfAppClients(appName); zk.client().mkdirs(appClientsPath); List<String> clients = zk.client().gets(appClientsPath); if (!CollectionUtil.isNullOrEmpty(clients)){ alives.addAll(clients); } }
/** * Update the job's scheudler * @param appName the app name * @param jobClass the job class * @param scheduler the scheduler * @return return true if update successfully, or false */ public Boolean updateJobScheduler(String appName, String jobClass, String scheduler) { String jobSchedulerNode = ZkPaths.pathOfJobScheduler(appName, jobClass); zk.client().mkdirs(jobSchedulerNode); return zk.client().update(jobSchedulerNode, scheduler); }
@Override public void doStart() { String jobInstancesLockPath = Lock.PREFIX + ZkPaths.JOB_INSTANCES; zk.client().mkdirs(jobInstancesLockPath); emptyChildCleaner = new ChildReaper(zk.client().client(), jobInstancesLockPath, Reaper.Mode.REAP_INDEFINITELY); try { String serversFailover = Lock.PREFIX + ZkPaths.SERVER_FAILOVER; zk.client().mkdirs(serversFailover); emptyChildCleaner.addPath(serversFailover); emptyChildCleaner.start(); } catch (Exception e) { throw new ZkException(e); } }
/** * Update the job running state directly * @param appName the app name * @param jobClass the job class * @param state the target state * @return return true if update successfully, or false */ public Boolean updateJobStateDirectly(String appName, String jobClass, JobState state){ String jobStateNode = ZkPaths.pathOfJobState(appName, jobClass); zk.client().mkdirs(jobStateNode); return zk.client().update(jobStateNode, state.value()); }
@Override public void doStart(){ // mk app clients path zk.mkdirs(ZkPaths.pathOfAppClients(client.getAppName())); // register client self clientRegister = new ClientRegister(client); clientRegister.start(); // get servers once getServersOnce(); // listen servers listenOnServerChanged(); }
@Override public Response<List<ClientInfo>> listClients(Long appId) { try { App app = appDao.findById(appId); if (app == null){ Logs.warn("The app(id={}) doesn't exist when list clients", appId); return Response.ok(Collections.<ClientInfo>emptyList()); } String appClientsPath = ZkPaths.pathOfAppClients(app.getAppName()); zk.client().mkdirs(appClientsPath); List<String> clients = zk.client().gets(appClientsPath); if(CollectionUtil.isNullOrEmpty(clients)){ return Response.ok(Collections.<ClientInfo>emptyList()); } List<ClientInfo> clientInfos = Lists.newArrayListWithExpectedSize(clients.size()); ClientInfo clientInfo; for (String client : clients){ clientInfo = new ClientInfo(); clientInfo.setAddr(client); clientInfos.add(clientInfo); } return Response.ok(clientInfos); } catch (Exception e){ Logs.error("failed to list clients, cause: {}", Throwables.getStackTraceAsString(e)); return Response.notOk("client.list.failed"); } }
@Override public void run() { String server = serverHost.get(); // mkdirs /cluster/servers if necessary zk.client().mkdirs(ZkPaths.SERVERS); // register the server node String serverPath = ZkPaths.pathOfServer(server); if (!zk.client().checkExists(serverPath)){ String result = zk.client().createEphemeral(ZkPaths.pathOfServer(server)); Logs.info("server({}) registered: {}", server, result); } } }, 1, 5, TimeUnit.SECONDS);