コード例 #1
0
        public void DeleteAzureStoreResource(AzureStoreResource resource)
        {
            using (AccountDataContext context = new AccountDataContext(ConfigurationDataProvider.AccountDataProviderConnectionString))
            {
                context.AzureStoreResources.Attach(resource);
                context.AzureStoreResources.Remove(resource);

                AccountDataProvider.RetryPolicy.ExecuteAction(() =>
                {
                    context.SaveChanges();
                });
            }
        }
コード例 #2
0
        public void CreateOrUpdateAzureStoreResource(AzureStoreResource resource)
        {
            using (AccountDataContext context = new AccountDataContext(ConfigurationDataProvider.AccountDataProviderConnectionString))
            {
                if (resource.id_AzureStoreResourceId == Guid.Empty)
                {
                    context.Entry(resource).State = EntityState.Added;
                    resource.dt_CreatedTime = DateTime.UtcNow;
                    resource.dt_ChangedTime = DateTime.UtcNow;
                }
                else
                {
                    context.Entry(resource).State = EntityState.Modified;
                    resource.dt_ChangedTime = DateTime.UtcNow;
                }

                AccountDataProvider.RetryPolicy.ExecuteAction(() =>
                {
                    context.SaveChanges();
                });
            }
        }
コード例 #3
0
        public void CreateOrUpdateAzureStoreResource(AzureStoreResource resource)
        {
            using (AccountDataContext context = new AccountDataContext(ConfigurationDataProvider.AccountDataProviderConnectionString))
            {
                if (resource.id_AzureStoreResourceId == Guid.Empty)
                {
                    context.Entry(resource).State = EntityState.Added;
                    resource.dt_CreatedTime       = DateTime.UtcNow;
                    resource.dt_ChangedTime       = DateTime.UtcNow;
                }
                else
                {
                    context.Entry(resource).State = EntityState.Modified;
                    resource.dt_ChangedTime       = DateTime.UtcNow;
                }

                AccountDataProvider.RetryPolicy.ExecuteAction(() =>
                {
                    context.SaveChanges();
                });
            }
        }
コード例 #4
0
        public void DeleteAzureStoreResource(AzureStoreResource resource)
        {
            using (AccountDataContext context = new AccountDataContext(ConfigurationDataProvider.AccountDataProviderConnectionString))
            {
                context.AzureStoreResources.Attach(resource);
                context.AzureStoreResources.Remove(resource);

                AccountDataProvider.RetryPolicy.ExecuteAction(() =>
                {
                    context.SaveChanges();
                });
            }
        }
コード例 #5
0
        private ResourceOutput MapAzureStoreResourceToResourceOutput(AzureStoreResource resource, bool expandOutputItems)
        {
            return new ResourceOutput
            {
                ETag            = resource.nvc_ETag,
                Type            = resource.nvc_ResourceType,
                Name            = resource.nvc_ResourceName,
                Plan            = resource.nvc_Plan,
                State           = ResourceState.Started.ToString(),

                OutputItems     = expandOutputItems ? this.GetOutputItemsForAzureStoreResource(resource) : null,
                UsageMeters     = new UsageMeterList(this.GetUsageForAzureStoreResource(resource)),

                CloudServiceSettings = new CloudServiceSettings
                {
                    GeoRegion   = resource.nvc_Region
                },

                OperationStatus = new OperationStatus()
                {
                    Result      = OperationResult.Succeeded,
                    Error       = new Error
                    {
                        HttpCode    = (int)HttpStatusCode.OK,
                        Message     = "OK"
                    },
                },
            };
        }
コード例 #6
0
 private string GetUsedServersForAzureStoreResource(AzureStoreResource resource)
 {
     return "42";
 }
コード例 #7
0
 private UsageMeter GetUsageForAzureStoreResource(AzureStoreResource resource)
 {
     return new UsageMeter()
     {
         Name        = "Servers",
         Unit        = "generic",
         Used        = this.GetUsedServersForAzureStoreResource(resource),
         Included    = this.GetIncludedServersForAzureStoreResource(resource),
     };
 }
コード例 #8
0
        public ResourceOutput CreateOrUpdateResource(string subscriptionId, string cloudServiceName, string resourceType, string resourceName)
        {
            if (!AzureStoreAuthorization.AuthorizeRequest(this.Request.GetClientCertificate()))
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            ResourceInput resourceInput = null;
            try
            {
                resourceInput = Request.Content.ReadAsAsync<ResourceInput>().Result;

                using (var provider = AccountDataProvider.Instance)
                {
                    if (String.IsNullOrEmpty(cloudServiceName) || String.IsNullOrEmpty(resourceType) || String.IsNullOrEmpty(resourceName) || (resourceInput == null))
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }

                    var eTag            = resourceInput.ETag;
                    var region          = resourceInput.CloudServiceSettings.GeoRegion;
                    var plan            = resourceInput.Plan;
                    var promotionCode   = resourceInput.PromotionCode;

                    var resource = provider.GetAzureStoreResource(
                        subscriptionId      : subscriptionId,
                        cloudServiceName    : cloudServiceName,
                        resourceType        : resourceType,
                        resourceName        : resourceName
                    );

                    if (resource == null)
                    {
                        var subscription = provider.GetAzureStoreSubscriptionBySubscriptionId(subscriptionId);
                        if (subscription == null)
                        {
                            Logger.ErrorFormat("CreateOrUpdateResource: Unable to find Azure Store resource {1} for subscription {0}. Raw data:\n{2}\n", subscriptionId, resourceName, resourceInput.AsJson());
                            throw new HttpResponseException(HttpStatusCode.BadRequest);
                        }

                        resource = new AzureStoreResource
                        {
                            id_TenantId             = subscription.id_TenantId,
                            nvc_SubscriptionId      = subscriptionId,
                            nvc_CloudServiceName    = cloudServiceName,
                            nvc_ResourceType        = resourceType,
                            nvc_ResourceName        = resourceName,
                        };
                    }

                    if (!eTag.Equals(resource.nvc_ETag, StringComparison.OrdinalIgnoreCase))
                    {
                        resource.nvc_ETag           = eTag;
                        resource.nvc_Region         = region ?? resource.nvc_Region;
                        resource.nvc_Plan           = plan ?? resource.nvc_Plan;
                        resource.nvc_PromotionCode  = promotionCode ?? resource.nvc_PromotionCode;
                        resource.nvc_RawData        = resourceInput.AsJson();

                        provider.CreateOrUpdateAzureStoreResource(resource);
                    }

                    Logger.InfoFormat("CreateOrUpdateResource: Azure Store resource {1} for subscription {0} create or updated. Raw data:\n{2}\n", subscriptionId, resourceName, resourceInput.AsJson());
                    return this.MapAzureStoreResourceToResourceOutput(resource, expandOutputItems: true);
                }
            }
            catch (Exception ex)
            {
                if (Utils.IsFatalException(ex) || ex is HttpResponseException)
                {
                    throw;
                }

                Logger.Error(
                    message     : String.Format(
                        "CreateOrUpdateResource: Unable to provision or update resource {1} for subscription {0}. Raw data:\n{2}\n",
                        subscriptionId,
                        resourceName,
                        resourceInput != null ? resourceInput.AsJson() : "<null>"
                    ),
                    exception   : ex
                );

                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
コード例 #9
0
 private OutputItemList GetOutputItemsForAzureStoreResource(AzureStoreResource resource)
 {
     using (var provider = AccountDataProvider.Instance)
     {
         return new OutputItemList(
             new OutputItem[]
             {
                  new OutputItem() { Key = "ApplicationToken"    , Value = Utils.GenerateSecurityToken()   },
                  new OutputItem() { Key = "ApplicationSecret"   , Value = Utils.GenerateSecurityToken()   },
             }
         );
     }
 }
コード例 #10
0
        private string GetIncludedServersForAzureStoreResource(AzureStoreResource resource)
        {
            if (resource.nvc_Plan.Equals("free"         , StringComparison.OrdinalIgnoreCase)) return "100";
            if (resource.nvc_Plan.Equals("advanced10"   , StringComparison.OrdinalIgnoreCase)) return "10";
            if (resource.nvc_Plan.Equals("advanced30"   , StringComparison.OrdinalIgnoreCase)) return "30";
            if (resource.nvc_Plan.Equals("advanced80"   , StringComparison.OrdinalIgnoreCase)) return "80";

            Logger.ErrorFormat("GetIncludedServersForAzureStoreResource: Unknown resource plan {0} encountered.", resource.nvc_Plan);
            return "100";
        }