Module: Nucleus::Adapters::V1::CloudControl::Data

Included in:
Nucleus::Adapters::V1::CloudControl
Defined in:
lib/nucleus/adapters/v1/cloud_control/data.rb

Overview

cloud control data management operations

Instance Method Summary collapse

Instance Method Details

#deploy(application_id, file, compression_format) ⇒ Object

See Also:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nucleus/adapters/v1/cloud_control/data.rb', line 8

def deploy(application_id, file, compression_format)
  # get deployment, also serves as 404 check for application
  deployment = default_deployment(application_id)
  current_state = application_state(deployment)

  user = get('/user').body[0]
  name = "nucleus.app.repo.cloudControl.deploy.#{application_id}.#{SecureRandom.uuid}"
  # push to the deployment branch, here: nucleus
  with_ssh_key do
    deployer = GitDeployer.new(name, deployment[:branch], user[:email], NUCLEUS_DEPLOYMENT)
    deployer.deploy(file, compression_format)
  end

  return if current_state == Enums::ApplicationStates::CREATED ||
            current_state == Enums::ApplicationStates::DEPLOYED

  # Deploy via the API, use version identifier -1 to refer a new build,
  # but ONLY (!) if the application is not in the CREATED or DEPLOYED state
  put("app/#{application_id}/deployment/#{NUCLEUS_DEPLOYMENT}", body: { version: '-1' })
end

#download(application_id, compression_format) ⇒ Object

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nucleus/adapters/v1/cloud_control/data.rb', line 30

def download(application_id, compression_format)
  # get deployment, also serves as 404 check for application
  deployment = default_deployment(application_id)
  if application_state(deployment) == Enums::ApplicationStates::CREATED
    fail Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be downloaded'
  end

  # compress files to archive but exclude the .git repo
  name = "nucleus.app.repo.cloudControl.download.#{application_id}.#{SecureRandom.uuid}"
  with_ssh_key do
    GitDeployer.new(name, deployment[:branch], nil, NUCLEUS_DEPLOYMENT).download(compression_format, true)
  end
end

#rebuild(application_id) ⇒ Object

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nucleus/adapters/v1/cloud_control/data.rb', line 45

def rebuild(application_id)
  # get deployment, also serves as 404 check for application
  deployment = default_deployment(application_id)
  if application_state(deployment) == Enums::ApplicationStates::CREATED
    fail Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be rebuild'
  end

  user = get('/user').body[0]
  name = "nucleus.app.repo.cloudControl.rebuild.#{application_id}.#{SecureRandom.uuid}"

  with_ssh_key do
    GitDeployer.new(name, deployment[:branch], user[:email], NUCLEUS_DEPLOYMENT).trigger_build
  end

  # now deploy via the API, use version identifier -1 to refer a new build
  put("app/#{application_id}/deployment/#{NUCLEUS_DEPLOYMENT}", body: { version: '-1' })

  # return with updated application
  application(application_id)
end