dtk-client 0.5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +12 -0
- data/README.md +78 -0
- data/bin/dtk +54 -0
- data/bin/dtk-shell +15 -0
- data/dtk-client.gemspec +49 -0
- data/lib/auxiliary.rb +13 -0
- data/lib/bundler_monkey_patch.rb +9 -0
- data/lib/client.rb +48 -0
- data/lib/command_helper.rb +16 -0
- data/lib/command_helpers/git_repo.rb +391 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +271 -0
- data/lib/command_helpers/jenkins_client.rb +91 -0
- data/lib/command_helpers/service_importer.rb +99 -0
- data/lib/command_helpers/service_link.rb +18 -0
- data/lib/command_helpers/ssh_processing.rb +43 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1089 -0
- data/lib/commands/common/thor/clone.rb +39 -0
- data/lib/commands/common/thor/common.rb +34 -0
- data/lib/commands/common/thor/edit.rb +168 -0
- data/lib/commands/common/thor/list_diffs.rb +84 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +11 -0
- data/lib/commands/common/thor/pull_from_remote.rb +99 -0
- data/lib/commands/common/thor/purge_clone.rb +26 -0
- data/lib/commands/common/thor/push_clone_changes.rb +45 -0
- data/lib/commands/common/thor/push_to_remote.rb +45 -0
- data/lib/commands/common/thor/reparse.rb +36 -0
- data/lib/commands/common/thor/set_required_params.rb +29 -0
- data/lib/commands/common/thor/task_status.rb +81 -0
- data/lib/commands/thor/account.rb +213 -0
- data/lib/commands/thor/assembly.rb +329 -0
- data/lib/commands/thor/attribute.rb +62 -0
- data/lib/commands/thor/component.rb +52 -0
- data/lib/commands/thor/component_module.rb +829 -0
- data/lib/commands/thor/component_template.rb +153 -0
- data/lib/commands/thor/dependency.rb +18 -0
- data/lib/commands/thor/developer.rb +105 -0
- data/lib/commands/thor/dtk.rb +117 -0
- data/lib/commands/thor/library.rb +107 -0
- data/lib/commands/thor/node.rb +411 -0
- data/lib/commands/thor/node_group.rb +211 -0
- data/lib/commands/thor/node_template.rb +88 -0
- data/lib/commands/thor/project.rb +17 -0
- data/lib/commands/thor/provider.rb +155 -0
- data/lib/commands/thor/repo.rb +35 -0
- data/lib/commands/thor/service.rb +656 -0
- data/lib/commands/thor/service_module.rb +806 -0
- data/lib/commands/thor/state_change.rb +10 -0
- data/lib/commands/thor/target.rb +94 -0
- data/lib/commands/thor/task.rb +100 -0
- data/lib/commands/thor/utils.rb +4 -0
- data/lib/commands/thor/workspace.rb +437 -0
- data/lib/commands.rb +40 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +18 -0
- data/lib/config/configuration.rb +82 -0
- data/lib/config/default.conf +14 -0
- data/lib/config/disk_cacher.rb +60 -0
- data/lib/configurator.rb +92 -0
- data/lib/context_router.rb +23 -0
- data/lib/core.rb +460 -0
- data/lib/domain/git_adapter.rb +221 -0
- data/lib/domain/response.rb +234 -0
- data/lib/dtk-client/version.rb +3 -0
- data/lib/dtk_constants.rb +23 -0
- data/lib/dtk_logger.rb +96 -0
- data/lib/error.rb +74 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +53 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +12 -0
- data/lib/parser/adapters/thor.rb +509 -0
- data/lib/require_first.rb +87 -0
- data/lib/search_hash.rb +27 -0
- data/lib/shell/context.rb +975 -0
- data/lib/shell/context_aux.rb +29 -0
- data/lib/shell/domain.rb +447 -0
- data/lib/shell/header_shell.rb +27 -0
- data/lib/shell/help_monkey_patch.rb +221 -0
- data/lib/shell/interactive_wizard.rb +233 -0
- data/lib/shell/parse_monkey_patch.rb +22 -0
- data/lib/shell/status_monitor.rb +105 -0
- data/lib/shell.rb +219 -0
- data/lib/util/console.rb +143 -0
- data/lib/util/dtk_puppet.rb +46 -0
- data/lib/util/os_util.rb +265 -0
- data/lib/view_processor/augmented_simple_list.rb +27 -0
- data/lib/view_processor/hash_pretty_print.rb +106 -0
- data/lib/view_processor/simple_list.rb +139 -0
- data/lib/view_processor/table_print.rb +277 -0
- data/lib/view_processor.rb +112 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +18 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/assembly_spec.rb +50 -0
- data/spec/assembly_template_spec.rb +51 -0
- data/spec/component_template_spec.rb +40 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +105 -0
- data/spec/module_spec.rb +35 -0
- data/spec/node_spec.rb +43 -0
- data/spec/node_template_spec.rb +25 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_spec.rb +41 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +351 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
class Target < CommandBaseThor
|
3
|
+
|
4
|
+
def self.pretty_print_cols()
|
5
|
+
PPColumns.get(:target)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.alternate_identifiers()
|
9
|
+
return ['PROVIDER']
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "TARGET-NAME/ID list-nodes","Lists node instances in given targets."
|
13
|
+
def list_nodes(context_params)
|
14
|
+
context_params.method_arguments = ["nodes"]
|
15
|
+
list_targets(context_params)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "TARGET-NAME/ID list-services","Lists service instances in given targets."
|
19
|
+
def list_services(context_params)
|
20
|
+
context_params.method_arguments = ["assemblies"]
|
21
|
+
list_targets(context_params)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def self.validation_list(context_params)
|
26
|
+
provider_id = context_params.retrieve_arguments([:provider_id])
|
27
|
+
|
28
|
+
if provider_id
|
29
|
+
# if assembly_id is present we're loading nodes filtered by assembly_id
|
30
|
+
post_body = {
|
31
|
+
:subtype => :instance,
|
32
|
+
:parent_id => provider_id
|
33
|
+
}
|
34
|
+
|
35
|
+
response = get_cached_response(:provider_target, "target/list", post_body)
|
36
|
+
else
|
37
|
+
# otherwise, load all nodes
|
38
|
+
response = get_cached_response(:target, "target/list", { :subtype => :instance })
|
39
|
+
end
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "list-targets","Lists available targets."
|
45
|
+
def list_targets(context_params)
|
46
|
+
provider_id, target_id, about = context_params.retrieve_arguments([:provider_id, :target_id, :option_1],method_argument_names||="")
|
47
|
+
|
48
|
+
if target_id.nil?
|
49
|
+
post_body = {
|
50
|
+
:subtype => :instance,
|
51
|
+
:parent_id => provider_id
|
52
|
+
}
|
53
|
+
response = post rest_url("target/list"), post_body
|
54
|
+
|
55
|
+
response.render_table(:target)
|
56
|
+
else
|
57
|
+
post_body = {
|
58
|
+
:target_id => target_id,
|
59
|
+
:about => about
|
60
|
+
}
|
61
|
+
|
62
|
+
case about
|
63
|
+
when "nodes"
|
64
|
+
response = post rest_url("target/info_about"), post_body
|
65
|
+
data_type = :node
|
66
|
+
when "assemblies"
|
67
|
+
response = post rest_url("target/info_about"), post_body
|
68
|
+
data_type = :assembly
|
69
|
+
else
|
70
|
+
raise_validation_error_method_usage('list')
|
71
|
+
end
|
72
|
+
|
73
|
+
response.render_table(data_type)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc "delete-target TARGET-IDENTIFIER","Deletes target or provider"
|
78
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
79
|
+
def delete_target(context_params)
|
80
|
+
target_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
81
|
+
|
82
|
+
# No -y options since risk is too great
|
83
|
+
return unless Console.confirmation_prompt("Are you sure you want to delete target '#{target_id}' (all assemblies/nodes that belong to this target will be deleted as well)'"+'?')
|
84
|
+
|
85
|
+
post_body = {
|
86
|
+
:target_id => target_id
|
87
|
+
}
|
88
|
+
|
89
|
+
@@invalidate_map << :target
|
90
|
+
|
91
|
+
return post rest_url("target/delete"), post_body
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
class Task < CommandBaseThor
|
3
|
+
|
4
|
+
def self.whoami()
|
5
|
+
return :task, "task/list", nil
|
6
|
+
end
|
7
|
+
|
8
|
+
# TODO: Current bug: Disable list method invocation from /task/111111> level
|
9
|
+
desc "list [--list]","List tasks"
|
10
|
+
method_option :list, :type => :boolean, :default => false
|
11
|
+
def list(context_params)
|
12
|
+
|
13
|
+
#TODO: just hard coded params now
|
14
|
+
search_hash = SearchHash.new()
|
15
|
+
search_hash.cols = [:commit_message,:status,:id,:created_at,:started_at,:ended_at]
|
16
|
+
search_hash.filter = [:eq, ":task_id", nil] #just top level tasks
|
17
|
+
search_hash.set_order_by!(:created_at,"DESC")
|
18
|
+
response = post rest_url("task/list"), search_hash.post_body_hash()
|
19
|
+
|
20
|
+
response.render_table(:task) unless options.list?
|
21
|
+
return response
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "[TASK-NAME/ID] status", "Return task status; if no TASK-ID then information about most recent task"
|
25
|
+
method_option "detail-level",:default => "summary", :aliases => "-d", :desc => "detail level to report task status"
|
26
|
+
def status(context_params)
|
27
|
+
task_id = context_params.retrieve_arguments([:task_id],method_argument_names)
|
28
|
+
detail_level = options["detail-level"]
|
29
|
+
post_hash_body = Hash.new
|
30
|
+
post_hash_body[:detail_level] = detail_level if detail_level
|
31
|
+
post_hash_body[:task_id] = task_id if task_id
|
32
|
+
post rest_url("task/status"),post_hash_body
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "commit-changes", "Commit changes"
|
36
|
+
def commit_changes(context_params)
|
37
|
+
scope = context_params.retrieve_arguments([:option_1],method_argument_names)
|
38
|
+
post_hash_body = Hash.new
|
39
|
+
post_hash_body.merge!(:scope => scope) if scope
|
40
|
+
post rest_url("task/create_task_from_pending_changes"),post_hash_body
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "TASK-NAME/ID execute", "Execute task"
|
44
|
+
def execute(context_params)
|
45
|
+
task_id = context_params.retrieve_arguments([:task_id!],method_argument_names)
|
46
|
+
post rest_url("task/execute"), :task_id => task_id
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "commit-changes-and-execute", "Commit changes and execute task"
|
50
|
+
def commit_changes_and_execute(context_params)
|
51
|
+
response = commit_changes(context_params)
|
52
|
+
if response.ok?
|
53
|
+
execute(response.data(:task_id))
|
54
|
+
else
|
55
|
+
response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
#alias for commit-changes-and-execute
|
59
|
+
desc "simple-run", "Commit changes and execute task"
|
60
|
+
def simple_run(context_params)
|
61
|
+
commit_changes_and_execute(context_params)
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "converge-node NODE-ID", "(Re)Converge node"
|
65
|
+
def converge_node(context_params)
|
66
|
+
node_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
67
|
+
|
68
|
+
scope = node_id && {:node_id => node_id}
|
69
|
+
response = post(rest_url("task/create_converge_state_changes"),scope)
|
70
|
+
return response unless response.ok?
|
71
|
+
response = commit_changes_and_execute(scope)
|
72
|
+
while not task_complete(response) do
|
73
|
+
response = status()
|
74
|
+
sleep(TASK_STATUS_POLLING_INTERVAL)
|
75
|
+
end
|
76
|
+
response
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "converge-nodes", "(Re)Converge nodes"
|
80
|
+
def converge_nodes()
|
81
|
+
converge_node(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
@@count = 0
|
87
|
+
|
88
|
+
TASK_STATUS_POLLING_INTERVAL = 3
|
89
|
+
TASK_STATUS_MAX_TIME = 60
|
90
|
+
|
91
|
+
def task_complete(response)
|
92
|
+
return true unless response.ok?
|
93
|
+
@@count += 1
|
94
|
+
return true if (@@count * TASK_STATUS_POLLING_INTERVAL) > TASK_STATUS_MAX_TIME
|
95
|
+
%w{succeeded failed}.include?(response.data(:status))
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
@@ -0,0 +1,437 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require 'colorize'
|
4
|
+
dtk_require_from_base("dtk_logger")
|
5
|
+
dtk_require_from_base("util/os_util")
|
6
|
+
dtk_require_from_base("command_helper")
|
7
|
+
dtk_require_common_commands('thor/task_status')
|
8
|
+
dtk_require_common_commands('thor/edit')
|
9
|
+
dtk_require_common_commands('thor/purge_clone')
|
10
|
+
dtk_require_common_commands('thor/assembly_workspace')
|
11
|
+
# LOG_SLEEP_TIME_W = DTK::Configuration.get(:tail_log_frequency)
|
12
|
+
|
13
|
+
module DTK::Client
|
14
|
+
class Workspace < CommandBaseThor
|
15
|
+
no_tasks do
|
16
|
+
include TaskStatusMixin
|
17
|
+
include SetRequiredParamsMixin
|
18
|
+
include EditMixin
|
19
|
+
include PurgeCloneMixin
|
20
|
+
include AssemblyWorkspaceMixin
|
21
|
+
|
22
|
+
def get_workspace_name(workspace_id)
|
23
|
+
get_name_from_id_helper(workspace_id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.whoami()
|
28
|
+
return :workspace, "assembly/list", {:subtype => 'instance'}
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.pretty_print_cols()
|
32
|
+
PPColumns.get(:assembly)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.valid_children()
|
36
|
+
[:utils]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.invisible_context()
|
40
|
+
[:node]
|
41
|
+
end
|
42
|
+
|
43
|
+
# using extended_context when we want to use autocomplete from other context
|
44
|
+
# e.g. we are in assembly/apache context and want to create-component we will use extended context to add
|
45
|
+
# component-templates to autocomplete
|
46
|
+
def self.extended_context()
|
47
|
+
{
|
48
|
+
:context => {
|
49
|
+
:add_component => "component_template",
|
50
|
+
:create_node => "node_template",
|
51
|
+
:add_component_dependency => "component_template"
|
52
|
+
},
|
53
|
+
:command => {
|
54
|
+
:edit_component_module => {
|
55
|
+
:endpoint => "assembly",
|
56
|
+
:url => "assembly/info_about",
|
57
|
+
:opts => {:subtype=>"instance", :about=>"modules"}
|
58
|
+
},
|
59
|
+
:push_component_module_updates => {
|
60
|
+
:endpoint => "assembly",
|
61
|
+
:url => "assembly/info_about",
|
62
|
+
:opts => {:subtype=>"instance", :about=>"modules"}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# this includes children of children
|
69
|
+
def self.all_children()
|
70
|
+
# [:node, :component, :attribute]
|
71
|
+
[:node]
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.multi_context_children()
|
75
|
+
[[:utils],[:node, :utils]]
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.valid_child?(name_of_sub_context)
|
79
|
+
return Workspace.valid_children().include?(name_of_sub_context.to_sym)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.validation_list(context_params)
|
83
|
+
get_cached_response(:workspace, "assembly/list_with_workspace", {})
|
84
|
+
end
|
85
|
+
|
86
|
+
# TODO: Hack which is necessery for the specific problem (DTK-541), something to reconsider down the line
|
87
|
+
# at this point not sure what would be clenear solution
|
88
|
+
|
89
|
+
# :all => include both for commands with command and identifier
|
90
|
+
# :command_only => only on command level
|
91
|
+
# :identifier_only => only on identifier level for given entity (command)
|
92
|
+
#
|
93
|
+
def self.override_allowed_methods()
|
94
|
+
return DTK::Shell::OverrideTasks.new({
|
95
|
+
:all => {
|
96
|
+
:node => [
|
97
|
+
# ['delete-component',"delete-component COMPONENT-ID [-y]","# Delete component from assembly's node"],
|
98
|
+
# ['list-attributes',"list-attributes","# List attributes associated with workspace's node."],
|
99
|
+
# ['list-components',"list-components","# List components associated with workspace's node."]
|
100
|
+
],
|
101
|
+
:component => [
|
102
|
+
['list-attributes',"list-attributes","# List attributes associated with given component."]
|
103
|
+
]
|
104
|
+
},
|
105
|
+
:command_only => {
|
106
|
+
:attribute => [
|
107
|
+
['list-attributes',"list-attributes","# List attributes."]
|
108
|
+
],
|
109
|
+
:node => [
|
110
|
+
# ['delete',"delete NAME/ID [-y] ","# Delete component from workspace."],
|
111
|
+
['delete',"delete NODE-NAME/ID [-y] ","# Delete node, terminating it if the node has been spun up."],
|
112
|
+
['list',"list","# List nodes."]
|
113
|
+
],
|
114
|
+
:component => [
|
115
|
+
['delete',"delete COMPONENT-NAME/ID [-y] ","# Delete component from workspace."],
|
116
|
+
['list-components',"list-components","# List components."]
|
117
|
+
],
|
118
|
+
:utils => [
|
119
|
+
['get-netstats',"get-netstats","# Get netstats."],
|
120
|
+
['get-ps',"get-ps [--filter PATTERN]","# Get ps."],
|
121
|
+
['grep',"grep LOG-PATH NODE-ID-PATTERN GREP-PATTERN [--first]","# Grep log from multiple nodes. --first option returns first match (latest log entry)."],
|
122
|
+
['tail',"tail NODE-ID LOG-PATH [REGEX-PATTERN] [--more]","# Tail specified number of lines from log."]
|
123
|
+
]
|
124
|
+
},
|
125
|
+
:identifier_only => {
|
126
|
+
:node => [
|
127
|
+
['add-component',"add-component COMPONENT","# Add a component to the node."],
|
128
|
+
['delete-component',"delete-component COMPONENT-NAME [-y]","# Delete component from workspace's node"],
|
129
|
+
['info',"info","# Return info about node instance belonging to given workspace."],
|
130
|
+
# ['link-attributes', "link-attributes TARGET-ATTR-TERM SOURCE-ATTR-TERM", "# Set TARGET-ATTR-TERM to SOURCE-ATTR-TERM."],
|
131
|
+
['list-attributes',"list-attributes","# List attributes associated with workspace's node."],
|
132
|
+
['list-components',"list-components","# List components associated with workspace's node."],
|
133
|
+
['set-attribute',"set-attribute ATTRIBUTE-NAME [VALUE] [-u]","# (Un)Set attribute value. The option -u will unset the attribute's value."],
|
134
|
+
['start', "start", "# Start node instance."],
|
135
|
+
['stop', "stop", "# Stop node instance."]
|
136
|
+
],
|
137
|
+
:component => [
|
138
|
+
['info',"info","# Return info about component instance belonging to given node."],
|
139
|
+
['edit',"edit","# Edit component module related to given component."],
|
140
|
+
# ['edit-dsl',"edit-dsl","# Edit component module dsl file related to given component."],
|
141
|
+
['link-components',"link-components ANTECEDENT-CMP-NAME [DEPENDENCY-NAME]","#Link components to satisfy component dependency relationship."],
|
142
|
+
['list-component-links',"list-component-links","# List component's links to other components."]
|
143
|
+
#['unlink-components',"unlink-components SERVICE-TYPE","# Delete service link on component."]
|
144
|
+
# ['create-attribute',"create-attribute SERVICE-TYPE DEP-ATTR ARROW BASE-ATTR","# Create an attribute to service link."],
|
145
|
+
],
|
146
|
+
:attribute => [
|
147
|
+
['info',"info","# Return info about attribute instance belonging to given component."]
|
148
|
+
]
|
149
|
+
}
|
150
|
+
}, [:utils])
|
151
|
+
end
|
152
|
+
|
153
|
+
desc "WORKSPACE-NAME/ID cancel-task [TASK-ID]", "Cancel an executing task. If task id is omitted, the most recent executing task is canceled."
|
154
|
+
def cancel_task(context_params)
|
155
|
+
cancel_task_aux(context_params)
|
156
|
+
end
|
157
|
+
|
158
|
+
#desc "WORKSPACE-NAME/ID clear-tasks", "Clears the tasks that have been run already."
|
159
|
+
#def clear_tasks(context_params)
|
160
|
+
# clear_tasks_aux(context_params)
|
161
|
+
#end
|
162
|
+
|
163
|
+
desc "WORKSPACE-NAME/ID converge [-m COMMIT-MSG]", "Converge workspace instance."
|
164
|
+
method_option "commit_msg",:aliases => "-m" ,
|
165
|
+
:type => :string,
|
166
|
+
:banner => "COMMIT-MSG",
|
167
|
+
:desc => "Commit message"
|
168
|
+
def converge(context_params)
|
169
|
+
converge_aux(context_params)
|
170
|
+
end
|
171
|
+
|
172
|
+
desc "WORKSPACE-NAME/ID push-component-module-updates COMPONENT-MODULE-NAME [--force]", "Push changes made to a component module in the workspace to its base component module."
|
173
|
+
method_option :force, :type => :boolean, :default => false, :aliases => '-f'
|
174
|
+
def push_component_module_updates(context_params)
|
175
|
+
push_module_updates_aux(context_params)
|
176
|
+
end
|
177
|
+
|
178
|
+
desc "WORKSPACE-NAME/ID push-assembly-updates SERVICE-MODULE-NAME/ASSEMBLY-NAME", "Push workspace instance to the designated assembly."
|
179
|
+
def push_service_updates(context_params)
|
180
|
+
workspace_id, qualified_assembly_name = context_params.retrieve_arguments([:workspace_id!,:option_1!],method_argument_names)
|
181
|
+
if qualified_assembly_name =~ /(^[^\/]*)\/([^\/]*$)/
|
182
|
+
service_module_name, assembly_template_name = [$1,$2]
|
183
|
+
else
|
184
|
+
raise DtkError,"The term (#{qualified_assembly_name}) must have form SERVICE-MODULE-NAME/ASSEMBLY-NAME"
|
185
|
+
end
|
186
|
+
response = promote_assembly_aux(:update,workspace_id, service_module_name, assembly_template_name)
|
187
|
+
return response unless response.ok?
|
188
|
+
@@invalidate_map << :assembly
|
189
|
+
Response::Ok.new()
|
190
|
+
end
|
191
|
+
|
192
|
+
desc "WORKSPACE-NAME/ID create-assembly SERVICE-MODULE-NAME ASSEMBLY-NAME [-p]", "Create a new assembly from the workspace instance in the designated service module."
|
193
|
+
# The option -p will purge the workspace after assembly creation."
|
194
|
+
method_option :purge, :aliases => '-p', :type => :boolean, :default => false
|
195
|
+
def create_service(context_params)
|
196
|
+
workspace_id, service_module_name, assembly_template_name = context_params.retrieve_arguments([:workspace_id!,:option_1!,:option_2!],method_argument_names)
|
197
|
+
response = promote_assembly_aux(:create,workspace_id,service_module_name,assembly_template_name)
|
198
|
+
return response unless response.ok?
|
199
|
+
if options.purge?
|
200
|
+
response = purge_aux(context_params)
|
201
|
+
return response unless response.ok?
|
202
|
+
end
|
203
|
+
|
204
|
+
@@invalidate_map << :assembly
|
205
|
+
@@invalidate_map << :service_module
|
206
|
+
Response::Ok.new()
|
207
|
+
end
|
208
|
+
|
209
|
+
desc "WORKSPACE-NAME/ID create-attribute ATTRIBUTE-NAME [VALUE] [--type DATATYPE] [--required] [--dynamic]", "Create a new attribute and optionally assign it a value."
|
210
|
+
method_option :required, :type => :boolean, :default => false
|
211
|
+
method_option :dynamic, :type => :boolean, :default => false
|
212
|
+
method_option :type, :aliases => "-t"
|
213
|
+
def create_attribute(context_params)
|
214
|
+
create_attribute_aux(context_params)
|
215
|
+
end
|
216
|
+
|
217
|
+
#only supported at node-level
|
218
|
+
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
219
|
+
desc "HIDE_FROM_BASE add-component NODE-NAME COMPONENT", "Add a component to a workspace."
|
220
|
+
def add_component(context_params)
|
221
|
+
response = create_component_aux(context_params)
|
222
|
+
return response unless response.ok?
|
223
|
+
|
224
|
+
@@invalidate_map << :service
|
225
|
+
@@invalidate_map << :service_node
|
226
|
+
|
227
|
+
response
|
228
|
+
end
|
229
|
+
|
230
|
+
# using ^^ before NODE-NAME to remove this command from workspace/node/node_id but show in workspace
|
231
|
+
desc "WORKSPACE-NAME/ID create-node ^^NODE-NAME NODE-TEMPLATE", "Add (stage) a new node in the workspace."
|
232
|
+
def create_node(context_params)
|
233
|
+
response = create_node_aux(context_params)
|
234
|
+
return response unless response.ok?
|
235
|
+
|
236
|
+
@@invalidate_map << :service_node
|
237
|
+
message = "Created node '#{response.data["display_name"]}'."
|
238
|
+
DTK::Client::OsUtil.print(message, :yellow)
|
239
|
+
end
|
240
|
+
|
241
|
+
desc "WORKSPACE-NAME/ID link-components TARGET-CMP-NAME SOURCE-CMP-NAME [DEPENDENCY-NAME]","Link the target component to the source component."
|
242
|
+
def link_components(context_params)
|
243
|
+
link_components_aux(context_params)
|
244
|
+
end
|
245
|
+
|
246
|
+
desc "delete NAME/ID [-y]", ""
|
247
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
248
|
+
def delete(context_params)
|
249
|
+
if context_params.is_last_command_eql_to?(:node)
|
250
|
+
response = delete_node_aux(context_params)
|
251
|
+
@@invalidate_map << :service_node
|
252
|
+
|
253
|
+
response
|
254
|
+
elsif context_params.is_last_command_eql_to?(:component)
|
255
|
+
response = delete_component_aux(context_params)
|
256
|
+
return response unless response.ok?
|
257
|
+
@@invalidate_map << :service_node_component
|
258
|
+
|
259
|
+
response
|
260
|
+
end
|
261
|
+
# delete_aux(context_params)
|
262
|
+
end
|
263
|
+
|
264
|
+
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
265
|
+
desc "HIDE_FROM_BASE delete-component COMPONENT-NAME [-y]","Delete component from the workspace."
|
266
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
267
|
+
def delete_component(context_params)
|
268
|
+
response = delete_component_aux(context_params)
|
269
|
+
return response unless response.ok?
|
270
|
+
|
271
|
+
@@invalidate_map << :service
|
272
|
+
@@invalidate_map << :service_node
|
273
|
+
@@invalidate_map << :service_node_component
|
274
|
+
|
275
|
+
return response
|
276
|
+
end
|
277
|
+
|
278
|
+
# using ^^ before NODE-NAME to remove this command from workspace/node/node_id but show in workspace
|
279
|
+
desc "WORKSPACE-NAME/ID delete-node ^^NODE-NAME [-y]","Delete node, terminating it if the node has been spun up."
|
280
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
281
|
+
def delete_node(context_params)
|
282
|
+
response = delete_node_aux(context_params)
|
283
|
+
@@invalidate_map << :service_node
|
284
|
+
|
285
|
+
return response
|
286
|
+
end
|
287
|
+
|
288
|
+
desc "WORKSPACE-NAME/ID unlink-components TARGET-CMP-NAME SOURCE-CMP-NAME [DEPENDENCY-NAME]", "Remove a component link."
|
289
|
+
def unlink_components(context_params)
|
290
|
+
unlink_components_aux(context_params)
|
291
|
+
end
|
292
|
+
|
293
|
+
desc "WORKSPACE-NAME/ID edit-component-module COMPONENT-MODULE-NAME", "Edit a component module used in the workspace."
|
294
|
+
def edit_component_module(context_params)
|
295
|
+
edit_module_aux(context_params)
|
296
|
+
end
|
297
|
+
|
298
|
+
desc "WORKSPACE-NAME/ID edit-workflow", "Edit workflow"
|
299
|
+
def edit_workflow(context_params)
|
300
|
+
edit_workflow_aux(context_params)
|
301
|
+
end
|
302
|
+
=begin
|
303
|
+
desc "WORKSPACE-NAME/ID edit-attributes", "Edit workspace's attributes."
|
304
|
+
def edit_attributes(context_params)
|
305
|
+
edit_attributes_aux(context_params)
|
306
|
+
end
|
307
|
+
=end
|
308
|
+
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
309
|
+
desc "HIDE_FROM_BASE get-netstats", "Get netstats"
|
310
|
+
def get_netstats(context_params)
|
311
|
+
get_netstats_aux(context_params)
|
312
|
+
end
|
313
|
+
|
314
|
+
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
315
|
+
desc "HIDE_FROM_BASE get-ps [--filter PATTERN]", "Get ps"
|
316
|
+
method_option :filter, :type => :boolean, :default => false, :aliases => '-f'
|
317
|
+
def get_ps(context_params)
|
318
|
+
get_ps_aux(context_params)
|
319
|
+
end
|
320
|
+
|
321
|
+
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
322
|
+
desc "HIDE_FROM_BASE grep LOG-PATH NODES-ID-PATTERN GREP-PATTERN [--first]","Grep log from multiple nodes. --first option returns first match (latest log entry)."
|
323
|
+
method_option :first, :type => :boolean, :default => false
|
324
|
+
def grep(context_params)
|
325
|
+
grep_aux(context_params)
|
326
|
+
end
|
327
|
+
|
328
|
+
desc "WORKSPACE-NAME/ID info", "Get info about content of the workspace."
|
329
|
+
def info(context_params)
|
330
|
+
info_aux(context_params)
|
331
|
+
end
|
332
|
+
|
333
|
+
desc "WORKSPACE-NAME/ID link-attributes TARGET-ATTR SOURCE-ATTR", "Link the value of the target attribute to the source attribute."
|
334
|
+
def link_attributes(context_params)
|
335
|
+
link_attributes_aux(context_params)
|
336
|
+
end
|
337
|
+
|
338
|
+
#desc "WORKSPACE-NAME/ID list-attribute-mappings SERVICE-LINK-NAME/ID", "List attribute mappings associated with service link"
|
339
|
+
#def list_attribute_mappings(context_params)
|
340
|
+
# list_attribute_mappings_aux(context_params)
|
341
|
+
#end
|
342
|
+
|
343
|
+
desc "list", ""
|
344
|
+
def list(context_params)
|
345
|
+
if context_params.is_last_command_eql_to?(:node)
|
346
|
+
list_nodes_aux(context_params)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
desc "WORKSPACE-NAME/ID list-attributes [-f FORMAT] [--links]","List attributes associated with workspace."
|
351
|
+
method_option :format,:aliases => '-f'
|
352
|
+
method_option :links, :type => :boolean, :default => false, :aliases => '-l'
|
353
|
+
def list_attributes(context_params)
|
354
|
+
list_attributes_aux(context_params)
|
355
|
+
end
|
356
|
+
|
357
|
+
desc "WORKSPACE-NAME/ID list-components [--deps]","List components associated with workspace."
|
358
|
+
method_option :deps, :type => :boolean, :default => false, :aliases => '-l'
|
359
|
+
def list_components(context_params)
|
360
|
+
list_components_aux(context_params)
|
361
|
+
end
|
362
|
+
|
363
|
+
desc "WORKSPACE-NAME/ID list-nodes","List nodes associated with workspace."
|
364
|
+
def list_nodes(context_params)
|
365
|
+
list_nodes_aux(context_params)
|
366
|
+
end
|
367
|
+
|
368
|
+
desc "WORKSPACE-NAME/ID list-component-links","List component links."
|
369
|
+
def list_component_links(context_params)
|
370
|
+
list_component_links_aux(context_params)
|
371
|
+
end
|
372
|
+
|
373
|
+
desc "WORKSPACE-NAME/ID list-component-modules","List component modules associated with workspace."
|
374
|
+
def list_modules(context_params)
|
375
|
+
list_modules_aux(context_params)
|
376
|
+
end
|
377
|
+
|
378
|
+
desc "WORKSPACE-NAME/ID list-tasks","List tasks associated with workspace."
|
379
|
+
def list_tasks(context_params)
|
380
|
+
list_tasks_aux(context_params)
|
381
|
+
end
|
382
|
+
|
383
|
+
desc "WORKSPACE-NAME/ID workflow-info", "Get the structure of the workflow associated with workspace."
|
384
|
+
def workflow_info(context_params)
|
385
|
+
workflow_info_aux(context_params)
|
386
|
+
end
|
387
|
+
|
388
|
+
desc "WORKSPACE-NAME/ID list-violations", "Finds violations in the workspace that will prevent a converge operation."
|
389
|
+
def list_violations(context_params)
|
390
|
+
list_violations_aux(context_params)
|
391
|
+
end
|
392
|
+
|
393
|
+
desc "WORKSPACE-NAME/ID purge [-y]", "Purge the workspace, deleting and terminating any nodes that have been spun up."
|
394
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
395
|
+
def purge(context_params)
|
396
|
+
purge_aux(context_params)
|
397
|
+
end
|
398
|
+
|
399
|
+
desc "WORKSPACE-NAME/ID set-target TARGET-NAME/ID", "Set target associated with workspace."
|
400
|
+
def set_target(context_params)
|
401
|
+
set_target_aux(context_params)
|
402
|
+
end
|
403
|
+
|
404
|
+
desc "WORKSPACE-NAME/ID set-attribute ATTRIBUTE-NAME [VALUE] [-u]", "(Un)Set attribute value. The option -u will unset the attribute's value."
|
405
|
+
method_option :unset, :aliases => '-u', :type => :boolean, :default => false
|
406
|
+
def set_attribute(context_params)
|
407
|
+
set_attribute_aux(context_params)
|
408
|
+
end
|
409
|
+
|
410
|
+
# desc "WORKSPACE-NAME/ID start [NODE-ID-PATTERN]", "Starts all workspace's nodes, specific nodes can be selected via node id regex."
|
411
|
+
desc "WORKSPACE-NAME/ID start [NODE-NAME]", "Starts all the workspace nodes. A single node can be selected."
|
412
|
+
def start(context_params)
|
413
|
+
start_aux(context_params)
|
414
|
+
end
|
415
|
+
|
416
|
+
# desc "WORKSPACE-NAME/ID stop [NODE-ID-PATTERN]", "Stops all workspace's nodes, specific nodes can be selected via node id regex."
|
417
|
+
desc "WORKSPACE-NAME/ID stop [NODE-NAME]", "Stops all the workspace nodes. A single node can be selected."
|
418
|
+
def stop(context_params)
|
419
|
+
stop_aux(context_params)
|
420
|
+
end
|
421
|
+
|
422
|
+
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
423
|
+
desc "HIDE_FROM_BASE tail NODES-IDENTIFIER LOG-PATH [REGEX-PATTERN] [--more]","Tail specified number of lines from log"
|
424
|
+
method_option :more, :type => :boolean, :default => false
|
425
|
+
def tail(context_params)
|
426
|
+
tail_aux(context_params)
|
427
|
+
end
|
428
|
+
|
429
|
+
desc "WORKSPACE-NAME/ID task-status [--wait]", "Get the task status of the running or last running workspace task."
|
430
|
+
method_option :wait, :type => :boolean, :default => false
|
431
|
+
def task_status(context_params)
|
432
|
+
task_status_aw_aux(context_params)
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
data/lib/commands.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module DTK
|
2
|
+
module Client
|
3
|
+
module CommandBase
|
4
|
+
#TODO: temp workaround
|
5
|
+
def rotate_args(rotated_args)
|
6
|
+
[rotated_args.last] + rotated_args[0..rotated_args.size-2]
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(url)
|
10
|
+
get_connection.get(self.class,url)
|
11
|
+
end
|
12
|
+
def post(url,body=nil)
|
13
|
+
get_connection.post(self.class,url,body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def post_file(url,body=nil)
|
17
|
+
get_connection.post_file(self.class,url,body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def rest_url(route)
|
21
|
+
get_connection.rest_url(route)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_connection
|
25
|
+
DTK::Client::Session.get_connection()
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.handle_argument_error(task, error)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def pretty_print_cols()
|
35
|
+
self.class.pretty_print_cols()
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|