Пример #1
0
        // CRON expressions format:: {second} {minute} {hour} {day} {month} {day-of-week}
        public static async Task RunAync([TimerTrigger("0 0 10 1/1 * *")] TimerInfo myTimer, TraceWriter log)
#endif
        {
            log.Info($"Get azure rate function execution started at {DateTime.UtcNow} UTC");
            try
            {
                log.Info($"Database initialization started.");
                DbInitializer.init(ConfigurationHelper.GetConnectionString(ConfigurationKeys.DbConnectoinString));
                log.Info($"Database initialization completed.");

                string partnerServiceApiRoot = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.PartnerServiceApiRoot),
                       authority             = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.Authority),
                       resourceUrl           = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ResourceUrl),
                       applicationId         = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationId),
                       applicationSecret     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationSecret),
                       applicationDomian     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationDomain),
                       RateCardCurrancy      = ConfigurationHelper.GetAppSetting(ConfigurationKeys.AzureRatesApi.Currancy),
                       RateCardRegion        = ConfigurationHelper.GetAppSetting(ConfigurationKeys.AzureRatesApi.Region);

                log.Verbose($"Partner Service Api Root {partnerServiceApiRoot}");
                log.Verbose($"Authority is {authority}");
                log.Verbose($"Resource URL is {resourceUrl}");
                log.Verbose($"Application Id is {applicationId}");
                log.Verbose($"Application Secret is {new string('*', applicationSecret.Length)}");
                log.Verbose($"Application Domain is {applicationDomian}");

                log.Info($"Connecting to MPN network");
                MpnApiClient mpnClient = await MpnApiClient.CreateAsync(partnerServiceApiRoot
                                                                        , authority
                                                                        , resourceUrl
                                                                        , applicationId
                                                                        , applicationSecret
                                                                        , applicationDomian);

                log.Info($"Connected to MPN network");

                AzureRateCard rateCard = await mpnClient.GetAzureRateCardAsync(RateCardCurrancy, RateCardRegion);

                if (rateCard != null)
                {
                    ProcessRateCard(rateCard, log);
                }
                log.Info($"Finished processing rate card");
            }
            catch (Exception ex)
            {
                log.Error("Some error occured in function - 'GetAzureRates'", ex);
            }
            log.Info($"Get azure rate function execution completed at {DateTime.UtcNow} UTC");
        }
Пример #2
0
        public static async Task RunAync([QueueTrigger("customers")] CustomerMessage message, TraceWriter log)

        //#if DEBUG
        //		public static async Task RunAync([HttpTrigger(Route = "GetSubscriptions")]HttpRequestMessage req, TraceWriter log)
        //#else
        //		public static async Task RunAync([QueueTrigger("customers")]CustomerMessage message, TraceWriter log)
        //#endif

        {
            //#if DEBUG
            //			var param = req.GetQueryNameValuePairs().FirstOrDefault(s => s.Key.Equals("customerid"));
            //			CustomerMessage message = new CustomerMessage()
            //			{
            //				CustomerId = param.Value
            //			};
            //#endif
            log.Info($"Get subscriptoins function execution started at {DateTime.UtcNow} UTC");
            try
            {
                log.Info($"Database initialization started.");
                DbInitializer.init(ConfigurationHelper.GetConnectionString(ConfigurationKeys.DbConnectoinString));
                log.Info($"Database initialization completed.");

                string partnerServiceApiRoot = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.PartnerServiceApiRoot),
                       authority             = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.Authority),
                       resourceUrl           = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ResourceUrl),
                       applicationId         = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationId),
                       applicationSecret     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationSecret),
                       applicationDomian     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationDomain);

                log.Info($"Partner Service Api Root {partnerServiceApiRoot}");
                log.Info($"Authority is {authority}");
                log.Info($"Resource URL is {resourceUrl}");
                log.Info($"Application Id is {applicationId}");
                log.Info($"Application Secret is {new string('*', applicationSecret.Length)}");
                log.Info($"Application Domain is {applicationDomian}");

                log.Info($"Connecting to MPN network");
                MpnApiClient mpnClient = await MpnApiClient.CreateAsync(partnerServiceApiRoot
                                                                        , authority
                                                                        , resourceUrl
                                                                        , applicationId
                                                                        , applicationSecret
                                                                        , applicationDomian);

                log.Info($"Connected to MPN network");
                var subscriptions = await mpnClient.GetSubscriptionsAsync(message.CustomerId);

                if (subscriptions != null)
                {
                    await ProcessSubscriptions(subscriptions, message.CustomerId, log);
                }
                else
                {
                    log.Verbose($"0 subscriptions found");
                }
                log.Info($"Finished processing customers");
            }
            catch (Exception ex)
            {
                log.Error("Some error occured in function - 'GetSubscriptions'", ex);
            }
            log.Info($"Get subscriptoins function execution completed at {DateTime.UtcNow} UTC");
        }
Пример #3
0
        // CRON expressions format:: {second} {minute} {hour} {day} {month} {day-of-week}
        public static async Task RunAync([TimerTrigger("0 0 10 1/1 * *")] TimerInfo myTimer, TraceWriter log)
#endif
        {
            log.Info($"Get customers function execution started at {DateTime.UtcNow} UTC");
            try
            {
                log.Info($"Database initialization started.");
                DbInitializer.init(ConfigurationHelper.GetConnectionString(ConfigurationKeys.DbConnectoinString));
                log.Info($"Database initialization completed.");

                string partnerServiceApiRoot = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.PartnerServiceApiRoot),
                       authority             = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.Authority),
                       resourceUrl           = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ResourceUrl),
                       applicationId         = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationId),
                       applicationSecret     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationSecret),
                       applicationDomian     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationDomain);

                log.Verbose($"Partner Service Api Root {partnerServiceApiRoot}");
                log.Verbose($"Authority is {authority}");
                log.Verbose($"Resource URL is {resourceUrl}");
                log.Verbose($"Application Id is {applicationId}");
                log.Verbose($"Application Secret is {new string('*', applicationSecret.Length)}");
                log.Verbose($"Application Domain is {applicationDomian}");

                log.Info($"Connecting to MPN network");
                MpnApiClient mpnClient = await MpnApiClient.CreateAsync(partnerServiceApiRoot
                                                                        , authority
                                                                        , resourceUrl
                                                                        , applicationId
                                                                        , applicationSecret
                                                                        , applicationDomian);

                log.Info($"Connected to MPN network");

                SeekBasedResourceCollection <Customer> customers;
                //Page size is only supported between 1 to 999
                IResourceCollectionEnumerator <SeekBasedResourceCollection <Customer> > enumerator = await mpnClient.GetCustomersAsync(500);

                if (enumerator != null)
                {
                    while (enumerator.HasValue)
                    {
                        customers = enumerator.Current;
                        if (customers?.Items != null && customers?.TotalCount > 0)
                        {
                            await ProcessCustomers(customers, log);
                        }
                        else
                        {
                            log.Info($"0 customers found");
                        }
                        log.Verbose($"Fetching next page");
                        await enumerator.NextAsync();

                        log.Verbose($"Next page retrived");
                    }
                }
                log.Info($"Finished processing customers");
            }
            catch (Exception ex)
            {
                log.Error("Some error occured in function - 'GetCustomers'", ex);
            }
            log.Info($"Get customers function execution completed at {DateTime.UtcNow} UTC");
        }
Пример #4
0
        public static async Task RunAync([QueueTrigger("subscriptions")] SubscriptionMessage message, TraceWriter log)

//#if DEBUG
//		public static async Task RunAync([HttpTrigger(Route = "GetUtilizations")]HttpRequestMessage req, TraceWriter log)
//#else
//		public static async Task RunAync([QueueTrigger("subscriptions")]SubscriptionMessage message, TraceWriter log)
//#endif

        {
//#if DEBUG
//			var customerId = req.GetQueryNameValuePairs().FirstOrDefault(s => s.Key.Equals("customerid"));
//			var subscriptionId = req.GetQueryNameValuePairs().FirstOrDefault(s => s.Key.Equals("subscriptionid"));
//			SubscriptionMessage message = new SubscriptionMessage()
//			{
//				CustomerId = customerId.Value,
//				SubscriptionId = subscriptionId.Value
//			};
//#endif
            log.Info($"Get utilizations function execution started at {DateTime.UtcNow} UTC");
            try
            {
                log.Info($"Database initialization started.");
                DbInitializer.init(ConfigurationHelper.GetConnectionString(ConfigurationKeys.DbConnectoinString));
                log.Info($"Database initialization completed.");

                string partnerServiceApiRoot = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.PartnerServiceApiRoot),
                       authority             = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.Authority),
                       resourceUrl           = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ResourceUrl),
                       applicationId         = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationId),
                       applicationSecret     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationSecret),
                       applicationDomian     = ConfigurationHelper.GetAppSetting(ConfigurationKeys.MPN.ApplicationDomain);

                log.Info($"Partner Service Api Root {partnerServiceApiRoot}");
                log.Info($"Authority is {authority}");
                log.Info($"Resource URL is {resourceUrl}");
                log.Info($"Application Id is {applicationId}");
                log.Info($"Application Secret is {new string('*', applicationSecret.Length)}");
                log.Info($"Application Domain is {applicationDomian}");

                log.Info($"Connecting to MPN network");
                MpnApiClient mpnClient = await MpnApiClient.CreateAsync(partnerServiceApiRoot
                                                                        , authority
                                                                        , resourceUrl
                                                                        , applicationId
                                                                        , applicationSecret
                                                                        , applicationDomian);

                log.Info($"Connected to MPN network");
                DateTimeOffset start = DateTimeOffset.UtcNow.Date.AddDays(-2),
                               end   = DateTimeOffset.UtcNow.Date.AddDays(-1);

                ResourceCollection <AzureUtilizationRecord> utilizations;
                IResourceCollectionEnumerator <ResourceCollection <AzureUtilizationRecord> > utilizationEnumerator = await mpnClient.GetUtilizationssAsync(message.CustomerId, message.SubscriptionId, start, end);

                if (utilizationEnumerator != null)
                {
                    while (utilizationEnumerator.HasValue)
                    {
                        utilizations = utilizationEnumerator.Current;
                        if (utilizations?.Items != null && utilizations?.TotalCount > 0)
                        {
                            ProcessUtilizations(utilizations, message.CustomerId, message.SubscriptionId, log);
                        }
                        else
                        {
                            log.Info($"0 utilizations found");
                        }
                        log.Verbose($"Fetching next page");
                        await utilizationEnumerator.NextAsync();

                        log.Verbose($"Next page retrived");
                    }
                }
                log.Info($"Finished processing utilizations");
            }
            catch (Exception ex)
            {
                log.Error("Some error occured in function - 'GetSubscriptions'", ex);
            }
            log.Info($"Get utilizations function execution completed at {DateTime.UtcNow} UTC");
        }