Skip to content

Create base of Cloud 7 Upgrade API V2 for crowbar-core#555

Merged
rsalevsky merged 12 commits intocrowbar:masterfrom
MaximilianMeister:v2
Aug 17, 2016
Merged

Create base of Cloud 7 Upgrade API V2 for crowbar-core#555
rsalevsky merged 12 commits intocrowbar:masterfrom
MaximilianMeister:v2

Conversation

@MaximilianMeister
Copy link
Copy Markdown
Member

No description provided.

# limitations under the License.
#

class Api::V2::Upgrade
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/ClassAndModuleChildren: Use nested module/class definitions instead of compact style.

@toabctl
Copy link
Copy Markdown
Contributor

toabctl commented Jul 20, 2016

@MaximilianMeister can you document (at least in the commit msg) why the current api is not enough? or can't be extended?

@MaximilianMeister
Copy link
Copy Markdown
Member Author

can you document (at least in the commit msg) why the current api is not enough? or can't be extended?

it is documented here https://w3.suse.de/~mmeister/screencast/upgrade-api.webm
but I can add it to the commit message as well if needed

@MaximilianMeister MaximilianMeister force-pushed the v2 branch 3 times, most recently from 2427952 to da2234b Compare July 20, 2016 13:16
@@ -0,0 +1,124 @@
#
# Copyright 2015, SUSE LINUX GmbH
Copy link
Copy Markdown
Member

@rsalevsky rsalevsky Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2015-2016

@rsalevsky
Copy link
Copy Markdown
Member

rsalevsky commented Jul 21, 2016

We need to prepare crowbarctl before merging this.

@toabctl
Copy link
Copy Markdown
Contributor

toabctl commented Jul 21, 2016

@MaximilianMeister my quesation was more about the difference between api v1 and v2 and if it's possible to just extend v1. introducing a new api version needs also more work on the client side and we need to support both versions for some time I think.

@rsalevsky
Copy link
Copy Markdown
Member

We had a long discussion before we started to design this API. The problem is that the new angular application needs a well defined restful API to work. An restful API means that we have entities and resources. To do this with the old API we need to change everything and this would also break a lot. Because of this we decided to create a V2 API where we can work on in parallel without breaking everything else and move the stuff step by step to the new API. (Moving means in this case keep the old logic but change the responses.)

@MaximilianMeister
Copy link
Copy Markdown
Member Author

rebased after #556 is merged (i had the same commit in here to test if it works)

Comment thread crowbar_framework/config/routes.rb Outdated

namespace :api,
constraints: { format: :json },
constraints: ApiConstraint.new(version: 2.0) do
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/DuplicatedKey: Duplicated key in hash literal.

@MaximilianMeister MaximilianMeister force-pushed the v2 branch 2 times, most recently from 551d773 to 8620e11 Compare August 2, 2016 11:05
@MaximilianMeister
Copy link
Copy Markdown
Member Author

Your client can support both, and calling Accept: application/vnd.crowbar.v3.1+json, application/vnd.crowbar.v2.3+json; q=0.1 it can indicate both supported types, and Content-Type: application/vnd.crowbar.v2.3+json will tell it that this is an old server and iterative approach is necessary

@kirushik

how can I best prevent creating a 500 error on the server when I use an iterative approach? or is it wanted to create an error?

from the client: first I try to request the old route utils/backups, and when that fails with 500 I use api/crowbar/backups.
can I catch this on the server side somehow to prevent logging the 500 errors during thes iterations? like sending a header which indicates the iteration phase, or what would you do here?

@kirushik
Copy link
Copy Markdown

kirushik commented Aug 10, 2016

@MaximilianMeister I'm afraid I don't understand your problem fully.

If your API consumer is newer than your API-providing server, then you should be expecting to get an error — because you're obviously relying in your logic on some features that are not there on server. You can use those errors to indicate to your customers that they need to update the server.

And after that maybe try asking for an older API version as a fallback, if it already supports what you want to do.

If we make our API Constraint a little bit smarter (multiple q-weighted options in the Accept headers of the request), it will allow you to negotiate the API version with server in a single roundtrip, without error detection and re-querying on client side. But that will take additional effort, and I don't know if you can afford that right now.

So the solution "Older clients work with newer servers, but newer clients ask politely to update your server" seems to be good enough for me, for now at least. (Once again, I don't know the full list of crowbar's requirements and constraints.)

it "doesn't upload a backup" do
allow_any_instance_of(Api::Backup).to receive(:save).and_return(false)

post "/api/crowbar/backups/upload", { backup: { payload: { file: File.open(tarball) } } }, headers
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. 104/100

@jsuchome
Copy link
Copy Markdown
Member

jsuchome commented Aug 12, 2016

Gating fails because of missing crowbar/crowbar-openstack#499, I think... retriggered


versions_requested = version_mime.match(request.accept)
!versions_requested.nil? &&
versions_requested[:major].to_i == major &&
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/MultilineOperationIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylemultilineoperationindentation)

this crowbar resource will treat all things related to crowbar

the API from 5 to 6 upgrade was too specific and therefore not
reusable to be extended or updated
we are moving just the json endpoints, the html endpoints that render
the UI are still in place where they were before.
the crowbar namespace applies because it is just a crowbar backup.
this helps to collect all the errors that happen during runtime
this resource would include all general upgrade specific endpoints
this would be the new NodeObject when we finally moved it from chef-server
into a database.
https://trello.com/c/EsVoyO2G/816-5-crowbar-create-node-object-that-is-backed-by-database

for the upgrade from 6 to 7 it would inherit not the whole "old" NodeObject
but instead some minimal information needed for the upgrade process, and
share the rest with the "old" NodeObject
this makes it easier to adapt to breaking api changes that could happen
in the future by enabling to send the specific requested api version
through the header
this shows the client, which version was used for the request.
as it is a before_action, any new method with a higher api version
can override the Content-Type
in rails it needs to be called destroy
for now don't test the responses body yet, this will be part of the
actual implementation. except in the backups, which already is
implemented
@MaximilianMeister MaximilianMeister force-pushed the v2 branch 3 times, most recently from 141b3e2 to ab33521 Compare August 15, 2016 12:19
this is a workaround for a bug in the Rails routing engine that
only happens sometimes and only when unit testing a custom controller.

I think it could have to do with the namespacing of crowbar in our
api/backups_controller.

There is some dynamic route/controller calculation in ActionDispatch's
routing see:
https://github.com/rails/rails/blob/v4.2.5/actionpack/lib/action_dispatch/routing/route_set.rb:62

most of the times the controller is calculated correctly when you read
the params at that point:
$ params
{:controller=>"api/backups", :action=>"upload"}

and only sometimes it looks like:
params
{:controller=>"api/crowbar/backups", :action=>"upload"}

which is creating an ActionDispatch::RoutingError:
  uninitialized constant Api::Crowbar::BackupsController

there is an issue on GitHub which is likely related, and the easiest fix
for now is to just skip the test if the error occurs.

a real fix to test the post route for uploading the backup would likely
require extensive stubbing within:
  ActionDispatch::Routing::RouteSet::Dispatcher
@rsalevsky
Copy link
Copy Markdown
Member

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

8 participants