public void Should_serialize_and_deserialize_properties() { foreach (var properties in TestProperties()) { var info = new ApplicationInfo(envName, appName, properties); var serialized = ApplicationNodeDataSerializer.Serialize(info); var deserialized = ApplicationNodeDataSerializer.Deserialize(envName, appName, serialized); deserialized.Should().BeEquivalentTo(info); } }
public async Task <bool> TryCreateApplicationAsync(IApplicationInfo application) { var applicationPath = pathHelper.BuildApplicationPath(application.Environment, application.Application); var applicationData = ApplicationNodeDataSerializer.Serialize(application); var createRequest = new CreateRequest(applicationPath, CreateMode.Persistent) { Data = applicationData }; return((await zooKeeperClient.CreateAsync(createRequest).ConfigureAwait(false)).IsSuccessful); }
public async Task <IApplicationInfo> GetApplicationAsync(string environment, string application) { var data = await zooKeeperClient.GetDataAsync(new GetDataRequest(pathHelper.BuildApplicationPath(environment, application))).ConfigureAwait(false); if (data.Status == ZooKeeperStatus.NodeNotFound) { return(null); } data.EnsureSuccess(); var appData = ApplicationNodeDataSerializer.Deserialize(environment, application, data.Data); return(appData); }
public void Should_deserialize_empty() { ApplicationNodeDataSerializer.Deserialize(envName, appName, new byte[0]).Should().BeEquivalentTo(new ApplicationInfo(envName, appName, null)); }
public void Update() { if (isDisposed) { return; } try { var applicationExists = zooKeeperClient.Exists(new ExistsRequest(applicationNodePath) { Watcher = nodeWatcher }); if (!applicationExists.IsSuccessful) { return; } if (applicationExists.Stat == null) { Clear(); return; } if (applicationContainer.NeedUpdate(applicationExists.Stat.ModifiedZxId)) { var applicationData = zooKeeperClient.GetData(new GetDataRequest(applicationNodePath) { Watcher = nodeWatcher }); if (applicationData.Status == ZooKeeperStatus.NodeNotFound) { Clear(); } if (!applicationData.IsSuccessful) { return; } var info = ApplicationNodeDataSerializer.Deserialize(environmentName, applicationName, applicationData.Data); if (applicationContainer.Update(applicationData.Stat.ModifiedZxId, info)) { UpdateServiceTopology(); } } if (replicasContainer.NeedUpdate(applicationExists.Stat.ModifiedChildrenZxId)) { var applicationChildren = zooKeeperClient.GetChildren(new GetChildrenRequest(applicationNodePath) { Watcher = nodeWatcher }); if (applicationChildren.Status == ZooKeeperStatus.NodeNotFound) { Clear(); } if (!applicationChildren.IsSuccessful) { return; } var replicas = UrlParser.Parse(applicationChildren.ChildrenNames.Select(pathHelper.Unescape)); if (replicasContainer.Update(applicationChildren.Stat.ModifiedChildrenZxId, replicas)) { UpdateServiceTopology(); } } } catch (Exception error) { log.Error(error, "Failed to update '{Application} application in '{Environment}' environment.", applicationName, environmentName); } }