mortar 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mortar/command/describe.rb +2 -3
- data/lib/mortar/command/illustrate.rb +2 -3
- data/lib/mortar/command/jobs.rb +3 -4
- data/lib/mortar/command/validate.rb +1 -4
- data/lib/mortar/git.rb +34 -1
- data/lib/mortar/version.rb +1 -1
- data/spec/mortar/command/jobs_spec.rb +5 -4
- data/spec/mortar/git_spec.rb +3 -9
- data/spec/spec_helper.rb +18 -2
- metadata +2 -4
- data/lib/mortar/snapshot.rb +0 -39
- data/spec/mortar/snapshot_spec.rb +0 -46
@@ -15,13 +15,12 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "mortar/command/base"
|
18
|
-
require "mortar/snapshot"
|
19
18
|
|
20
19
|
# show data schema for pigscript
|
21
20
|
#
|
22
21
|
class Mortar::Command::Describe < Mortar::Command::Base
|
23
22
|
|
24
|
-
include Mortar::
|
23
|
+
include Mortar::Git
|
25
24
|
|
26
25
|
# describe [PIGSCRIPT] [ALIAS]
|
27
26
|
#
|
@@ -43,7 +42,7 @@ class Mortar::Command::Describe < Mortar::Command::Base
|
|
43
42
|
validate_arguments!
|
44
43
|
validate_git_based_project!
|
45
44
|
pigscript = validate_pigscript!(pigscript_name)
|
46
|
-
git_ref = create_and_push_snapshot_branch(
|
45
|
+
git_ref = git.create_and_push_snapshot_branch(project)
|
47
46
|
|
48
47
|
describe_id = nil
|
49
48
|
action("Starting describe") do
|
@@ -15,13 +15,12 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "mortar/command/base"
|
18
|
-
require "mortar/snapshot"
|
19
18
|
|
20
19
|
# sample and show data flowing through a pigscript
|
21
20
|
#
|
22
21
|
class Mortar::Command::Illustrate < Mortar::Command::Base
|
23
22
|
|
24
|
-
include Mortar::
|
23
|
+
include Mortar::Git
|
25
24
|
|
26
25
|
# illustrate [PIGSCRIPT] [ALIAS]
|
27
26
|
#
|
@@ -49,7 +48,7 @@ class Mortar::Command::Illustrate < Mortar::Command::Base
|
|
49
48
|
validate_arguments!
|
50
49
|
validate_git_based_project!
|
51
50
|
pigscript = validate_pigscript!(pigscript_name)
|
52
|
-
git_ref = create_and_push_snapshot_branch(
|
51
|
+
git_ref = git.create_and_push_snapshot_branch(project)
|
53
52
|
|
54
53
|
illustrate_id = nil
|
55
54
|
action("Starting illustrate") do
|
data/lib/mortar/command/jobs.rb
CHANGED
@@ -15,14 +15,13 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "mortar/command/base"
|
18
|
-
require "mortar/snapshot"
|
19
18
|
require "time"
|
20
19
|
|
21
20
|
# run and view status of pig jobs (run, status)
|
22
21
|
#
|
23
22
|
class Mortar::Command::Jobs < Mortar::Command::Base
|
24
23
|
|
25
|
-
include Mortar::
|
24
|
+
include Mortar::Git
|
26
25
|
|
27
26
|
# jobs
|
28
27
|
#
|
@@ -77,7 +76,7 @@ class Mortar::Command::Jobs < Mortar::Command::Base
|
|
77
76
|
clusters = api.get_clusters().body['clusters']
|
78
77
|
|
79
78
|
largest_free_cluster = clusters.select{ |c| \
|
80
|
-
c['
|
79
|
+
c['running_jobs'].length == 0 && c['status_code'] == Mortar::API::Clusters::STATUS_RUNNING }.
|
81
80
|
max_by{|c| c['size']}
|
82
81
|
|
83
82
|
if largest_free_cluster.nil?
|
@@ -100,7 +99,7 @@ class Mortar::Command::Jobs < Mortar::Command::Base
|
|
100
99
|
|
101
100
|
validate_git_based_project!
|
102
101
|
pigscript = validate_pigscript!(pigscript_name)
|
103
|
-
git_ref = create_and_push_snapshot_branch(
|
102
|
+
git_ref = git.create_and_push_snapshot_branch(project)
|
104
103
|
notify_on_job_finish = ! options[:donotnotify]
|
105
104
|
|
106
105
|
# post job to API
|
@@ -15,13 +15,10 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "mortar/command/base"
|
18
|
-
require "mortar/snapshot"
|
19
18
|
|
20
19
|
# check script syntax
|
21
20
|
#
|
22
21
|
class Mortar::Command::Validate < Mortar::Command::Base
|
23
|
-
|
24
|
-
include Mortar::Snapshot
|
25
22
|
|
26
23
|
# validate [PIGSCRIPT]
|
27
24
|
#
|
@@ -41,7 +38,7 @@ class Mortar::Command::Validate < Mortar::Command::Base
|
|
41
38
|
validate_arguments!
|
42
39
|
validate_git_based_project!
|
43
40
|
pigscript = validate_pigscript!(pigscript_name)
|
44
|
-
git_ref = create_and_push_snapshot_branch(
|
41
|
+
git_ref = git.create_and_push_snapshot_branch(project)
|
45
42
|
|
46
43
|
validate_id = nil
|
47
44
|
action("Starting validate") do
|
data/lib/mortar/git.rb
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require "vendor/mortar/uuid"
|
18
|
+
require "mortar/helpers"
|
18
19
|
require "set"
|
19
20
|
|
20
21
|
module Mortar
|
@@ -91,6 +92,12 @@ module Mortar
|
|
91
92
|
unless has_commits?
|
92
93
|
raise GitError, "No commits found in repository. You must do an initial commit to initialize the repository."
|
93
94
|
end
|
95
|
+
|
96
|
+
# Copy code into a temp directory so we don't confuse editors while snapshotting
|
97
|
+
curdir = Dir.pwd
|
98
|
+
tmpdir = Dir.mktmpdir
|
99
|
+
FileUtils.cp_r(Dir.glob('*', File::FNM_DOTMATCH) - ['.', '..'], tmpdir)
|
100
|
+
Dir.chdir(tmpdir)
|
94
101
|
|
95
102
|
starting_branch = current_branch
|
96
103
|
snapshot_branch = "mortar-snapshot-#{Mortar::UUID.create_random.to_s}"
|
@@ -122,7 +129,33 @@ module Mortar
|
|
122
129
|
end
|
123
130
|
end
|
124
131
|
|
125
|
-
|
132
|
+
Dir.chdir(curdir)
|
133
|
+
return tmpdir, snapshot_branch
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_and_push_snapshot_branch(project)
|
137
|
+
curdir = Dir.pwd
|
138
|
+
|
139
|
+
# create a snapshot branch in a temporary directory
|
140
|
+
snapshot_dir, snapshot_branch = Helpers.action("Taking code snapshot") do
|
141
|
+
create_snapshot_branch()
|
142
|
+
end
|
143
|
+
|
144
|
+
Dir.chdir(snapshot_dir)
|
145
|
+
|
146
|
+
git_ref = Helpers.action("Sending code snapshot to Mortar") do
|
147
|
+
# push the code
|
148
|
+
push(project.remote, snapshot_branch)
|
149
|
+
|
150
|
+
# grab the commit hash and clean out the branch from the local branches
|
151
|
+
ref = git_ref(snapshot_branch)
|
152
|
+
branch_delete(snapshot_branch)
|
153
|
+
ref
|
154
|
+
end
|
155
|
+
|
156
|
+
FileUtils.remove_entry_secure(snapshot_dir)
|
157
|
+
Dir.chdir(curdir)
|
158
|
+
return git_ref
|
126
159
|
end
|
127
160
|
|
128
161
|
#
|
data/lib/mortar/version.rb
CHANGED
@@ -188,11 +188,12 @@ STDOUT
|
|
188
188
|
mock(Mortar::Auth.api).get_clusters() {
|
189
189
|
Excon::Response.new(:body => {
|
190
190
|
'clusters' => [
|
191
|
-
{ 'cluster_id' => small_cluster_id, 'size' => small_cluster_size, '
|
192
|
-
{ 'cluster_id' => large_cluster_id, 'size' => large_cluster_size, '
|
193
|
-
{ 'cluster_id' => starting_cluster_id, 'size' => starting_cluster_size, '
|
191
|
+
{ 'cluster_id' => small_cluster_id, 'size' => small_cluster_size, 'running_jobs' => [], 'status_code' => small_cluster_status },
|
192
|
+
{ 'cluster_id' => large_cluster_id, 'size' => large_cluster_size, 'running_jobs' => [], 'status_code' => large_cluster_status },
|
193
|
+
{ 'cluster_id' => starting_cluster_id, 'size' => starting_cluster_size, 'running_jobs' => [], 'status_code' => starting_cluster_status },
|
194
194
|
{ 'cluster_id' => huge_busy_cluster_id, 'size' => huge_busy_cluster_size,
|
195
|
-
'
|
195
|
+
'running_jobs' => [ { 'job_id' => 'c571a8c7f76a4fd4a67c103d753e2dd5',
|
196
|
+
'job_name' => "", 'start_timestamp' => ""} ], 'status_code' => huge_busy_cluster_status }
|
196
197
|
]})
|
197
198
|
}
|
198
199
|
mock(Mortar::Auth.api).post_job_existing_cluster("myproject", "my_script", is_a(String), large_cluster_id,
|
data/spec/mortar/git_spec.rb
CHANGED
@@ -262,27 +262,21 @@ STASH
|
|
262
262
|
|
263
263
|
it "creates a snapshot branch for a clean working directory" do
|
264
264
|
with_git_initialized_project do |p|
|
265
|
-
|
266
|
-
snapshot_branch = @git.create_snapshot_branch
|
267
|
-
post_validate_git_snapshot(@git, starting_status, snapshot_branch)
|
265
|
+
create_and_validate_git_snapshot(@git)
|
268
266
|
end
|
269
267
|
end
|
270
268
|
|
271
269
|
it "creates a snapshot branch for an added file" do
|
272
270
|
with_git_initialized_project do |p|
|
273
271
|
git_add_file(@git, p)
|
274
|
-
|
275
|
-
snapshot_branch = @git.create_snapshot_branch
|
276
|
-
post_validate_git_snapshot(@git, starting_status, snapshot_branch)
|
272
|
+
create_and_validate_git_snapshot(@git)
|
277
273
|
end
|
278
274
|
end
|
279
275
|
|
280
276
|
it "creates a snapshot branch for an untracked file" do
|
281
277
|
with_git_initialized_project do |p|
|
282
278
|
git_create_untracked_file(p)
|
283
|
-
|
284
|
-
snapshot_branch = @git.create_snapshot_branch
|
285
|
-
post_validate_git_snapshot(@git, starting_status, snapshot_branch)
|
279
|
+
create_and_validate_git_snapshot(@git)
|
286
280
|
end
|
287
281
|
end
|
288
282
|
|
data/spec/spec_helper.rb
CHANGED
@@ -247,15 +247,31 @@ def git_create_untracked_file(project)
|
|
247
247
|
untracked_file
|
248
248
|
end
|
249
249
|
|
250
|
-
def
|
250
|
+
def create_and_validate_git_snapshot(git)
|
251
|
+
initial_status = git.status
|
252
|
+
initial_git_branches = git.branches
|
253
|
+
snapshot_dir, snapshot_branch = git.create_snapshot_branch
|
254
|
+
|
255
|
+
snapshot_dir.should_not be_nil
|
251
256
|
snapshot_branch.should_not be_nil
|
252
257
|
snapshot_branch.should_not == "master"
|
253
258
|
git.current_branch.should == "master"
|
254
|
-
git.status.should ==
|
259
|
+
git.status.should == initial_status
|
255
260
|
git.has_conflicts?.should be_false
|
261
|
+
|
262
|
+
# ensure snapshot is in a temp directory
|
263
|
+
File.exists?(snapshot_dir).should be_true
|
264
|
+
|
265
|
+
curdir = Dir.pwd
|
266
|
+
Dir.chdir(snapshot_dir)
|
256
267
|
|
257
268
|
# ensure the snapshot branch exists
|
258
269
|
git.git("branch").include?(snapshot_branch).should be_true
|
270
|
+
|
271
|
+
Dir.chdir(curdir)
|
272
|
+
FileUtils.remove_entry_secure(snapshot_dir)
|
273
|
+
|
274
|
+
git.branches.should == initial_git_branches
|
259
275
|
end
|
260
276
|
|
261
277
|
require "mortar/helpers"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mortar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mortar-api-ruby
|
@@ -190,7 +190,6 @@ files:
|
|
190
190
|
- lib/mortar/git.rb
|
191
191
|
- lib/mortar/helpers.rb
|
192
192
|
- lib/mortar/project.rb
|
193
|
-
- lib/mortar/snapshot.rb
|
194
193
|
- lib/mortar/templates/macro/macro.pig
|
195
194
|
- lib/mortar/templates/pigscript/pigscript.pig
|
196
195
|
- lib/mortar/templates/pigscript/python_udf.py
|
@@ -221,7 +220,6 @@ files:
|
|
221
220
|
- spec/mortar/git_spec.rb
|
222
221
|
- spec/mortar/helpers_spec.rb
|
223
222
|
- spec/mortar/project_spec.rb
|
224
|
-
- spec/mortar/snapshot_spec.rb
|
225
223
|
- spec/mortar/updater_spec.rb
|
226
224
|
- spec/spec.opts
|
227
225
|
- spec/spec_helper.rb
|
data/lib/mortar/snapshot.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Mortar Data Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
module Mortar
|
18
|
-
module Snapshot
|
19
|
-
|
20
|
-
extend self
|
21
|
-
|
22
|
-
def create_and_push_snapshot_branch(git, project)
|
23
|
-
# create / push a snapshot branch
|
24
|
-
snapshot_branch = action("Taking code snapshot") do
|
25
|
-
git.create_snapshot_branch()
|
26
|
-
end
|
27
|
-
|
28
|
-
git_ref = action("Sending code snapshot to Mortar") do
|
29
|
-
# push the code
|
30
|
-
git.push(project.remote, snapshot_branch)
|
31
|
-
|
32
|
-
# grab the commit hash and clean out the branch from the local branches
|
33
|
-
ref = git.git_ref(snapshot_branch)
|
34
|
-
git.branch_delete(snapshot_branch)
|
35
|
-
ref
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Mortar Data Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
require "spec_helper"
|
18
|
-
require "mortar/helpers"
|
19
|
-
|
20
|
-
module Mortar
|
21
|
-
describe Snapshot do
|
22
|
-
include Mortar::Helpers
|
23
|
-
include Mortar::Snapshot
|
24
|
-
|
25
|
-
before(:each) do
|
26
|
-
@git = Mortar::Git::Git.new
|
27
|
-
end
|
28
|
-
|
29
|
-
it "create and push a snapshot to the remote repository" do
|
30
|
-
with_git_initialized_project do |p|
|
31
|
-
# stub git
|
32
|
-
mock(@git).push("mortar", is_a(String))
|
33
|
-
mock.proxy(@git).create_snapshot_branch
|
34
|
-
|
35
|
-
stub(self).display
|
36
|
-
|
37
|
-
initial_git_branches = @git.branches
|
38
|
-
create_and_push_snapshot_branch(@git, p)
|
39
|
-
|
40
|
-
# ensure that no additional branches are left behind
|
41
|
-
@git.branches.should == initial_git_branches
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|