<commit_before>require_relative  "../ManagedService.rb"

class VolumeService < ManagedService
  def add_consumer_to_service(service_hash)

    return add_volume(service_hash)
  end

  def rm_consumer_from_service (service_hash)

    return  rm_volume(service_hash)
  end

  def add_volume(service_hash)
    p :adding_Volume
    p service_hash

    begin

      dest = SysConfig.LocalFSVolHome() + "/" + service_hash[:parent_engine] + "/" + service_hash[:service_handle]
      if Dir.exists?( dest) == false
        p dest
        FileUtils.mkdir_p(dest)
      end
      #currently the build scripts do this
      #save details with some manager
      return true
    rescue  Exception=>e
      SystemUtils.log_exception(e)
      return false
    end
  end

  def rm_volume(service_hash)

    begin
      cmd = "docker run  --name volbuilder --memory=20m -e fw_user=www-data    -v /var/lib/engines/fs/" + service_hash[:parent_engine] + ":/dest/fs:rw   -t engines/volbuilder:" + SystemUtils.system_release + " /home/remove_container.sh fs"  
      retval =  SystemUtils.run_system(cmd)
      if retval == true
        Dir.delete( SysConfig.LocalFSVolHome() + "/" + service_hash[:parent_engine])
          return true 
      else
        SystemUtils.log_error_mesg("Failed to Delete FS:" + retval.to_s ,service_hash)
        return false        
      end
      puts "would remove " + service_hash.to_s
      #update details with some manager
      return true
    rescue  Exception=>e
      SystemUtils.log_exception(e)<commit_msg>strip \n from release<commit_after>require_relative  "../ManagedService.rb"

class VolumeService < ManagedService
  def add_consumer_to_service(service_hash)

    return add_volume(service_hash)
  end

  def rm_consumer_from_service (service_hash)

    return  rm_volume(service_hash)
  end

  def add_volume(service_hash)
    p :adding_Volume
    p service_hash

    begin

      dest = SysConfig.LocalFSVolHome() + "/" + service_hash[:parent_engine] + "/" + service_hash[:service_handle]
      if Dir.exists?( dest) == false
        p dest
        FileUtils.mkdir_p(dest)
      end
      #currently the build scripts do this
      #save details with some manager
      return true
    rescue  Exception=>e
      SystemUtils.log_exception(e)
      return false
    end
  end

  def rm_volume(service_hash)

    begin
      cmd = "docker run  --name volbuilder --memory=20m -e fw_user=www-data    -v /var/lib/engines/fs/" + service_hash[:parent_engine] + ":/dest/fs:rw   -t engines/volbuilder:" + SystemUtils.system_release + " /home/remove_container.sh fs"  
      retval =  SystemUtils.run_system(cmd)
      if retval == true
        Dir.delete( SysConfig.LocalFSVolHome() + "/" + service_hash[:parent_engine])
          return true 
      else
        SystemUtils.log_error_mesg("Failed to Delete FS:" + retval.to_s ,service_hash)
        @last_error="Failed to Delete FS:" + retval.to_s
        return false        
      end
    
      #update details with some manager
      return true
    rescue  Exception=>e
      SystemUtils.log_exception(e)
{'fraction_non_alphanumeric': 0.0902304446608244, 'fraction_numerical': 0.0012982797792924375, 'mean_word_length': 2.7769607843137254, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '414456', 'n_tokens_mistral': 968, 'n_tokens_neox': 942, 'n_words': 221}