Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Add default manifest and API controller for loading it #8

Merged
merged 6 commits into from
Aug 8, 2019

Conversation

mturley
Copy link
Collaborator

@mturley mturley commented Aug 6, 2019

This PR adds a copy of the v1.0.0 manifest at config/default-manifest.json, and adds a new API endpoint at /api/migration_analytics_manifest for fetching it in the UI.

The API call will:

  • Check to see if there is a user-provided manifest at /tmp/migration-analytics-manifest.json on the appliance, and use that manifest if it is present and contains valid JSON.
  • If no valid tmp_manifest is present, it will instead use the default manifest stored in the gem.
  • Return an object with the following properties:
    • tmp_manifest_present (boolean) - whether or not there is a file at /tmp/migration-analytics-manifest.json
    • tmp_manifest_valid (boolean) - whether or not there is a valid JSON file at /tmp/migration-analytics-manifest.json
    • path (string) - the path to the manifest JSON file being used
    • body (object) - the parsed contents of the manifest JSON

We can use this to load a manifest into the UI, and:

  • Display the current version of that manifest
  • Indicate whether the user's manually provided manifest is being used or is invalid
  • Pass it to the data collector API (still to be developed).

@mturley
Copy link
Collaborator Author

mturley commented Aug 6, 2019

@Fryguy now that I'm adding some real Ruby code to this repo, we'll need to set up Ruby unit testing stuff and fix the setup/update scripts (#2), which I could use some help with.

Also, based on some discussions with @agrare, I'm not sure exactly how we should move forward with the API for running the data collector and downloading the file. We'll need to:

  • Add an API endpoint that takes the manifest and selected providers, and calls Cfme::CloudServices::InventorySync::bundle_queue
  • Add some way of exposing the output .tar.gz file from that task as a URL the user's browser can download from (this is tricky, I have no idea where to start... @agrare suggested we could specify a server_guid when calling bundle_queue to make sure the file ends up on the same server as the API, and then make sure we're specifying a destination path that is within the apache root, and using that context to produce a URL?)
  • Add some API request the user can make to determine that payload download URL based on the task object
  • Add some mechanism for cleaning up the old .tar.gz files, maybe as a scheduled task? I also have no idea where to start here.

Are you guys (@Fryguy @agrare) still planning to develop all of the above, or do we need to get some help from @djberg96 and others? I know they are busy with Warm Migration for IMS, and I know you guys are busy too. But I'm a little worried that by offering to help take a stab at some of this stuff I gave the impression that I had it all covered, and if we do really need to get this done for the code freeze on Monday, I don't think I'll be able to build it on time myself considering I'm a JS guy learning Ruby/Rails as I go.

Thanks for all the help so far.

cc @bthurber

def index
tmp_manifest_path = '/tmp/migration-analytics-manifest.json'
tmp_manifest = File.file?(tmp_manifest_path) ? parse_json_if_valid(File.read(tmp_manifest_path)) : nil
tmp_manifest_valid = tmp_manifest != nil && tmp_manifest != :invalid
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we take this one step at a time and just return the builtin manifest for now, then expand to handle user uploaded also

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can break this into two PRs if you want. But I know Miguel was asking for us to make sure there is always a way for the user to manually upgrade the included manifest, in case we ship this feature and then release some change to the cloud.redhat.com part of Migration Analytics that depends on a newer manifest that hasn't been released built-in yet.

Maybe he'll have an opinion here.. cc @mperezco

Copy link
Member

Choose a reason for hiding this comment

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

I don't like having it in /tmp because some systems clear that on reboot and on a schedule as a cron task, but I don't want to hold this PR up while we discuss where the user could upload it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

manifest = tmp_manifest
else
manifest_path = File.join(
Bundler.environment.specs['cfme-migration_analytics'].first.full_gem_path,
Copy link
Member

Choose a reason for hiding this comment

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

Think you can just do Cfme::MigrationAnalytics::Engine.root.join("config", "default-manifest.json")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that is better, thanks.

Also, I notice that examples from you and @Fryguy all use double-quotes and I've been using single-quotes in all my Ruby so far, just because that's what we did in v2v. Do you guys have an opinion on which should be used? I can switch them all over to double-quotes.

Copy link
Member

Choose a reason for hiding this comment

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

That's mostly a personal preference, in ruby you can't do string interpolation in a string with single quotes which some people think is a good thing (i.e. it indicates the string is a constant).

Personally I think it looks sloppy having a mixture of '' and "". You have to use "" if you do any string interpolation, so I tend to just use "" everywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good. I agree it's sloppy to have both. Changed them all to "".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I pushed this commit too late to be merged in this PR, so I added it to #10.

@agrare
Copy link
Member

agrare commented Aug 7, 2019

@abellotti can you help review this from the API side?

@agrare
Copy link
Member

agrare commented Aug 7, 2019

@mturley I tested with my local changes and I had to re-enable vmdb_plugin? in the engine here to get the manageiq-api to mount this plugin's API, after that it worked great


res = {
:tmp_manifest_present => tmp_manifest != nil,
:tmp_manifest_valid => tmp_manifest_valid,
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is part of an API response, are these the right key names we want ? tmp_... what if it's in a different location ? I would expect just "manifest_present" and "manifest_valid".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My goal here was to have the UI be able to tell if the manifest being returned is the one built-in on the appliance (the default-manifest.json file being added here) or a file they included in the /tmp/ directory, and whether the latter is being ignored because it's invalid JSON. Maybe it should be "override_manifest_present" and "override_manifest_valid" instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this feature for now per @agrare 's request.

config/api.yml Outdated Show resolved Hide resolved
render_resource :migration_analytics_manifest, res
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

we need specs added for the API. so spec/requests/migration_analytics_manifest_spec.rb, maybe look at https://github.com/RedHatCloudForms/cfme-cloud_services/pull/23/files for spec/ files for the api file plus the spec_helper.rb and support/api_request_helpers.rb.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I'll take a look and try to get these started. I got stuck trying to get the Travis config's Ruby checks to work in this repo though, I may need some help figuring that out (the bin/setup script fails, probably because it was depending on something from https://github.com/martinpovolny/miq_plugin_example that I removed). I have an issue to track that: #2

@mturley
Copy link
Collaborator Author

mturley commented Aug 7, 2019

@agrare we have vmdb_plugin? disabled here just because @bthurber asked for the UI to be hidden in current builds. Do you think I should re-enable it in this PR? It would certainly make it easier to test these changes on appliance builds, but it would mean the UI can be reached if you know the URL (I think?). That's probably fine, I assume, but I'll check with others.

@miq-bot
Copy link

miq-bot commented Aug 7, 2019

Some comments on commits mturley/cfme-migration_analytics@7e2d7e7~...1c9d3e2

app/controllers/api/migration_analytics_manifest_controller.rb

  • 💣 💥 🔥 🚒 - 13 - Detected cfme

@miq-bot
Copy link

miq-bot commented Aug 7, 2019

Checked commits mturley/cfme-migration_analytics@7e2d7e7~...1c9d3e2 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 2 offenses detected

**

  • 💣 💥 🔥 🚒 - Linter/Rubocop - missing config files
  • 💣 💥 🔥 🚒 - Linter/Yaml - missing config files

@bthurber
Copy link

bthurber commented Aug 7, 2019

@agrare we have vmdb_plugin? disabled here just because @bthurber asked for the UI to be hidden in current builds. Do you think I should re-enable it in this PR? It would certainly make it easier to test these changes on appliance builds, but it would mean the UI can be reached if you know the URL (I think?). That's probably fine, I assume, but I'll check with others.

The only requirement we have is that MA isn't visible as an option under Migration in the UI with the ability to add it back to the menu if needed. Similar to what we did for IMS 1.0 beta.

@agrare
Copy link
Member

agrare commented Aug 8, 2019

@agrare we have vmdb_plugin? disabled here just because @bthurber asked for the UI to be hidden in current builds. Do you think I should re-enable it in this PR? It would certainly make it easier to test these changes on appliance builds, but it would mean the UI can be reached if you know the URL (I think?). That's probably fine, I assume, but I'll check with others.

The only requirement we have is that MA isn't visible as an option under Migration in the UI with the ability to add it back to the menu if needed. Similar to what we did for IMS 1.0 beta.

Okay thanks @bthurber, I'm fine leaving vmdb_plugin? false for now but we'll need to turn it on for the API to work. Without the UI the API isn't really helpful though anyway so its really just an issue for testing/development.

@agrare agrare self-assigned this Aug 8, 2019
Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

This is a good starting point, thanks @mturley !

@agrare agrare merged commit 9ed71c3 into RedHatCloudForms:master Aug 8, 2019
agrare added a commit that referenced this pull request Aug 8, 2019
Add default manifest and API controller for loading it
simaishi pushed a commit that referenced this pull request Aug 8, 2019
Add default manifest and API controller for loading it

(cherry picked from commit 3847740)
@simaishi
Copy link

simaishi commented Aug 8, 2019

Ivanchuk backport details:

$ git log -1
commit 3b1e74f9e81a9812ce0358618b66be8bbcfe1194
Author: Adam Grare <[email protected]>
Date:   Thu Aug 8 11:57:10 2019 -0400

    Merge pull request #8 from mturley/manifest-api-endpoint
    
    Add default manifest and API controller for loading it
    
    (cherry picked from commit 3847740a36fa5bb0a4fcad174160d1419165cb7c)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants