コード例 #1
0
        /// <summary>
        /// Gets a plan within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="planUniqueName">The name of the plan to get.</param>
        /// <returns>The plan.</returns>
        public async Task <Plan> GetAsync(string offerName, string planUniqueName)
        {
            // Check that a plan with the provided planUniqueName exists within the given offer
            if (!(await ExistsAsync(offerName, planUniqueName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Plan).Name,
                                                                                             planUniqueName,
                                                                                             offerName: offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Plan).Name, planUniqueName, offerName: offerName));

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Find the plan that matches the planUniqueName provided
            var plan = await _context.Plans
                       .SingleOrDefaultAsync(p => (p.OfferId == offer.Id) && (p.PlanName == planUniqueName));

            plan = await SetArmTemplateAndWebhookNames(plan);

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Plan).Name,
                                                                          planUniqueName,
                                                                          JsonSerializer.Serialize(plan),
                                                                          offerName: offerName));
            return(plan);
        }
コード例 #2
0
        /// <summary>
        /// Gets a restructedUser
        /// </summary>
        /// <param name="offerName">The offer name.</param>
        /// <param name="planName">The plan name.</param>
        /// <param name="tenantId">The tenant id.</param>
        /// <returns>The restrictedUser.</returns>
        public async Task <RestrictedUser> GetAsync(string offerName, string planName, Guid tenantId)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName));

            // Check that a restrictedUser with the provided tenantId
            var plan = await _planService.GetAsync(offerName, planName);

            // Get all restrictedUsers with a FK to the plan
            var restrictedUser = await _context.RestrictedUsers.SingleAsync(r => r.PlanId == plan.Id && r.TenantId == tenantId);

            // Check that an restrictedUser with the provided id exists
            if (restrictedUser is null)
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(RestrictedUser).Name,
                                                                                             tenantId.ToString()));
            }

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(RestrictedUser).Name,
                                                                          tenantId.ToString(),
                                                                          JsonSerializer.Serialize(restrictedUser),
                                                                          offerName: offerName,
                                                                          planName: planName));

            return(restrictedUser);
        }
コード例 #3
0
        /// <summary>
        /// Updates a TelemetryDataConnector.
        /// </summary>
        /// <param name="name">The name of the TelemetryDataConnector.</param>
        /// <param name="connector">The updated TelemetryDataConnector.</param>
        /// <returns>The updated TelemetryDataConnector.</returns>
        public async Task <TelemetryDataConnector> UpdateAsync(string name, TelemetryDataConnector connector)
        {
            if (connector is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(TelemetryDataConnector).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(TelemetryDataConnector).Name,
                                                                             name, payload: JsonSerializer.Serialize(connector)));

            if (!await ExistsAsync(name))
            {
                throw new LunaConflictUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(TelemetryDataConnector).Name,
                                                                                             name));
            }

            // Get the customMeter that matches the meterName provided
            var connectorDb = await GetAsync(name);

            // Copy over the changes
            connectorDb.Copy(connector);

            // Update connector values and save changes in db
            _context.TelemetryDataConnectors.Update(connectorDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(TelemetryDataConnector).Name, name));

            return(connector);
        }
コード例 #4
0
        /// <summary>
        /// Gets an aadSecretTmp within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the aadSecretTmp to get.</param>
        /// <returns>An aadSecretTmp object.</returns>
        public async Task <AadSecretTmp> GetAsync(string offerName, string name)
        {
            // Check that an aadSecretTmp with the provided name exists within the given offer
            if (!(await ExistsAsync(offerName, name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(AadSecretTmp).Name,
                                                                                             name,
                                                                                             offerName: offerName));
            }

            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(AadSecretTmp).Name, name, offerName: offerName));

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Find the aadSecretTmp that matches the name provided
            var aadSecretTmp = await _context.AadSecretTmps
                               .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.Name == name));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(AadSecretTmp).Name,
                                                                          name,
                                                                          JsonSerializer.Serialize(aadSecretTmp),
                                                                          offerName: offerName));

            return(aadSecretTmp);
        }
コード例 #5
0
        /// <summary>
        /// Gets a webhook within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="webhookName">The name of the webhook to get.</param>
        /// <returns>The webhook.</returns>
        public async Task <Webhook> GetAsync(string offerName, string webhookName)
        {
            // Check that a webhook with the provided webhook exists within the given offer
            if (!(await ExistsAsync(offerName, webhookName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Webhook).Name,
                                                                                             webhookName, offerName: offerName));
            }

            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Webhook).Name, webhookName, offerName: offerName));

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Find the webhook that matches the webhookName provided
            var webhook = await _context.Webhooks
                          .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.WebhookName == webhookName));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Webhook).Name,
                                                                          webhookName,
                                                                          JsonSerializer.Serialize(webhook),
                                                                          offerName: offerName));

            return(webhook);
        }
コード例 #6
0
ファイル: CustomMeterService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Gets a customMeter.
        /// </summary>
        /// <param name="offerName">The offer name of the customMeter.</param>
        /// <param name="meterName">The name of the customMeter.</param>
        /// <returns>The customMeter.</returns>
        public async Task <CustomMeter> GetAsync(string offerName, string meterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeter).Name, meterName, offerName: offerName));

            if (!(await ExistsAsync(offerName, meterName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeter).Name,
                                                                                             meterName, offerName: offerName));
            }

            var offer = await _offerService.GetAsync(offerName);

            // Get the customMeter that matches the provided meterName
            var customMeter = await _context.CustomMeters.SingleOrDefaultAsync(c => c.OfferId == offer.Id && c.MeterName == meterName);

            customMeter.OfferName = offerName;
            var connector = await _context.TelemetryDataConnectors.FindAsync(customMeter.TelemetryDataConnectorId);

            customMeter.TelemetryDataConnectorName = connector.Name;

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(
                                       typeof(CustomMeter).Name,
                                       meterName,
                                       JsonSerializer.Serialize(customMeter),
                                       offerName: offerName));

            return(customMeter);
        }
コード例 #7
0
ファイル: IpConfigService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Gets an ipConfig within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the ipConfig to get.</param>
        /// <returns>The ipConfig.</returns>
        public async Task <IpConfig> GetAsync(string offerName, string name)
        {
            // Check that an ipConfig with the provided name exists within the given offer
            if (!(await ExistsAsync(offerName, name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(IpConfig).Name,
                                                                                             name,
                                                                                             offerName: offerName));
            }

            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(IpConfig).Name, name, offerName: offerName));

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Find the ipConfig that matches the name provided
            var ipConfig = await _context.IpConfigs
                           .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.Name == name));

            // Populate the IpBlocks this IpConfig has
            ipConfig.IpBlocks = await GetIpBlocks(ipConfig.Id);

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(IpConfig).Name,
                                                                          name,
                                                                          JsonSerializer.Serialize(ipConfig),
                                                                          offerName: offerName));

            return(ipConfig);
        }
コード例 #8
0
        /// <summary>
        /// Updates a webhook within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="webhookName">The name of the webhook to update.</param>
        /// <param name="webhook">The new webhook.</param>
        /// <returns>The updated webhook.</returns>
        public async Task <Webhook> UpdateAsync(string offerName, string webhookName, Webhook webhook)
        {
            if (webhook is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Webhook).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check if (the webhookName has been updated) &&
            //          (a webhook with the same new webhookName does not already exist)
            if ((webhookName != webhook.WebhookName) && (await ExistsAsync(offerName, webhook.WebhookName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Webhook).Name,
                                                                                             webhook.WebhookName, offerName: offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(Webhook).Name, webhook.WebhookName, offerName: offerName, payload: JsonSerializer.Serialize(webhook)));

            // Get the webhook that matches the webhookName provided
            var webhookDb = await GetAsync(offerName, webhookName);

            // Copy over the changes
            webhookDb.Copy(webhook);

            // Update webhook values and save changes in db
            _context.Webhooks.Update(webhookDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(nameof(Webhook), webhookName, offerName: offerName));

            await UpdateWebhookParameters(await _offerService.GetAsync(offerName), webhookDb, webhookDb.Id);

            return(webhook);
        }
コード例 #9
0
        /// <summary>
        /// Gets a SubscriptionCustomMeterUsage.
        /// </summary>
        /// <param name="subscriptionId">The subscription id.</param>
        /// <param name="meterName">The name of the SubscriptionCustomMeterUsage.</param>
        /// <returns>The SubscriptionCustomMeterUsage.</returns>
        public async Task <SubscriptionCustomMeterUsage> GetAsync(Guid subscriptionId, string meterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName));

            if (!(await ExistsAsync(subscriptionId, meterName)))
            {
                throw new LunaNotFoundUserException(
                          LoggingUtils.ComposeNotFoundErrorMessage(typeof(SubscriptionCustomMeterUsage).Name,
                                                                   meterName,
                                                                   subscriptionId: subscriptionId));
            }

            var subscription = await _subscriptionService.GetAsync(subscriptionId);

            // Get the subscriptionCustomMeterUsage that matches the provided subscription id and meterName
            var customMeter = await _customMeterService.GetAsync(subscription.OfferName, meterName);

            var subscriptionCustomMeterUsage = await _context.SubscriptionCustomMeterUsages
                                               .SingleOrDefaultAsync(c => c.MeterId == customMeter.Id && c.SubscriptionId.Equals(subscriptionId));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(
                                       typeof(SubscriptionCustomMeterUsage).Name,
                                       meterName,
                                       JsonSerializer.Serialize(subscriptionCustomMeterUsage)));

            return(subscriptionCustomMeterUsage);
        }
コード例 #10
0
        /// <summary>
        /// Gets a customMeterDimension by id.
        /// </summary>
        /// <param name="id">The id of the customMeterDimension.</param>
        /// <returns>The customMeterDimension.</returns>
        public async Task <CustomMeterDimension> GetAsync(string offerName, string planName, string meterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeterDimension).Name, meterName, planName, offerName));

            var meter = await _customMeterService.GetAsync(offerName, meterName);

            var plan = await _planService.GetAsync(offerName, planName);

            // Find the customMeterDimension that matches the id provided
            var customMeterDimension = await _context.CustomMeterDimensions.SingleOrDefaultAsync(c => c.PlanId == plan.Id && c.MeterId == meter.Id);

            // Check that an customMeterDimension with the provided id exists
            if (customMeterDimension is null)
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeterDimension).Name,
                                                                                             meterName, planName, offerName));
            }

            // Set the customMeterDimension's meterName
            customMeterDimension.MeterName = meter.MeterName;
            customMeterDimension.PlanName  = plan.PlanName;

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(CustomMeterDimension).Name,
                                                                          meterName,
                                                                          JsonSerializer.Serialize(customMeterDimension),
                                                                          planName,
                                                                          offerName));

            return(customMeterDimension);
        }
コード例 #11
0
        /// <summary>
        /// Find offer by the offer id
        /// </summary>
        /// <param name="offerId"></param>
        /// <returns></returns>
        private async Task <Offer> FindOfferById(long offerId)
        {
            Offer offer = await _context.Offers.FindAsync(offerId);

            if (offer == null)
            {
                throw new LunaProvisioningException(
                          LoggingUtils.ComposeNotFoundErrorMessage("Offer", "id", offerName: offerId.ToString()),
                          false);
            }
            return(offer);
        }
コード例 #12
0
        /// <summary>
        /// Find plan by the plan id
        /// </summary>
        /// <param name="planId"></param>
        /// <returns></returns>
        private async Task <Plan> FindPlanById(long planId)
        {
            Plan plan = await _context.Plans.FindAsync(planId);

            if (plan == null)
            {
                throw new LunaServerException(
                          LoggingUtils.ComposeNotFoundErrorMessage("Plan", "id", planName: planId.ToString()),
                          false);
            }
            return(plan);
        }
コード例 #13
0
        /// <summary>
        /// Validate the input provisioning state
        /// </summary>
        /// <param name="subscription">The subscription</param>
        /// <param name="callerName">The caller name</param>
        ///
        private void ValidateSubscriptionAndInputState(Subscription subscription, [CallerMemberName] string callerName = "")
        {
            if (subscription == null)
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Subscription).Name, subscription.SubscriptionId.ToString()));
            }

            MethodInfo method = typeof(ProvisioningService).GetMethod(callerName);

            InputStatesAttribute attribute = (InputStatesAttribute)Attribute.GetCustomAttribute(method, typeof(InputStatesAttribute));

            if (!attribute.InputStates.Contains(subscription.ProvisioningStatus))
            {
                throw new LunaConflictUserException($"Cannot call function {method.Name} when subscription provisioning state is {subscription.ProvisioningStatus}.");
            }
        }
コード例 #14
0
ファイル: OfferService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Gets an offer by name.
        /// </summary>
        /// <param name="offerName">The name of the offer to get.</param>
        /// <returns>The offer.</returns>
        public async Task <Offer> GetAsync(string offerName)
        {
            if (!await ExistsAsync(offerName))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Offer).Name,
                                                                                             offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Offer).Name, offerName));

            // Get the offer that matches the provided offerName and that has not been deleted
            var offer = await _context.Offers.SingleOrDefaultAsync(o => (o.OfferName == offerName) && (o.DeletedTime == null));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Offer).Name,
                                                                          offerName,
                                                                          JsonSerializer.Serialize(offer)));

            return(offer);
        }
コード例 #15
0
        /// <summary>
        /// Gets a customMeter.
        /// </summary>
        /// <param name="meterName">The name of the customMeter.</param>
        /// <returns>The customMeter.</returns>
        public async Task <CustomMeter> GetAsync(string meterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeter).Name, meterName));

            if (!(await ExistsAsync(meterName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeter).Name,
                                                                                             meterName));
            }

            // Get the customMeter that matches the provided meterName
            var customMeter = await _context.CustomMeters.SingleOrDefaultAsync(c => c.MeterName == meterName);

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(
                                       typeof(CustomMeter).Name,
                                       meterName,
                                       JsonSerializer.Serialize(customMeter)));

            return(customMeter);
        }
コード例 #16
0
        public async Task <SubscriptionParameter> GetAsync(Guid subscriptionId, string name)
        {
            // Check that an armTemplateParameter with the provided name exists within the given offer
            if (!(await ExistsAsync(subscriptionId, name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(SubscriptionParameter).Name,
                                                                                             name));
            }

            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(SubscriptionParameter).Name, name));
            // Find the armTemplateParameter that matches the name provided
            var parameter = await _context.SubscriptionParameters
                            .SingleOrDefaultAsync(p => (p.SubscriptionId == subscriptionId) && (p.Name == name));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(SubscriptionParameter).Name,
                                                                          name,
                                                                          JsonSerializer.Serialize(parameter),
                                                                          subscriptionId: subscriptionId));

            return(parameter);
        }
コード例 #17
0
        /// <summary>
        /// Gets a TelemetryDataConnector.
        /// </summary>
        /// <param name="name">The name of the TelemetryDataConnector.</param>
        /// <returns>The TelemetryDataConnector.</returns>
        public async Task <TelemetryDataConnector> GetAsync(string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(TelemetryDataConnector).Name, name));

            if (!(await ExistsAsync(name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(TelemetryDataConnector).Name,
                                                                                             name));
            }


            // Get the TelemetryDataConnector that matches the provided meterName
            var connector = await _context.TelemetryDataConnectors.SingleOrDefaultAsync(c => c.Name == name);

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(
                                       typeof(TelemetryDataConnector).Name,
                                       name,
                                       JsonSerializer.Serialize(connector)));

            return(connector);
        }
コード例 #18
0
        /// <summary>
        /// Deletes a TelemetryDataConnector.
        /// </summary>
        /// <param name="name">The name of the TelemetryDataConnector to delete.</param>
        /// <returns>The deleted TelemetryDataConnector.</returns>
        public async Task <TelemetryDataConnector> DeleteAsync(string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(TelemetryDataConnector).Name, name));

            if (!await ExistsAsync(name))
            {
                throw new LunaConflictUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(TelemetryDataConnector).Name,
                                                                                             name));
            }

            // Get the TelemetryDataConnector that matches the name provide
            var connector = await GetAsync(name);

            // Update and save changes in db
            _context.TelemetryDataConnectors.Remove(connector);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(TelemetryDataConnector).Name, name));

            return(connector);
        }
コード例 #19
0
ファイル: SubscriptionService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Gets a subscription by id.
        /// </summary>
        /// <param name="subscriptionId">The id of the subscription.</param>
        /// <returns>The subscription.</returns>
        public async Task <Subscription> GetAsync(Guid subscriptionId)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Subscription).Name, subscriptionId.ToString()));

            // Find the subscription that matches the subscriptionId provided
            var subscription = await _context.Subscriptions.FindAsync(subscriptionId);

            // Check if subscription exists
            if (subscription is null)
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Subscription).Name,
                                                                                             subscriptionId.ToString()));
            }

            subscription.OfferName = (await _context.Offers.FindAsync(subscription.OfferId)).OfferName;
            subscription.PlanName  = (await _context.Plans.FindAsync(subscription.PlanId)).PlanName;
            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Subscription).Name,
                                                                          subscriptionId.ToString(),
                                                                          JsonSerializer.Serialize(subscription)));

            return(subscription); //Task.FromResult(subscription);
        }
コード例 #20
0
ファイル: ArmTemplateService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Uploads the given armTemplate as a JSON file in blob storage and records the URI to the
        /// created resrouce in the db.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="templateName">The name of the ARM template.</param>
        /// <param name="armTemplateJSON">The ARM Template's raw JSON data.</param>
        /// <returns>The created armTemplate db record.</returns>
        public async Task <ArmTemplate> UpdateAsync(string offerName, string templateName, object armTemplateJSON)
        {
            if (armTemplateJSON is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(ArmTemplate).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check that the offer does already have an armTemplate with the same templateName
            if (!await ExistsAsync(offerName, templateName))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(ArmTemplate).Name,
                                                                                             templateName,
                                                                                             offerName: offerName));
            }

            ArmTemplate armTemplate = await GetAsync(offerName, templateName);

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Get the container name associated with the offer
            var containerName = offer.ContainerName.ToString();

            // Upload the armTemplateJSON as a file in blob storage and get the URL to the created resource
            var url = await uploadToBlobStorageAsync(containerName, GetArmTemplateFileName(templateName), armTemplateJSON.ToString());

            _logger.LogInformation($"Arm template {templateName} in offer {offerName} is uploaded to {url}.");

            armTemplate.TemplateFilePath = url;

            // Add armTemplate to db
            _context.ArmTemplates.Update(armTemplate);
            await _context._SaveChangesAsync();

            await UpdateArmTemplateParameters(offer, armTemplateJSON, armTemplate.Id);

            return(armTemplate);
        }
コード例 #21
0
ファイル: ArmTemplateService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Gets an armTemplate within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="templateName">The name of the armTemplate to get.</param>
        /// <param name="useSaSKey">Specify if use SaS key in the uri</param>
        /// <returns>The armTemplate.</returns>
        public async Task <ArmTemplate> GetAsync(string offerName, string templateName, bool useSaSKey = true)
        {
            if (!await _offerService.ExistsAsync(offerName))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Offer).Name,
                                                                                             offerName));
            }

            // Check that an armTemplate with the provided templateName exists within the given offer
            if (!(await ExistsAsync(offerName, templateName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(ArmTemplate).Name,
                                                                                             templateName,
                                                                                             offerName: offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(ArmTemplate).Name, templateName, offerName: offerName));

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Find the armTemplate that matches the templateName provided
            var armTemplate = await _context.ArmTemplates
                              .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.TemplateName == templateName));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(ArmTemplate).Name,
                                                                          templateName,
                                                                          JsonSerializer.Serialize(armTemplate),
                                                                          offerName: offerName));

            if (useSaSKey)
            {
                // Generate Sas key
                armTemplate.TemplateFilePath = await _storageUtility.GetFileReferenceWithSasKeyAsync(armTemplate.TemplateFilePath);
            }

            _logger.LogInformation("Sas key generated.");

            return(armTemplate);
        }
コード例 #22
0
        /// <summary>
        /// Gets a customMeterDimension by id.
        /// </summary>
        /// <param name="id">The id of the customMeterDimension.</param>
        /// <returns>The customMeterDimension.</returns>
        public async Task <CustomMeterDimension> GetAsync(long id)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeterDimension).Name, id.ToString()));

            // Find the customMeterDimension that matches the id provided
            var customMeterDimension = await _context.CustomMeterDimensions.FindAsync(id);

            // Check that an customMeterDimension with the provided id exists
            if (customMeterDimension is null)
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeterDimension).Name,
                                                                                             id.ToString()));
            }

            // Set the customMeterDimension's meterName
            customMeterDimension.MeterName = (await _context.CustomMeters.FindAsync(customMeterDimension.MeterId)).MeterName;

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(CustomMeterDimension).Name,
                                                                          id.ToString(),
                                                                          JsonSerializer.Serialize(customMeterDimension)));

            return(customMeterDimension);
        }
コード例 #23
0
ファイル: IpConfigService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Updates an ipConfig within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the ipConfig to update.</param>
        /// <param name="ipConfig">The updated ipConfig.</param>
        /// <returns>The updated ipConfig.</returns>
        public async Task <IpConfig> UpdateAsync(string offerName, string name, IpConfig ipConfig)
        {
            if (ipConfig is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Plan).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check that that an IpConfig with the given name exists within the Offer
            if (!(await ExistsAsync(offerName, name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(IpConfig).Name,
                                                                                             name,
                                                                                             offerName: offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(IpConfig).Name, name, offerName: offerName, payload: JsonSerializer.Serialize(ipConfig)));

            // Validate that the values provided for the IpConfig are syntactically and logically correct
            ipConfig = validateIpConfig(ipConfig);

            // Get the ipConfig that matches the name provided
            var ipConfigDb = await GetAsync(offerName, name);

            // Verify that the only change is the addition of new IpBlocks
            List <string> addedBlocks = OnlyIpBlocksAdded(ipConfigDb, ipConfig);

            // Process the added IpBlocks
            await ProcessIpBlocks(addedBlocks, ipConfigDb.Id);

            // Get the ipConfig from the db again to repopulate the IpBlocks
            ipConfigDb = await GetAsync(offerName, name);

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(IpConfig).Name, name, offerName: offerName));

            return(ipConfigDb);
        }