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
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.
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.
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.
Added BZ https://bugzilla.redhat.com/show_bug.cgi?id=741993 while attempting to verify this BZ.
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.
disregard above comment. i got it now. if i leave the argument out ... everything works.
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
uploading the sample Bundle I used in verification
Created attachment 525810 [details] sample bundle used in verification
verified, as documented above
added BZ https://bugzilla.redhat.com/show_bug.cgi?id=742617 on a negative test with empty byte array.