Exemplo n.º 1
0
        public ProfileWithDefinition NewAzureTrafficManagerProfile(
            string profileName,
            string domainName,
            string loadBalancingMethod,
            int monitorPort,
            string monitorProtocol,
            string monitorRelativePath,
            int ttl)
        {
            // Create the profile
            this.CreateTrafficManagerProfile(profileName, domainName);

            // Create the definition
            DefinitionCreateParameters definitionParameter = this.InstantiateTrafficManagerDefinition(
                loadBalancingMethod,
                monitorPort,
                monitorProtocol,
                monitorRelativePath,
                ttl,
                // not adding any endpoints at this time
                new List <TrafficManagerEndpoint>());

            this.CreateTrafficManagerDefinition(profileName, definitionParameter);

            return(this.GetTrafficManagerProfileWithDefinition(profileName));
        }
Exemplo n.º 2
0
        public DefinitionCreateParameters InstantiateTrafficManagerDefinition(Definition definition)
        {
            var definitionCreateParams = new DefinitionCreateParameters();

            var endpoints = new List <DefinitionEndpointCreateParameters>();

            foreach (DefinitionEndpointResponse endpointReponse in definition.Policy.Endpoints)
            {
                var endpoint = new DefinitionEndpointCreateParameters
                {
                    DomainName        = endpointReponse.DomainName,
                    Location          = endpointReponse.Location,
                    Type              = endpointReponse.Type,
                    Status            = endpointReponse.Status,
                    Weight            = endpointReponse.Weight,
                    MinChildEndpoints = endpointReponse.MinChildEndpoints
                };

                endpoints.Add(endpoint);
            }

            definitionCreateParams.Policy = new DefinitionPolicyCreateParameters
            {
                Endpoints           = endpoints,
                LoadBalancingMethod = definition.Policy.LoadBalancingMethod
            };

            definitionCreateParams.DnsOptions = definition.DnsOptions;
            definitionCreateParams.Monitors   = definition.Monitors;

            return(definitionCreateParams);
        }
        public void CreateADefinitionAndEnableTheProfile(
            string profileName,
            LoadBalancingMethod loadBalancingMethod,
            IList <DefinitionEndpointCreateParameters> endpoints)
        {
            DefinitionCreateParameters       definitionParameter = new DefinitionCreateParameters();
            DefinitionMonitor                monitor             = new DefinitionMonitor();
            DefinitionDnsOptions             dnsOption           = new DefinitionDnsOptions();
            DefinitionPolicyCreateParameters policyParameter     = new DefinitionPolicyCreateParameters();
            DefinitionMonitorHTTPOptions     monitorHttpOption   = new DefinitionMonitorHTTPOptions();

            definitionParameter.DnsOptions = dnsOption;
            definitionParameter.Policy     = policyParameter;
            definitionParameter.Monitors.Add(monitor);
            monitor.HttpOptions = monitorHttpOption;

            dnsOption.TimeToLiveInSeconds = 30;

            monitorHttpOption.RelativePath       = "/randomFile.aspx";
            monitorHttpOption.Verb               = "GET";
            monitorHttpOption.ExpectedStatusCode = (int)HttpStatusCode.OK;

            monitor.Protocol = DefinitionMonitorProtocol.Http;
            //Set fixed values required by services
            monitor.IntervalInSeconds         = 30;
            monitor.TimeoutInSeconds          = 10;
            monitor.ToleratedNumberOfFailures = 3;
            monitor.Port = 80;

            policyParameter.LoadBalancingMethod = loadBalancingMethod;
            policyParameter.Endpoints           = endpoints;

            TrafficManagerClient.Definitions.Create(profileName, definitionParameter);
        }
Exemplo n.º 4
0
        public override void ExecuteCmdlet()
        {
            ProfileWithDefinition profile = TrafficManagerProfile.GetInstance();

            if (string.IsNullOrEmpty(Name))
            {
                this.Name = profile.Name;
            }

            if (!profile.Name.Equals(Name))
            {
                throw new Exception(Resources.SetTrafficManagerProfileAmbiguous);
            }

            DefinitionCreateParameters updatedDefinitionAsParam =
                TrafficManagerClient.InstantiateTrafficManagerDefinition(
                    LoadBalancingMethod ?? profile.LoadBalancingMethod.ToString(),
                    MonitorPort.HasValue ? MonitorPort.Value : profile.MonitorPort,
                    MonitorProtocol ?? profile.MonitorProtocol.ToString(),
                    MonitorRelativePath ?? profile.MonitorRelativePath,
                    Ttl.HasValue ? Ttl.Value : profile.TimeToLiveInSeconds,
                    profile.Endpoints);

            ProfileWithDefinition newDefinition =
                TrafficManagerClient.AssignDefinitionToProfile(Name, updatedDefinitionAsParam);

            WriteObject(newDefinition);
        }
Exemplo n.º 5
0
        public DefinitionCreateParameters InstantiateTrafficManagerDefinition(
            string loadBalancingMethod,
            int monitorPort,
            string monitorProtocol,
            string monitorRelativePath,
            int ttl,
            IList <TrafficManagerEndpoint> endpoints)
        {
            // Create the definition
            var definitionParameter = new DefinitionCreateParameters();
            var dnsOptions          = new DefinitionDnsOptions();
            var monitor             = new DefinitionMonitor();
            var policyParameter     = new DefinitionPolicyCreateParameters();
            var monitorHttpOption   = new DefinitionMonitorHTTPOptions();

            dnsOptions.TimeToLiveInSeconds = ttl;

            monitorHttpOption.RelativePath       = monitorRelativePath;
            monitorHttpOption.Verb               = Constants.monitorHttpOptionVerb;
            monitorHttpOption.ExpectedStatusCode = Constants.monitorHttpOptionExpectedStatusCode;

            monitor.Protocol =
                (DefinitionMonitorProtocol)Enum.Parse(typeof(DefinitionMonitorProtocol), monitorProtocol);
            monitor.IntervalInSeconds         = Constants.monitorIntervalInSeconds;
            monitor.TimeoutInSeconds          = Constants.monitorTimeoutInSeconds;
            monitor.ToleratedNumberOfFailures = Constants.monitorToleratedNumberOfFailures;
            monitor.Port = monitorPort;
            policyParameter.LoadBalancingMethod =
                (LoadBalancingMethod)Enum.Parse(typeof(LoadBalancingMethod), loadBalancingMethod);

            policyParameter.Endpoints = new List <DefinitionEndpointCreateParameters>();
            foreach (TrafficManagerEndpoint endpoint in endpoints)
            {
                var endpointParam = new DefinitionEndpointCreateParameters
                {
                    DomainName        = endpoint.DomainName,
                    Location          = endpoint.Location,
                    Status            = endpoint.Status,
                    Type              = endpoint.Type,
                    Weight            = endpoint.Weight,
                    MinChildEndpoints = endpoint.MinChildEndpoints
                };

                policyParameter.Endpoints.Add(endpointParam);
            }

            definitionParameter.DnsOptions = dnsOptions;
            definitionParameter.Policy     = policyParameter;
            definitionParameter.Monitors.Add(monitor);
            monitor.HttpOptions = monitorHttpOption;

            return(definitionParameter);
        }
Exemplo n.º 6
0
 public ProfileWithDefinition AssignDefinitionToProfile(string profileName, DefinitionCreateParameters definitionParameter)
 {
     this.Client.Definitions.Create(profileName, definitionParameter);
     return(this.GetTrafficManagerProfileWithDefinition(profileName));
 }
Exemplo n.º 7
0
 public void CreateTrafficManagerDefinition(string profileName, DefinitionCreateParameters parameters)
 {
     this.Client.Definitions.Create(profileName, parameters);
 }
        public void ProcessSetProfileTestAllArgs()
        {
            // Setup
            ProfileWithDefinition oldProfileWithDefinition = defaultProfileWithDefinition;

            var newProfileWithDefinition = new ProfileWithDefinition
            {
                DomainName          = ProfileDomainName,
                Name                = ProfileName,
                Endpoints           = new List <TrafficManagerEndpoint>(),
                LoadBalancingMethod = NewLoadBalancingMethod,
                MonitorPort         = NewMonitorPort,
                Status              = ProfileDefinitionStatus.Enabled,
                MonitorRelativePath = NewMonitorRelativePath,
                MonitorProtocol     = NewMonitorProtocol,
                TimeToLiveInSeconds = NewTtl
            };


            var newMonitor = new DefinitionMonitor
            {
                HttpOptions = new DefinitionMonitorHTTPOptions
                {
                    ExpectedStatusCode = MonitorExpectedStatusCode,
                    RelativePath       = NewMonitorRelativePath,
                    Verb = Verb
                }
            };

            var updateDefinitionCreateParameters = new DefinitionCreateParameters
            {
                DnsOptions = new DefinitionDnsOptions
                {
                    TimeToLiveInSeconds = NewTtl
                },
                Policy = new DefinitionPolicyCreateParameters
                {
                    LoadBalancingMethod = NewLoadBalancingMethod,
                    Endpoints           = new DefinitionEndpointCreateParameters[0]
                },
                Monitors = new[] { newMonitor }
            };

            clientMock
            .Setup(c => c.AssignDefinitionToProfile(ProfileName, It.IsAny <DefinitionCreateParameters>()))
            .Returns(newProfileWithDefinition);

            clientMock
            .Setup(c => c.InstantiateTrafficManagerDefinition(
                       NewLoadBalancingMethod.ToString(),
                       NewMonitorPort,
                       NewMonitorProtocol.ToString(),
                       NewMonitorRelativePath,
                       NewTtl,
                       oldProfileWithDefinition.Endpoints))
            .Returns(updateDefinitionCreateParameters);

            cmdlet = new SetAzureTrafficManagerProfile
            {
                Name = ProfileName,
                LoadBalancingMethod = NewLoadBalancingMethod.ToString(),
                MonitorPort         = NewMonitorPort,
                MonitorProtocol     = NewMonitorProtocol.ToString(),
                MonitorRelativePath = NewMonitorRelativePath,
                Ttl = NewTtl,
                TrafficManagerClient  = clientMock.Object,
                CommandRuntime        = mockCommandRuntime,
                TrafficManagerProfile = oldProfileWithDefinition
            };


            // Action
            cmdlet.ExecuteCmdlet();
            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(newProfileWithDefinition.Name, actual.Name);
            Assert.AreEqual(newProfileWithDefinition.DomainName, actual.DomainName);
            Assert.AreEqual(newProfileWithDefinition.LoadBalancingMethod, actual.LoadBalancingMethod);
            Assert.AreEqual(newProfileWithDefinition.MonitorPort, actual.MonitorPort);
            Assert.AreEqual(newProfileWithDefinition.MonitorProtocol, actual.MonitorProtocol);
            Assert.AreEqual(newProfileWithDefinition.MonitorRelativePath, actual.MonitorRelativePath);
            Assert.AreEqual(newProfileWithDefinition.TimeToLiveInSeconds, actual.TimeToLiveInSeconds);

            // Most important assert; the cmdlet is passing the right parameters
            clientMock.Verify(c => c.InstantiateTrafficManagerDefinition(
                                  NewLoadBalancingMethod.ToString(),
                                  NewMonitorPort,
                                  NewMonitorProtocol.ToString(),
                                  NewMonitorRelativePath,
                                  NewTtl,
                                  oldProfileWithDefinition.Endpoints), Times.Once());
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new definition for a specified profile.  (see
 /// http://msdn.microsoft.com/en-us/library/hh758257.aspx for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.TrafficManager.IDefinitionOperations.
 /// </param>
 /// <param name='profileName'>
 /// Required. The name of the profile to create a new definition for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Definition operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task <OperationResponse> CreateAsync(this IDefinitionOperations operations, string profileName, DefinitionCreateParameters parameters)
 {
     return(operations.CreateAsync(profileName, parameters, CancellationToken.None));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new definition for a specified profile.  (see
 /// http://msdn.microsoft.com/en-us/library/hh758257.aspx for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.TrafficManager.IDefinitionOperations.
 /// </param>
 /// <param name='profileName'>
 /// Required. The name of the profile to create a new definition for.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Definition operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse Create(this IDefinitionOperations operations, string profileName, DefinitionCreateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IDefinitionOperations)s).CreateAsync(profileName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }