コード例 #1
0
		public NodeWatcher(DisconfCoreProcessor disconfCoreMgr, string monitorPath, string keyName, DisConfigTypeEnum disConfigTypeEnum, DisconfSysUpdateCallback disconfSysUpdateCallback, bool debug) : base()
		{

			this.debug = debug;
			this.disconfCoreMgr = disconfCoreMgr;
			this.monitorPath = monitorPath;
			this.keyName = keyName;
			this.disConfigTypeEnum = disConfigTypeEnum;
			this.disconfSysUpdateCallback = disconfSysUpdateCallback;
		}
コード例 #2
0
		/// <summary>
		/// 通知某个Node更新
		/// </summary>
		/// <param name="app"> </param>
		/// <param name="env"> </param>
		/// <param name="version"> </param>
		/// <param name="disConfigTypeEnum"> </param>
		public virtual void notifyNodeUpdate(string app, string env, string version, string key, string value, DisConfigTypeEnum disConfigTypeEnum)
		{

			//
			// 获取路径
			//
			string baseUrlString = ZooPathMgr.getZooBaseUrl(zooConfig.ZookeeperUrlPrefix, app, env, version);

			string path = "";
			if (disConfigTypeEnum.Equals(DisConfigTypeEnum.ITEM))
			{

				path = ZooPathMgr.getItemZooPath(baseUrlString);
			}
			else
			{
				path = ZooPathMgr.getFileZooPath(baseUrlString);
			}

			try
			{

				path = ZooPathMgr.joinPath(path, key);

				bool isExist = ZookeeperMgr.Instance.exists(path);
				if (!isExist)
				{

					LOG.info(path + " not exist. not update ZK.");

				}
				else
				{
					//
					// 通知
					//
					ZookeeperMgr.Instance.writePersistentUrl(path, value);
				}

			}
			catch (Exception e)
			{

				LOG.error(e.ToString(), e);
				throw new RemoteException("zk.notify.error", e);
			}
		}
コード例 #3
0
		/// <summary>
		/// 对于一个 get/is 方法,返回其相对应的Field
		/// </summary>
		public static Field getFieldFromMethod(Method method, Field[] expectedFields, DisConfigTypeEnum disConfigTypeEnum)
		{

			string fieldName;

			if (disConfigTypeEnum.Equals(DisConfigTypeEnum.FILE))
			{

				DisconfFileItem disconfFileItem = method.getAnnotation(typeof(DisconfFileItem));
				// 根据用户设定的注解来获取
				fieldName = disconfFileItem.associateField();

			}
			else
			{

				DisconfItem disItem = method.getAnnotation(typeof(DisconfItem));
				// 根据用户设定的注解来获取
				fieldName = disItem.associateField();
			}

			//
			// 如果用户未设定注解,则猜其名字
			//
			if (StringUtils.isEmpty(fieldName))
			{
				// 从方法名 获取其 Field 名
				fieldName = ClassUtils.getFieldNameByGetMethodName(method.Name);
			}

			// 确认此Field名是正确的
			foreach (Field field in expectedFields)
			{

				if (field.Name.Equals(fieldName))
				{
					return field;
				}
			}

			LOGGER.error(method.ToString() + " cannot get its related field name. ");

			return null;
		}
コード例 #4
0
		/// <summary>
		/// 新建监控
		/// </summary>
		/// <exception cref="Exception"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private String makeMonitorPath(com.baidu.disconf.core.common.constants.DisConfigTypeEnum disConfigTypeEnum, com.baidu.disconf.client.common.model.DisConfCommonModel disConfCommonModel, String key, String value) throws Exception
		private string makeMonitorPath(DisConfigTypeEnum disConfigTypeEnum, DisConfCommonModel disConfCommonModel, string key, string value)
		{

			// 应用根目录
			/*
			    应用程序的 Zoo 根目录
			*/
			string clientRootZooPath = ZooPathMgr.getZooBaseUrl(zooUrlPrefix, disConfCommonModel.App, disConfCommonModel.Env, disConfCommonModel.Version);
			ZookeeperMgr.Instance.makeDir(clientRootZooPath, ZooUtils.Ip);

			// 监控路径
			string monitorPath;
			if (disConfigTypeEnum.Equals(DisConfigTypeEnum.FILE))
			{

				// 新建Zoo Store目录
				string clientDisconfFileZooPath = ZooPathMgr.getFileZooPath(clientRootZooPath);
				makePath(clientDisconfFileZooPath, ZooUtils.Ip);

				monitorPath = ZooPathMgr.joinPath(clientDisconfFileZooPath, key);

			}
			else
			{

				// 新建Zoo Store目录
				string clientDisconfItemZooPath = ZooPathMgr.getItemZooPath(clientRootZooPath);
				makePath(clientDisconfItemZooPath, ZooUtils.Ip);
				monitorPath = ZooPathMgr.joinPath(clientDisconfItemZooPath, key);
			}

			// 先新建路径
			makePath(monitorPath, "");

			// 新建一个代表自己的临时结点
			makeTempChildPath(monitorPath, value);

			return monitorPath;
		}
コード例 #5
0
		/// <summary>
		/// 获取 配置项 或者 是配置ITEM 的远程URL
		/// 
		/// @return
		/// </summary>
		public static string getRemoteUrlParameter(string urlPrefix, string app, string version, string env, string key, DisConfigTypeEnum disConfigTypeEnum)
		{

			IDictionary<string, string> parameterMap = getConfServerBasePathMap(app, version, env, key);

			// 配置文件或配置项
			parameterMap[Constants.TYPE] = disConfigTypeEnum.Type.ToString();

			StringBuilder sb = new StringBuilder();
			sb.Append(urlPrefix);

			if (disConfigTypeEnum.Type == DisConfigTypeEnum.FILE.Type)
			{
				sb.Append(Constants.SEP_STRING + Constants.STORE_FILE_URL_KEY);
			}
			else
			{
				sb.Append(Constants.SEP_STRING + Constants.STORE_ITEM_URL_KEY);
			}

			sb.Append("?");
			foreach (string thisKey in parameterMap.Keys)
			{

				string cur = thisKey + "=" + parameterMap[thisKey];
				cur += "&";
				sb.Append(cur);
			}

			if (sb.Length > 0)
			{
				sb.Remove(sb.Length - 1, 1);
			}

			return sb.ToString();
		}
コード例 #6
0
		public virtual ZkDisconfData getZkDisconfData(string app, string env, string version, DisConfigTypeEnum disConfigTypeEnum, string keyName)
		{

			return zooKeeperDriver.getDisconfData(app, env, version, disConfigTypeEnum, keyName);
		}
コード例 #7
0
		/// <summary>
		/// 校验新建 配置
		/// </summary>
		/// <param name="confNewForm"> </param>
		/// <param name="disConfigTypeEnum"> </param>
		public virtual void validateNew(ConfNewItemForm confNewForm, DisConfigTypeEnum disConfigTypeEnum)
		{

			//
			// app
			//
			App app = appMgr.getById(confNewForm.AppId);
			if (app == null)
			{
				throw new FieldException(ConfNewForm.APPID, "app.not.exist", null);
			}

			//
			validateAppAuth(app.Id);

			//
			// env
			//
			Env env = envMgr.getById(confNewForm.EnvId);
			if (env == null)
			{
				throw new FieldException(ConfNewForm.ENVID, "env.not.exist", null);
			}

			//
			// key
			//
			Config config = configFetchMgr.getConfByParameter(app.Id, env.Id, confNewForm.Version, confNewForm.Key, disConfigTypeEnum);
			if (config != null)
			{
				throw new FieldException(ConfNewItemForm.KEY, "key.exist", null);
			}

		}
コード例 #8
0
		/// <summary>
		/// 获取分布式配置 Map
		/// </summary>
		/// <param name="app"> </param>
		/// <param name="env"> </param>
		/// <param name="version">
		/// 
		/// @return </param>
		public virtual ZkDisconfData getDisconfData(string app, string env, string version, DisConfigTypeEnum disConfigTypeEnum, string keyName)
		{

			string baseUrl = ZooPathMgr.getZooBaseUrl(zooConfig.ZookeeperUrlPrefix, app, env, version);

			try
			{

				ZookeeperMgr zooKeeperMgr = ZookeeperMgr.Instance;
				ZooKeeper zooKeeper = zooKeeperMgr.Zk;

				if (disConfigTypeEnum.Equals(DisConfigTypeEnum.FILE))
				{

					return getDisconfData(ZooPathMgr.getFileZooPath(baseUrl), keyName, zooKeeper);

				}
				else if (disConfigTypeEnum.Equals(DisConfigTypeEnum.ITEM))
				{

					return getDisconfData(ZooPathMgr.getItemZooPath(baseUrl), keyName, zooKeeper);
				}

			}
			catch (KeeperException e)
			{
				LOG.error(e.Message, e);
			}
			catch (InterruptedException e)
			{
				LOG.error(e.Message, e);
			}

			return null;
		}
コード例 #9
0
		public virtual ZkDisconfData getDisconfData(string app, string env, string version, DisConfigTypeEnum disConfigTypeEnum, string keyName)
		{
			return null;
		}
コード例 #10
0
		public virtual void notifyNodeUpdate(string app, string env, string version, string key, string value, DisConfigTypeEnum disConfigTypeEnum)
		{

		}
コード例 #11
0
		/// <summary>
		/// 监控路径,监控前会事先创建路径,并且会新建一个自己的Temp子结点
		/// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void watchPath(com.baidu.disconf.client.core.processor.DisconfCoreProcessor disconfCoreMgr, com.baidu.disconf.client.common.model.DisConfCommonModel disConfCommonModel, String keyName, com.baidu.disconf.core.common.constants.DisConfigTypeEnum disConfigTypeEnum, String value) throws Exception
		public virtual void watchPath(DisconfCoreProcessor disconfCoreMgr, DisConfCommonModel disConfCommonModel, string keyName, DisConfigTypeEnum disConfigTypeEnum, string value)
		{

			// 新建
			string monitorPath = makeMonitorPath(disConfigTypeEnum, disConfCommonModel, keyName, value);

			// 进行监控
			NodeWatcher nodeWatcher = new NodeWatcher(disconfCoreMgr, monitorPath, keyName, disConfigTypeEnum, new DisconfSysUpdateCallback(), debug);
			nodeWatcher.monitorMaster();
		}