<commit_before># -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L.                                        #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

module OpenNebula
    class Service < DocumentJSON

        DOCUMENT_TYPE = 100

        STATE = {
            'PENDING'            => 0,
            'DEPLOYING'          => 1,
            'RUNNING'            => 2,
            'UNDEPLOYING'        => 3,
            'WARNING'            => 4,
            'DONE'               => 5,
            'FAILED_UNDEPLOYING' => 6,
            'FAILED_DEPLOYING'   => 7,
            'SCALING'            => 8,
            'FAILED_SCALING'     => 9,
            'COOLDOWN'           => 10
        }

        STATE_STR = [
            'PENDING',
            'DEPLOYING',
            'RUNNING',
            'UNDEPLOYING',
            'WARNING',
            'DONE',
            'FAILED_UNDEPLOYING',
            'FAILED_DEPLOYING',
            'SCALING',
            'FAILED_SCALING',
            'COOLDOWN'
        ]

        LOG_COMP = "SER"

        # Returns the service state
        # @return [Integer] the service state
        def state
            return @body['state'].to_i
        end

        # Returns the service strategy
        # @return [String] the service strategy
        def strategy
            return @body['deployment']
        end

        # Returns the string representation of the service state
        # @return the state string
        def state_str
            return STATE_STR[state]
        end

        # Sets a new state
        # @param [Integer] the new state
        # @return [true, false] true if the value was changed
        def set_state(state)
            if state < 0 || state > STATE_STR.size
                return false
            end

            @body['state'] = state

            msg = "New state: #{STATE_STR[state]}"
            Log.info LOG_COMP, msg, self.id()
            self.log_info(msg)

            return true
        end

        # Returns the owner username
        # @return [String] the service's owner username
        def owner_name()
            return self['UNAME']
        end

        # Replaces this object's client with a new one
        # @param [OpenNebula::Client] owner_client the new client
        def replace_client(owner_client)
            @client = owner_client
        end

        # Returns all the node Roles
        # @return [Hash<String,Role>] all the node Roles
        def get_roles
            return @roles
        end

        # Returns true if all the nodes are correctly deployed
        # @return [true, false] true if all the nodes are correctly deployed
        def all_roles_running?()
            @roles.each { |name, role|
                if role.state != Role::STATE['RUNNING']
                    return false
                end
            }

            return true
        end

        # Returns true if all the nodes are in done state
        # @return [true, false] true if all the nodes are correctly deployed
        def all_roles_done?()
            @roles.each { |name, role|
                if role.state != Role::STATE['DONE']
                    return false
                end
            }

            return true
        end

        # Returns true if any of the roles is in failed state
        # @return [true, false] true if any of the roles is in failed state
        def any_role_failed?()
            failed_states = [
                Role::STATE['FAILED_DEPLOYING'],
                Role::STATE['FAILED_UNDEPLOYING']]

            @roles.each { |name, role|
                if failed_states.include?(role.state)
                    return true
                end
            }

            return false
        end

        def any_role_scaling?()
            @roles.each do |name, role|
                if role.state == Role::STATE['SCALING']
                    return true
                end
            end

            return false
        end

        def any_role_failed_scaling?()
            @roles.each do |name, role|
                if role.state == Role::STATE['FAILED_SCALING']
                    return true
                end
            end

            return false
        end

        def any_role_cooldown?()
            @roles.each do |name, role|
                if role.state == Role::STATE['COOLDOWN']
                    return true
                end
            end

            return false
        end<commit_msg>Feature #2917: The service now reports whether it has running_status_gate<commit_after># -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L.                                        #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

module OpenNebula
    class Service < DocumentJSON

        DOCUMENT_TYPE = 100

        STATE = {
            'PENDING'            => 0,
            'DEPLOYING'          => 1,
            'RUNNING'            => 2,
            'UNDEPLOYING'        => 3,
            'WARNING'            => 4,
            'DONE'               => 5,
            'FAILED_UNDEPLOYING' => 6,
            'FAILED_DEPLOYING'   => 7,
            'SCALING'            => 8,
            'FAILED_SCALING'     => 9,
            'COOLDOWN'           => 10
        }

        STATE_STR = [
            'PENDING',
            'DEPLOYING',
            'RUNNING',
            'UNDEPLOYING',
            'WARNING',
            'DONE',
            'FAILED_UNDEPLOYING',
            'FAILED_DEPLOYING',
            'SCALING',
            'FAILED_SCALING',
            'COOLDOWN'
        ]

        LOG_COMP = "SER"

        # Returns the service state
        # @return [Integer] the service state
        def state
            return @body['state'].to_i
        end

        # Returns the service strategy
        # @return [String] the service strategy
        def strategy
            return @body['deployment']
        end

        # Returns the string representation of the service state
        # @return the state string
        def state_str
            return STATE_STR[state]
        end

        # Sets a new state
        # @param [Integer] the new state
        # @return [true, false] true if the value was changed
        def set_state(state)
            if state < 0 || state > STATE_STR.size
                return false
            end

            @body['state'] = state

            msg = "New state: #{STATE_STR[state]}"
            Log.info LOG_COMP, msg, self.id()
            self.log_info(msg)

            return true
        end

        # Returns the owner username
        # @return [String] the service's owner username
        def owner_name()
            return self['UNAME']
        end

        # Replaces this object's client with a new one
        # @param [OpenNebula::Client] owner_client the new client
        def replace_client(owner_client)
            @client = owner_client
        end

        # Returns all the node Roles
        # @return [Hash<String,Role>] all the node Roles
        def get_roles
            return @roles
        end

        # Returns true if all the nodes are correctly deployed
        # @return [true, false] true if all the nodes are correctly deployed
        def all_roles_running?()
            @roles.each { |name, role|
                if role.state != Role::STATE['RUNNING']
                    return false
                end
            }

            return true
        end

        # Returns true if all the nodes are in done state
        # @return [true, false] true if all the nodes are correctly deployed
        def all_roles_done?()
            @roles.each { |name, role|
                if role.state != Role::STATE['DONE']
                    return false
                end
            }

            return true
        end

        # Returns true if any of the roles is in failed state
        # @return [true, false] true if any of the roles is in failed state
        def any_role_failed?()
            failed_states = [
                Role::STATE['FAILED_DEPLOYING'],
                Role::STATE['FAILED_UNDEPLOYING']]

            @roles.each { |name, role|
                if failed_states.include?(role.state)
                    return true
                end
            }

            return false
        end

        # Returns the running_status_vm option
        # @return [true, false] true if the running_status_vm option is enabled
        def running_status_gate
            return @body['running_status_gate']
        end

        def any_role_scaling?()
            @roles.each do |name, role|
                if role.state == Role::STATE['SCALING']
                    return true
                end
            end

            return false
        end

        def any_role_failed_scaling?()
            @roles.each do |name, role|
                if role.state == Role::STATE['FAILED_SCALING']
                    return true
                end
            end

            return false
        end

        def any_role_cooldown?()
            @roles.each do |name, role|
                if role.state == Role::STATE['COOLDOWN']
                    return true
                end
            end

            return false
        end
{'fraction_non_alphanumeric': 0.09750707213578501, 'fraction_numerical': 0.005657708628005658, 'mean_word_length': 1.0903547671840355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6863374', 'n_tokens_mistral': 2797, 'n_tokens_neox': 2635, 'n_words': 871}