kvm 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/AGPL-3.0 +661 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +23 -0
- data/README.md +73 -0
- data/Rakefile +48 -0
- data/bin/kvm +6 -0
- data/kvm.gemspec +28 -0
- data/lib/kvm.rb +286 -0
- data/lib/kvm/archive.rb +56 -0
- data/lib/kvm/artifact.rb +28 -0
- data/lib/kvm/db/jdbc_adapter.rb +71 -0
- data/lib/kvm/db/oracle.rb +23 -0
- data/lib/kvm/db/types.rb +11 -0
- data/lib/kvm/impex.rb +109 -0
- data/lib/kvm/log.rb +7 -0
- data/lib/kvm/resource.rb +72 -0
- data/lib/kvm/rice_release.rb +79 -0
- data/lib/kvm/rice_release_generated_dataset.rb +68 -0
- data/lib/kvm/source.rb +33 -0
- data/lib/kvm/subversion.rb +52 -0
- data/lib/kvm/version.rb +3 -0
- data/lib/kvm/wallet.rb +64 -0
- data/support/ant/INSTALL +2 -0
- data/support/ant/KEYS +1398 -0
- data/support/ant/LICENSE +272 -0
- data/support/ant/NOTICE +6 -0
- data/support/ant/README +97 -0
- data/support/ant/WHATSNEW +5467 -0
- data/support/ant/bin/ant +335 -0
- data/support/ant/bin/ant.bat +218 -0
- data/support/ant/bin/ant.cmd +93 -0
- data/support/ant/bin/antRun +24 -0
- data/support/ant/bin/antRun.bat +50 -0
- data/support/ant/bin/antRun.pl +66 -0
- data/support/ant/bin/antenv.cmd +98 -0
- data/support/ant/bin/complete-ant-cmd.pl +114 -0
- data/support/ant/bin/envset.cmd +131 -0
- data/support/ant/bin/lcp.bat +31 -0
- data/support/ant/bin/runant.pl +153 -0
- data/support/ant/bin/runant.py +102 -0
- data/support/ant/bin/runrc.cmd +60 -0
- data/support/ant/etc/ant-bootstrap.jar +0 -0
- data/support/ant/etc/changelog.xsl +148 -0
- data/support/ant/etc/checkstyle/checkstyle-frames.xsl +299 -0
- data/support/ant/etc/checkstyle/checkstyle-text.xsl +34 -0
- data/support/ant/etc/checkstyle/checkstyle-xdoc.xsl +130 -0
- data/support/ant/etc/coverage-frames.xsl +489 -0
- data/support/ant/etc/jdepend-frames.xsl +487 -0
- data/support/ant/etc/jdepend.xsl +276 -0
- data/support/ant/etc/junit-frames-xalan1.xsl +733 -0
- data/support/ant/etc/junit-frames.xsl +902 -0
- data/support/ant/etc/junit-noframes.xsl +478 -0
- data/support/ant/etc/log.xsl +203 -0
- data/support/ant/etc/maudit-frames.xsl +503 -0
- data/support/ant/etc/mmetrics-frames.xsl +1026 -0
- data/support/ant/etc/tagdiff.xsl +179 -0
- data/support/ant/fetch.xml +343 -0
- data/support/ant/get-m2.xml +121 -0
- data/support/ant/lib/README +3 -0
- data/support/ant/lib/ant-antlr.jar +0 -0
- data/support/ant/lib/ant-antlr.pom +76 -0
- data/support/ant/lib/ant-apache-bcel.jar +0 -0
- data/support/ant/lib/ant-apache-bcel.pom +72 -0
- data/support/ant/lib/ant-apache-bsf.jar +0 -0
- data/support/ant/lib/ant-apache-bsf.pom +75 -0
- data/support/ant/lib/ant-apache-log4j.jar +0 -0
- data/support/ant/lib/ant-apache-log4j.pom +70 -0
- data/support/ant/lib/ant-apache-oro.jar +0 -0
- data/support/ant/lib/ant-apache-oro.pom +75 -0
- data/support/ant/lib/ant-apache-regexp.jar +0 -0
- data/support/ant/lib/ant-apache-regexp.pom +71 -0
- data/support/ant/lib/ant-apache-resolver.jar +0 -0
- data/support/ant/lib/ant-apache-resolver.pom +70 -0
- data/support/ant/lib/ant-apache-xalan2.jar +0 -0
- data/support/ant/lib/ant-apache-xalan2.pom +95 -0
- data/support/ant/lib/ant-commons-logging.jar +0 -0
- data/support/ant/lib/ant-commons-logging.pom +71 -0
- data/support/ant/lib/ant-commons-net.jar +0 -0
- data/support/ant/lib/ant-commons-net.pom +76 -0
- data/support/ant/lib/ant-jai.jar +0 -0
- data/support/ant/lib/ant-jai.pom +85 -0
- data/support/ant/lib/ant-javamail.jar +0 -0
- data/support/ant/lib/ant-javamail.pom +79 -0
- data/support/ant/lib/ant-jdepend.jar +0 -0
- data/support/ant/lib/ant-jdepend.pom +73 -0
- data/support/ant/lib/ant-jmf.jar +0 -0
- data/support/ant/lib/ant-jmf.pom +66 -0
- data/support/ant/lib/ant-jsch.jar +0 -0
- data/support/ant/lib/ant-jsch.pom +75 -0
- data/support/ant/lib/ant-junit.jar +0 -0
- data/support/ant/lib/ant-junit.pom +101 -0
- data/support/ant/lib/ant-junit4.jar +0 -0
- data/support/ant/lib/ant-junit4.pom +71 -0
- data/support/ant/lib/ant-launcher.jar +0 -0
- data/support/ant/lib/ant-launcher.pom +58 -0
- data/support/ant/lib/ant-netrexx.jar +0 -0
- data/support/ant/lib/ant-netrexx.pom +99 -0
- data/support/ant/lib/ant-parent.pom +120 -0
- data/support/ant/lib/ant-swing.jar +0 -0
- data/support/ant/lib/ant-swing.pom +67 -0
- data/support/ant/lib/ant-testutil.jar +0 -0
- data/support/ant/lib/ant-testutil.pom +75 -0
- data/support/ant/lib/ant.jar +0 -0
- data/support/ant/lib/ant.pom +222 -0
- data/support/ant/lib/libraries.properties +65 -0
- data/test/data/files/rice-0.0.0.0-bin.tar.gz +0 -0
- data/test/data/svn/README.txt +5 -0
- data/test/data/svn/conf/authz +32 -0
- data/test/data/svn/conf/passwd +8 -0
- data/test/data/svn/conf/svnserve.conf +47 -0
- data/test/data/svn/db/current +1 -0
- data/test/data/svn/db/format +2 -0
- data/test/data/svn/db/fs-type +1 -0
- data/test/data/svn/db/fsfs.conf +37 -0
- data/test/data/svn/db/min-unpacked-rev +1 -0
- data/test/data/svn/db/rep-cache.db +0 -0
- data/test/data/svn/db/revprops/0/0 +5 -0
- data/test/data/svn/db/revprops/0/1 +13 -0
- data/test/data/svn/db/revs/0/0 +11 -0
- data/test/data/svn/db/revs/0/1 +0 -0
- data/test/data/svn/db/txn-current +1 -0
- data/test/data/svn/db/txn-current-lock +0 -0
- data/test/data/svn/db/uuid +1 -0
- data/test/data/svn/db/write-lock +0 -0
- data/test/data/svn/format +1 -0
- data/test/data/svn/hooks/post-commit.tmpl +50 -0
- data/test/data/svn/hooks/post-lock.tmpl +44 -0
- data/test/data/svn/hooks/post-revprop-change.tmpl +56 -0
- data/test/data/svn/hooks/post-unlock.tmpl +42 -0
- data/test/data/svn/hooks/pre-commit.tmpl +81 -0
- data/test/data/svn/hooks/pre-lock.tmpl +71 -0
- data/test/data/svn/hooks/pre-revprop-change.tmpl +66 -0
- data/test/data/svn/hooks/pre-unlock.tmpl +63 -0
- data/test/data/svn/hooks/start-commit.tmpl +65 -0
- data/test/data/svn/locks/db-logs.lock +3 -0
- data/test/data/svn/locks/db.lock +3 -0
- data/test/helper.rb +146 -0
- data/test/int_test_generate_sql.rb +58 -0
- data/test/test_archive.rb +35 -0
- data/test/test_generate_sql.rb +0 -0
- data/test/test_rice_release.rb +61 -0
- data/test/test_rice_release_generated_dataset.rb +12 -0
- data/test/test_source.rb +31 -0
- data/test/test_subversion.rb +20 -0
- metadata +298 -0
data/lib/kvm/archive.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'kvm/resource'
|
2
|
+
require 'kvm/artifact'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module KVM
|
6
|
+
class Archive < FileResource
|
7
|
+
BASE_DIR=File.expand_path('archives', KVM_DIR)
|
8
|
+
|
9
|
+
attr_reader :filename
|
10
|
+
|
11
|
+
def initialize(name, dist = "bin")
|
12
|
+
@info = Artifact.parse_name(name, dist)
|
13
|
+
@ext = Archive.project_extension(@info[:project])
|
14
|
+
@filename = Artifact.filename(@info, @ext)
|
15
|
+
super(File.expand_path(Artifact.filename(@info, @ext), BASE_DIR))
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate!
|
19
|
+
download
|
20
|
+
end
|
21
|
+
|
22
|
+
def download_url
|
23
|
+
"http://downloads.#{@info[:project]}.kuali.org/#{@info[:version]}/#{@filename}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def download
|
27
|
+
FileUtils.mkdir_p BASE_DIR
|
28
|
+
# this performs a redundant copy
|
29
|
+
# TODO: make moar bettar
|
30
|
+
# Thor get helper?
|
31
|
+
open(download_url) do |src|
|
32
|
+
File.open(File.join(BASE_DIR, @filename), "wb") do |dst|
|
33
|
+
FileUtils.copy_stream(src, dst)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
#system("wget -P #{BASE_DIR} #{url}") || raise("Error downloading #{url}")
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def self.project_extension(project)
|
42
|
+
case project
|
43
|
+
when 'kfs'
|
44
|
+
'zip'
|
45
|
+
when 'rice'
|
46
|
+
'tar.gz'
|
47
|
+
else
|
48
|
+
'tar.gz'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.from_file(f)
|
53
|
+
Archive.new(File.basename(f))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/kvm/artifact.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module KVM
|
2
|
+
module Artifact
|
3
|
+
def self.parse_name(name, dist = "bin")
|
4
|
+
results = name.scan(/([[:alpha:]]+)-([[:alnum:]\.]+)(?:-([[:alpha:]]+))?.*/)
|
5
|
+
raise "Invalid artifact identifier #{name}" if results.length == 0
|
6
|
+
parsed = {
|
7
|
+
:name => name,
|
8
|
+
:project => results[0][0],
|
9
|
+
:version => results[0][1],
|
10
|
+
:dist => results[0][2]
|
11
|
+
}
|
12
|
+
parsed[:dist] = dist unless parsed[:project] == "kfs" # kfs only has a single distribution
|
13
|
+
parsed
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.to_name(info)
|
17
|
+
[ info[:project], info[:version], info[:dist] ].join('-')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.filename(info, ext)
|
21
|
+
[ dirname(info), ext ].join(".")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.dirname(info)
|
25
|
+
to_name(info)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module KVM
|
2
|
+
module Db
|
3
|
+
class JdbcAdapter
|
4
|
+
DB_DRIVERS = {
|
5
|
+
'oracle' => 'oracle.jdbc.driver.OracleDriver',
|
6
|
+
'mysql' => 'com.mysql.jdbc.Driver'
|
7
|
+
}
|
8
|
+
|
9
|
+
def initialize(db_config)
|
10
|
+
ensure_jruby
|
11
|
+
@db_config = db_config
|
12
|
+
@driver_jar = db_config.jar
|
13
|
+
load_driver
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute_update(sqls)
|
17
|
+
for sql in sqls
|
18
|
+
with_statement do |stmt|
|
19
|
+
next unless sql and sql.length > 0
|
20
|
+
KVM::LOG.info("Executing statement: " + sql)
|
21
|
+
stmt.executeUpdate(sql)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def with_statement
|
29
|
+
with_connection do |con|
|
30
|
+
stmt = con.createStatement
|
31
|
+
begin
|
32
|
+
yield stmt
|
33
|
+
ensure
|
34
|
+
stmt.close
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def with_connection
|
40
|
+
con = jdbc_connect
|
41
|
+
begin
|
42
|
+
yield con
|
43
|
+
ensure
|
44
|
+
con.close
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def jdbc_connect
|
49
|
+
# load the jdbc driver
|
50
|
+
Java::JavaClass.for_name(DB_DRIVERS[@db_config.db_type])
|
51
|
+
props = java.util.Properties.new
|
52
|
+
props.setProperty("user", @db_config.username)
|
53
|
+
props.setProperty("password", @db_config.password)
|
54
|
+
# special case to automatically log in as sysdba when using 'sys' username
|
55
|
+
props.setProperty("internal_logon", "sysdba") if @db_config.db_type == 'oracle' and @db_config.username == 'sys'
|
56
|
+
java.sql.DriverManager.getConnection(@db_config.url, props)
|
57
|
+
end
|
58
|
+
|
59
|
+
def ensure_jruby
|
60
|
+
raise "This command must be run under JRuby" unless defined? JRUBY_VERSION
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_driver
|
64
|
+
raise "Please specify the driver jar in the 'jar' property" unless @driver_jar
|
65
|
+
# jrubiness follows...
|
66
|
+
require 'java'
|
67
|
+
require @driver_jar
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'kvm/log'
|
2
|
+
|
3
|
+
module KVM
|
4
|
+
module Db
|
5
|
+
module Oracle
|
6
|
+
def self.create_user(username, password)
|
7
|
+
[ %Q(create user #{username} identified by "#{password}" default tablespace users),
|
8
|
+
"grant connect, resource to #{username}",
|
9
|
+
"grant create view to #{username}" ]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.drop_user(user)
|
13
|
+
[ "drop user #{user} cascade" ]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.parse_sql(db, file)
|
17
|
+
sql = File.read(file)
|
18
|
+
# naively strip comments and split statements
|
19
|
+
statements = sql.gsub(/^--.*$/, '').split(/^\/$/).map { |s| s.strip }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/kvm/db/types.rb
ADDED
data/lib/kvm/impex.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'kvm/subversion'
|
2
|
+
require 'kvm/source'
|
3
|
+
require 'kvm/db/jdbc_adapter'
|
4
|
+
require 'kvm/log'
|
5
|
+
#require 'rake'
|
6
|
+
#require 'ant'
|
7
|
+
|
8
|
+
module KVM
|
9
|
+
class Impex
|
10
|
+
IMPEX_SOURCE=KVM::Source.new(KVM::Subversion::IMPEX_TOOL_REPO_PATH)
|
11
|
+
DRIVERS_DIRECTORY_OPT = 'drivers.directory'
|
12
|
+
DEFAULT_DRIVERS_DIRECTORY = '/opt/java/drivers'
|
13
|
+
BUNDLED_ANT = File.expand_path(File.join('..', '..', 'support', 'ant'), File.dirname(__FILE__))
|
14
|
+
|
15
|
+
def initialize(dir)
|
16
|
+
@dir = dir
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_ddl(schema_dir, db_type, output_dir, opts = {})
|
20
|
+
run_gensql('create-ddl', schema_dir, db_type, { 'torque.sql.dir' => "#{output_dir}/sql" }.merge(opts))
|
21
|
+
end
|
22
|
+
|
23
|
+
def dataxml_to_sql(schema_dir, db_type, output_dir, opts = {})
|
24
|
+
# generates datasql subdir in release
|
25
|
+
run_gensql('dataxml-to-sql', schema_dir, db_type, opts)
|
26
|
+
mv_dir "#{schema_dir}/datasql/", "#{output_dir}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def prepare_sqlloader(schema_dir, db_type, output_dir, opts = {})
|
30
|
+
# generates sqlloader subdir in release
|
31
|
+
run_gensql('prepare-sqlloader', schema_dir, db_type, opts)
|
32
|
+
mv_dir "#{schema_dir}/sqlloader/", "#{output_dir}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def apply_ddl(dataset_dir, db_type, url, user, password, opts = {})
|
36
|
+
run_db('apply-ddl', dataset_dir, db_type, url, user, password, opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
def apply_data_sql(dataset_dir, db_type, url, user, password, opts = {})
|
40
|
+
run_db('apply-data-sql', dataset_dir, db_type, url, user, password, opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
def apply_constraint_ddl(dataset_dir, db_type, url, user, password, opts = {})
|
44
|
+
run_db('apply-constraint-ddl', dataset_dir, db_type, url, user, password, opts)
|
45
|
+
end
|
46
|
+
|
47
|
+
# compound commands
|
48
|
+
|
49
|
+
def generate_sql(schema_dir, db_type, output_dir, opts = {})
|
50
|
+
LOG.info "Generating sql #{schema_dir} #{db_type} #{output_dir}"
|
51
|
+
create_ddl(schema_dir, db_type, output_dir, opts)
|
52
|
+
dataxml_to_sql(schema_dir, db_type, output_dir)
|
53
|
+
#prepare_sqlloader(schema_dir, db_type, output_dir)
|
54
|
+
end
|
55
|
+
|
56
|
+
# like 'import' except can be used against pregenerated sql datasets
|
57
|
+
def apply_sql(dataset_dir, db_type, url, user, password, opts = {})
|
58
|
+
LOG.info "Applying sql #{dataset_dir} #{db_type}"
|
59
|
+
# first run without constraints
|
60
|
+
apply_ddl(dataset_dir, db_type, url, user, password, opts) &&
|
61
|
+
# insert data
|
62
|
+
apply_data_sql(dataset_dir, db_type, url, user, password, opts) &&
|
63
|
+
# apply constraints
|
64
|
+
apply_constraint_ddl(dataset_dir, db_type, url, user, password, opts)
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def mv_dir(src, tgt_parent)
|
70
|
+
FileUtils.mkdir_p tgt_parent
|
71
|
+
FileUtils.mv src, tgt_parent
|
72
|
+
end
|
73
|
+
|
74
|
+
def run_db(command, dataset_dir, db_type, url, user, password, opts = {})
|
75
|
+
run(command, {
|
76
|
+
'torque.schema.dir' => dataset_dir,
|
77
|
+
'import.torque.database' => db_type,
|
78
|
+
'import.torque.database.driver' => KVM::Db::JdbcAdapter::DB_DRIVERS[db_type],
|
79
|
+
'import.torque.database.url' => url,
|
80
|
+
'import.torque.database.user' => user,
|
81
|
+
'import.torque.database.password' => password
|
82
|
+
}.merge(opts))
|
83
|
+
end
|
84
|
+
|
85
|
+
def run_gensql(command, schema_dir, db_type, opts = {})
|
86
|
+
run(command, {
|
87
|
+
'torque.schema.dir' => schema_dir,
|
88
|
+
'import.torque.database' => db_type
|
89
|
+
}.merge(opts))
|
90
|
+
end
|
91
|
+
|
92
|
+
def run(command, opts)
|
93
|
+
LOG.debug command
|
94
|
+
LOG.debug opts
|
95
|
+
# HACK: because i don't have time to futz with this
|
96
|
+
drivers_dir = ENV['JDBC_DRIVERS_DIR'] || DEFAULT_DRIVERS_DIRECTORY
|
97
|
+
opts[DRIVERS_DIRECTORY_OPT] = drivers_dir unless opts[DRIVERS_DIRECTORY_OPT]
|
98
|
+
|
99
|
+
prop_array = opts.map { |k, v| "-D#{k}=#{v}" }
|
100
|
+
LOG.debug prop_array
|
101
|
+
ant_args = prop_array + [ "-f", "#{@dir}/impex/build.xml", command ]
|
102
|
+
command_line = ([ File.join(BUNDLED_ANT, 'bin', 'ant') ] + ant_args).join(" ")
|
103
|
+
LOG.debug command_line
|
104
|
+
system (command_line) || raise("Error running impex")
|
105
|
+
end
|
106
|
+
|
107
|
+
IMPEX = KVM::Impex.new(IMPEX_SOURCE.path)
|
108
|
+
end
|
109
|
+
end
|
data/lib/kvm/log.rb
ADDED
data/lib/kvm/resource.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module KVM
|
2
|
+
class Resource
|
3
|
+
def exists?
|
4
|
+
false
|
5
|
+
end
|
6
|
+
|
7
|
+
def generate!
|
8
|
+
end
|
9
|
+
|
10
|
+
def get
|
11
|
+
exists = exists?
|
12
|
+
generate! unless exists
|
13
|
+
!exists
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.list
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class FileSystemResource < KVM::Resource
|
26
|
+
attr_reader :path
|
27
|
+
|
28
|
+
def initialize(path)
|
29
|
+
@path = path
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
File.basename(@path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def exists?
|
37
|
+
!@path.nil? and self.class.is_resource?(@path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def nested_path(paths)
|
41
|
+
File.expand_path(File.join(paths), path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.list(glob=File.join(self::BASE_DIR, "*"))
|
45
|
+
Dir[glob].select { |f| is_resource?(f) }.map { |f| from_file(f) }
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def self.is_resource?(file)
|
51
|
+
file.exists?(file)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.from_file(file)
|
55
|
+
file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class FileResource < KVM::FileSystemResource
|
60
|
+
protected
|
61
|
+
def self.is_resource?(f)
|
62
|
+
File.file?(f)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class DirResource < KVM::FileSystemResource
|
67
|
+
protected
|
68
|
+
def self.is_resource?(f)
|
69
|
+
File.directory?(f)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'kvm/resource'
|
2
|
+
require 'kvm/artifact'
|
3
|
+
require 'kvm/log'
|
4
|
+
|
5
|
+
module KVM
|
6
|
+
class RiceRelease < DirResource
|
7
|
+
BASE_DIR=File.expand_path('releases', KVM_DIR)
|
8
|
+
|
9
|
+
EXTRACTOR = {
|
10
|
+
'.tar.gz' => 'tar -zxf %s'
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(name, dist = "bin")
|
14
|
+
@info = Artifact.parse_name(name, dist)
|
15
|
+
super(File.expand_path(Artifact.dirname(@info), BASE_DIR))
|
16
|
+
LOG.debug "RELEASE DIR: " + path
|
17
|
+
LOG.debug "PATH EXISTS?"
|
18
|
+
LOG.debug File.directory?(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
#def name
|
22
|
+
# super.gsub(/-bin$/, '')
|
23
|
+
#end
|
24
|
+
|
25
|
+
def generate!
|
26
|
+
LOG.info "Extracting Rice release #{@info[:version]}"
|
27
|
+
RiceRelease.extract_release(Archive.new(Artifact.to_name(@info)), path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def dataset_dirs
|
31
|
+
Dir.glob(dataset_base_dir("*"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def dataset_base_dir(ds_name)
|
35
|
+
File.join(path, "database", ds_name + '-dataset')
|
36
|
+
end
|
37
|
+
|
38
|
+
def dataset_dir(ds_name, db_type)
|
39
|
+
LOG.debug "dataset_dir " + ds_name
|
40
|
+
LOG.debug File.join(dataset_base_dir(ds_name), db_type)
|
41
|
+
File.join(dataset_base_dir(ds_name), db_type)
|
42
|
+
end
|
43
|
+
|
44
|
+
def datasets
|
45
|
+
dataset_dirs.map { |d| File.basename(d).gsub(/-dataset$/, '') }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_sql_file(type)
|
49
|
+
File.expand_path("scripts/ddl/rice-test-tables-#{type}.sql", path)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def self.extract_release(archive, target_dir)
|
55
|
+
archive.get
|
56
|
+
EXTRACTOR.each do |key, cmd_format|
|
57
|
+
if archive.name =~ /.#{key}$/
|
58
|
+
command = cmd_format % archive.path
|
59
|
+
LOG.debug "Extracting #{archive.path} to #{BASE_DIR}"
|
60
|
+
LOG.debug command
|
61
|
+
FileUtils.mkdir_p target_dir
|
62
|
+
LOG.debug Dir[BASE_DIR + "/*"]
|
63
|
+
LOG.debug Dir[BASE_DIR + "/" + target_dir]
|
64
|
+
LOG.debug "target dir #{target_dir} exists?"
|
65
|
+
LOG.debug File.directory?(target_dir)
|
66
|
+
Dir.chdir target_dir do
|
67
|
+
system(command) || raise("Error extracting #{archive.path}")
|
68
|
+
return
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
raise "Unable to extract #{archive}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.from_file(f)
|
76
|
+
RiceRelease.new(File.basename(f))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|