Class: StackMate::StackNest
- Inherits:
-
Ruote::Participant
- Object
- Ruote::Participant
- StackMate::StackNest
- Defined in:
- lib/stackmate/participants/common.rb
Constant Summary
Constants included from Resolver
Resolver::INTEXP, Resolver::STRINGEXP, Resolver::UUIDEXP
Instance Method Summary collapse
Methods included from StackPi
Methods included from Resolver
#get_named_tag, #get_resolved, #resolve_tags, #resolve_to_deviceid, #validate_param
Methods included from Intrinsic
#fn_base64, #fn_getatt, #fn_join, #fn_lookup, #fn_map, #fn_ref, #fn_select, #intrinsic
Methods included from Logging
configure_logger_for, #logger, logger_for
Instance Method Details
#create ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/stackmate/participants/common.rb', line 162 def create logger.debug("Creating nested stack #{@stackname}") #Get template from URL #Call stackmate API for launching new stack #read outputs from predefined location #copy all critical fields from workitems #CAVEAT - needs file storage. may be move to database backed # needs a Outputs tag. Not a big deal since nested stacks anyways need #outputs tags workitem[@stack_name] = {} params = workitem['ResolvedNames'] stack_props = workitem['Resources'][@stack_name]['Properties'] template_url = URI(get_resolved(stack_props['TemplateURL'],workitem)) logger.debug("Fetching template for #{@stack_name} from URL #{template_url}") http = Net::HTTP.new(template_url.host,template_url.port) if template_url.scheme == 'https' http.use_ssl = true end http.start { http.request_get(template_url.path) { |res| File.open("/tmp/#{@stack_name}.template", 'w') { |file| file.write(res.body) } } } stack_props['Parameters'].each_key do |k| params[k] = get_resolved(stack_props['Parameters'][k],workitem) end params['stackrand'] = Time.now().to_i #TODO use subid from fei or something params['isnested'] = "True" StackMate::StackPi.create_stack("/tmp/#{@stack_name}.template",@stack_name,format_params(params),true) file_name = "/tmp/#{@stack_name}.workitem.#{params['stackrand']}" if(File.exists?(file_name)) output_workitem = YAML.load(File.read(file_name)) workitem[@stack_name]['ResolvedNames'] = output_workitem['ResolvedNames'].clone workitem[@stack_name]['Outputs'] = output_workitem['Outputs'].clone workitem[@stack_name]['Resources'] = output_workitem['Resources'].clone workitem[@stack_name]['IdMap'] = output_workitem['IdMap'].clone #copy all resources created output_workitem['Resources'].each_key do |resource| workitem[@stack_name][resource] = output_workitem[resource].clone end logger.debug("Successfully created nested stack #{@stack_name}") else logger.debug("Unable to create nested stack #{@stack_name}") raise "Nested Stack Failed" end end |
#delete ⇒ Object
210 211 212 213 214 215 |
# File 'lib/stackmate/participants/common.rb', line 210 def delete logger.debug("Deleting stack #{@stack_name}") #TODO write code to roll back all stack info #Probably nothing needed since new engine launched takes care of it #No, need to clean up if parent stack fails after the nested stack is successfully created end |
#format_params(params) ⇒ Object
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/stackmate/participants/common.rb', line 228 def format_params(params) result = "" add_semi = false params.each_key do |k| result = result + ";" if add_semi result = result + k + "=" + params[k].to_s if !params[k].nil? add_semi = true end result end |
#on_workitem ⇒ Object
217 218 219 220 221 222 223 224 225 226 |
# File 'lib/stackmate/participants/common.rb', line 217 def on_workitem @stack_name = workitem.participant_name if workitem['params']['operation'] == 'create' create else #rollback / delete delete end reply end |