private const double days = -10; //max = -90  (90 days of logs is stored by audit logs)

        static void Main(string[] args)
        {
            Console.WriteLine("Starting operations log export.");

            string token = GetAuthorizationHeader();

            TokenCloudCredentials credentials = new TokenCloudCredentials(SubscriptionID, token);
            InsightsClient client = new InsightsClient(credentials);

            DateTime endDateTime = DateTime.Now;
            DateTime startDateTime = endDateTime.AddDays(days);
            
            string filterString = FilterString.Generate<ListEventsForResourceProviderParameters>(eventData => (eventData.EventTimestamp >= startDateTime) && (eventData.EventTimestamp <= endDateTime));
                     
            EventDataListResponse response = client.EventOperations.ListEvents(filterString, selectedProperties: null);
            List<EventData> logList = new List<EventData>(response.EventDataCollection.Value);

            while (!string.IsNullOrEmpty(response.EventDataCollection.NextLink))
            {
                Console.WriteLine($"Retrieving page {response.EventDataCollection.NextLink}");

                response = client.EventOperations.ListEventsNext(response.EventDataCollection.NextLink);
                logList.AddRange(response.EventDataCollection.Value);
            }

            ResourceManagementClient resClient = new ResourceManagementClient(credentials);
          
            Console.WriteLine($"Page retrieval completed, preparing to write to a file {CSVExportNamePath}.");

            ExportOpsLogToCSV(logList, resClient);

            Console.WriteLine("Export completed.");
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
예제 #2
0
        public void GetShare()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.ShareGetResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);

            var result = client.Shares.Get(Constants.ResourceGroupName, Constants.FarmId, Constants.ShareAName);

            var expectedUri = string.Format(
                GetUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId, 
                Uri.EscapeDataString(Constants.ShareAName)
                );

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            Assert.Equal(HttpMethod.Get, handler.Method);
            
            CompareExpectedResult(result.Share);
        }
예제 #3
0
        private static void CallSDK(string resourceManagementEndpoint, string subscriptionId, string header, string resourceGroupName)
        {
            TokenCloudCredentials aadTokenCredentials = new TokenCloudCredentials(subscriptionId, header);
            Uri resourceManagerUri = new Uri(resourceManagementEndpoint);
            DataPipelineManagementClient client = new DataPipelineManagementClient(aadTokenCredentials, resourceManagerUri);

            // create a data factory
            Console.WriteLine("Creating a data factory");
            try
            { 
                client.DataFactories.CreateOrUpdate(resourceGroupName,
                    new DataFactoryCreateOrUpdateParameters()
                    {
                        DataFactory = new DataFactory()
                        {
                            Name = dataFactoryName,
                            Location = "westus",
                            Properties = new DataFactoryProperties() { }
                        }
                    }
                );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        /// <summary>
        /// Initiates creation of a new cluster.
        /// </summary>
        /// <remarks>
        /// If a cluster with the given domain could not be created, an exception should be thrown indicating the failure reason.
        /// </remarks>
        /// <param name="name">A unique name for the cluster.</param>
        /// <returns>The FQDN of the new cluster.</returns>
        public async Task<string> CreateClusterAsync(string name, IEnumerable<int> ports)
        {
            string token = await this.GetAuthorizationTokenAsync();
            TokenCloudCredentials credential = new TokenCloudCredentials(this.settings.SubscriptionID.ToUnsecureString(), token);

            string rgStatus = await this.CreateResourceGroupAsync(credential, name);

            if (rgStatus == "Exists")
            {
                throw new System.InvalidOperationException(
                    "ResourceGroup/Cluster already exists. Please try passing a different name, or delete the ResourceGroup/Cluster first.");
            }

            string templateContent = this.armTemplate;
            string parameterContent = this.armParameters
                .Replace("_CLUSTER_NAME_", name)
                .Replace("_CLUSTER_LOCATION_", this.settings.Region)
                .Replace("_USER_", this.settings.Username.ToUnsecureString())
                .Replace("_PWD_", this.settings.Password.ToUnsecureString());

            int ix = 1;
            foreach(int port in ports)
            {
                parameterContent = parameterContent.Replace($"_PORT{ix}_", port.ToString());
                ++ix;
            }

            await this.CreateTemplateDeploymentAsync(credential, name, templateContent, parameterContent);

            return (name + "." + this.settings.Region + ".cloudapp.azure.com");
        }
 public WebSiteManagementClient GetWebSiteManagementClient(RecordedDelegatingHandler handler)
 {
     handler.IsPassThrough = false;
     var token = new TokenCloudCredentials(Guid.NewGuid().ToString(), "abc123");
     var client = new WebSiteManagementClient(token).WithHandler(handler);
     client = client.WithHandler(handler);
     return client;
 }
        public FeatureClient GetFeatureClient(RecordedDelegatingHandler handler)
        {
            var token = new TokenCloudCredentials(Guid.NewGuid().ToString(), "abc123");
            handler.IsPassThrough = false;
            var client = new FeatureClient(token).WithHandler(handler);

            HttpMockServer.Mode = HttpRecorderMode.Playback;
            return client;
        }
        public UsageAggregationManagementClient GetUsageAggregationManagementClient(RecordedDelegatingHandler handler)
        {
            handler.IsPassThrough = false;

            var token = new TokenCloudCredentials(Guid.NewGuid().ToString(), "abc123");
            UsageAggregationManagementClient client = new UsageAggregationManagementClient(token, new Uri("https://mn-azure/management/"));
            client = client.WithHandler(handler);
            return client;
        }
예제 #8
0
 public void TestAsyncOperationWithEmptyPayload()
 {
     var tokenCredentials = new TokenCloudCredentials("123", "abc");
     var handler = new PlaybackTestHandler(MockAsyncOperaionWithEmptyBody());
     var fakeClient = new RedisManagementClient(tokenCredentials, handler);
     fakeClient.LongRunningOperationInitialTimeout = fakeClient.LongRunningOperationRetryTimeout = 0;
     var error = Assert.Throws<CloudException>(() =>
         fakeClient.RedisOperations.Delete("rg", "redis", "1234"));
     Assert.Equal("The response from long running operation does not contain a body.", error.Message);
 }
예제 #9
0
 private async Task RefreshTokenAsync()
 {
     var token = await GetTokenAsync(Guid.Parse(_connectionData.AzureRMTenantId));
     
     if (token == null)
         throw new InvalidOperationException("Sorry, a token could not be accquired. Please verify your Service Principal.");
     
     if (_accessToken == null)
         _accessToken = new TokenCloudCredentials(_connectionData.AzureSubscriptionId, token.access_token);
 }
예제 #10
0
        public void TokenCloudCredentialAddsHeader()
        {
            var tokenCredentials = new TokenCloudCredentials("123","abc");
            var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };
            var fakeClient = new FakeServiceClientWithCredentials(tokenCredentials);
            fakeClient = new FakeServiceClientWithCredentials(tokenCredentials, handler);
            fakeClient.DoStuff().Wait();

            Assert.Equal("Bearer", handler.RequestHeaders.Authorization.Scheme);
            Assert.Equal("abc", handler.RequestHeaders.Authorization.Parameter);
        }
예제 #11
0
        public void ListHistoryActiveFaults()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.HistoryActiveFaultListResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);
            var startTime = new DateTime(2015, 3, 18);
            var endTime = new DateTime(2015, 3, 18);
            var ResourceUri = "/subscriptions/serviceAdmin/resourceGroups/system/providers/Microsoft.Storage.Admin/farms/WEST_US_1/tableserverinstances/woss-node1";

            var result = client.Faults.ListHistoryFaults(
                Constants.ResourceGroupName,
                Constants.FarmId,
                startTime.ToString("o"),
                endTime.ToString("o"),
                ResourceUri);

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Get);

            var expectedUri = string.Format(
                FaultListUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId);

            var expectedFilterUri = string.Format(
                HistoryFaultFilterUriTemplate,
                Uri.EscapeDataString(startTime.ToString("o")),
                Uri.EscapeDataString(endTime.ToString("o")),
                Uri.EscapeDataString(ResourceUri));

            expectedUri = string.Concat(expectedUri, expectedFilterUri);
            expectedUri = expectedUri.Replace(" ", "%20");

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            Assert.True(result.Faults.Count > 1);
            CompareExpectedResult(result.Faults[0], false);
        }
예제 #12
0
        static void Main(string[] args)
        {
            //https://msdn.microsoft.com/en-us/library/azure/dn790557.aspx#bk_portal
            string token = GetAuthorizationHeader();

            TokenCloudCredentials creds = new TokenCloudCredentials(subscriptionId,token);

            RedisManagementClient client = new RedisManagementClient(creds);
            var redisProperties = new RedisProperties();
            redisProperties.Sku = new Sku(redisSKUName,redisSKUFamily,redisSKUCapacity);
            redisProperties.RedisVersion = redisVersion;
            var redisParams = new RedisCreateOrUpdateParameters(redisProperties, redisCacheRegion);
            client.Redis.CreateOrUpdate(resourceGroupName,cacheName, redisParams);
        }
예제 #13
0
        static void Main(string[] args)
        {
            // Define the base URI for management operations
            Uri baseUri = new Uri("https://management.azure.com");

            string token = GetAuthorizationHeader();
            var startTime = DateTime.Now;
            var endTime = startTime.ToUniversalTime().AddHours(1.0).ToLocalTime();
            var redisConnection = "";

            ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(redisConnection);
            IDatabase cachedb = connection.GetDatabase();
            for (int i = 0; i < 10; i++)
            {
                cachedb.StringIncrement(i.ToString());
                Console.WriteLine("value=" + cachedb.StringGet(i.ToString()));

            }

            // Get the credentials
            // You can find instructions on how to get the token here:
            // http://msdn.microsoft.com/en-us/library/azure/dn790557.aspx
            SubscriptionCloudCredentials credentials = new TokenCloudCredentials(subscriptionId, token);

            // Create an instance of the InsightsClient from Microsoft.Azure.Insights
            InsightsClient client = new InsightsClient(credentials, baseUri);

            // Get the events for an Azure Resource (e.g. Website) (as described by the Azure Resource Manager APIs here:http://msdn.microsoft.com/en-us/library/azure/dn790569.aspx)
            // A resource URI looks like the following string:
            //"/subscriptions/########-####-####-####-############/resourceGroups/resourcegroupname1/providers/resourceprovider1/resourcename1"
            string resourceUri = string.Format("subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Cache/redis/{2}", subscriptionId,resourceGroupName, cacheName);

            //Define a FilterString
            string filterString = FilterString.Generate<ListEventsForResourceParameters>(eventData => (eventData.EventTimestamp >= startTime) && (eventData.EventTimestamp <= endTime) && (eventData.ResourceUri == resourceUri));

            //Get the events logs
            EventDataListResponse response = client.EventOperations.ListEvents(filterString, selectedProperties: null);

            //Check the status code of the response
            Console.WriteLine("HTTP Status Code returned for the call:" + response.StatusCode);

            var response2 = client.MetricDefinitionOperations.GetMetricDefinitions(resourceUri, "");
            var metrics = client.MetricOperations.GetMetrics(resourceUri, "startTime eq 2015-01-14T02:19:03.0712821Z and endTime eq 2015-01-14T03:19:03.0712821Z and timeGrain eq duration'PT5M'", response2.MetricDefinitionCollection.Value);
            Console.WriteLine("Print out the metrics logs");
            foreach (var item in metrics.MetricCollection.Value)
            {
                Console.WriteLine(item.Name.Value + "--" +item.MetricValues.Count);
            }
        }
예제 #14
0
        public async Task <IList <SubscriptionObject> > GetSubscriptions()
        {
            if (azureADAuthResult == null)
            {
                throw new Exception(Properties.Resources.AzureADAuthResult);
            }

            // Common subscription object to host subscriptions from RDFE & ARM
            IList <SubscriptionObject> subscriptionList = new List <SubscriptionObject>();

            subscriptionCredentials = new Microsoft.Azure.TokenCloudCredentials(azureADAuthResult.AccessToken);
            subscriptionClient      = new Microsoft.Azure.Subscriptions.SubscriptionClient(subscriptionCredentials, new Uri(Properties.Settings.Default.appIdURI));

            var cancelToken = new CancellationToken();

            var tenants = subscriptionClient.Tenants.ListAsync(cancelToken).Result;

            // Get subscriptions for each tenant
            foreach (var tenant in tenants.TenantIds)
            {
                try
                {
                    AuthenticationResult tenantTokenCreds =
                        AuthenticateHelper.RefreshTokenByAuthority(tenant.TenantId,
                                                                   Properties.Settings.Default.appIdURI);
                    subscriptionCredentials = new Microsoft.Azure.TokenCloudCredentials(tenantTokenCreds.AccessToken);
                    var tenantSubscriptionClient =
                        new Microsoft.Azure.Subscriptions.SubscriptionClient(subscriptionCredentials,
                                                                             new Uri(Properties.Settings.Default.appIdURI));
                    var subscriptionListResults = tenantSubscriptionClient.Subscriptions.ListAsync(cancelToken).Result;

                    foreach (var subscription in subscriptionListResults.Subscriptions)
                    {
                        var subList = new SubscriptionObject();
                        subList.Name           = subscription.DisplayName;
                        subList.SubscriptionId = subscription.SubscriptionId;
                        subList.Authority      = tenant.TenantId;
                        subscriptionList.Add(subList);
                    }
                }
                catch (Exception ex)
                {
                    // ignored
                }
            }

            return(subscriptionList);
        }
예제 #15
0
        private void create_adf_client()
        {
            var authenticationContext = new AuthenticationContext($"https://login.windows.net/{tenant_id}");
            var credential = new ClientCredential(clientId: client_id, clientSecret: client_key);
            var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential);

            if (result == null)
            {
                throw new InvalidOperationException("Failed to obtain the JWT token");
            }

            var token = result.AccessToken;

            var _credentials = new TokenCloudCredentials(subscription_id, token);
            inner_client = new DataFactoryManagementClient(_credentials);
        }
        public async Task <IList <SubscriptionObject> > GetSubscriptions()
        {
            if (azureADAuthResult == null)
            {
                throw new Exception(Properties.Resources.AzureADAuthResult);
            }

            // Common subscription object to host subscriptions from RDFE & ARM
            IList <SubscriptionObject> subscriptionList = new List <SubscriptionObject>();

            subscriptionCredentials = new Microsoft.Azure.TokenCloudCredentials(azureADAuthResult.AccessToken);
            subscriptionClient      = new Microsoft.Azure.Subscriptions.SubscriptionClient(subscriptionCredentials);

            var cancelToken = new CancellationToken();

            Microsoft.Azure.Subscriptions.Models.SubscriptionListResult subscriptionResults = await subscriptionClient.Subscriptions.ListAsync(cancelToken);

            // Add any ARM subscriptions to the common subscription object
            foreach (var subscription in subscriptionResults.Subscriptions)
            {
                var subList = new SubscriptionObject();
                subList.Name           = subscription.DisplayName;
                subList.SubscriptionId = subscription.SubscriptionId;
                subList.Authority      = "common";
                subscriptionList.Add(subList);
            }

            // Add any RDFE subscriptions to the common subscription object
            IList <Microsoft.WindowsAzure.Subscriptions.Models.SubscriptionListOperationResponse.Subscription> RDFEsubscriptions = await GetRDFESubscriptions();

            foreach (var subscription in RDFEsubscriptions)
            {
                // Only add subscriptions that are not already in the subscription list
                if (subscriptionList.Where(x => x.SubscriptionId == subscription.SubscriptionId).Count() == 0)
                {
                    var subList = new SubscriptionObject();
                    subList.Name           = subscription.SubscriptionName;
                    subList.SubscriptionId = subscription.SubscriptionId;
                    subList.Authority      = subscription.ActiveDirectoryTenantId;
                    subscriptionList.Add(subList);
                }
            }

            return(subscriptionList);
        }
예제 #17
0
        public void TestCreateOrUpdateWithAsyncHeader()
        {
            var tokenCredentials = new TokenCloudCredentials("123", "abc");
            var handler = new PlaybackTestHandler(MockCreateOrUpdateWithTwoTries());
            var fakeClient = new RedisManagementClient(tokenCredentials, handler);
            fakeClient.LongRunningOperationInitialTimeout = fakeClient.LongRunningOperationRetryTimeout = 0;
            fakeClient.RedisOperations.CreateOrUpdate("rg", "redis", new RedisCreateOrUpdateParameters(), "1234");

            Assert.Equal(HttpMethod.Put, handler.Requests[0].Method);
            Assert.Equal("https://management.azure.com/subscriptions/1234/resourceGroups/rg/providers/Microsoft.Cache/Redis/redis", 
                handler.Requests[0].RequestUri.ToString());
            Assert.Equal(HttpMethod.Get, handler.Requests[1].Method);
            Assert.Equal("http://custom/status",
                handler.Requests[1].RequestUri.ToString());
            Assert.Equal(HttpMethod.Get, handler.Requests[2].Method);
            Assert.Equal("https://management.azure.com/subscriptions/1234/resourceGroups/rg/providers/Microsoft.Cache/Redis/redis",
                handler.Requests[2].RequestUri.ToString());
        }
예제 #18
0
        private static async Task MainAsync()
        {
            // Obtain an access token using the "common" AAD resource. This allows the application
            // to query AAD for information that lies outside the application's tenant (such as for
            // querying subscription information in your Azure account).
            AuthenticationContext authContext = new AuthenticationContext(AuthorityUri);
            AuthenticationResult authResult = authContext.AcquireToken(ResourceUri,
                                                                       ClientId,
                                                                       new Uri(RedirectUri),
                                                                       PromptBehavior.Auto);

            // The first credential object is used when querying for subscriptions, and is therefore
            // not associated with a specific subscription.
            TokenCloudCredentials subscriptionCreds = new TokenCloudCredentials(authResult.AccessToken);

            string subscriptionId = String.Empty;
            using (SubscriptionClient subClient = new SubscriptionClient(subscriptionCreds))
            {
                // Ask the user to select a subscription. We'll use the selected subscription's
                // ID when constructing another credential object used in initializing the management
                // clients for the remainder of the sample.
                subscriptionId = await SelectSubscriptionAsync(subClient);
            }

            // These credentials are associated with a subscription, and can therefore be used when
            // creating Resource and Batch management clients for use in manipulating entities within
            // the subscription (e.g. resource groups and Batch accounts).
            TokenCloudCredentials creds = new TokenCloudCredentials(subscriptionId, authResult.AccessToken);

            // With the ResourceManagementClient, we create a resource group in which to create the Batch account.
            using (ResourceManagementClient resourceManagementClient = new ResourceManagementClient(creds))
            {
                // Register with the Batch resource provider; this only needs to be performed once per subscription.
                resourceManagementClient.Providers.Register(BatchNameSpace);
                
                string location = await PromptUserForLocationAsync(resourceManagementClient);
                
                await CreateResourceGroupAsync(resourceManagementClient, location);

                await PerformBatchAccountOperationsAsync(creds, location);

                await DeleteResourceGroupAsync(resourceManagementClient);
            }
        }
        public async Task<IList<SubscriptionObject>> GetSubscriptions()
        {
            if (azureADAuthResult == null)
                throw new Exception(Properties.Resources.AzureADAuthResult);

            // Common subscription object to host subscriptions from RDFE & ARM
            IList<SubscriptionObject> subscriptionList = new List<SubscriptionObject>();

            subscriptionCredentials = new Microsoft.Azure.TokenCloudCredentials(azureADAuthResult.AccessToken);
            subscriptionClient = new Microsoft.Azure.Subscriptions.SubscriptionClient(subscriptionCredentials);

            var cancelToken = new CancellationToken();
            Microsoft.Azure.Subscriptions.Models.SubscriptionListResult subscriptionResults = await subscriptionClient.Subscriptions.ListAsync(cancelToken);

            // Add any ARM subscriptions to the common subscription object
            foreach (var subscription in subscriptionResults.Subscriptions)
            {
                var subList = new SubscriptionObject();
                subList.Name = subscription.DisplayName;
                subList.SubscriptionId = subscription.SubscriptionId;
                subList.Authority = "common";
                subscriptionList.Add(subList);
            }

            // Add any RDFE subscriptions to the common subscription object
            IList<Microsoft.WindowsAzure.Subscriptions.Models.SubscriptionListOperationResponse.Subscription> RDFEsubscriptions = await GetRDFESubscriptions();
            foreach (var subscription in RDFEsubscriptions)
            {
                // Only add subscriptions that are not already in the subscription list
                if (subscriptionList.Where(x => x.SubscriptionId == subscription.SubscriptionId).Count() == 0)
                {
                    var subList = new SubscriptionObject();
                    subList.Name = subscription.SubscriptionName;
                    subList.SubscriptionId = subscription.SubscriptionId;
                    subList.Authority = subscription.ActiveDirectoryTenantId;
                    subscriptionList.Add(subList);
                }
            }

            return subscriptionList;
        }
예제 #20
0
        public void CreateQuota()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.QuotaGetResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);

            var quotaReq = new QuotaCreateOrUpdateParameters
            {
                Properties = new Quota
                {
                    CapacityInGB = 100,
                    NumberOfStorageAccounts = 10
                }
            };

            var result = client.Quotas.CreateOrUpdate(Constants.LocationName, Constants.QuotaName, quotaReq);

            var expectedUri = string.Format(
                CreateOrUpdateOrDeleteOrGetUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.LocationName,
                Constants.QuotaName);

            Assert.Equal(expectedUri, handler.Uri.AbsoluteUri);

            Assert.Equal(HttpMethod.Put, handler.Method);

            CompareExpectedResult(result.Quota, subscriptionId);
        }
        public void ListStorageAccounts()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.StorageAccountListResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);

            var result = client.StorageAccounts.List(Constants.ResourceGroupName, Constants.FarmId, null, true);

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Get);

            var expectedUri = string.Format(
                ListUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                "true");

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            // Validate headers 
            Assert.Equal(HttpMethod.Get, handler.Method);

            Assert.True(result.StorageAccounts.Count == 3);

            CompareExpectedListResultCommon(result);

            CompareExpectedListResultWacProperties(result, true);
        }
예제 #22
0
        static void Main(string[] args)
        {
            // Read region values from parameters.txt file.
            // We will create on retraining pipeline and one scoring pipeline for each region values.
            // Note: You will typically replace this with code to read this from your data store.
            string[] parameters =  System.IO.File.ReadAllLines(@"parameters.txt");

            // create data factory management client. This will pop up a UI for
            // Azure login for your subscription.
            TokenCloudCredentials aadTokenCredentials =
                new TokenCloudCredentials(
                    ConfigurationManager.AppSettings["SubscriptionId"],
                    Utilities.GetAuthorizationHeader());

            Uri resourceManagerUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerEndpoint"]);

            DataFactoryManagementClient client = new DataFactoryManagementClient(aadTokenCredentials, resourceManagerUri);

            Utilities.CreateDataFactory(DataFactoryConfig.ResourceGroupName, DataFactoryConfig.DataFactoryName, client);

            // We use the same storage account to put results of both retraining and scoring. Hence create the shared
            // linked servive for the storage account before creating the 2 pipelines.
            Utilities.CreateStorageLinkedService(DataFactoryConfig.ResourceGroupName, DataFactoryConfig.DataFactoryName, client);

            // Note: The CreateMLEndpoints creates as many endpoint entries in the endpoints collection as there are regions.
            // In this sample we are using the same hardwired value of the endpoint for each entry in the collection. You will need
            // to replace this code with code that programatically creates multiple endpoints.
            IList<UpdateResourceEndpoint> mlEndpoints;
            Utilities.CreateMLEndpoints(out mlEndpoints, parameters.Length);

            // Note: retraining pipeline generation code creates the scoring linked services that are referenced by
            // scoring pipeline. Hence retraining pipeline code MUST run before the scoring pipeline code.
            RetrainingPipeline.CreateObjects(parameters, client, mlEndpoints);
            ScoringPipeline.CreateObjects(parameters, client);

            // We don't have a copy step. This is commented out bonus code for copying data if you needed to have data movement as well.
            //CopyPipeline.CreateObjects(parameters, client);

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
예제 #23
0
        public void GetFarmMetricDefinitions()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.MetricDefinitionResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);

            var client = GetClient(handler, token);

            const string filter = "name";

            var result = client.Farms.GetMetricDefinitions(Constants.ResourceGroupName, Constants.FarmId, filter);

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Get);

            var expectedUri = string.Format(
                FarmMetricDefinitionsUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                filter);

            Assert.Equal(expectedUri, handler.Uri.AbsoluteUri);

            // Validate headers 
            Assert.Equal(HttpMethod.Get, handler.Method);

            CompareMetricDefinition(result);
        }
예제 #24
0
        public void ListRoleInstance()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.RoleInstanceListResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);

            var result = client.TableMasterInstances.List(Constants.ResourceGroupName, Constants.FarmId).ToList();

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Get);

            var expectedUri = string.Format(
                ListUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                Constants.TableMasterRole);

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            // Validate headers 
            Assert.Equal(HttpMethod.Get, handler.Method);

            CompareExpectedResult(result[0]);

            //TODO: deployment information?
        }
예제 #25
0
        private void DeployASJob(SAJobConfigModel cfg)
        {
            // Get authentication token
            TokenCloudCredentials aadTokenCredentials =
                new TokenCloudCredentials(cfg.subscriptionID, GetAuthorizationHeader());

            // Create Stream Analytics management client
            StreamAnalyticsManagementClient client = new StreamAnalyticsManagementClient(aadTokenCredentials);

            // Create a Stream Analytics job
            JobCreateOrUpdateParameters jobCreateParameters = new JobCreateOrUpdateParameters()
            {
                Job = new Job()
                {
                    Name = cfg.streamAnalyticsJobName,
                    Location = cfg.location,
                    Properties = new JobProperties()
                    {
                        EventsOutOfOrderPolicy = EventsOutOfOrderPolicy.Adjust,
                        Sku = new Sku()
                        {
                            Name = "Standard"
                        }
                    }
                }
            };

            JobCreateOrUpdateResponse jobCreateResponse = client.StreamingJobs.CreateOrUpdate(cfg.resourceGroupName, jobCreateParameters);
            TempData["jobName"] = jobCreateResponse.Job.Name;
            TempData["jobCreationStatus"] = jobCreateResponse.StatusCode;

            // Create a Stream Analytics input source
            InputCreateOrUpdateParameters jobInputCreateParameters = new InputCreateOrUpdateParameters()
            {
                Input = new Input()
                {
                    Name = cfg.streamAnalyticsInputName,
                    Properties = new StreamInputProperties()
                    {
                        Serialization = new CsvSerialization
                        {
                            Properties = new CsvSerializationProperties
                            {
                                Encoding = "UTF8",
                                FieldDelimiter = ","
                            }
                        },
                        DataSource = new EventHubStreamInputDataSource
                        {
                            Properties = new EventHubStreamInputDataSourceProperties
                            {
                                EventHubName = cfg.EventHubName,
                                ServiceBusNamespace = cfg.ServiceBusNamespace,
                                SharedAccessPolicyKey = cfg.SharedAccessPolicyKey,
                                SharedAccessPolicyName = cfg.SharedAccessPolicyName,
                            }
                        }
                    }
                }
            };

            InputCreateOrUpdateResponse inputCreateResponse =
                client.Inputs.CreateOrUpdate(cfg.resourceGroupName, cfg.streamAnalyticsJobName, jobInputCreateParameters);
            TempData["jobInputName"] = inputCreateResponse.Input.Name;
            TempData["jobInputCreationStatus"] = inputCreateResponse.StatusCode;

        }
예제 #26
0
 public static WebSiteManagementClient CreateWebSiteManagementClient(this CloudClients clients, TokenCloudCredentials credentials, Uri baseUri)
 {
     return(new WebSiteManagementClient(credentials, baseUri));
 }
예제 #27
0
        public void DismissFaults()
        {
            var handler = new RecordedDelegatingHandler
            {
                StatusCodeToReturn = HttpStatusCode.NoContent
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);

            client.Faults.Dismiss(
                Constants.ResourceGroupName,
                Constants.FarmId,
                Constants.FaultId
                );

            Assert.Equal(handler.Method, HttpMethod.Post);

            var expectedUri = string.Format(
                FaultDismissUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                Constants.FaultId);

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);
        }
예제 #28
0
 protected StorageAdminManagementClient GetClient(RecordedDelegatingHandler handler, TokenCloudCredentials token)
 {
     handler.IsPassThrough = false;
     var client = new StorageAdminManagementClient(token, new Uri(Constants.BaseUri)).WithHandler(handler);
     return client;
 }
        public async Task<ClusterOperationStatus> GetClusterStatusAsync(string name)
        {
            string token = await this.GetAuthorizationTokenAsync();
            TokenCloudCredentials credential = new TokenCloudCredentials(this.settings.SubscriptionID.ToUnsecureString(), token);

            DeploymentGetResult dpResult;
            ResourceGroupGetResult rgResult;

            using (ResourceManagementClient templateDeploymentClient = new ResourceManagementClient(credential))
            {
                DeploymentExistsResult exists = templateDeploymentClient.Deployments.CheckExistence(name, name + "dp");
                if (!exists.Exists)
                {
                    // This might also imply that the cluster never existed in the first place.
                    return ClusterOperationStatus.ClusterNotFound;
                }


                dpResult = templateDeploymentClient.Deployments.Get(name, name + "dp");
                rgResult = templateDeploymentClient.ResourceGroups.Get(name);
            }

            //Either the resource group might exists, but resources are being added or deleted via the template, or the RG itself might be getting created or deleted.
            //This means we have to seaparate out the provisioning states of both the RG along with teh template deployment to get a cluster status. 
            //string result = dpResult.Deployment.Properties.ProvisioningState + rgResult.ResourceGroup.ProvisioningState;
            //result = result.Replace("Succeeded", "");
            if (rgResult.ResourceGroup.ProvisioningState.Contains("Failed"))
            {
                return ClusterOperationStatus.DeleteFailed;
            }

            if (rgResult.ResourceGroup.ProvisioningState.Contains("Deleting"))
            {
                return ClusterOperationStatus.Deleting;
            }

            if (dpResult.Deployment.Properties.ProvisioningState.Contains("Accepted") || dpResult.Deployment.Properties.ProvisioningState.Contains("Running"))
            {
                return ClusterOperationStatus.Creating;
            }

            if (dpResult.Deployment.Properties.ProvisioningState.Contains("Failed"))
            {
                return ClusterOperationStatus.CreateFailed;
            }

            if (dpResult.Deployment.Properties.ProvisioningState.Contains("Succeeded"))
            {
                return ClusterOperationStatus.Ready;
            }


            return ClusterOperationStatus.Unknown;
        }
        public async Task DeleteClusterAsync(string name)
        {
            string rgName = name;

            string token = await this.GetAuthorizationTokenAsync();
            TokenCloudCredentials credential = new TokenCloudCredentials(this.settings.SubscriptionID.ToUnsecureString(), token);

            using (ResourceManagementClient resourceGroupClient = new ResourceManagementClient(credential))
            {
                AzureOperationResponse deleteResult = await resourceGroupClient.ResourceGroups.BeginDeletingAsync(rgName);
            }
        }
 public static BatchManagementClient CreateBatchManagementClient(this CloudClients clients, TokenCloudCredentials credentials, Uri baseUri)
 {
     return(new BatchManagementClient(credentials, baseUri));
 }
        private async Task CreateTemplateDeploymentAsync(TokenCloudCredentials credential, string rgName, string templateContent, string parameterContent)
        {
            Deployment deployment = new Deployment();

            string deploymentname = rgName + "dp";
            deployment.Properties = new DeploymentProperties
            {
                Mode = DeploymentMode.Incremental,
                Template = templateContent,
                Parameters = parameterContent,
            };

            using (ResourceManagementClient templateDeploymentClient = new ResourceManagementClient(credential))
            {
                try
                {
                    DeploymentOperationsCreateResult dpResult =
                        await templateDeploymentClient.Deployments.CreateOrUpdateAsync(rgName, deploymentname, deployment);
                    ServiceEventSource.Current.Message("ArmClusterOperator: Deployment in RG {0}: {1} ({2})", rgName, dpResult.RequestId, dpResult.StatusCode);
                }
                catch (Exception e)
                {
                    ServiceEventSource.Current.Message(
                        "ArmClusterOperator: Failed deploying ARM template to create a cluster in RG {0}. {1}",
                        rgName,
                        e.Message);

                    throw;
                }
            }
        }
        private async Task<string> CreateResourceGroupAsync(TokenCloudCredentials credential, string rgName)
        {
            ResourceGroup resourceGroup = new ResourceGroup {Location = this.settings.Region};

            using (ResourceManagementClient resourceManagementClient = new ResourceManagementClient(credential))
            {
                ResourceGroupExistsResult exists = await resourceManagementClient.ResourceGroups.CheckExistenceAsync(rgName);

                if (exists.Exists)
                {
                    return "Exists";
                }

                ResourceGroupCreateOrUpdateResult rgResult = await resourceManagementClient.ResourceGroups.CreateOrUpdateAsync(rgName, resourceGroup);

                return rgResult.StatusCode.ToString();
            }
        }
예제 #34
0
        private void VerifyGetSubResourceMetrics(string subResourceType, string subResourceName, string metricsUriTemplate,
            Func<StorageAdminManagementClient, string, string, string, string, MetricsResult> func)
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ExpectedResults.MetricResponse)
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);

            var client = GetClient(handler, token);

            const string filter = "name";

            var result = func(client, Constants.ResourceGroupName, Constants.FarmId, subResourceName, filter);

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Get);

            var expectedUri = string.Format(
                metricsUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                subResourceType,
                Uri.EscapeDataString(subResourceName),
                filter);

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            // Validate headers 
            Assert.Equal(HttpMethod.Get, handler.Method);

            CompareMetric(result);
        }