Пример #1
0
        public void CrudProfileFullCycle()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string profileName = TestUtilities.GenerateName("hydratestwatmv2profile");
                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                // Create the profile
                ProfileCreateOrUpdateResponse createResponse = trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = TrafficManagerHelper.GenerateDefaultProfile(profileName)
                });

                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // Get the profile
                ProfileGetResponse getResponse = trafficManagerClient.Profiles.Get(
                    resourceGroup.Name,
                    profileName);

                Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);

                // Delete the profile
                AzureOperationResponse deleteResponse = trafficManagerClient.Profiles.Delete(resourceGroup.Name, profileName);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
            }
        }
        public static ProfileGetResponse Unmarshall(UnmarshallerContext context)
        {
            ProfileGetResponse profileGetResponse = new ProfileGetResponse();

            profileGetResponse.HttpResponse             = context.HttpResponse;
            profileGetResponse.ErrorCode                = context.IntegerValue("ProfileGet.ErrorCode");
            profileGetResponse.ErrorMessage             = context.StringValue("ProfileGet.ErrorMessage");
            profileGetResponse.Success                  = context.BooleanValue("ProfileGet.Success");
            profileGetResponse.RequestId                = context.StringValue("ProfileGet.RequestId");
            profileGetResponse.UserId                   = context.LongValue("ProfileGet.UserId");
            profileGetResponse.AutoInstall              = context.BooleanValue("ProfileGet.AutoInstall");
            profileGetResponse.EnableInstallAgentNewECS = context.BooleanValue("ProfileGet.EnableInstallAgentNewECS");

            return(profileGetResponse);
        }
Пример #3
0
        private string testCreateDefinition(LoadBalancingMethod testMethod, DefinitionEndpointCreateParameters endpoint)
        {
            //Arrange
            using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase())
            {
                string profileName = _testFixture.CreateTestProfile();

                _testFixture.CreateADefinitionAndEnableTheProfile(
                    profileName,
                    testMethod,
                    endpoint);

                //Act, try 'List'
                DefinitionsListResponse listResponse = _testFixture.TrafficManagerClient.Definitions.List(profileName);

                //Assert
                Assert.Equal(1, listResponse.Count());
                Assert.Equal(testMethod, listResponse.First().Policy.LoadBalancingMethod);

                //Act, try 'Get'
                DefinitionGetResponse getResponse = _testFixture.TrafficManagerClient.Definitions.Get(profileName);

                //Assert
                Assert.Equal(testMethod, getResponse.Definition.Policy.LoadBalancingMethod);
                Assert.Equal(1, getResponse.Definition.Policy.Endpoints.Count);
                Assert.Equal(endpoint.Type, getResponse.Definition.Policy.Endpoints[0].Type);
                Assert.Equal(endpoint.Weight ?? 1, getResponse.Definition.Policy.Endpoints[0].Weight);
                Assert.Equal(endpoint.Location, getResponse.Definition.Policy.Endpoints[0].Location);
                Assert.Equal(endpoint.MinChildEndpoints, getResponse.Definition.Policy.Endpoints[0].MinChildEndpoints);

                //verify the profile itself has an associated definition enabled.
                //(due to the service limitation of one defintion per one profile, the enabled version is 1 always
                ProfileGetResponse profileGetResponse = _testFixture.TrafficManagerClient.Profiles.Get(profileName);
                Assert.Equal(1, profileGetResponse.Profile.StatusDetails.EnabledDefinitionVersion);

                return(profileGetResponse.Profile.DomainName);
            }
        }
Пример #4
0
        public void UpdateProfile()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                //Arrange
                using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase())
                {
                    string profileName = _testFixture.CreateTestProfile();
                    string serviceName = _testFixture.CreateTestCloudService();
                    _testFixture.CreateADefinitionAndEnableTheProfile(profileName, serviceName,
                                                                      EndpointType.CloudService);

                    //Act (disable the profile)
                    _testFixture.TrafficManagerClient.Profiles.Update(profileName,
                                                                      ProfileDefinitionStatus.Disabled,
                                                                      1 /*Version will always be 1*/);

                    //Assert
                    ProfileGetResponse profileGetResponse = _testFixture.TrafficManagerClient.Profiles.Get(profileName);
                    Assert.True(profileGetResponse.Profile.Status == ProfileDefinitionStatus.Disabled);
                }
            }
        }
Пример #5
0
        public void CreateProfile()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                //Arrange
                using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase())
                {
                    string testDomainName  = _testFixture.GenerateRandomDomainName();
                    string testProfileName = _testFixture.CreateTestProfile(testDomainName);

                    //Act
                    ProfileGetResponse profileGetResponse =
                        _testFixture.TrafficManagerClient.Profiles.Get(testProfileName);

                    //Assert
                    Assert.True(profileGetResponse.StatusCode == HttpStatusCode.OK);
                    Assert.Equal <string>(testProfileName, profileGetResponse.Profile.Name);
                    Assert.Equal <string>(testDomainName, profileGetResponse.Profile.DomainName);
                    Assert.True(profileGetResponse.Profile.Definitions.Count == 0);
                    Assert.True(profileGetResponse.Profile.Status == ProfileDefinitionStatus.Disabled);
                }
            }
        }
        /// <summary>
        /// Returns profile details, including all definition versions and
        /// their statuses.  (see
        /// http://msdn.microsoft.com/en-us/library/hh758248.aspx for more
        /// information)
        /// </summary>
        /// <param name='profileName'>
        /// Required. The name of the profile.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get Profile Details operation response.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.TrafficManager.Models.ProfileGetResponse> GetAsync(string profileName, CancellationToken cancellationToken)
        {
            // Validate
            if (profileName == null)
            {
                throw new ArgumentNullException("profileName");
            }

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("profileName", profileName);
                Tracing.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            // Construct URL
            string url     = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/WATM/profiles/" + profileName.Trim();
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2011-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ProfileGetResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new ProfileGetResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement profileElement = responseDoc.Element(XName.Get("Profile", "http://schemas.microsoft.com/windowsazure"));
                    if (profileElement != null)
                    {
                        Profile profileInstance = new Profile();
                        result.Profile = profileInstance;

                        XElement domainNameElement = profileElement.Element(XName.Get("DomainName", "http://schemas.microsoft.com/windowsazure"));
                        if (domainNameElement != null)
                        {
                            string domainNameInstance = domainNameElement.Value;
                            profileInstance.DomainName = domainNameInstance;
                        }

                        XElement nameElement = profileElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                        if (nameElement != null)
                        {
                            string nameInstance = nameElement.Value;
                            profileInstance.Name = nameInstance;
                        }

                        XElement statusElement = profileElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
                        if (statusElement != null)
                        {
                            ProfileDefinitionStatus statusInstance = ((ProfileDefinitionStatus)Enum.Parse(typeof(ProfileDefinitionStatus), statusElement.Value, true));
                            profileInstance.Status = statusInstance;
                        }

                        XElement statusDetailsElement = profileElement.Element(XName.Get("StatusDetails", "http://schemas.microsoft.com/windowsazure"));
                        if (statusDetailsElement != null)
                        {
                            ProfileStatusDetails statusDetailsInstance = new ProfileStatusDetails();
                            profileInstance.StatusDetails = statusDetailsInstance;

                            XElement enabledVersionElement = statusDetailsElement.Element(XName.Get("EnabledVersion", "http://schemas.microsoft.com/windowsazure"));
                            if (enabledVersionElement != null)
                            {
                                int enabledVersionInstance = int.Parse(enabledVersionElement.Value, CultureInfo.InvariantCulture);
                                statusDetailsInstance.EnabledDefinitionVersion = enabledVersionInstance;
                            }
                        }

                        XElement definitionsSequenceElement = profileElement.Element(XName.Get("Definitions", "http://schemas.microsoft.com/windowsazure"));
                        if (definitionsSequenceElement != null)
                        {
                            foreach (XElement definitionsElement in definitionsSequenceElement.Elements(XName.Get("Definition", "http://schemas.microsoft.com/windowsazure")))
                            {
                                DefinitionStatusAndVersion definitionInstance = new DefinitionStatusAndVersion();
                                profileInstance.Definitions.Add(definitionInstance);

                                XElement statusElement2 = definitionsElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
                                if (statusElement2 != null)
                                {
                                    ProfileDefinitionStatus statusInstance2 = ((ProfileDefinitionStatus)Enum.Parse(typeof(ProfileDefinitionStatus), statusElement2.Value, true));
                                    definitionInstance.Status = statusInstance2;
                                }

                                XElement versionElement = definitionsElement.Element(XName.Get("Version", "http://schemas.microsoft.com/windowsazure"));
                                if (versionElement != null)
                                {
                                    int versionInstance = int.Parse(versionElement.Value, CultureInfo.InvariantCulture);
                                    definitionInstance.Version = versionInstance;
                                }
                            }
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Пример #7
0
        public TrafficManagerProfile GetTrafficManagerProfile(string resourceGroupName, string profileName)
        {
            ProfileGetResponse response = this.TrafficManagerManagementClient.Profiles.Get(resourceGroupName, profileName);

            return(TrafficManagerClient.GetPowershellTrafficManagerProfile(resourceGroupName, profileName, response.Profile));
        }