Class: JIJI::Migration::Migrator1_2_0

Inherits:
Object
  • Object
show all
Defined in:
lib/jiji/migration/migrator1_2_0.rb

Overview

1.1.3 → 1.2.0

Instance Method Summary collapse

Instance Method Details

#convert_out_dir(out_dir, info, logger) ⇒ Object

各出力ディリクトリデータのリネーム



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jiji/migration/migrator1_2_0.rb', line 42

def convert_out_dir( out_dir, info, logger )
  begin
    agent_id = JIJI::Util.decode( File.basename(out_dir))
    agent_name = resolve_name( info, agent_id )
    FileLock.new( "#{out_dir}/#{JIJI::Output::PROPERTIES_FILE_NAME}" ).writelock { |f|
      f.write( YAML.dump({:agent_name=>agent_name}) )
    }
    FileUtils.mv out_dir, "#{File.dirname(out_dir)}/#{agent_id}"
  rescue Exception
    logger.error $!
  end
end

#migrate(registry) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jiji/migration/migrator1_2_0.rb', line 14

def migrate( registry )
  logger = registry.server_logger

  #出力の保存先を置換
  Dir.glob("#{registry.process_dir}/*") {|d|
    
    logger.info "convert : #{d}"
    process_id = File.basename(d)
    process_info = {}
    begin
      file = "#{d}/#{JIJI::ProcessInfo::PROPERTY_FILE}"
      process_info = YAML.load_file(file) if  File.exist?(file)
    rescue Exception
      logger.error $!
    end
    
    begin
      # 出力データを列挙
      Dir.glob("#{d}/out/*").map.each {|out_dir|
        convert_out_dir( out_dir, process_info, logger )
      }
    rescue Exception
      logger.error $!
    end
  }
end

#resolve_name(process_info, agent_id) ⇒ Object

エージェント名を解決する



55
56
57
58
59
60
61
# File 'lib/jiji/migration/migrator1_2_0.rb', line 55

def resolve_name( process_info, agent_id )
  if ( process_info["agents"]  )
    item = process_info["agents"].find {|i| i["id"] == agent_id }
    return item["name"] if item
  end
  return "不明"
end