Class: Nucleus::Adapters::V1::CloudControl

Inherits:
Stub show all
Includes:
Application, Authentication, Buildpacks, Data, Domains, Lifecycle, Logs, Regions, Scaling, SemanticErrors, Services, Vars, Logging
Defined in:
lib/nucleus/adapters/v1/cloud_control/data.rb,
lib/nucleus/adapters/v1/cloud_control/logs.rb,
lib/nucleus/adapters/v1/cloud_control/vars.rb,
lib/nucleus/adapters/v1/cloud_control/token.rb,
lib/nucleus/adapters/v1/cloud_control/domains.rb,
lib/nucleus/adapters/v1/cloud_control/regions.rb,
lib/nucleus/adapters/v1/cloud_control/scaling.rb,
lib/nucleus/adapters/v1/cloud_control/services.rb,
lib/nucleus/adapters/v1/cloud_control/lifecycle.rb,
lib/nucleus/adapters/v1/cloud_control/buildpacks.rb,
lib/nucleus/adapters/v1/cloud_control/log_poller.rb,
lib/nucleus/adapters/v1/cloud_control/application.rb,
lib/nucleus/adapters/v1/cloud_control/cloud_control.rb,
lib/nucleus/adapters/v1/cloud_control/authentication.rb,
lib/nucleus/adapters/v1/cloud_control/semantic_errors.rb

Defined Under Namespace

Modules: Application, Authentication, Buildpacks, Data, Domains, Lifecycle, Logs, Regions, Scaling, SemanticErrors, Services, Vars Classes: Token

Constant Summary collapse

NUCLEUS_DEPLOYMENT =

The default deployment name of cloud control applications that is used by Nucleus

'nucleus'
CC_EXCLUSIVE_SEMANTIC_ERROR_MSGS =

Error messages of semantic errors that are platform specific

['cannot use this name', 'may only contain', 'this field has no more than']
CC_SEMANTIC_ERROR_MSGS =

Error messages of common semantic errors

['must be unique', 'already exists',
'not a valid addon name', 'not a valid addon option']
CC_CONFLICT_ERROR_MSGS =
['Addon already exists']

Constants included from Logs

Logs::LOG_TYPES

Constants included from Domains

Domains::CC_URLS

Constants included from BuildpackTranslator

BuildpackTranslator::PUBLIC_BUILDPACKS

Constants inherited from Stub

Stub::NOT_IMPLEMENTED_ERROR

Instance Attribute Summary

Attributes inherited from BaseAdapter

#endpoint_url

Instance Method Summary collapse

Methods included from Vars

#create_env_var, #delete_env_var, #env_var, #env_vars, #update_env_var

Methods included from Services

#add_service, #change_service, #installed_service, #installed_services, #remove_service, #service, #service_plan, #service_plans, #services

Methods included from SemanticErrors

#semantic_error_messages

Methods included from Scaling

#scale

Methods included from Regions

#region, #regions

Methods included from Logs

#log?, #log_entries, #logs, #tail

Methods included from Lifecycle

#start

Methods included from Data

#deploy, #download, #rebuild

Methods included from Domains

#create_domain, #delete_domain, #domain, #domains

Methods included from Buildpacks

#vendor_specific_runtimes

Methods included from BuildpackTranslator

#find_runtime, #native_runtime?

Methods included from Application

#application, #applications, #create_application, #delete_application

Methods included from Authentication

#auth_client

Methods included from Logging

configure_logger_for, #log, logger_for

Methods inherited from Stub

#add_service, #application, #applications, #auth_client, #change_service, #create_application, #create_domain, #create_env_var, #delete_application, #delete_domain, #delete_env_var, #deploy, #domain, #domains, #download, #env_var, #env_vars, #installed_service, #installed_services, #log?, #log_entries, #logs, #rebuild, #region, #regions, #remove_service, #restart, #scale, #service, #service_plan, #service_plans, #services, #start, #stop, #tail, #update_application, #update_env_var

Methods inherited from BaseAdapter

#cache, #cache?, #cache_key, #cached, #endpoint_call, #fail_with

Methods included from HttpTailClient

#tail_http_response

Methods included from HttpClient

#delete, #get, #head, #patch, #post, #put

Constructor Details

#initialize(endpoint_url, endpoint_app_domain = nil, check_certificates = true) ⇒ CloudControl

Returns a new instance of CloudControl.



30
31
32
# File 'lib/nucleus/adapters/v1/cloud_control/cloud_control.rb', line 30

def initialize(endpoint_url, endpoint_app_domain = nil, check_certificates = true)
  super(endpoint_url, endpoint_app_domain, check_certificates)
end

Instance Method Details

#handle_error(error_response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nucleus/adapters/v1/cloud_control/cloud_control.rb', line 34

def handle_error(error_response)
  message = error_response.body.match(/{(.*?)}/)
  message = message[1] if message

  # cloud control responds almost every time with 400...
  if error_response.status == 400
    handle_400(message)
  elsif error_response.status == 409 && CC_CONFLICT_ERROR_MSGS.any? { |msg| message.include? msg }
    fail Errors::SemanticAdapterRequestError, message
  elsif error_response.status == 410
    fail Errors::AdapterResourceNotFoundError, 'Resource not found'
  elsif error_response.status == 503
    fail Errors::PlatformUnavailableError, 'The cloudControl API is currently not available'
  end
  # error still unhandled, will result in a 500, server error
  log.warn "cloudControl error still unhandled: #{error_response}"
end