Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ The following services are supported:
* get_server
* list_instances
* list_servers
* scale_in_a_cluster
* scale_out_a_cluster
* scale_a_node
* list_backups
* get_backup
* backup_instance
* list_restorations
* get_restoration
* restoration_instance
* SOA Cloud Service
* create_instance
* delete_instance
Expand Down
14 changes: 13 additions & 1 deletion lib/fog/oraclecloud/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Java < Fog::Service
collection :instances
model :server
collection :servers
model :backup
collection :backups
model :restoration
collection :restorations

request_path 'fog/oraclecloud/requests/java'
request :list_instances
Expand All @@ -20,7 +24,13 @@ class Java < Fog::Service
request :scale_out_a_cluster
request :scale_in_a_cluster
request :scale_a_node

request :backup_instance
request :list_backups
request :get_backup
request :restoration_instance
request :list_restorations
request :get_restoration

class Real

def initialize(options={})
Expand Down Expand Up @@ -96,6 +106,8 @@ def self.data
@data ||= {
:instances => {},
:servers => {},
:backups => {},
:restorations => {},
:maintenance_at => {},
:deleted_at => {},
:created_at => {}
Expand Down
51 changes: 51 additions & 0 deletions lib/fog/oraclecloud/models/java/backup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'fog/core/model'

module Fog
module OracleCloud
class Java
class Backup < Fog::Model
identity :backup_id, :aliases=>'backupId'

attribute :job_id, :aliases=>'jobId'
attribute :backup_startDate, :aliases=>'backupStartDate'
attribute :backup_complete_date, :aliases=>'backupCompleteDate'
attribute :deleted_on_date, :aliases=>'deletedOnDate'
attribute :expiration_date, :aliases=>'expirationDate'
attribute :force_scale_in_required_for_restore, :aliases=>'forceScaleInRequiredForRestore'
attribute :full
attribute :local
attribute :local_copy, :aliases=>'localCopy'
attribute :database_included, :aliases=>'databaseIncluded'
attribute :size
attribute :size_in_bytes, :aliases=>'sizeInBytes'
attribute :status
attribute :service_components, :aliases=>'serviceComponents'
attribute :job_history, :aliases=>'jobHistory'
attribute :db_tag, :aliases=>'dbTag'
attribute :service_name

def completed?
status == "Completed"
end

private

# Had to override reload as we need to pass the service_name
def reload
requires :identity, :service_name

data = begin
collection.get(service_name, identity)
rescue Excon::Errors::SocketError
nil
end
return unless data

new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
end
end
end
end
24 changes: 24 additions & 0 deletions lib/fog/oraclecloud/models/java/backups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'fog/core/collection'

module Fog
module OracleCloud
class Java
class Backups < Fog::Collection

model Fog::OracleCloud::Java::Backup

def all(service_name)
data = service.list_backups(service_name).body['backups']
load(data)
end

def get(service_name, backup_id)
data = service.get_backup(service_name, backup_id).body
data['service_name'] = service_name
new(data)
end

end
end
end
end
21 changes: 20 additions & 1 deletion lib/fog/oraclecloud/models/java/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,26 @@ def stopped?
def servers
service.servers.all(service_name)
end


def backup
requires :service_name
service.backup_instance(service_name)
end

def backups
service.backups.all(service_name)
end

def restoration(backup_id, options)
requires :service_name
service.restoration_instance(service_name, backup_id, options)
end

def restorations
requires :service_name
service.restorations.all(service_name)
end

def destroy
requires :service_name, :dba_name, :dba_password
service.delete_instance(service_name, dba_name, dba_password, :force_delete => force_delete).body
Expand Down
50 changes: 50 additions & 0 deletions lib/fog/oraclecloud/models/java/restoration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'fog/core/model'

module Fog
module OracleCloud
class Java
class Restoration < Fog::Model

attribute :backup_id, :aliases=>'backupId'
attribute :backup_date, :aliases=>'backupDate'
attribute :job_id, :aliases=>'jobId'
attribute :recovery_start_date, :aliases=>'recoveryStartDate'
attribute :recovery_complete_date, :aliases=>'recoveryCompleteDate'
attribute :status
attribute :status_details, :aliases=>'statusDetails'
attribute :static_data_included, :aliases=>'staticDataIncluded'
attribute :config_data_included, :aliases=>'configDataIncluded'
attribute :otd_included, :aliases=>'otdIncluded'
attribute :database_included, :aliases=>'databaseIncluded'
attribute :notes
attribute :timestamp
attribute :service_name

def completed?
status == "COMPLETED"
end

private

def reload
requires :service_name

data = begin
if !db_tag.nil? then
collection.get(service_name, 'tag', db_tag)
else
collection.get(service_name)
end
rescue Excon::Errors::SocketError
nil
end
return unless data

new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
end
end
end
end
24 changes: 24 additions & 0 deletions lib/fog/oraclecloud/models/java/restorations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'fog/core/collection'

module Fog
module OracleCloud
class Java
class Restorations < Fog::Collection

model Fog::OracleCloud::Java::Restoration

def all(service_name)
data = service.list_restorations(service_name).body['restoreHistory']
load(data)
end

def get(service_name, job_id)
data = service.get_restoration(service_name, job_id).body
data['service_name'] = service_name
new(data)
end

end
end
end
end
52 changes: 52 additions & 0 deletions lib/fog/oraclecloud/requests/java/backup_instance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Fog
module OracleCloud
class Java
class Real

def backup_instance(service_name, options={})
# Oracle Cloud requires an empty JSON object in the body
body_data = {
'databaseIncluded' => options[:databaseIncluded],
'expirationDate' => options[:expirationDate],
'full' => options[:full],
'notes' => options[:notes]
}
body_data = body_data.reject {|key, value| value.nil?}

response = request(
:method => 'POST',
:expects => 202,
:path => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/backups",
:body => Fog::JSON.encode(body_data),
)

response
end
end

class Mock
def backup_instance(service_name)
response = Excon::Response.new

if !self.data[:backups].is_a? Array
self.data[:backups] = []
end

self.data[:backups].push({
'backupId'=>'999',
'backupStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'),
'dbTag'=>'TAG' + Time.now.strftime('%Y%m%dT%H%M%S'),
'status'=>'Completed',
'service_name'=>service_name
})

response.status = 202
response.body ={
'operationName'=>'start-backup'
}
response
end
end
end
end
end
34 changes: 34 additions & 0 deletions lib/fog/oraclecloud/requests/java/get_backup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Fog
module OracleCloud
class Java
class Real
def get_backup(service_name, backup_id)
response = request(
:expects => 200,
:method => 'GET',
:path => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/backups/#{backup_id}"
)
response
end
end

class Mock
def get_backup(service_name, backup_id)
response = Excon::Response.new

backup = {}
self.data[:backups].each_with_index { |r, i|
if r['backupId'].eql?(backup_id)
backup = self.data[:backups][i]
end
}

response.status = 200
response.body = backup
response

end
end
end
end
end
34 changes: 34 additions & 0 deletions lib/fog/oraclecloud/requests/java/get_restoration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Fog
module OracleCloud
class Java
class Real
def get_restoration(service_name, job_id)
response = request(
:expects => 200,
:method => 'GET',
:path => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/restoredbackups/#{job_id}"
)
response
end
end

class Mock
def get_restoration(service_name, job_id)
response = Excon::Response.new

restoration = {}
self.data[:restorations].each_with_index{ |r,i|
if r['jobId'].eql?(job_id)
restoration = self.data[:restorations][i]
end
}

response.status = 200
response.body = restoration
response

end
end
end
end
end
32 changes: 32 additions & 0 deletions lib/fog/oraclecloud/requests/java/list_backups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Fog
module OracleCloud
class Java
class Real
def list_backups(service_name)
response = request(
:expects => 200,
:method => 'GET',
:path => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/backups"
)
response
end
end

class Mock
def list_backups(service_name)
response = Excon::Response.new

if !self.data[:backups] then
self.data[:backups] = []
end

backups = self.data[:backups]
response.body = {
'backups' => backups
}
response
end
end
end
end
end
Loading