Exemplo n.º 1
0
        public void TestWithValidCredentials()
        {
            string accessToken = "somestring";
            IHDInsightSubscriptionCredentials credentials = new HDInsightAccessTokenCredential()
            {
                AccessToken         = accessToken,
                DeploymentNamespace = "hdinsight",
                Endpoint            = new Uri("http://notrdfe.com/"),
                SubscriptionId      = Guid.NewGuid()
            };
            Exception error = null;

            try
            {
                IHttpClientAbstraction validAbstraction =
                    ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(credentials, false);
                Assert.IsTrue(validAbstraction.RequestHeaders.ContainsKey("Authorization"));
                Assert.AreEqual(validAbstraction.RequestHeaders["Authorization"], "Bearer " + accessToken);
            }
            catch (NotSupportedException e)
            {
                error = e;
            }
            Assert.IsNull(error);
        }
Exemplo n.º 2
0
        public void ListClustersWithAccessToken()
        {
            string accessToken = "eyiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1THdqcHdBSk9NOW4tQSJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC83MmY5ODhiZi04NmYxLTQxYWYtOTFhYi0yZDdjZDAxMWRiNDcvIiwiaWF0IjoxMzg0ODAyNzY5LCJuYmYiOjEzODQ4MDI3NjksImV4cCI6MTM4NDgwNjM2OSwidmVyIjoiMS4wIiwidGlkIjoiNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3Iiwib2lkIjoiMzMxMDNiMzEtZTNlNS00NzAxLTk1YmYtOGNjZTA1MTY3MzdjIiwidXBuIjoicGhhbmlyYWpAbWljcm9zb2Z0LmNvbSIsInVuaXF1ZV9uYW1lIjoicGhhbmlyYWpAbWljcm9zb2Z0LmNvbSIsInN1YiI6ImtMYVVCODA2TmxYMjdJSnhka2NtR0FBSUNpSk94T3lVSVZCeVhQMlNIbnciLCJwdWlkIjoiMTAwMzAwMDA4MDFCQ0IxNSIsImZhbWlseV9uYW1lIjoiWWF5YXZhcmFtIE5hcmFzaW1oYSIsImdpdmVuX25hbWUiOiJQaGFuaSBSYWoiLCJhcHBpZCI6IjE5NTBhMjU4LTIyN2ItNGUzMS1hOWNmLTcxNzQ5NTk0NWZjMiIsImFwcGlkYWNyIjoiMCIsInNjcCI6InVzZXJfaW1wZXJzb25hdGlvbiIsImFjciI6IjEifQ.UejKWEUhF35F7NqhfFg73zoXclmrWhCTowpc78TICFOvMzFQYzR8bpBc-NtGOpwcFDN2yIp1eJhPV_QL_gl2Y4HXIl-_ziw_g9KhYeZXTxnhvpS9zquefzTiIoZL4eo-nm6cBkxvHqaeq6P9mkgp6Y3xd9Py1YRkkwKndnoynzWPKHipO0pL_vEpJgMLHzDLkPq2RbFg4ANp35vfxQpPhC0YrbjWYiwsyrsrjYHN9rIkfqyhePcEaLH-jNdZFzL5yJHo3JiDD6CvbeiFpY4_S1y9PEFHSwbXSAmgKBzr9SzBTR0Pm54FMVvsHsYyTdpMS9Pmdzzd9qr3FyXsUrXTaQ";
            IHDInsightSubscriptionCredentials credentials = new HDInsightAccessTokenCredential()
            {
                AccessToken         = accessToken,
                DeploymentNamespace = "hdinsight",
                SubscriptionId      = IntegrationTestBase.TestCredentials.SubscriptionId
            };
            Exception error = null;

            try
            {
                var client     = HDInsightClient.Connect(credentials);
                var myClusters = client.ListClusters();
            }
            catch (NotSupportedException e)
            {
                error = e;
            }
            Assert.IsNull(error);
        }
Exemplo n.º 3
0
        [Timeout(5 * 60 * 1000)] // ms
        public async Task ICanPerformA_CreateDeleteContainers_Using_RestClient_ManualEnvironment()
        {
            var creds = IntegrationTestBase.GetCredentialsForEnvironmentType(EnvironmentType.Current);

            if (creds == null)
            {
                Assert.Inconclusive("Alternative Azure Endpoint wasn't set up");
            }

            IHDInsightCertificateCredential   certCreds       = IntegrationTestBase.GetValidCredentials() as IHDInsightCertificateCredential;
            IHDInsightAccessTokenCredential   tokenCreds      = IntegrationTestBase.GetValidCredentials() as IHDInsightAccessTokenCredential;
            IHDInsightSubscriptionCredentials tempCredentials = null;

            if (certCreds != null)
            {
                tempCredentials = new HDInsightCertificateCredential()
                {
                    SubscriptionId = creds.SubscriptionId,
                    Certificate    = certCreds.Certificate
                };
            }
            else if (tokenCreds != null)
            {
                tempCredentials = new HDInsightAccessTokenCredential()
                {
                    SubscriptionId = creds.SubscriptionId,
                    AccessToken    = tokenCreds.AccessToken
                };
            }
            IHDInsightSubscriptionCredentials credentials = new AlternativeEnvironmentIHDInsightSubscriptionCertificateCredentialsFactory().Create(tempCredentials);

            var client         = new HDInsightManagementRestClient(credentials, GetAbstractionContext(), false);
            var dnsName        = GetRandomClusterName();
            var location       = "East US";
            var subscriptionId = credentials.SubscriptionId;

            var createPayload = String.Format(CreateContainerGenericRequest, dnsName, location, subscriptionId, Guid.NewGuid());
            var xmlReader     = new XmlTextReader(new StringReader(createPayload));
            var resource      = new Resource()
            {
                IntrinsicSettings = new[] { new XmlDocument().ReadNode(xmlReader) }
            };
            var result = await client.ListCloudServices();

            Assert.IsTrue(!this.ContainsContainer(dnsName, result.Content));

            await client.CreateContainer(dnsName, location, resource.SerializeToXml());

            result = await client.ListCloudServices();

            bool containsContiner = false;

            while (!containsContiner)
            {
                result = await client.ListCloudServices();

                containsContiner = this.ContainsContainer(dnsName, result.Content);
                await Task.Delay(100);
            }

            await client.DeleteContainer(dnsName, location);

            containsContiner = true;
            while (containsContiner)
            {
                result = await client.ListCloudServices();

                containsContiner = this.ContainsContainer(dnsName, result.Content);
                await Task.Delay(100);
            }
        }
Exemplo n.º 4
0
        [Timeout(5 * 60 * 1000)] // ms
        public async Task ICanPerformA_CreateDeleteContainers_Using_RestClient_ManualEnvironment()
        {
            var creds = IntegrationTestBase.GetCredentialsForEnvironmentType(EnvironmentType.Current);

            if (creds == null)
                Assert.Inconclusive("Alternative Azure Endpoint wasn't set up");
            
            IHDInsightCertificateCredential certCreds = IntegrationTestBase.GetValidCredentials() as IHDInsightCertificateCredential;
            IHDInsightAccessTokenCredential tokenCreds = IntegrationTestBase.GetValidCredentials() as IHDInsightAccessTokenCredential;
            IHDInsightSubscriptionCredentials tempCredentials = null;
            if (certCreds != null)
            {
                tempCredentials = new HDInsightCertificateCredential()
                {
                    SubscriptionId = creds.SubscriptionId,
                    Certificate = certCreds.Certificate
                };
            }
            else if (tokenCreds != null)
            {
                tempCredentials = new HDInsightAccessTokenCredential()
                {
                    SubscriptionId = creds.SubscriptionId,
                    AccessToken = tokenCreds.AccessToken
                };
            }
            IHDInsightSubscriptionCredentials credentials = new AlternativeEnvironmentIHDInsightSubscriptionCertificateCredentialsFactory().Create(tempCredentials);

            var client = new HDInsightManagementRestClient(credentials, GetAbstractionContext(), false);
            var dnsName = GetRandomClusterName();
            var location = "East US";
            var subscriptionId = credentials.SubscriptionId;

            var createPayload = String.Format(CreateContainerGenericRequest, dnsName, location, subscriptionId, Guid.NewGuid());
            var xmlReader = new XmlTextReader(new StringReader(createPayload));
            var resource = new Resource()
            {
                IntrinsicSettings = new[] { new XmlDocument().ReadNode(xmlReader) }
            };
            var result = await client.ListCloudServices();

            Assert.IsTrue(!this.ContainsContainer(dnsName, result.Content));

            await client.CreateContainer(dnsName, location, resource.SerializeToXml());
            result = await client.ListCloudServices();
            bool containsContiner = false;
            while (!containsContiner)
            {
                result = await client.ListCloudServices();
                containsContiner = this.ContainsContainer(dnsName, result.Content);
                await Task.Delay(100);
            }

            await client.DeleteContainer(dnsName, location);
            containsContiner = true;
            while (containsContiner)
            {
                result = await client.ListCloudServices();
                containsContiner = this.ContainsContainer(dnsName, result.Content);
                await Task.Delay(100);
            }
        }