Bug 681708 - Add ability to remotely upload bundle distribution file to create bundle through CLI
Summary: Add ability to remotely upload bundle distribution file to create bundle thro...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: CLI
Version: 3.0.0
Hardware: All
OS: All
high
medium
Target Milestone: ---
: ---
Assignee: John Mazzitelli
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks: rhq42
TreeView+ depends on / blocked
 
Reported: 2011-03-02 23:10 UTC by Marc Shirley
Modified: 2018-11-14 14:17 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-08-31 10:47:31 UTC
Embargoed:


Attachments (Terms of Use)
sample bundle used in verification (472 bytes, application/zip)
2011-09-30 18:59 UTC, Mike Foley
no flags Details

Description Marc Shirley 2011-03-02 23:10:35 UTC
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 21:48:42 UTC
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 21:50:29 UTC
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 15:32:02 UTC
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 18:06:07 UTC
Added BZ https://bugzilla.redhat.com/show_bug.cgi?id=741993  while attempting to verify this BZ.

Comment 9 Mike Foley 2011-09-30 18:53:35 UTC
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 18:57:17 UTC
disregard above comment.  i got it now.  if i leave the argument out ... everything works.

Comment 11 Mike Foley 2011-09-30 18:58:18 UTC
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")
bc.addFilterName(bundleName);
print("Bundle filter created\n")
var bundles = BundleManager.findBundlesByCriteria(bc);

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

// 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 18:58:48 UTC
uploading the sample Bundle I used in verification

Comment 13 Mike Foley 2011-09-30 18:59:21 UTC
Created attachment 525810 [details]
sample bundle used in verification

Comment 14 Mike Foley 2011-09-30 19:00:07 UTC
verified, as documented above

Comment 15 Mike Foley 2011-09-30 19:08:37 UTC
added BZ https://bugzilla.redhat.com/show_bug.cgi?id=742617  on a negative test with empty byte array.


Note You need to log in before you can comment on or make changes to this bug.