Beispiel #1
0
        public void TestSerializeRoundTrip()
        {
            string           serialized       = JObject.Parse(_serializer.Serialize(_deploymentConfig)).ToString();
            DeploymentConfig deploymentConfig = _serializer.Deserialize(serialized);
            string           roundTripJson    = JObject.Parse(_serializer.Serialize(deploymentConfig)).ToString();

            Assert.Equal(_deploymentConfig, deploymentConfig);
            Assert.Equal(serialized, roundTripJson);
        }
        public async Task TestPublishThenFetchDeploymentConfig()
        {
            string           data             = File.ReadAllText(_deploymentConfigFilePath);
            DeploymentConfig deploymentConfig = _serializer.Deserialize(data);
            await _deploymentRepository.PublishDeploymentConfig(deploymentConfig);

            DeploymentConfig newDeploymentConfig = await _deploymentRepository.FetchDeploymentConfig();

            Assert.Equal(_serializer.Serialize(deploymentConfig), _serializer.Serialize(newDeploymentConfig));
        }
Beispiel #3
0
        private async Task <DeploymentConfig> FetchDeploymentConfig(StorageAccountConnectionInfo connectionInfo)
        {
            string path = GetDeploymentConfigLocalPath(connectionInfo.AccountName);

            if (File.Exists(path))
            {
                return(_deploymentConfigSerializer.Deserialize(File.ReadAllText(path)));
            }
            IDeploymentRepository connection       = _deploymentRepositoryManager.GetRepository(connectionInfo);
            DeploymentConfig      deploymentConfig = await connection.FetchDeploymentConfig();

            SaveLocalDeploymentConfig(connectionInfo, _deploymentConfigSerializer.Serialize(deploymentConfig));
            return(deploymentConfig);
        }
        public async Task <DeploymentConfig> FetchDeploymentConfig()
        {
            var blob = _blobContainer.GetBlockBlobReference(Constants.DeploymentConfigFileName);

            if (!await blob.ExistsAsync())
            {
                Trace.TraceInformation("The DeploymentConfig.json file was not found in the Yams repository");
                return(new DeploymentConfig());
            }

            string data = await blob.DownloadTextAsync();

            return(_serializer.Deserialize(data));
        }
        public Task <DeploymentConfig> FetchDeploymentConfig()
        {
            string data = File.ReadAllText(_deploymentConfigPath);

            return(Task.FromResult(_deploymentConfigSerializer.Deserialize(data)));
        }
        public async Task <DeploymentConfig> FetchDeploymentConfig()
        {
            // Increment app version
            LocalAppDeploymentConfig IncrementVersion(string exeRoot, AppDeploymentConfig app)
            {
                var version     = app.AppIdentity.Version;
                var nextVersion = new Semver.SemVersion(version.Major, version.Minor, version.Patch + 1);

                return(new LocalAppDeploymentConfig(exeRoot,
                                                    new AppIdentity(app.AppIdentity.Id, nextVersion),
                                                    app.TargetClusters,
                                                    app.Properties));
            }

            // Convert to LocalAppDeploymentConfig
            LocalAppDeploymentConfig ToLocalAppConfig(string exeRoot, AppDeploymentConfig app) =>
            new LocalAppDeploymentConfig(
                exeRoot,
                new AppIdentity(app.AppIdentity.Id, app.AppIdentity.Version),
                app.TargetClusters,
                app.Properties);

            // Check if the app has an available update
            LocalAppDeploymentConfig CheckAppUpdated(AppDeploymentConfig input)
            {
                var exeRoot = GetBinariesPath(input);

                // Carry newly generated versions over
                if (ActiveConfiguration != null &&
                    ActiveConfiguration.TryGetValue(input.AppIdentity.Id, out var a) &&
                    a is LocalAppDeploymentConfig activeVersion)
                {
                    var nextVersion = IncrementVersion(exeRoot, input);

                    if (activeVersion.EntryPointCreatedDate < nextVersion.EntryPointCreatedDate &&
                        nextVersion.EntryPointCreatedDate < DateTimeOffset.UtcNow.AddSeconds(-10))
                    {
                        return(nextVersion);
                    }
                    else
                    {
                        return(activeVersion);
                    }
                }
                else
                {
                    return(ToLocalAppConfig(exeRoot, input));
                }
            }

            using (var file = File.Open(_deploymentConfigPath, FileMode.Open, FileAccess.Read))
                using (var sr = new StreamReader(file))
                {
                    // Check if any changes have been made
                    var updates = _serializer
                                  .Deserialize(await sr.ReadToEndAsync())
                                  .Select(CheckAppUpdated)
                                  .ToList();

                    ActiveConfiguration = updates.ToDictionary(keySelector: u => u.AppIdentity.Id);

                    return(new DeploymentConfig(updates));
                }
        }