public static async Task <bool> DeployServiceFabricSolution(this IServiceFabricClient Client, ServiceFabricSolution apps, bool symlinkProvision, ILogger Logger = null) { var cluster = FabricSerializers.ClusterManifestFromString((await Client.Cluster.GetClusterManifestAsync()).Manifest); var appTypes = await Client.ApplicationTypes.GetApplicationTypeInfoListAsync(); apps.Validate(); var appsToUpload = apps.Applications.Where(a => !appTypes.Data.Any(ap => ap.Name == a.Manifest.ApplicationTypeName && ap.Version == a.Manifest.ApplicationTypeVersion)).ToList(); if (appsToUpload.Any()) { var imageStore = cluster.FabricSettings.First(s => s.Name == "Management").Parameter.First(s => s.Name == "ImageStoreConnectionString").Value; Logger?.LogVerbose($"Using image store {imageStore}"); var imageStorePath = new Uri(imageStore).LocalPath; // if (symlinkProvision && Directory.Exists(imageStorePath)) // await Task.WhenAll(appsToUpload.Select(i => UploadAppToLocalPath(imageStore, imageStorePath, i)).ToList()); // else await Task.WhenAll(appsToUpload.Select(i => Client.UploadApp(imageStore, i)).ToList()); Logger?.LogInfo($"Apps uploaded"); } foreach (var app in apps.Applications) { await Client.DeployServiceFabricApp(app); } return(true); }
private static async Task UploadAppToLocalPath(this IServiceFabricClient Client, string imageStore, string imageStorep, ServiceFabricApplicationSpec app) { var name = app.Manifest.ApplicationTypeName + "." + app.Manifest.ApplicationTypeVersion; try { Symlink.CreateSymbolicLink(Path.Combine(imageStorep, name), app.PackagePath, SymbolicLink.Directory); await Client.ApplicationTypes.ProvisionApplicationTypeAsync(new ProvisionApplicationTypeDescription(name), 240, CancellationToken.None); Symlink.DeleteIfExists(Path.Combine(imageStorep, name)); } catch (FileNotFoundException) { Symlink.DeleteIfExists(Path.Combine(imageStorep, name)); await Client.UploadApp(imageStore, app); } }