private static async Task Run(DeployArgs parsedArgs) { var deploymentRepository = new BlobStorageDeploymentRepository(parsedArgs.YamsStorage); var appIdentity = new AppIdentity(parsedArgs.AppId, parsedArgs.AppVersion); Console.WriteLine("Uploading binaries from: \"{0}\", to {1}", parsedArgs.BinariesPath, appIdentity); await deploymentRepository.UploadApplicationBinaries(appIdentity, parsedArgs.BinariesPath, ConflictResolutionMode.FailIfBinariesExist); Console.WriteLine("Binaries uploaded"); var config = await deploymentRepository.FetchDeploymentConfig(); Console.WriteLine("Current DeploymentConfig.json is:\n\r{0}", config.RawData()); if (config.HasApplication(parsedArgs.AppId)) { config = config.RemoveApplication(parsedArgs.AppId); } config = config.AddApplication(appIdentity, parsedArgs.ClusterId); Console.WriteLine("Writing new config:\n\r{0}", config.RawData()); await deploymentRepository.PublishDeploymentConfig(config); Console.WriteLine("DeploymentConfig uploaded"); }
protected override void ProcessRecord() { try { if (string.IsNullOrWhiteSpace(ConnectionString)) { throw new ArgumentException(nameof(ConnectionString)); } int activityId = 0; var progressRecord = new ProgressRecord(activityId++, "Connect to blob storage", "Connecting to blob storage"); WriteProgress(progressRecord); var deploymentRepository = BlobStorageDeploymentRepository.Create(ConnectionString); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); progressRecord = new ProgressRecord(activityId++, "FetchDeploymentConfig", "Fetching DeploymentConfig.json from blob storage"); WriteProgress(progressRecord); var deploymentConfig = deploymentRepository.FetchDeploymentConfig().Result; progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); WriteObject(deploymentConfig); } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(e, "0", ErrorCategory.OperationStopped, null)); } }
private DeploymentStatus GetClusterDeploymentStatus(BlobStorageDeploymentRepository deploymentRepository, string clusterId) { var apps = deploymentRepository.FetchClusterDeploymentStatus(clusterId, ttlSeconds: ActiveSince).Result; return(new DeploymentStatus(apps)); }
protected override void ProcessRecord() { if (string.IsNullOrWhiteSpace(ConnectionString)) { throw new ArgumentException(nameof(ConnectionString)); } int activityId = 0; var progressRecord = new ProgressRecord(activityId++, "Connect to blob storage", "Connecting to blob storage"); WriteProgress(progressRecord); var deploymentRepository = BlobStorageDeploymentRepository.Create(ConnectionString); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); progressRecord = new ProgressRecord(activityId++, "FetchDeploymentConfig", "Fetching DeploymentConfig from storage"); WriteProgress(progressRecord); var deploymentConfig = deploymentRepository.FetchDeploymentConfig().Result; progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); progressRecord = new ProgressRecord(activityId++, "FetchDeploymentStatus", $"Fetching DeploymentStatus"); WriteProgress(progressRecord); var deploymentStatus = GetDeploymentStatus(deploymentRepository); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); WriteObject(deploymentStatus); }
private DeploymentStatus GetDeploymentStatus(BlobStorageDeploymentRepository deploymentRepository) { if (string.IsNullOrWhiteSpace(ClusterId)) { return(GetAllClustersDeploymentStatus(deploymentRepository)); } return(GetClusterDeploymentStatus(deploymentRepository, ClusterId)); }
protected override void ProcessRecord() { if (string.IsNullOrWhiteSpace(ConnectionString)) { throw new ArgumentException(nameof(ConnectionString)); } var deploymentRepository = BlobStorageDeploymentRepository.Create(ConnectionString); WriteObject(deploymentRepository); }
public BlobStorageDeploymentRepositoryTest(AzureStorageEmulatorTestFixture fixture) { fixture.ClearBlobStorage(); _blobClient = fixture.BlobClient; JsonSerializer jsonSerializer = new JsonSerializer(new DiagnosticsTraceWriter()); _serializer = new JsonDeploymentConfigSerializer(jsonSerializer); _deploymentStatusSerializer = new JsonDeploymentStatusSerializer(jsonSerializer); _deploymentRepository = new BlobStorageDeploymentRepository(EmulatorDataConnectionString, _serializer, _deploymentStatusSerializer); }
public static IYamsService Create(YamsConfig yamsConfig, string deploymentRepositoryStorageConnectionString, string updateSessionStorageConnectionString) { IUpdateSessionManager updateSessionManager = new AzureBlobStorageUpdateSessionDiModule( yamsConfig.ClusterDeploymentId, yamsConfig.InstanceId, yamsConfig.InstanceUpdateDomain, updateSessionStorageConnectionString).UpdateSessionManager; IDeploymentRepository deploymentRepository = new BlobStorageDeploymentRepository(deploymentRepositoryStorageConnectionString); return(new YamsDiModule(yamsConfig, deploymentRepository, updateSessionManager).YamsService); }
private DeploymentStatus GetAllClustersDeploymentStatus(BlobStorageDeploymentRepository deploymentRepository) { var deploymentConfig = deploymentRepository.FetchDeploymentConfig().Result; IEnumerable <string> clustersIds = deploymentConfig.ListClusters(); var apps = new List <AppDeploymentStatus>(); foreach (string clusterId in clustersIds) { var clusterStatus = deploymentRepository.FetchClusterDeploymentStatus(clusterId, ttlSeconds: ActiveSince).Result; apps.AddRange(clusterStatus.ListAll()); } return(new DeploymentStatus(apps)); }
protected override void ProcessRecord() { try { if (string.IsNullOrWhiteSpace(ConnectionString)) { throw new ArgumentException(nameof(ConnectionString)); } if (ClustersIds?.Length != AppsIds.Length) { throw new ArgumentException(nameof(ClustersIds)); } if (Versions?.Length != AppsIds.Length) { throw new ArgumentException(nameof(Versions)); } if (BinariesPath?.Length != AppsIds.Length) { throw new ArgumentException(nameof(BinariesPath)); } if (AppsIds?.Length == 0) { throw new ArgumentException(nameof(AppsIds)); } int activityId = 0; var progressRecord = new ProgressRecord(activityId++, "Connect to blob storage", "Connecting to blob storage"); WriteProgress(progressRecord); var deploymentRepository = BlobStorageDeploymentRepository.Create(ConnectionString); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); if (BinariesPath != null) { var tasks = new List <Task>(); for (int i = 0; i < AppsIds.Length; ++i) { string appId = AppsIds[i]; string version = Versions[i]; string binariesPath = BinariesPath[i]; var newAppIdentity = new AppIdentity(appId, version); if (BinariesPath != null) { tasks.Add(deploymentRepository.UploadApplicationBinaries(newAppIdentity, binariesPath, BinariesConflictResolutionMode)); } } progressRecord = new ProgressRecord(activityId++, "UploadApplicationBinaries", "Uploading binaries to blob storage"); WriteProgress(progressRecord); Task.WhenAll(tasks).Wait(); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); } if (Deploy) { progressRecord = new ProgressRecord(activityId++, "FetchDeploymentConfig", "Fetching DeploymentConfig.json from blob storage"); WriteProgress(progressRecord); var deploymentConfig = deploymentRepository.FetchDeploymentConfig().Result; progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); for (int i = 0; i < AppsIds.Length; ++i) { string appId = AppsIds[i]; string version = Versions[i]; string clusterId = ClustersIds[i]; if (RemoveOldVersions && deploymentConfig.HasApplication(appId)) { deploymentConfig = deploymentConfig.RemoveApplication(appId, clusterId); } var newAppIdentity = new AppIdentity(appId, version); if (!deploymentConfig.HasApplication(newAppIdentity, clusterId)) { var appDeploymentConfig = deploymentConfig.HasApplication(newAppIdentity)? deploymentConfig.GetApplicationConfig(newAppIdentity) : new AppDeploymentConfig(newAppIdentity); appDeploymentConfig = appDeploymentConfig.AddClusterId(clusterId); if (Properties?.Length > i) { var appProperties = JsonConvert.DeserializeObject <Dictionary <string, string> >(Properties[i]); foreach (var kvp in appProperties) { appDeploymentConfig = appDeploymentConfig.AddProperty(kvp.Key, kvp.Value); } } deploymentConfig = deploymentConfig.SetApplicationConfig(appDeploymentConfig); } } progressRecord = new ProgressRecord(activityId++, "PublishDeploymentConfig", "Publishing DeploymentConfig.json to blob storage"); WriteProgress(progressRecord); deploymentRepository.PublishDeploymentConfig(deploymentConfig).Wait(); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); WriteObject(deploymentConfig); } if (WaitForDeploymentsToComplete) { var waitForDeploymentsProgressRecord = new ProgressRecord(activityId++, "WaitForDeploymentsToComplete", "Waiting for all deployments to complete"); WriteProgress(waitForDeploymentsProgressRecord); List <AppInfo> pendingApps = new List <AppInfo>(); for (int i = 0; i < AppsIds.Length; ++i) { AppInfo app = new AppInfo { Id = AppsIds[i], Version = Versions[i], ClusterId = ClustersIds[i] }; pendingApps.Add(app); } while (pendingApps.Any()) { var appDeployments = new List <AppDeploymentStatus>(); var fetchTasks = new List <Task <ClusterDeploymentStatus> >(); progressRecord = new ProgressRecord(activityId++, "FetchClusterDeploymentStatus", "Fetching deployments status"); WriteProgress(progressRecord); foreach (string clusterId in ClustersIds) { fetchTasks.Add( deploymentRepository.FetchClusterDeploymentStatus(clusterId, ttlSeconds: 60)); } progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); ClusterDeploymentStatus[] result = Task.WhenAll(fetchTasks).Result; foreach (var clusterDeploymentStatus in result) { appDeployments.AddRange(clusterDeploymentStatus.ListAll()); } foreach (var appDeploymentStatus in appDeployments) { AppInfo app = pendingApps.FirstOrDefault( appInfo => appInfo.ClusterId == appDeploymentStatus.ClusterId && appInfo.Id == appDeploymentStatus.Id && appInfo.Version == appDeploymentStatus.Version); if (app != null) { pendingApps.Remove(app); float quotient = (float)(AppsIds.Length - pendingApps.Count) / AppsIds.Length; waitForDeploymentsProgressRecord.PercentComplete = (int)(100 * quotient); WriteProgress(waitForDeploymentsProgressRecord); } } Task.Delay(TimeSpan.FromSeconds(1)).Wait(); } waitForDeploymentsProgressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(waitForDeploymentsProgressRecord); } } catch (ArgumentException argException) { ThrowTerminatingError(new ErrorRecord(argException, "0", ErrorCategory.InvalidArgument, null)); } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(e, "0", ErrorCategory.OperationStopped, null)); } }
protected override void ProcessRecord() { try { if (string.IsNullOrWhiteSpace(ConnectionString)) { throw new ArgumentException(nameof(ConnectionString)); } if (ClustersIds.Length != AppsIds.Length) { throw new ArgumentException(nameof(ClustersIds)); } if (Versions.Length != AppsIds.Length) { throw new ArgumentException(nameof(Versions)); } if (AppsIds.Length == 0) { throw new ArgumentException(nameof(AppsIds)); } int activityId = 0; var progressRecord = new ProgressRecord(activityId++, "Connect to blob storage", "Connecting to blob storage"); WriteProgress(progressRecord); var deploymentRepository = BlobStorageDeploymentRepository.Create(ConnectionString); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); progressRecord = new ProgressRecord(activityId++, "FetchDeploymentConfig", "Fetching DeploymentConfig.json from blob storage"); WriteProgress(progressRecord); var deploymentConfig = deploymentRepository.FetchDeploymentConfig().Result; progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); for (int i = 0; i < AppsIds.Length; ++i) { string appId = AppsIds[i]; string version = Versions[i]; string clusterId = ClustersIds[i]; var toRemove = new AppIdentity(appId, version); if (deploymentConfig.HasApplication(toRemove)) { deploymentConfig = deploymentConfig.RemoveApplication(toRemove); } } progressRecord = new ProgressRecord(activityId++, "PublishDeploymentConfig", "Publishing DeploymentConfig.json to blob storage"); WriteProgress(progressRecord); deploymentRepository.PublishDeploymentConfig(deploymentConfig).Wait(); progressRecord.RecordType = ProgressRecordType.Completed; WriteProgress(progressRecord); WriteObject(deploymentConfig); } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(e, "0", ErrorCategory.OperationStopped, null)); } }