-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As a v3 API user, my POST requests to /v3/service_brokers are asynchr…
…onous (#1440) This commit covers most of the happy paths and some unhappy ones. User story comes right up soon for more interesting unhappy paths. [#168083026] [finishes #168476345] Co-authored-by: Felisia Martini <fmartini@pivotal.io> Co-authored-by: Winna Bridgewater <wbridgewater@pivotal.io> Co-authored-by: Oleksii Fedorov <ofedorov@pivotal.io> Co-authored-by: Derik Evangelista <devangelista@pivotal.io> Co-authored-by: Joao Lebre <jlebre@pivotal.io>
- Loading branch information
1 parent
f3125b1
commit 8eeabf5
Showing
28 changed files
with
1,174 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
module VCAP::CloudController | ||
module V3 | ||
class SynchronizeBrokerCatalogJob < VCAP::CloudController::Jobs::CCJob | ||
def initialize(broker_guid) | ||
@broker_guid = broker_guid | ||
end | ||
|
||
def perform | ||
Perform.new(broker_guid).perform | ||
end | ||
|
||
def job_name_in_configuration | ||
:synchronize_service_broker_catalog | ||
end | ||
|
||
def max_attempts | ||
1 | ||
end | ||
|
||
def resource_type | ||
'service_brokers' | ||
end | ||
|
||
def resource_guid | ||
broker_guid | ||
end | ||
|
||
def display_name | ||
'service_broker.catalog.synchronize' | ||
end | ||
|
||
private | ||
|
||
attr_reader :broker_guid | ||
|
||
class Perform | ||
def initialize(broker_guid) | ||
@broker_guid = broker_guid | ||
@broker = ServiceBroker.find(guid: broker_guid) | ||
@formatter = VCAP::Services::ServiceBrokers::ValidationErrorsFormatter.new | ||
@service_event_repository = VCAP::CloudController::Repositories::ServiceEventRepository::WithBrokerActor.new | ||
@client_manager = VCAP::Services::SSO::DashboardClientManager.new(broker, service_event_repository) | ||
@broker_client = VCAP::Services::ServiceClientProvider.provide(broker: broker) | ||
@service_manager = VCAP::Services::ServiceBrokers::ServiceManager.new(service_event_repository) | ||
end | ||
|
||
def perform | ||
ensure_state_present | ||
|
||
catalog = VCAP::Services::ServiceBrokers::V2::Catalog.new(broker, broker_client.catalog) | ||
|
||
raise fail_with_invalid_catalog(catalog.validation_errors) unless catalog.valid? | ||
raise fail_with_incompatible_catalog(catalog.incompatibility_errors) unless catalog.compatible? | ||
|
||
unless client_manager.synchronize_clients_with_catalog(catalog) | ||
# TODO: raise some humanized exceptions if it failed | ||
end | ||
|
||
service_manager.sync_services_and_plans(catalog) | ||
|
||
# TODO: if service_manager.has_warnings? | ||
# TODO: if client_manager.has_warnings? | ||
|
||
available_state | ||
rescue | ||
failed_state | ||
raise | ||
end | ||
|
||
private | ||
|
||
attr_reader :broker_guid, :broker, :broker_client, | ||
:formatter, :client_manager, :service_event_repository, | ||
:service_manager | ||
|
||
def ensure_state_present | ||
if broker.service_broker_state.nil? | ||
broker.service_broker_state = ServiceBrokerState.new( | ||
state: ServiceBrokerStateEnum::SYNCHRONIZING | ||
) | ||
end | ||
end | ||
|
||
def failed_state | ||
broker.service_broker_state.update( | ||
state: ServiceBrokerStateEnum::SYNCHRONIZATION_FAILED | ||
) | ||
end | ||
|
||
def available_state | ||
broker.service_broker_state.update( | ||
state: ServiceBrokerStateEnum::AVAILABLE | ||
) | ||
end | ||
|
||
def fail_with_invalid_catalog(errors) | ||
full_message = formatter.format(errors) | ||
raise CloudController::Errors::ApiError.new_from_details('ServiceBrokerCatalogInvalid', full_message) | ||
end | ||
|
||
def fail_with_incompatible_catalog(errors) | ||
full_message = formatter.format(errors) | ||
raise CloudController::Errors::ApiError.new_from_details('ServiceBrokerCatalogIncompatible', full_message) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module VCAP::CloudController | ||
class ServiceBrokerState < Sequel::Model | ||
import_attributes :state, :service_broker_guid | ||
export_attributes :guid, :state, :service_broker_guid | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module VCAP::CloudController | ||
class ServiceBrokerStateEnum | ||
SYNCHRONIZING = 'SYNCHRONIZING'.freeze | ||
SYNCHRONIZATION_FAILED = 'SYNCHRONIZATION_FAILED'.freeze | ||
AVAILABLE = 'AVAILABLE'.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'presenters/helpers/censorship' | ||
|
||
module VCAP::CloudController | ||
module Presenters | ||
module V3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
db/migrations/20190905131313_create_service_broker_states.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Sequel.migration do | ||
change do | ||
create_table(:service_broker_states) do | ||
VCAP::Migration.common(self) | ||
|
||
String :state, size: 50, null: false | ||
|
||
Integer :service_broker_id, null: false | ||
foreign_key :service_broker_id, :service_brokers, name: :fk_service_brokers_id | ||
index [:service_broker_id], name: :fk_service_brokers_id_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'credhub/config_helpers' | ||
require 'diego/action_builder' | ||
|
||
module VCAP::CloudController | ||
module Diego | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.