Пример #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);
        }
Пример #2
0
 private AppDeploymentConfig AddVersionConfigIfNoneExists(AppDeploymentConfig appDeploymentConfig, string version)
 {
     if (!appDeploymentConfig.Versions.ContainsKey(version))
     {
         return(appDeploymentConfig.SetVersionConfig(new VersionDeploymentConfig(version)));
     }
     return(appDeploymentConfig);
 }
Пример #3
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));
        }
Пример #4
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);
        }
Пример #5
0
 private AppDeploymentConfig AddVersionConfigIfNoneExists(AppDeploymentConfig appDeploymentConfig, string version)
 {
     if (!appDeploymentConfig.Versions.ContainsKey(version))
     {
         return appDeploymentConfig.SetVersionConfig(new VersionDeploymentConfig(version));
     }
     return appDeploymentConfig;
 }