2017-10-13 17:21:23 +00:00
|
|
|
module Clusters
|
|
|
|
module Gcp
|
|
|
|
class ProvisionService
|
|
|
|
attr_reader :provider
|
|
|
|
|
|
|
|
def execute(provider)
|
|
|
|
@provider = provider
|
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
get_operation_id do |operation_id|
|
|
|
|
if provider.make_creating(operation_id)
|
|
|
|
WaitForClusterCreationWorker.perform_in(
|
|
|
|
Clusters::Gcp::VerifyProvisionStatusService::INITIAL_INTERVAL,
|
2017-11-01 16:10:41 +00:00
|
|
|
provider.cluster_id)
|
2017-10-23 08:36:35 +00:00
|
|
|
else
|
|
|
|
provider.make_errored!("Failed to update provider record; #{provider.errors}")
|
|
|
|
end
|
2017-10-13 17:21:23 +00:00
|
|
|
end
|
2017-10-23 08:36:35 +00:00
|
|
|
end
|
2017-10-13 17:21:23 +00:00
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
private
|
2017-10-13 17:21:23 +00:00
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
def get_operation_id
|
|
|
|
operation = provider.api_client.projects_zones_clusters_create(
|
|
|
|
provider.gcp_project_id,
|
|
|
|
provider.zone,
|
|
|
|
provider.cluster.name,
|
|
|
|
provider.num_nodes,
|
|
|
|
machine_type: provider.machine_type)
|
2017-10-13 17:21:23 +00:00
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
unless operation.status == 'PENDING' || operation.status == 'RUNNING'
|
|
|
|
return provider.make_errored!("Operation status is unexpected; #{operation.status_message}")
|
2017-10-13 17:21:23 +00:00
|
|
|
end
|
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
operation_id = provider.api_client.parse_operation_id(operation.self_link)
|
2017-10-13 17:21:23 +00:00
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
unless operation_id
|
|
|
|
return provider.make_errored!('Can not find operation_id from self_link')
|
|
|
|
end
|
2017-10-13 17:21:23 +00:00
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
yield(operation_id)
|
2017-10-13 17:21:23 +00:00
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
|
|
|
|
provider.make_errored!("Failed to request to CloudPlatform; #{e.message}")
|
2017-10-13 17:21:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|