Inheritance: Etg.Yams.Install.AppInstallConfig
Example #1
0
        public DeploymentConfig RemoveApplication(AppIdentity appIdentity, string deploymentId)
        {
            string appId   = appIdentity.Id;
            string version = appIdentity.Version.ToString();
            var    apps    = GetAppsCopy();

            if (!apps.ContainsKey(appId))
            {
                throw new InvalidOperationException($"Cannot remove deployment because app {appId} was not found");
            }
            AppDeploymentConfig appDeploymentConfig = apps[appId];

            if (!appDeploymentConfig.Versions.ContainsKey(version))
            {
                throw new InvalidOperationException(
                          $"Cannot remove deployment because app {appId}, version {version} was not found");
            }
            VersionDeploymentConfig versionDeploymentConfig = appDeploymentConfig.Versions[version];

            if (!versionDeploymentConfig.DeploymentIds.Contains(deploymentId))
            {
                throw new InvalidOperationException(
                          $"Cannot remove deployment {deploymentId} from app {appId}, version {version} because it was not found");
            }
            versionDeploymentConfig = versionDeploymentConfig.RemoveDeployment(deploymentId);
            appDeploymentConfig     = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
            apps[appId]             = appDeploymentConfig;
            DeploymentConfig dc = new DeploymentConfig(apps);

            if (!dc._apps[appId].Versions[version].DeploymentIds.Any())
            {
                dc = dc.RemoveApplication(appIdentity);
            }
            return(dc);
        }
Example #2
0
        public DeploymentConfig RemoveApplication(AppIdentity appIdentity)
        {
            string appId   = appIdentity.Id;
            string version = appIdentity.Version.ToString();
            var    apps    = GetAppsCopy();

            if (!apps.ContainsKey(appId))
            {
                throw new InvalidOperationException($"Cannot remove version {version} because {appId} was not found");
            }
            AppDeploymentConfig appDeploymentConfig = apps[appId];

            if (!appDeploymentConfig.Versions.ContainsKey(version))
            {
                throw new InvalidOperationException(
                          $"Cannot remove version {version} from application {appId} because version {version} was not found");
            }
            appDeploymentConfig = appDeploymentConfig.RemoveVersionConfig(version);
            if (!appDeploymentConfig.Versions.Any())
            {
                apps.Remove(appId);
            }
            else
            {
                apps[appId] = appDeploymentConfig;
            }

            return(new DeploymentConfig(apps));
        }
Example #3
0
 private AppDeploymentConfig AddVersionConfigIfNoneExists(AppDeploymentConfig appDeploymentConfig, string version)
 {
     if (!appDeploymentConfig.Versions.ContainsKey(version))
     {
         return(appDeploymentConfig.SetVersionConfig(new VersionDeploymentConfig(version)));
     }
     return(appDeploymentConfig);
 }
Example #4
0
 private static Dictionary <string, AppDeploymentConfig> AddAppConfigIfNoneExists(
     Dictionary <string, AppDeploymentConfig> apps, string appId)
 {
     if (!apps.ContainsKey(appId))
     {
         var appConfig = new AppDeploymentConfig(appId);
         apps[appId] = appConfig;
     }
     return(apps);
 }
 public bool IsMatch(AppDeploymentConfig appDeploymentConfig)
 {
     foreach (var kvp in _matchProperties)
     {
         string value;
         if (!appDeploymentConfig.Properties.TryGetValue(kvp.Key, out value))
         {
             return false;
         }
         if (value != kvp.Value)
         {
             return false;
         }
     }
     return true;
 }
        public async Task TestParseApplicationConfig()
        {
            string path = Path.Combine(Directory.GetCurrentDirectory(), "Data\\ApplicationConfigParser\\AppConfig.json");
            const string clusterId = "clusterid1";
            const string instanceId = "instanceid1";
            
            AppIdentity identity = new AppIdentity("HelloApp", new SemVersion(1,0,0));
            Dictionary<string, string> properties = new Dictionary<string, string> {["NodeType"] = "PROD"};
            AppDeploymentConfig appDeploymentConfig = new AppDeploymentConfig(identity, new [] {clusterId}, properties);
            ApplicationConfig appConfig = await new ApplicationConfigParser(new ApplicationConfigSymbolResolver(clusterId, instanceId),
                new JsonSerializer(new DiagnosticsTraceWriter())).ParseFile(path, appDeploymentConfig);

            Assert.Equal(identity, appConfig.Identity);
            Assert.Equal("HelloApp.exe", appConfig.ExeName);
            Assert.Equal("HelloApp_1.0_instanceid1 foo bar=HelloApp_1.0_clusterid1 nodeType=PROD", appConfig.ExeArgs);
        }
        public DeploymentConfig Deserialize(string data)
        {
            DeploymentConfig deploymentConfig = new DeploymentConfig();
            Dictionary<string, AppDeploymentConfig> apps = new Dictionary<string, AppDeploymentConfig>();
            if (string.IsNullOrEmpty(data))
            {
                return deploymentConfig;
            }

            var appDeploymentConfigs = new List<AppDeploymentConfig>();
            ApplicationsData appsData = _jsonSerializer.Deserialize<ApplicationsData>(data);
            foreach (ApplicationData appData in appsData.Applications)
            {
                AppIdentity appIdentity = new AppIdentity(appData.Id, appData.Version);
                AppDeploymentConfig appDeploymentConfig 
                    = new AppDeploymentConfig(appIdentity, appData.TargetClusters, appData.Properties);
                appDeploymentConfigs.Add(appDeploymentConfig);
            }
            return new DeploymentConfig(appDeploymentConfigs);
        }
Example #8
0
        public string RawData()
        {
            var applicationsList = new List <ApplicationData>();

            foreach (KeyValuePair <string, AppDeploymentConfig> app in _apps)
            {
                string appId = app.Key;
                AppDeploymentConfig appDeploymentConfig = app.Value;
                foreach (KeyValuePair <string, VersionDeploymentConfig> v in appDeploymentConfig.Versions)
                {
                    string version = v.Key;
                    VersionDeploymentConfig versionDeploymentConfig = v.Value;
                    applicationsList.Add(new ApplicationData(appId, version,
                                                             versionDeploymentConfig.DeploymentIds.ToArray()));
                }
            }
            ApplicationsData applicationsData = new ApplicationsData(applicationsList.ToArray());

            return(JsonUtils.Serialize(applicationsData));
        }
Example #9
0
        public DeploymentConfig AddApplication(AppIdentity appIdentity, string deploymentId)
        {
            string appId   = appIdentity.Id;
            string version = appIdentity.Version.ToString();
            Dictionary <string, AppDeploymentConfig> apps = GetAppsCopy();

            apps = AddAppConfigIfNoneExists(apps, appId);
            AppDeploymentConfig appDeploymentConfig = apps[appId];

            appDeploymentConfig = AddVersionConfigIfNoneExists(appDeploymentConfig, version);
            VersionDeploymentConfig versionDeploymentConfig = appDeploymentConfig.Versions[version];

            if (versionDeploymentConfig.DeploymentIds.Contains(deploymentId))
            {
                throw new InvalidOperationException(
                          $"Cannot add the deployment {deploymentId} to application {appId}, version {version} because it's already there");
            }
            versionDeploymentConfig = versionDeploymentConfig.AddDeployment(deploymentId);
            appDeploymentConfig     = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
            apps[appId]             = appDeploymentConfig;
            return(new DeploymentConfig(apps));
        }
Example #10
0
        private static Dictionary <string, AppDeploymentConfig> ParseDeploymentsConfig(string json)
        {
            Dictionary <string, AppDeploymentConfig> apps = new Dictionary <string, AppDeploymentConfig>();

            if (string.IsNullOrEmpty(json))
            {
                return(apps);
            }

            ApplicationsData appsData = JsonUtils.Deserialize <ApplicationsData>(json);

            foreach (ApplicationData appData in appsData.Applications)
            {
                VersionDeploymentConfig versionDeploymentConfig = new VersionDeploymentConfig(appData.Version,
                                                                                              appData.DeploymentIds);
                apps = AddAppConfigIfNoneExists(apps, appData.Id);
                AppDeploymentConfig appDeploymentConfig = apps[appData.Id];
                appDeploymentConfig = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
                apps[appData.Id]    = appDeploymentConfig;
            }
            return(apps);
        }
Example #11
0
        public DeploymentConfig Deserialize(string data)
        {
            DeploymentConfig deploymentConfig             = new DeploymentConfig();
            Dictionary <string, AppDeploymentConfig> apps = new Dictionary <string, AppDeploymentConfig>();

            if (string.IsNullOrEmpty(data))
            {
                return(deploymentConfig);
            }

            var appDeploymentConfigs  = new List <AppDeploymentConfig>();
            ApplicationsData appsData = _jsonSerializer.Deserialize <ApplicationsData>(data);

            foreach (ApplicationData appData in appsData.Applications)
            {
                AppIdentity         appIdentity = new AppIdentity(appData.Id, appData.Version);
                AppDeploymentConfig appDeploymentConfig
                    = new AppDeploymentConfig(appIdentity, appData.TargetClusters, appData.Properties);
                appDeploymentConfigs.Add(appDeploymentConfig);
            }
            return(new DeploymentConfig(appDeploymentConfigs));
        }
Example #12
0
 protected new bool Equals(AppDeploymentConfig other)
 {
     return(base.Equals(other) && (new HashSet <string>(TargetClusters).SetEquals(other.TargetClusters)));
 }
Example #13
0
 protected new bool Equals(AppDeploymentConfig other)
 {
     return base.Equals(other) && (new HashSet<string>(TargetClusters).SetEquals(other.TargetClusters));
 }
Example #14
0
 protected bool Equals(AppDeploymentConfig other)
 {
     bool res = Equals(AppIdentity, other.AppIdentity)
                && Properties.SequenceEqual(other.Properties);
     return res;
 }
 public bool IsMatch(AppDeploymentConfig appDeploymentConfig)
 {
     return appDeploymentConfig.TargetClusters.Contains(_clusterId);
 }
Example #16
0
 private static Dictionary<string, AppDeploymentConfig> AddAppConfigIfNoneExists(
     Dictionary<string, AppDeploymentConfig> apps, string appId)
 {
     if (!apps.ContainsKey(appId))
     {
         var appConfig = new AppDeploymentConfig(appId);
         apps[appId] = appConfig;
     }
     return apps;
 }
Example #17
0
 private AppDeploymentConfig AddVersionConfigIfNoneExists(AppDeploymentConfig appDeploymentConfig, string version)
 {
     if (!appDeploymentConfig.Versions.ContainsKey(version))
     {
         return appDeploymentConfig.SetVersionConfig(new VersionDeploymentConfig(version));
     }
     return appDeploymentConfig;
 }
Example #18
0
 public bool IsMatch(AppDeploymentConfig appDeploymentConfig)
 {
     return _matchers.All(matcher => matcher.IsMatch(appDeploymentConfig));
 }