From ea4af856e49cf5933b6995965fa7d6b922e38c20 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Wed, 4 Oct 2017 15:14:01 +0200 Subject: [PATCH] Fix cluster event names to be prefixed with: `make_` --- app/models/gcp/cluster.rb | 6 +++--- app/services/ci/fetch_gcp_operation_service.rb | 2 +- app/services/ci/finalize_cluster_creation_service.rb | 4 ++-- app/services/ci/integrate_cluster_service.rb | 2 +- app/services/ci/provision_cluster_service.rb | 10 +++++----- app/workers/wait_for_cluster_creation_worker.rb | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/models/gcp/cluster.rb b/app/models/gcp/cluster.rb index 18e16135a57..21eab9d8c1c 100644 --- a/app/models/gcp/cluster.rb +++ b/app/models/gcp/cluster.rb @@ -67,15 +67,15 @@ module Gcp validate :restrict_modification, on: :update, unless: :status_changed? state_machine :status, initial: :scheduled do - event :creating do + event :make_creating do transition any - [:creating] => :creating end - event :created do + event :make_created do transition any - [:created] => :created end - event :errored do + event :make_errored do transition any - [:errored] => :errored end diff --git a/app/services/ci/fetch_gcp_operation_service.rb b/app/services/ci/fetch_gcp_operation_service.rb index 415afaf901f..0b68e4d6ea9 100644 --- a/app/services/ci/fetch_gcp_operation_service.rb +++ b/app/services/ci/fetch_gcp_operation_service.rb @@ -11,7 +11,7 @@ module Ci yield(operation) if block_given? rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e - return cluster.errored!("Failed to request to CloudPlatform; #{e.message}") + return cluster.make_errored!("Failed to request to CloudPlatform; #{e.message}") end end end diff --git a/app/services/ci/finalize_cluster_creation_service.rb b/app/services/ci/finalize_cluster_creation_service.rb index a469acc0467..347875c5697 100644 --- a/app/services/ci/finalize_cluster_creation_service.rb +++ b/app/services/ci/finalize_cluster_creation_service.rb @@ -10,7 +10,7 @@ module Ci cluster.gcp_cluster_zone, cluster.gcp_cluster_name) rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e - return cluster.errored!("Failed to request to CloudPlatform; #{e.message}") + return cluster.make_errored!("Failed to request to CloudPlatform; #{e.message}") end endpoint = gke_cluster.endpoint @@ -23,7 +23,7 @@ module Ci api_url, ca_cert, username, password).execute unless kubernetes_token - return cluster.errored!('Failed to get a default token of kubernetes') + return cluster.make_errored!('Failed to get a default token of kubernetes') end Ci::IntegrateClusterService.new.execute( diff --git a/app/services/ci/integrate_cluster_service.rb b/app/services/ci/integrate_cluster_service.rb index ae7dccb0f42..857bca3f953 100644 --- a/app/services/ci/integrate_cluster_service.rb +++ b/app/services/ci/integrate_cluster_service.rb @@ -10,7 +10,7 @@ module Ci username: username, password: password, service: cluster.project.find_or_initialize_service('kubernetes'), - status_event: :created) + status_event: :make_created) cluster.service.update!( active: true, diff --git a/app/services/ci/provision_cluster_service.rb b/app/services/ci/provision_cluster_service.rb index 6fcbdd8b483..52d80b01813 100644 --- a/app/services/ci/provision_cluster_service.rb +++ b/app/services/ci/provision_cluster_service.rb @@ -12,24 +12,24 @@ module Ci cluster.gcp_cluster_size, machine_type: cluster.gcp_machine_type) rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e - return cluster.errored!("Failed to request to CloudPlatform; #{e.message}") + return cluster.make_errored!("Failed to request to CloudPlatform; #{e.message}") end unless operation.status == 'RUNNING' || operation.status == 'PENDING' - return cluster.errored!("Operation status is unexpected; #{operation.status_message}") + return cluster.make_errored!("Operation status is unexpected; #{operation.status_message}") end cluster.gcp_operation_id = api_client.parse_operation_id(operation.self_link) unless cluster.gcp_operation_id - return cluster.errored!('Can not find operation_id from self_link') + return cluster.make_errored!('Can not find operation_id from self_link') end - if cluster.creating + if cluster.make_creating WaitForClusterCreationWorker.perform_in( WaitForClusterCreationWorker::INITIAL_INTERVAL, cluster.id) else - return cluster.errored!("Failed to update cluster record; #{cluster.errors}") + return cluster.make_errored!("Failed to update cluster record; #{cluster.errors}") end end end diff --git a/app/workers/wait_for_cluster_creation_worker.rb b/app/workers/wait_for_cluster_creation_worker.rb index aa1cd84fa8c..f72bf409b20 100644 --- a/app/workers/wait_for_cluster_creation_worker.rb +++ b/app/workers/wait_for_cluster_creation_worker.rb @@ -12,14 +12,14 @@ class WaitForClusterCreationWorker case operation.status when 'RUNNING' if TIMEOUT < Time.zone.now - operation.start_time.to_time - return cluster.errored!("Cluster creation time exceeds timeout; #{TIMEOUT}") + return cluster.make_errored!("Cluster creation time exceeds timeout; #{TIMEOUT}") end WaitForClusterCreationWorker.perform_in(EAGER_INTERVAL, cluster.id) when 'DONE' Ci::FinalizeClusterCreationService.new.execute(cluster) else - return cluster.errored!("Unexpected operation status; #{operation.status} #{operation.status_message}") + return cluster.make_errored!("Unexpected operation status; #{operation.status} #{operation.status_message}") end end end