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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/lds-cf-plugin/marklogic_service.rb', line 19
def create_marklogic_service
offerings = client.services
offerings.keep_if { |s| s.label == 'marklogic-service' && s.provider.start_with?('ICS') && s.active }
service = offerings.first
if !service
fail "Cannot find Marklogic service on #{client.target}"
end
if service.version != "0.1"
fail "Your lds-cf-plugin version is out of date. To update execute `gem update lds-cf-plugin`"
end
rest_client = CFoundry::RestClient.new(service.url, client.token)
rest_client.trace = client.trace
instance_name = input[:name]
if !instance_name
instance_name = ask("Name")
end
plans = service.service_plans
selected_plan = nil
plans.each do |plan|
selcted_plan = plan if plan.name == input[:plan]
end unless input[:plan].nil?
existing_plan = nil?
plans.each do | plan |
existing_plan = plan if plan.name == "Existing"
end
provision_plan = nil?
plans.each do | plan |
provision_plan = plan if plan.name == "Default"
end
plan_type = nil
plan_type = "Default" unless existing_plan.nil?
if(plans.length > 1 && !existing_plan.nil? && selected_plan.nil?)
choices = ["Existing", "Provision New"]
options = {
:choices => choices,
:default => "Existing",
:allow_other => false
}
plan_type = ask("What type of Marklogic Service", options)
end
if plan_type == "Existing"
selected_plan = existing_plan
host = input[:host]
if !host
host = ask("Marklogic host")
end
port = input[:port]
if !port
port = ask("Marklogic Port")
end
username = input[:username]
if !username
username = ask("Marklogic User")
end
password = input[:password]
if !password
password = ask("Marklogic password", :echo => "*", :forget => true)
end
payload = {
:space_guid => client.current_space.guid,
:name => instance_name,
:host => host,
:port => port,
:username => username,
:password => password
}
options = {
:payload => JSON.generate(payload)
}
request, response = rest_client.request("POST", "/register", options)
if response[:status].to_i != 200
fail "Error registering Marklogic service with gateway:\n#{response[:body]}"
end
else
selected_plan = provision_plan
end
instance = client.managed_service_instance
instance.name = instance_name
instance.service_plan = selected_plan
instance.space = client.current_space
with_progress("Creating service #{c(instance.name, :name)}") do
instance.create!
end
instance
end
|