Ejemplo n.º 1
0
        public DeploymentSettings(ServiceSettings settings, string packagePath, string configPath, string label, string deploymentName)
        {
            Validate.ValidateNullArgument(settings, Resources.InvalidServiceSettingMessage);
            Validate.ValidateFileFull(packagePath, Resources.Package);
            Validate.ValidateFileFull(configPath, Resources.ServiceConfiguration);
            Validate.ValidateStringIsNullOrEmpty(label, "Label");
            Validate.ValidateStringIsNullOrEmpty(deploymentName, "Deployment name");

            this.ServiceSettings = settings;
            this.PackagePath = packagePath;
            this.ConfigPath = configPath;
            this.Label = label;
            this.DeploymentName = deploymentName;

            if (!string.IsNullOrEmpty(settings.Subscription))
            {
                GlobalComponents globalComponents = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory);

                SubscriptionId = globalComponents.GetSubscriptionId(settings.Subscription);
            }
            else
            {
                throw new ArgumentNullException("settings.Subscription", Resources.InvalidSubscriptionNameMessage);
            }
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            string[] locations = { "West US", "East US", "East Asia", "North Europe" };
            foreach (string item in locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    mockCommandRuntime = new MockCommandRuntime();
                    setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                    settings.Save(paths.Settings);

                    settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(item, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    Assert.AreEqual<string>(item, settings.Location);
                    ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                    Assert.AreEqual<string>(item, settings.Location);
                }
            }
        }
Ejemplo n.º 3
0
        public PublishContext(
            ServiceSettings settings,
            string packagePath,
            string configPath,
            string serviceName,
            string deploymentName,
            string rootPath)
        {
            Validate.ValidateNullArgument(settings, Resources.InvalidServiceSettingMessage);
            Validate.ValidateStringIsNullOrEmpty(packagePath, "packagePath");
            Validate.ValidateFileFull(configPath, Resources.ServiceConfiguration);
            Validate.ValidateStringIsNullOrEmpty(serviceName, "serviceName");

            this.ServiceSettings = settings;
            this.PackagePath = packagePath;
            this.ConfigPath = configPath;
            this.RootPath = rootPath;
            this.ServiceName = serviceName;
            this.DeploymentName = string.IsNullOrEmpty(deploymentName) ?
                char.ToLower(ServiceSettings.Slot[0]) + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff")
                : deploymentName;

            if (!string.IsNullOrEmpty(settings.Subscription))
            {
                GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory);
                SubscriptionId = globalSettingsManager.GetSubscriptionId(settings.Subscription);
            }
            else
            {
                throw new ArgumentNullException("settings.Subscription", Resources.InvalidSubscriptionNameMessage);
            }
        }
Ejemplo n.º 4
0
        public static void AreEqualDeploymentSettings(ServiceSettings settings, string configPath, string deploymentName, string label, string packagePath, string subscriptionId, DeploymentSettings actual)
        {
            AreEqualServiceSettings(settings, actual.ServiceSettings);
            Assert.AreEqual<string>(configPath, actual.ConfigPath);
            Assert.AreEqual<string>(deploymentName, actual.DeploymentName);
            Assert.AreEqual<string>(label, actual.Label);
            Assert.AreEqual<string>(packagePath, actual.PackagePath);
            Assert.AreEqual<string>(subscriptionId, actual.SubscriptionId);

            Assert.IsTrue(File.Exists(actual.ConfigPath));
            Assert.IsTrue(File.Exists(actual.PackagePath));
        }
        public void SetAzureServiceProjectTestsLocationEmptyFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => setServiceProjectCmdlet.SetAzureServiceProjectProcess(string.Empty, null, null, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Location"));
            }
        }
        public void OnPublish(IServiceManagement channel, AzureService service, ServiceSettings publishSettings, string subscriptionId)
        {
            StorageService storageService = channel.GetStorageKeys(subscriptionId, publishSettings.StorageAccountName);
            string name = publishSettings.StorageAccountName;
            string key = storageService.StorageServiceKeys.Primary;

            ConfigConfigurationSetting connectionStringConfig = new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = string.Empty };
            service.Components.ForEachRoleSettings(
            r => Array.Exists<ConfigConfigurationSetting>(r.ConfigurationSettings, c => c.Equals(connectionStringConfig)),
            delegate(RoleSettings r)
            {
                int index = Array.IndexOf<ConfigConfigurationSetting>(r.ConfigurationSettings, connectionStringConfig);
                r.ConfigurationSettings[index] = new ConfigConfigurationSetting
                {
                    name = Resources.CachingConfigStoreConnectionStringSettingName,
                    value = string.Format(Resources.CachingConfigStoreConnectionStringSettingValue, name, key)
                };
            });

            service.Components.Save(service.Paths);
        }
        private void InitializeData()
        {
            ServiceSettings settings;

            Data = new Dictionary<ServiceSettingsState, ServiceSettings>();
            Data.Add(ServiceSettingsState.Default, new ServiceSettings());

            settings = new ServiceSettings();
            settings.Location = ArgumentConstants.Locations[LocationName.SouthCentralUS];
            settings.Slot = ArgumentConstants.Slots[SlotType.Production];
            settings.StorageAccountName = "mystore";
            settings.Subscription = "TestSubscription2";
            Data.Add(ServiceSettingsState.Sample1, settings);

            settings = new ServiceSettings();
            settings.Location = ArgumentConstants.Locations[LocationName.SouthCentralUS];
            settings.Slot = ArgumentConstants.Slots[SlotType.Production];
            settings.StorageAccountName = "mystore";
            settings.Subscription = "Does not exist subscription";
            Data.Add(ServiceSettingsState.DoesNotExistSubscription, settings);
        }
        private void InitializeData()
        {
            ServiceSettings settings;

            Data = new Dictionary<ServiceSettingsState, ServiceSettings>();
            Data.Add(ServiceSettingsState.Default, new ServiceSettings());

            settings = new ServiceSettings();
            settings.Location = "South Central US";
            settings.Slot = DeploymentSlotType.Production;
            settings.StorageServiceName = "mystore";
            settings.Subscription = "TestSubscription2";
            Data.Add(ServiceSettingsState.Sample1, settings);

            settings = new ServiceSettings();
            settings.Location = "South Central US";
            settings.Slot = DeploymentSlotType.Production;
            settings.StorageServiceName = "mystore";
            settings.Subscription = "Does not exist subscription";
            Data.Add(ServiceSettingsState.DoesNotExistSubscription, settings);
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            foreach (KeyValuePair<LocationName, string> item in ArgumentConstants.Locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    mockCommandRuntime = new MockCommandRuntime();
                    setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                    settings.Save(paths.Settings);

                    settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    Assert.AreEqual<string>(item.Value, settings.Location);
                    ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                    Assert.AreEqual<string>(item.Value, settings.Location);
                }
            }
        }
        public void SetAzureServiceProjectTestsSlotTests()
        {
            string[] slots = { DeploymentSlotType.Production, DeploymentSlotType.Staging };
            foreach (string item in slots)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);

                    setServiceProjectCmdlet.SetAzureServiceProjectProcess(null, item, null, null, paths.Settings);

                    // Assert slot is changed
                    //
                    settings = ServiceSettings.Load(paths.Settings);
                    Assert.AreEqual<string>(item, settings.Slot);
                }
            }
        }
 public void ServiceSettingsTest()
 {
     ServiceSettings settings = new ServiceSettings();
     AzureAssert.AreEqualServiceSettings(string.Empty, string.Empty, string.Empty, string.Empty, settings);
 }
        public void TestInitialize()
        {
            CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();

            serviceName = Path.GetRandomFileName();
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            service = new AzureServiceWrapper(Directory.GetCurrentDirectory(), Path.GetRandomFileName(), null);
            service.CreateVirtualCloudPackage();
            packagePath = service.Paths.CloudPackage;
            configPath = service.Paths.CloudConfiguration;
            settings = ServiceSettingsTestData.Instance.Data[ServiceSettingsState.Default];
            mockCommandRuntime = new MockCommandRuntime();
            importCmdlet = new ImportAzurePublishSettingsCommand();
            importCmdlet.CommandRuntime = mockCommandRuntime;
            importCmdlet.ImportSubscriptionFile(Data.ValidPublishSettings.First(), null);
            importCmdlet.SubscriptionClient = CreateMockSubscriptionClient();
        }
Ejemplo n.º 13
0
        public static ServiceSettings LoadDefault(
            string path,
            string slot,
            string location,
            string affinityGroup,
            string subscription,
            string storageAccountName,
            string suppliedServiceName,
            string serviceDefinitionName,
            out string serviceName)
        {
            ServiceSettings local;
            ServiceSettings defaultServiceSettings = new ServiceSettings();

            if (string.IsNullOrEmpty(path))
            {
                local = new ServiceSettings();
            }
            else
            {
                Validate.ValidateFileFull(path, Resources.ServiceSettings);
                local = Load(path);
            }

            defaultServiceSettings._slot = GetDefaultSlot(local.Slot, null, slot);
            defaultServiceSettings._location = GetDefaultLocation(local.Location, location);
            defaultServiceSettings._subscription = GetDefaultSubscription(local.Subscription, subscription);
            serviceName = GetServiceName(suppliedServiceName, serviceDefinitionName);
            defaultServiceSettings._storageAccountName = GetDefaultStorageName(local.StorageAccountName, null, storageAccountName, serviceName).ToLower();
            defaultServiceSettings._affinityGroup = affinityGroup;

            return defaultServiceSettings;
        }
        public void SetAzureServiceProjectTestsSubscriptionValid()
        {
            foreach (string item in Data.ValidSubscriptionName)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);
                    setServiceProjectCmdlet.PassThru = false;

                    settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(null, null, null, item, paths.Settings);

                    // Assert subscription is changed
                    //
                    Assert.AreEqual<string>(item, settings.Subscription);
                    Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count);
                }
            }
        }
        public void SetAzureServiceProjectTestsUnknownLocation()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);
                string unknownLocation = "Unknown Location";

                settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(unknownLocation, null, null, null, paths.Settings);

                // Assert location is changed
                //
                Assert.AreEqual<string>(unknownLocation, settings.Location);
                ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                Assert.AreEqual<string>(unknownLocation, settings.Location);
            }
        }
        public void SetAzureServiceProjectTestsSlotTestsInvalidFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => setServiceProjectCmdlet.SetAzureServiceProjectProcess(null, "MyHome", null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Slot"));
            }
        }
        public void SetAzureServiceProjectTestsStorageTests()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                mockCommandRuntime = new MockCommandRuntime();
                setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                settings.Save(paths.Settings);

                settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(null, null, "companystore", null, paths.Settings);

                // Assert storageAccountName is changed
                //
                Assert.AreEqual<string>("companystore", settings.StorageServiceName);
                ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                Assert.AreEqual<string>("companystore", settings.StorageServiceName);
            }
        }
        private LocationName GetSettingsLocation(ServiceSettings settings)
        {
            if (ArgumentConstants.ReverseLocations.ContainsKey(settings.Location.ToLower()))
            {
                return ArgumentConstants.ReverseLocations[settings.Location.ToLower()];
            }

            throw new ArgumentException(string.Format(Resources.RuntimeDeploymentLocationError,
                settings.Location));
        }
Ejemplo n.º 19
0
        private void LoadComponents(ServicePathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);

            try
            {
                Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);
            }
            catch (FileNotFoundException)
            {
                // Try recreating the settings file
                File.WriteAllText(paths.Settings, Resources.SettingsFileEmptyContent);
            }

            Definition = General.DeserializeXmlFile<ServiceDefinition>(paths.Definition);
            CloudConfig = General.DeserializeXmlFile<ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = General.DeserializeXmlFile<ServiceConfiguration>(paths.LocalConfiguration);
            Settings = ServiceSettings.Load(paths.Settings);
        }
        /// <summary>
        /// Set up runtime deployment info for each role in the service - after this method is called, 
        /// each role will have its startup configured with the URI of a runtime package to install at 
        /// role start
        /// </summary>
        /// <param name="service">The service to prepare</param>
        /// <param name="settings">The runtime settings to use to determine location</param>
        /// <param name="manifest"> </param>
        /// <returns>True if requested runtimes were successfully resolved, otherwise false</returns>
        internal bool PrepareRuntimeDeploymentInfo(AzureService service, ServiceSettings settings, string manifest = null)
        {
            CloudRuntimeCollection availableRuntimePackages;
            LocationName deploymentLocation = GetSettingsLocation(settings);
            if (!CloudRuntimeCollection.CreateCloudRuntimeCollection(out availableRuntimePackages, manifestFile: manifest))
            {
                throw new ArgumentException(string.Format(Resources.ErrorRetrievingRuntimesForLocation,
                    deploymentLocation));
            }

            ServiceDefinition definition = service.Components.Definition;
            StringBuilder warningText = new StringBuilder();
            bool shouldWarn = false;
            List<CloudRuntimeApplicator> applicators = new List<CloudRuntimeApplicator>();
            if (definition.WebRole != null)
            {
                foreach (WebRole role in definition.WebRole.Where(role => role.Startup != null && CloudRuntime.GetRuntimeStartupTask(role.Startup) != null))
                {
                    CloudRuntime.ClearRuntime(role);
                    string rolePath = Path.Combine(service.Paths.RootPath, role.name);
                    foreach (CloudRuntime runtime in CloudRuntime.CreateRuntime(role, rolePath))
                    {
                        CloudRuntimePackage package;
                        if (!availableRuntimePackages.TryFindMatch(runtime, out package))
                        {
                            string warning;
                            if (!runtime.ValidateMatch(package, out warning))
                            {
                                shouldWarn = true;
                                warningText.AppendFormat("{0}\r\n", warning);
                            }
                        }

                        applicators.Add(CloudRuntimeApplicator.CreateCloudRuntimeApplicator(runtime,
                            package, role));
                    }
                }
            }

            if (definition.WorkerRole != null)
            {
                foreach (WorkerRole role in definition.WorkerRole.Where(role => role.Startup != null && CloudRuntime.GetRuntimeStartupTask(role.Startup) != null))
                {
                    string rolePath = Path.Combine(service.Paths.RootPath, role.name);
                    CloudRuntime.ClearRuntime(role);
                    foreach (CloudRuntime runtime in CloudRuntime.CreateRuntime(role, rolePath))
                    {
                        CloudRuntimePackage package;
                        if (!availableRuntimePackages.TryFindMatch(runtime, out package))
                        {
                            string warning;
                            if (!runtime.ValidateMatch(package, out warning))
                            {
                                shouldWarn = true;
                                warningText.AppendFormat("{0}\r\n", warning);
                            }
                        }
                        applicators.Add(CloudRuntimeApplicator.CreateCloudRuntimeApplicator(runtime,
                            package, role));
                    }
                }
            }

            if (!shouldWarn || ShouldProcess(string.Format(Resources.RuntimeMismatchWarning,
                _azureService.ServiceName)))
            {
                if (!shouldWarn || Force || ShouldContinue(warningText.ToString(),
                    string.Format(Resources.RuntimeMismatchWarning, _azureService.ServiceName)))
                {
                    applicators.ForEach<CloudRuntimeApplicator>(a => a.Apply());
                    service.Components.Save(service.Paths);
                    return true;
                }
            }

            return false;
        }
        public void SetAzureServiceProjectTestsSlotTests()
        {
            foreach (KeyValuePair<SlotType, string> item in ArgumentConstants.Slots)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);

                    setServiceProjectCmdlet.SetAzureServiceProjectProcess(null, item.Value, null, null, paths.Settings);

                    // Assert slot is changed
                    //
                    settings = ServiceSettings.Load(paths.Settings);
                    Assert.AreEqual<string>(item.Value, settings.Slot);
                }
            }
        }
Ejemplo n.º 22
0
 public static void AreEqualServiceSettings(ServiceSettings expected, ServiceSettings actual)
 {
     AreEqualServiceSettings(expected.Location, expected.Slot, expected.StorageAccountName, expected.Subscription, actual);
 }
Ejemplo n.º 23
0
        public static void AzureServiceExists(string serviceRootPath, string scaffoldFilePath, string serviceName, ServiceSettings settings = null, WebRoleInfo[] webRoles = null, WorkerRoleInfo[] workerRoles = null, string webScaff = null, string workerScaff = null, RoleInfo[] roles = null)
        {
            ServiceComponents components = new Microsoft.WindowsAzure.Management.Utilities.CloudService.ServiceComponents(new Microsoft.WindowsAzure.Management.Utilities.CloudService.ServicePathInfo(serviceRootPath));

            ScaffoldingExists(serviceRootPath, scaffoldFilePath);

            if (webRoles != null)
            {
                for (int i = 0; i < webRoles.Length; i++)
                {
                    ScaffoldingExists(Path.Combine(serviceRootPath, webRoles[i].Name), webScaff);
                }
            }

            if (workerRoles != null)
            {
                for (int i = 0; i < workerRoles.Length; i++)
                {
                    ScaffoldingExists(Path.Combine(serviceRootPath, workerRoles[i].Name), workerScaff);
                }
            }

            AreEqualServiceConfiguration(components.LocalConfig, serviceName, roles);
            AreEqualServiceConfiguration(components.CloudConfig, serviceName, roles);
            IsValidServiceDefinition(components.Definition, serviceName, webRoles, workerRoles);
            AreEqualServiceSettings(settings ?? new ServiceSettings(), components.Settings);
        }
Ejemplo n.º 24
0
 public static void AreEqualServiceSettings(string location, string slot, string storageAccountName, string subscriptionName, ServiceSettings actual)
 {
     Assert.AreEqual<string>(location, actual.Location);
     Assert.AreEqual<string>(slot, actual.Slot);
     Assert.AreEqual<string>(storageAccountName, actual.StorageAccountName);
     Assert.AreEqual<string>(subscriptionName, actual.Subscription);
 }