Esempio n. 1
0
        public void TestApplicationPackage(string connectionEndpoint, string applicationPackagePath, string applicationParameter, string imageStoreConnectionString, string certThumbprint)
        {
            string[] parameters = applicationParameter.Split(',');
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            for (int i = 0; i < parameters.Length / 2; i += 2)
            {
                dictionary.Add(parameters[i], parameters[i + 1]);
            }

            var testRootPath = Path.Combine(Path.GetTempPath(), string.Format(CultureInfo.InvariantCulture, "{0}_{1}", "TestApplicationPackage", DateTime.Now.Ticks));

            try
            {
                var applicationName         = new DirectoryInfo(applicationPackagePath).Name;
                var testRootApplicationPath = Path.Combine(testRootPath, applicationName);
                FabricDirectory.Copy(applicationPackagePath, testRootApplicationPath, true);
                ImageBuilderUtility.RemoveReadOnlyFlag(testRootApplicationPath);

                var fileImageStoreConnectionString = string.Format(CultureInfo.InvariantCulture, "{0}{1}", "file:", testRootPath.TrimEnd(Path.DirectorySeparatorChar));
                var sourceImageStore = ImageStoreFactoryProxy.CreateImageStore(fileImageStoreConnectionString);

                IImageStore destinationImageStore = null;
                if (string.IsNullOrEmpty(imageStoreConnectionString))
                {
                    destinationImageStore = sourceImageStore;
                }
                else
                {
                    destinationImageStore = this.CreateImageStore(connectionEndpoint, imageStoreConnectionString, testRootPath, certThumbprint);
                }

                var imagebuilder = new ImageBuilder(sourceImageStore, destinationImageStore, this.GetFabricFilePath("ServiceFabricServiceModel.xsd"), testRootPath);

                imagebuilder.ValidateApplicationPackage(
                    applicationName,
                    dictionary);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                FabricDirectory.Delete(testRootPath, true, true);
            }
        }
Esempio n. 2
0
        protected void TestSFApplicationPackage(string applicationPackagePath, Hashtable applicationParameters, string imageStoreConnectionString)
        {
            var testRootPath = Path.Combine(Path.GetTempPath(), string.Format(CultureInfo.InvariantCulture, "{0}_{1}", Constants.BaseTestRootFolderName, Stopwatch.GetTimestamp()));

            try
            {
                var absolutePath            = this.GetAbsolutePath(applicationPackagePath);
                var applicationName         = this.GetPackageName(absolutePath);
                var testRootApplicationPath = Path.Combine(testRootPath, applicationName);
                FabricDirectory.Copy(absolutePath, testRootApplicationPath, true);
                ImageBuilderUtility.RemoveReadOnlyFlag(testRootApplicationPath);

                var fileImageStoreConnectionString =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}{1}",
                        Constants.ImageStoreConnectionFileType,
                        testRootPath.TrimEnd(Path.DirectorySeparatorChar));
                var sourceImageStore = ImageStoreFactoryProxy.CreateImageStore(fileImageStoreConnectionString);

                IImageStore destinationImageStore = null;
                if (string.IsNullOrEmpty(imageStoreConnectionString))
                {
                    destinationImageStore = sourceImageStore;
                }
                else
                {
                    destinationImageStore = this.CreateImageStore(imageStoreConnectionString, testRootPath);
                }

                var imagebuilder = new ImageBuilder(
                    sourceImageStore,
                    destinationImageStore,
                    this.GetFabricFilePath(Constants.ServiceModelSchemaFileName),
                    testRootPath);

                // Set SFVolumeDiskServiceEnabled to true so that client side validation does the right thing
                // if corresponding UseServiceFabricReplicatedStore attribute is set.
                //
                // We always have a final validation at runtime to catch any issues.
                imagebuilder.IsSFVolumeDiskServiceEnabled = true;

                imagebuilder.ValidateApplicationPackage(
                    applicationName,
                    this.GetDictionary(applicationParameters));

                this.WriteObject(true);
            }
            catch (AggregateException exception)
            {
                exception.Handle((ae) =>
                {
                    this.WriteObject(false);
                    this.ThrowTerminatingError(
                        ae,
                        Constants.TestApplicationPackageErrorId,
                        null);
                    return(true);
                });
            }
            catch (Exception exception)
            {
                this.WriteObject(false);
                this.ThrowTerminatingError(
                    exception,
                    Constants.TestApplicationPackageErrorId,
                    null);
            }
            finally
            {
                FabricDirectory.Delete(testRootPath, true, true);
            }
        }