This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathon_host_instrumentation_builder.rb
75 lines (65 loc) · 3.23 KB
/
on_host_instrumentation_builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require './src/common/install/definitions/install_definition'
require './src/install/install_definitions/builder'
require "./src/common/logger/logger_factory"
module Install
module InstallDefinitions
class OnHostInstrumentationBuilder < Builder
def initialize(context, provisioned_resources)
super(context, provisioned_resources)
end
def build_install_definitions()
install_definitions = []
resource_instrumentors = get_resource_instrumentors()
Common::Logger::LoggerFactory.get_logger().debug("OnHostInstrumentationBuilder for #{resource_instrumentors.length} resource instrumentors")
resource_instrumentors.each do |resource_instrumentor|
resource_id = resource_instrumentor.get_resource().get_id()
if is_resource_included(resource_id)
Common::Logger::LoggerFactory.get_logger().debug("OnHostInstrumentationBuilder building definitions for resource #{resource_id}")
params = collect_params([resource_id])
instrumentor_install_definition = assemble_install_definition(resource_instrumentor, params)
install_definitions.push(instrumentor_install_definition)
end
end
return install_definitions
end
private
def assemble_install_definition(instrumentor, params = {})
resource_id = instrumentor.get_resource().get_id()
provisioned_resource = get_provision_resource(resource_id)
roles_path = get_roles_path(instrumentor)
yaml_output_path = get_yaml_output_path(instrumentor, resource_id)
action_vars_lambda = lambda { return get_action_vars(instrumentor, provisioned_resource, params) }
return Common::Install::Definitions::InstallDefinition.new(resource_id, provisioned_resource, get_erb_input_path(), yaml_output_path, roles_path, action_vars_lambda)
end
def get_action_vars(instrumentor, provisioned_resource, params = {})
resource_id = provisioned_resource.get_resource().get_id()
tags = provisioned_resource.get_resource().get_tags().to_json()
deployment_name = get_deployment_name()
vars = {}
vars["resource_id"] = resource_id
vars["version"] = instrumentor.get_version()
vars["remote_user"] = provisioned_resource.get_user_name()
vars["resource_display_name"] = provisioned_resource.get_resource().get_display_name()
vars["deployment_name"] = deployment_name
vars["deployment_path"] = get_deployment_path()
vars["resource_deployment_name"] = "#{deployment_name}_#{resource_id}"
vars["tags"] = tags
credential = get_instrumentor_credential(instrumentor)
unless (credential.nil?)
vars = vars.merge(credential.to_h())
end
credential = get_instrumentor_provider_credential(instrumentor)
unless (credential.nil?)
vars = vars.merge(credential.to_h())
end
vars = vars.merge(params)
instrumentor_params = instrumentor.get_params().get_all()
vars = vars.merge(instrumentor_params)
return vars
end
def get_yaml_output_path(instrumentor, resource_id)
return "#{get_deployment_name()}/#{resource_id}/#{instrumentor.get_id()}"
end
end
end
end