Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/actions/space_diff_manifest.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'presenters/v3/app_manifest_presenter'
require 'messages/app_manifest_message'
require 'json-diff'

module VCAP::CloudController
Expand Down Expand Up @@ -62,7 +63,7 @@ def self.filter_manifest_app_hash(manifest_app_hash)
# rubocop:todo Metrics/CyclomaticComplexity
def self.generate_diff(app_manifests, space)
json_diff = []
recognized_top_level_keys = NamedAppManifestMessage.allowed_keys.map(&:to_s)
recognized_top_level_keys = AppManifestMessage.allowed_keys.map(&:to_s)
app_manifests.each_with_index do |manifest_app_hash, index|
manifest_app_hash = SpaceDiffManifest.filter_manifest_app_hash(manifest_app_hash)
existing_app = space.app_models.find { |app| app.name == manifest_app_hash['name'] }
Expand Down
70 changes: 0 additions & 70 deletions app/controllers/v3/app_manifests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@
class AppManifestsController < ApplicationController
include AppSubResource

wrap_parameters :body, format: [:yaml]

before_action :validate_content_type!, only: :apply_manifest

def apply_manifest
message = AppManifestMessage.create_from_yml(parsed_app_manifest_params)
compound_error!(message.errors.full_messages) unless message.valid?

app, space, org = AppFetcher.new.fetch(hashed_params[:guid])

app_not_found! unless app && permission_queryer.can_read_from_space?(space.guid, org.guid)
unauthorized! unless permission_queryer.can_write_to_space?(space.guid)
unsupported_for_docker_apps!(message) if incompatible_with_buildpacks(app.lifecycle_type, message)

apply_manifest_action = AppApplyManifest.new(user_audit_info)
apply_manifest_job = VCAP::CloudController::Jobs::AppApplyManifestActionJob.new(app.guid, message, apply_manifest_action)

record_apply_manifest_audit_event(app, message, space)
job = Jobs::Enqueuer.new(apply_manifest_job, queue: Jobs::Queues.generic).enqueue_pollable
TelemetryLogger.v3_emit(
'apply-manifest',
{
'app-id' => app.guid,
'user-id' => current_user.guid
}
)

head HTTP::ACCEPTED, 'Location' => url_builder.build_url(path: "/v3/jobs/#{job.guid}")
end

def show
app, space, org = AppFetcher.new.fetch(hashed_params[:guid])

Expand All @@ -45,44 +15,4 @@ def show
manifest_yaml = manifest_presenter.to_hash.deep_stringify_keys.to_yaml
render status: :ok, plain: manifest_yaml, content_type: YAML_CONTENT_TYPE
end

private

def record_apply_manifest_audit_event(app, message, space)
audited_request_yaml = { 'applications' => [message.audit_hash] }.to_yaml
Repositories::AppEventRepository.new.record_app_apply_manifest(app, space, user_audit_info, audited_request_yaml)
end

def unsupported_for_docker_apps!(manifest)
error_message = manifest.buildpacks ? 'Buildpacks' : 'Buildpack'
raise unprocessable(error_message + ' cannot be configured for a docker lifecycle app.')
end

def incompatible_with_buildpacks(lifecycle_type, manifest)
lifecycle_type == 'docker' && (manifest.buildpack || manifest.buildpacks)
end

def compound_error!(error_messages)
underlying_errors = error_messages.map { |message| unprocessable(message) }
raise CloudController::Errors::CompoundError.new(underlying_errors)
end

def validate_content_type!
if !request_content_type_is_yaml?
logger.error("Context-type isn't yaml: #{request.content_type}")
bad_request!('Content-Type must be yaml')
end
end

def request_content_type_is_yaml?
Mime::Type.lookup(request.content_type) == :yaml
end

def parsed_app_manifest_params
parsed_application = parsed_yaml['applications'] && parsed_yaml['applications'].first

raise bad_request!('Invalid app manifest') unless parsed_application.present?

parsed_application
end
end
1 change: 0 additions & 1 deletion app/controllers/v3/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
require 'messages/update_environment_variables_message'
require 'messages/app_manifest_message'
require 'messages/app_builds_list_message'
require 'messages/named_app_manifest_message'
require 'presenters/v3/app_presenter'
require 'presenters/v3/app_env_presenter'
require 'presenters/v3/app_environment_variables_presenter'
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/v3/space_manifests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'presenters/v3/app_manifest_presenter'
require 'repositories/app_event_repository'
require 'messages/named_app_manifest_message'
require 'messages/app_manifest_message'
require 'actions/app_find_or_create_skeleton'
require 'actions/app_create'
require 'actions/space_diff_manifest'
Expand All @@ -15,7 +15,7 @@ def apply_manifest
space_not_found! unless space && permission_queryer.can_read_from_space?(space.guid, space.organization.guid)
unauthorized! unless permission_queryer.can_write_to_space?(space.guid)

messages = parsed_app_manifests.map { |app_manifest| NamedAppManifestMessage.create_from_yml(app_manifest) }
messages = parsed_app_manifests.map { |app_manifest| AppManifestMessage.create_from_yml(app_manifest) }
errors = messages.each_with_index.flat_map { |message, i| errors_for_message(message, i) }
compound_error!(errors) unless errors.empty?

Expand Down Expand Up @@ -49,7 +49,7 @@ def diff_manifest

parsed_manifests = parsed_app_manifests.map(&:to_hash)

messages = parsed_app_manifests.map { |app_manifest| NamedAppManifestMessage.create_from_yml(app_manifest) }
messages = parsed_app_manifests.map { |app_manifest| AppManifestMessage.create_from_yml(app_manifest) }
errors = messages.each_with_index.flat_map { |message, i| errors_for_message(message, i) }
compound_error!(errors) unless errors.empty?

Expand Down
59 changes: 0 additions & 59 deletions app/jobs/app_apply_manifest_action_job.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/messages/app_manifest_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AppManifestMessage < BaseMessage
:instances,
:metadata,
:memory,
:name,
:no_route,
:processes,
:random_route,
Expand Down Expand Up @@ -53,6 +54,7 @@ def self.underscore_keys(hash)
end
end

validates :name, presence: { message: 'must not be empty' }, string: true
validate :validate_top_level_web_process!
validate :validate_processes!, if: ->(record) { record.requested?(:processes) }
validate :validate_sidecars!, if: ->(record) { record.requested?(:sidecars) }
Expand Down
10 changes: 0 additions & 10 deletions app/messages/named_app_manifest_message.rb

This file was deleted.

1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
get '/apps/:guid/ssh_enabled', to: 'app_features#ssh_enabled'

# app manifests
post '/apps/:guid/actions/apply_manifest', to: 'app_manifests#apply_manifest'
get '/apps/:guid/manifest', to: 'app_manifests#show'

# app revisions
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Sidecars are useful for any app processes that need to communicate with another


#### Steps to create a sidecar
The recommended way to create sidecars for your app is with an [app manifest](#app-manifest).
The recommended way to create sidecars for your app is with a [manifest](#manifests).

```yaml
sidecars:
Expand Down
Loading