public void UnitTestDoWork_With_No_Explicit_Roles_Configured_For_White_List_Service()
        {
            MockRepository   mockRepository   = new MockRepository();
            WhiteListService whiteListService = new WhiteListService {
                Name = "wls1"
            };

            WhiteListService[] whiteListServices = new[] { whiteListService };

            // Arrange
            ISubscription mockSubscription = mockRepository.StrictMock <ISubscription>();

            mockSubscription
            .Expect(s => s.ListHostedServices())
            .Repeat.Once()
            .Return(new[] { "wls1" });
            mockSubscription
            .Expect(s => s.SubscriptionId)
            .Repeat.Any()
            .Return(SubscriptionId);
            mockSubscription
            .Expect(s => s.CertificateThumbprint)
            .Repeat.Any()
            .Return(CertificateThumbprint);
            ISubscription[] subscriptions  = new[] { mockSubscription };
            IDeployment     mockDeployment = mockRepository.StrictMock <IDeployment>();
            IOperation      mockOperation  = mockRepository.StrictMock <IOperation>();

            // Act
            // There are no roles configured for the white list service, therefore there should be no checks made against
            // the service, we just accept however it is deployed for instance count or instance size.
            mockRepository.ReplayAll();
            WhiteListForecastWorker whiteListForecastWorker = new WhiteListForecastWorker(subscriptions, mockDeployment, mockOperation, whiteListServices, 1);

            whiteListForecastWorker.DoWork();
            whiteListForecastWorker.DoWork(); // Call twice to test the polling interval (nothing should be invoked the second time).

            // Assert
            mockRepository.VerifyAll();
        }
Beispiel #2
0
        public Host()
        {
            this.ForecastWorkers = new List <ForecastWorker>();
            WhiteListForecastWorker whiteListForecastWorker = StealFocusForecastConfiguration.GetWhiteListForecastWorker();

            if (whiteListForecastWorker != null)
            {
                this.ForecastWorkers.Add(whiteListForecastWorker);
            }

            DeploymentDeleteForecastWorker[] deploymentDeleteForecastWorkers = StealFocusForecastConfiguration.GetDeploymentDeleteForecastWorkers();
            foreach (DeploymentDeleteForecastWorker deploymentDeleteForecastWorker in deploymentDeleteForecastWorkers)
            {
                this.ForecastWorkers.Add(deploymentDeleteForecastWorker);
            }

            DeploymentCreateForecastWorker[] deploymentCreateForecastWorkers = StealFocusForecastConfiguration.GetDeploymentCreateForecastWorkers();
            foreach (DeploymentCreateForecastWorker deploymentCreateForecastWorker in deploymentCreateForecastWorkers)
            {
                this.ForecastWorkers.Add(deploymentCreateForecastWorker);
            }

            ScheduledHorizontalScaleForecastWorker[] scheduledHorizontalScaleForecastWorkers = StealFocusForecastConfiguration.GetScheduledHorizontalScaleForecastWorkers();
            foreach (ScheduledHorizontalScaleForecastWorker scheduledHorizontalScaleForecastWorker in scheduledHorizontalScaleForecastWorkers)
            {
                this.ForecastWorkers.Add(scheduledHorizontalScaleForecastWorker);
            }

            TableDeleteForecastWorker[] tableDeleteForecastWorkers = StealFocusForecastConfiguration.GetTableDeleteForecastWorkers();
            foreach (TableDeleteForecastWorker tableDeleteForecastWorker in tableDeleteForecastWorkers)
            {
                this.ForecastWorkers.Add(tableDeleteForecastWorker);
            }

            BlobContainerDeleteForecastWorker[] blobContainerDeleteForecastWorkers = StealFocusForecastConfiguration.GetBlobContainerDeleteForecastWorkers();
            foreach (BlobContainerDeleteForecastWorker blobContainerDeleteForecastWorker in blobContainerDeleteForecastWorkers)
            {
                this.ForecastWorkers.Add(blobContainerDeleteForecastWorker);
            }
        }
        public void UnitTestGetWhiteListForecastWorker()
        {
            WhiteListForecastWorker whiteListForecastWorker = StealFocusForecastConfiguration.GetWhiteListForecastWorker();

            Assert.IsNotNull(whiteListForecastWorker);
        }
        public void UnitTestDoWork_With_One_Role_Having_Instance_Count_Too_High_And_Second_Role_Having_Instance_Size_Too_Large()
        {
            MockRepository   mockRepository   = new MockRepository();
            WhiteListService whiteListService = new WhiteListService {
                Name = "wls1"
            };
            WhiteListRole whiteListRole = new WhiteListRole {
                Name = "wlr1", MaxInstanceSize = InstanceSize.ExtraSmall, MaxInstanceCount = 1
            };

            whiteListService.Roles.Add(whiteListRole);
            WhiteListService[] whiteListServices = new[] { whiteListService };

            // Arrange
            ISubscription mockSubscription = mockRepository.StrictMock <ISubscription>();

            mockSubscription
            .Expect(s => s.ListHostedServices())
            .Repeat.Once()
            .Return(new[] { "bls1", "wls1" });
            mockSubscription
            .Expect(s => s.SubscriptionId)
            .Repeat.Any()
            .Return(SubscriptionId);
            mockSubscription
            .Expect(s => s.CertificateThumbprint)
            .Repeat.Any()
            .Return(CertificateThumbprint);
            ISubscription[] subscriptions  = new[] { mockSubscription };
            IDeployment     mockDeployment = mockRepository.StrictMock <IDeployment>();
            IOperation      mockOperation  = mockRepository.StrictMock <IOperation>();

            // Delete the black listed service from Staging and Production
            SetupDeleteRequestWithStatusCheck(mockDeployment, mockOperation, "bls1", DeploymentSlot.Staging, "deleteRequest1");
            SetupDeleteRequestWithStatusCheck(mockDeployment, mockOperation, "bls1", DeploymentSlot.Production, "deleteRequest2");

            // Get the instance size of White List Role 1 from Staging, all okay.
            mockDeployment
            .Expect(d => d.GetInstanceSize(SubscriptionId, CertificateThumbprint, "wls1", DeploymentSlot.Staging, "wlr1"))
            .Repeat.Once()
            .Return(InstanceSize.ExtraSmall.ToString());

            // Get the instance count of White List Role 1 from Staging, horizontally scale as a result.
            mockDeployment
            .Expect(d => d.GetInstanceCount(SubscriptionId, CertificateThumbprint, "wls1", DeploymentSlot.Staging, "wlr1"))
            .Repeat.Once()
            .Return(2);
            SetupHorizontallyScaleWithStatusCheck(mockDeployment, mockOperation, "wls1", DeploymentSlot.Staging, new[] { new HorizontalScale {
                                                                                                                             RoleName = "wlr1", InstanceCount = 1
                                                                                                                         } }, "scaleRequest1");

            // Get the instance size of the White List Role 1 from Production, delete as a result.
            mockDeployment
            .Expect(d => d.GetInstanceSize(SubscriptionId, CertificateThumbprint, "wls1", DeploymentSlot.Production, "wlr1"))
            .Repeat.Once()
            .Return(InstanceSize.ExtraLarge.ToString());
            SetupDeleteRequestWithStatusCheck(mockDeployment, mockOperation, "wls1", DeploymentSlot.Production, "deleteRequest3");

            // Act
            mockRepository.ReplayAll();
            WhiteListForecastWorker whiteListForecastWorker = new WhiteListForecastWorker(subscriptions, mockDeployment, mockOperation, whiteListServices, 1);

            whiteListForecastWorker.DoWork();
            whiteListForecastWorker.DoWork(); // Call twice to test the polling interval (nothing should be invoked the second time).

            // Assert
            mockRepository.VerifyAll();
        }
Beispiel #5
0
        internal static WhiteListForecastWorker GetWhiteListForecastWorker()
        {
            IConfigurationSource   configurationSource    = GetConfigurationSource();
            WhiteListConfiguration whiteListConfiguration = configurationSource.GetWindowsAzureHostedServiceWhiteListConfiguration();

            if (whiteListConfiguration != null)
            {
                SubscriptionConfiguration[] subscriptionConfigurations = configurationSource.GetAllWindowsAzureSubscriptionConfigurations();
                ISubscription[]             subscriptions = new ISubscription[subscriptionConfigurations.Length];
                for (int i = 0; i < subscriptionConfigurations.Length; i++)
                {
                    subscriptions[i] = subscriptionConfigurations[i].Convert();
                }

                if (whiteListConfiguration.IncludeDeploymentCreateServices)
                {
                    foreach (DeploymentCreateConfiguration deploymentCreateConfiguration in configurationSource.GetWindowsAzureDeploymentCreateConfigurations())
                    {
                        bool alreadyIncluded = false;
                        foreach (WhiteListService configuredWhiteListService in whiteListConfiguration.Services)
                        {
                            if (configuredWhiteListService.Name == deploymentCreateConfiguration.ServiceName)
                            {
                                alreadyIncluded = true;
                            }
                        }

                        if (!alreadyIncluded)
                        {
                            WhiteListService whiteListService = new WhiteListService {
                                Name = deploymentCreateConfiguration.ServiceName
                            };
                            whiteListConfiguration.Services.Add(whiteListService);
                        }
                    }
                }

                if (whiteListConfiguration.IncludeDeploymentDeleteServices)
                {
                    foreach (DeploymentDeleteConfiguration deploymentDeleteConfiguration in configurationSource.GetWindowsAzureDeploymentDeleteConfigurations())
                    {
                        bool alreadyIncluded = false;
                        foreach (WhiteListService configuredWhiteListService in whiteListConfiguration.Services)
                        {
                            if (configuredWhiteListService.Name == deploymentDeleteConfiguration.ServiceName)
                            {
                                alreadyIncluded = true;
                            }
                        }

                        if (!alreadyIncluded)
                        {
                            WhiteListService whiteListService = new WhiteListService {
                                Name = deploymentDeleteConfiguration.ServiceName
                            };
                            whiteListConfiguration.Services.Add(whiteListService);
                        }
                    }
                }

                if (whiteListConfiguration.IncludeHorizontalScaleServices)
                {
                    foreach (ScheduledHorizontalScaleConfiguration windowsAzureScheduledHorizontalScaleConfiguration in configurationSource.GetWindowsAzureScheduledHorizontalScaleConfigurations())
                    {
                        bool alreadyIncluded = false;
                        foreach (WhiteListService configuredWhiteListService in whiteListConfiguration.Services)
                        {
                            if (configuredWhiteListService.Name == windowsAzureScheduledHorizontalScaleConfiguration.ServiceName)
                            {
                                alreadyIncluded = true;
                            }
                        }

                        if (!alreadyIncluded)
                        {
                            WhiteListService whiteListService = new WhiteListService {
                                Name = windowsAzureScheduledHorizontalScaleConfiguration.ServiceName
                            };
                            whiteListConfiguration.Services.Add(whiteListService);
                        }
                    }
                }

                WhiteListForecastWorker whiteListForecastWorker = new WhiteListForecastWorker(
                    subscriptions,
                    new Deployment(),
                    new Operation(),
                    whiteListConfiguration.Services.ToArray(),
                    whiteListConfiguration.PollingIntervalInMinutes);
                return(whiteListForecastWorker);
            }

            return(null);
        }