<commit_before>module JellyfishAzure
  module Operation
    class AzureProvisionOperation < AzureOperation
      DEPLOYMENT_NAME = 'Deployment'

      def setup
      end

      def location
      end

      def template_url
      end

      def template_parameters
      end

      def execute
        setup

        set_status :provisioning, 'Provisioning service'

        @cloud_client.resource_group.create_resource_group @service.resource_group_name, location

        @cloud_client.deployment.create_deployment @service.resource_group_name, DEPLOYMENT_NAME, template_url, template_parameters

        outputs = wait_for_deployment DEPLOYMENT_NAME

        save_outputs outputs

        set_status :available, 'Deployment successful'

      rescue WaitUtil::TimeoutError
        handle_errors ['The provisioning operation timed out.']
      rescue ValidationError => e
        handle_errors [e.to_s]
      rescue AzureDeploymentErrors => e
        handle_errors e.errors
      rescue MsRestAzure::AzureOperationError => e
        handle_azure_error e
      rescue => e
        handle_errors ["Unexpected error: #{e.class}: #{e.message}"]
      end

      private

      def wait_for_deployment(deployment_name)
        state = nil
        outputs = nil
        WaitUtil.wait_for_condition 'deployment', timeout_sec: deploy_timeout, delay_sec: deploy_delay do
          state, outputs = @cloud_client.deployment.get_deployment_status @service.resource_group_name, deployment_name<commit_msg>Additional logging messages<commit_after>module JellyfishAzure
  module Operation
    class AzureProvisionOperation < AzureOperation
      DEPLOYMENT_NAME = 'Deployment'

      def setup
      end

      def location
      end

      def template_url
      end

      def template_parameters
      end

      def execute
        setup

        log_note 'Provisioning started'

        set_status :provisioning, 'Provisioning service'

        @cloud_client.resource_group.create_resource_group @service.resource_group_name, location

        @cloud_client.deployment.create_deployment @service.resource_group_name, DEPLOYMENT_NAME, template_url, template_parameters

        outputs = wait_for_deployment DEPLOYMENT_NAME

        save_outputs outputs

        set_status :available, 'Deployment successful'
        log_note 'Provisioning completed successfully'

      rescue WaitUtil::TimeoutError
        handle_errors ['The provisioning operation timed out.']
      rescue ValidationError => e
        handle_errors [e.to_s]
      rescue AzureDeploymentErrors => e
        handle_errors e.errors
      rescue MsRestAzure::AzureOperationError => e
        handle_azure_error e
      rescue => e
        handle_errors ["Unexpected error: #{e.class}: #{e.message}"]
      end

      private

      def wait_for_deployment(deployment_name)
        state = nil
        outputs = nil
        WaitUtil.wait_for_condition 'deployment', timeout_sec: deploy_timeout, delay_sec: deploy_delay do
          state, outputs = @cloud_client.deployment.get_deployment_status @service.resource_group_name, deployment_name
{'fraction_non_alphanumeric': 0.05544809800128949, 'fraction_numerical': 0.0, 'mean_word_length': 2.973111395646607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5626314', 'n_tokens_mistral': 844, 'n_tokens_neox': 813, 'n_words': 198}