<commit_before>module Weavr
  class Cluster < Resource
    field :cluster_id,      Integer
    field :cluster_name,    String
    field :version,         String
    field :desired_configs, Hash       # Fix
    collection :requests,   Request, key_method: 'id'
    collection :services,   Service, key_method: 'service_name'
    collection :hosts,      Host,    key_method: 'host_name'
    field :configurations,  Array, of: Configuration

    def create options
      resource_action(:post, self.class.label => { version: 'HDP-2.1' }.merge(options))
    end

    def add_hosts(*names)
      names.each do |name|
        host = Host.receive(href: File.join(href, 'hosts', name))
        host.create
      end
      refresh!
    end

    def add_services(*names)
      names.each do |name|
        srvc = Service.receive(service_name: name, href: File.join(href, 'services'))
        srvc.create
      end
      refresh!
    end

    def add_components(srvc, names)
      names.each do |name|
        comp = Component.receive(component_name: name, href: File.join(href, 'services', srvc, 'components', name))
        comp.create
      end
      refresh!
    end

    def assign_host_components mapping
      mapping.each_pair do |host, comps|
        comps.each do |comp|
          role = HostRole.receive(href: File.join(href, 'hosts', host, 'host_components', comp))
          role.create
        end
      end
    end

    def create_config(type, version, properties)
      resource_action(:put, self.class.label => { desired_config: { type: type, tag: version, properties: properties } })
      refresh!
    end

    def delete
      resource_action(:delete)
    end

    # Weird persist method for the browser
    def persist
      connection.resource(:post, 'persist', 'CLUSTER_CURRENT_STATUS' => { 'clusterState' => 'CLUSTER_STARTED_5' }.to_json)
    end
  end
end
<commit_msg>make sure to return the newly created cluster<commit_after>module Weavr
  class Cluster < Resource
    field :cluster_id,      Integer
    field :cluster_name,    String
    field :version,         String
    field :desired_configs, Hash       # Fix
    collection :requests,   Request, key_method: 'id'
    collection :services,   Service, key_method: 'service_name'
    collection :hosts,      Host,    key_method: 'host_name'
    field :configurations,  Array, of: Configuration

    def create options
      resource_action(:post, self.class.label => { version: 'HDP-2.1' }.merge(options))
      self
    end

    def add_hosts(*names)
      names.each do |name|
        host = Host.receive(href: File.join(href, 'hosts', name))
        host.create
      end
      refresh!
    end

    def add_services(*names)
      names.each do |name|
        srvc = Service.receive(service_name: name, href: File.join(href, 'services'))
        srvc.create
      end
      refresh!
    end

    def add_components(srvc, names)
      names.each do |name|
        comp = Component.receive(component_name: name, href: File.join(href, 'services', srvc, 'components', name))
        comp.create
      end
      refresh!
    end

    def assign_host_components mapping
      mapping.each_pair do |host, comps|
        comps.each do |comp|
          role = HostRole.receive(href: File.join(href, 'hosts', host, 'host_components', comp))
          role.create
        end
      end
    end

    def create_config(type, version, properties)
      resource_action(:put, self.class.label => { desired_config: { type: type, tag: version, properties: properties } })
      refresh!
    end

    def delete
      resource_action(:delete)
    end

    # Weird persist method for the browser
    def persist
      connection.resource(:post, 'persist', 'CLUSTER_CURRENT_STATUS' => { 'clusterState' => 'CLUSTER_STARTED_5' }.to_json)
    end
  end
end

{'fraction_non_alphanumeric': 0.1008668242710796, 'fraction_numerical': 0.0015760441292356187, 'mean_word_length': 2.595845136921624, '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': '2949001', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1128, 'n_words': 312}