Class: VCAP::Services::Base::SnapshotV2::BaseRollbackSnapshotJob

Inherits:
SnapshotJob show all
Defined in:
lib/base/snapshot_v2/snapshot.rb

Instance Attribute Summary collapse

Attributes inherited from SnapshotJob

#name, #snapshot_id

Instance Method Summary collapse

Methods inherited from SnapshotJob

#cleanup, #create_lock, #fmt_error, #get_dump_path, #handle_error, #init_worker_logger, #initialize, #parse_config, queue_lookup_key, #required_options, select_queue

Constructor Details

This class inherits a constructor from VCAP::Services::Base::SnapshotV2::SnapshotJob

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



190
191
192
# File 'lib/base/snapshot_v2/snapshot.rb', line 190

def manifest
  @manifest
end

#snapshot_filesObject (readonly)

Returns the value of attribute snapshot_files.



190
191
192
# File 'lib/base/snapshot_v2/snapshot.rb', line 190

def snapshot_files
  @snapshot_files
end

Instance Method Details

#performObject

workflow template Subclass implement execute method which returns true for a successful rollback



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/base/snapshot_v2/snapshot.rb', line 193

def perform
  begin
    required_options :service_id, :snapshot_id
    @name = options["service_id"]
    @snapshot_id = options["snapshot_id"]
    @logger.info("Launch job: #{self.class} for #{name}")

    lock = create_lock

    @snapshot_files = []
    lock.lock do
      # extract origin files from package
      dump_path = get_dump_path(name, snapshot_id)
      package_file = "#{snapshot_id}.zip"
      package = Package.load(File.join(dump_path, package_file))
      @manifest = package.manifest
      @snapshot_files = package.unpack(dump_path)
      @logger.debug("Unpack files from #{package_file}: #{@snapshot_files}")
      raise "Package file doesn't contain snapshot file." if @snapshot_files.empty?

      result = execute
      @logger.info("Results of rollback snapshot: #{result}")

      completed(Yajl::Encoder.encode({:result => :ok}))
      @logger.info("Complete job: #{self.class} for #{name}")
    end
  rescue => e
    handle_error(e)
  ensure
    set_status({:complete_time => Time.now.to_s})
    @snapshot_files.each{|f| File.delete(f) if File.exists? f} if @snapshot_files
  end
end