Bug 681708

Summary: Add ability to remotely upload bundle distribution file to create bundle through CLI
Product: [Other] RHQ Project Reporter: Marc Shirley <mshirley>
Component: CLIAssignee: John Mazzitelli <mazz>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: medium Docs Contact:
Priority: high    
Version: 3.0.0CC: hrupp, mazz
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: All   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-31 06:47:31 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 734807    
Description Flags
sample bundle used in verification none

Description Marc Shirley 2011-03-02 18:10:35 EST
Description of problem:
There should be a way to remotely upload a bundle distribution file to the JON server to create a new bundle.  The current state does not offer a directly accessible method for a CLI user remote to the JON server to create a bundle from a distribution file.  All methods available require extra steps:

1) createBundleVersionViaFile requires the distribution file to be locally accessible to the JON server so would require use of FTP/network share/etc to achieve this requirement.

2) createBundleVersionViaURL requires the distribution to be available via URL. 

3) createBundleVersionViaRecipe requires disassembly of the distribution file to obtain the recipe and then requires a separate upload for the bundle file with addBundleFileViaByteArray.  

Version-Release number of selected component (if applicable):
JON 2.4.0
Comment 1 John Mazzitelli 2011-09-27 17:48:42 EDT
for a quick and dirty implementation (that supports bundle distro files that aren't too large such that they fit in memory), just duplicate:

org.rhq.enterprise.server.bundle.BundleManagerRemote.createBundleVersionViaFile(Subject, File)

where the File is, instead, a byte[]. This would be exposed to the CLI and the CLI script could just slurp the content in memory and send it over the wire. This should be simple to do, but of course has the limitation of requiring the distro file to be loaded in memory. Probably not a problem for small-to-medium sized bundles. Once you start getting in the hundreds of MBs, then you are going to probably hit issues.
Comment 2 Charles Crouch 2011-09-27 17:50:29 EDT
If you do hit problems you can always increase the Xmx setting used to start the CLI with, that maybe a workaround for some issues.
Comment 4 John Mazzitelli 2011-09-28 11:32:02 EDT
git commit 3787402

new remote API:

public BundleVersion createBundleVersionViaByteArray(Subject subject, byte[] fileBytes) throws Exception

as the javadoc warns, if you have very large files, this requires them to be loaded in memory which could cause OutOfMemoryErrors in either the CLI OR the RHQ Server.
Comment 8 Mike Foley 2011-09-28 14:06:07 EDT
Added BZ https://bugzilla.redhat.com/show_bug.cgi?id=741993  while attempting to verify this BZ.
Comment 9 Mike Foley 2011-09-30 14:53:35 EDT
explicitly requiring Subject in the signature is inconsistent with the rest of the remote API.  no other signatures in the remote API have Subject in the signature.  it is inconsistent.  

For example:  BundleManager.createBundleVersionViaFile(distributionFile);  //does not require Subject ... why should createBundleVersionViaByteArray??

Signature is passed automatically.

Reference Documentation: http://www.rhq-project.org/display/JOPR2/Running+the+RHQ+CLI#RunningtheRHQCLI-Examples

[Subject] Represents the current, logged in user. For security purposes, all remote service invocations require the subject to be passed; however, the CLI will implicitly pass the subject for you. 

The API will be more usable if it is consistent.  Consider removing Subject from the signature.
Comment 10 Mike Foley 2011-09-30 14:57:17 EDT
disregard above comment.  i got it now.  if i leave the argument out ... everything works.
Comment 11 Mike Foley 2011-09-30 14:58:18 EDT
Documenting the CLI script I wrote to verify this:

var bundleName = 'mikesbundle2';
var bundleDistroV1Path = '/home/mfoley/exampleBundles/bundle1.zip';

// delete the test bundle if it exists
var bc = new BundleCriteria();
print("Bundle Criteria Created\n")
print("Bundle filter created\n")
var bundles = BundleManager.findBundlesByCriteria(bc);

if (null != bundles  && bundles.size() > 0 ) {
    print("\nDeleting [" + bundleName + "] to re-run sample scripts...")

// create bundleVersion 1.0 for the sample bundle
var distributionFile = new java.io.File(bundleDistroV1Path);
distributionFile = new java.io.File(distributionFile.getAbsolutePath());
Assert.assertTrue(distributionFile.exists(), "Missing ant bundle distribution file: " + distributionFile);

theBytes = new Array();
theBytes = org.rhq.core.util.stream.StreamUtil.slurp(new java.io.FileInputStream(distributionFile));
var bundleVersion1 = BundleManager.createBundleVersionViaByteArray(theBytes);

print("\nCreated " + bundleVersion1 + "!")

//now verify in the UI the bundle was created
Comment 12 Mike Foley 2011-09-30 14:58:48 EDT
uploading the sample Bundle I used in verification
Comment 13 Mike Foley 2011-09-30 14:59:21 EDT
Created attachment 525810 [details]
sample bundle used in verification
Comment 14 Mike Foley 2011-09-30 15:00:07 EDT
verified, as documented above
Comment 15 Mike Foley 2011-09-30 15:08:37 EDT
added BZ https://bugzilla.redhat.com/show_bug.cgi?id=742617  on a negative test with empty byte array.