Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/608#discussion_r107735424
--- Diff:
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
---
@@ -129,6 +176,97 @@ public Response create(String yaml) {
return Response.status(Status.CREATED).entity(result).build();
}
+ @Override
+ @Beta
+ public Response createFromArchive(byte[] zipInput) {
+ if (!Entitlements.isEntitled(mgmt().getEntitlementManager(),
Entitlements.ROOT, null)) {
+ throw WebResourceUtils.forbidden("User '%s' is not authorized
to add catalog item",
+ Entitlements.getEntitlementContext().user());
+ }
+
+ BundleMaker bm = new BundleMaker(mgmt());
+ File f=null, f2=null;
+ try {
+ f = Os.newTempFile("brooklyn-posted-archive", "zip");
+ try {
+ Files.write(zipInput, f);
+ } catch (IOException e) {
+ Exceptions.propagate(e);
+ }
+
+ ZipFile zf;
+ try {
+ zf = new ZipFile(f);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Invalid ZIP/JAR
archive: "+e);
+ }
+ ZipArchiveEntry bom = zf.getEntry("catalog.bom");
+ if (bom==null) {
+ bom = zf.getEntry("/catalog.bom");
+ }
+ if (bom==null) {
+ throw new IllegalArgumentException("Archive must contain a
catalog.bom file in the root");
+ }
+ String bomS;
+ try {
+ bomS = Streams.readFullyString(zf.getInputStream(bom));
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Error reading
catalog.bom from ZIP/JAR archive: "+e);
+ }
+ VersionedName vn = BasicBrooklynCatalog.getVersionedName(
BasicBrooklynCatalog.getCatalogMetadata(bomS) );
+
+ Manifest mf = bm.getManifest(f);
+ if (mf==null) {
+ mf = new Manifest();
+ }
+ String bundleNameInMF =
mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+ if (Strings.isNonBlank(bundleNameInMF)) {
+ if (!bundleNameInMF.equals(vn.getSymbolicName())) {
+ throw new IllegalArgumentException("JAR MANIFEST
symbolic-name '"+bundleNameInMF+"' does not match '"+vn.getSymbolicName()+"'
defined in BOM");
+ }
+ } else {
+
mf.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,
vn.getSymbolicName());
+ }
+
+ String bundleVersionInMF =
mf.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
+ if (Strings.isNonBlank(bundleVersionInMF)) {
+ if (!bundleVersionInMF.equals(vn.getVersion().toString()))
{
+ throw new IllegalArgumentException("JAR MANIFEST
version '"+bundleVersionInMF+"' does not match '"+vn.getVersion()+"' defined in
BOM");
+ }
+ } else {
+ mf.getMainAttributes().putValue(Constants.BUNDLE_VERSION,
vn.getVersion().toString());
+ }
+ if
(mf.getMainAttributes().getValue(Attributes.Name.MANIFEST_VERSION)==null) {
+
mf.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),
"1.0");
+ }
+
+ f2 = bm.copyAddingManifest(f, mf);
+
+ Bundle bundle = bm.installBundle(f2, true);
+
+ if
(!BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_LOAD_BUNDLE_CATALOG_BOM))
{
+ // if the above feature is not enabled, let's do it
manually (as a contract of this method)
+ try {
+ new CatalogBomScanner().new
CatalogBundleLoader(mgmt()).scanForCatalog(bundle);
--- End diff --
This should just be `new
CatalogBundleLoader(mgmt()).scanForCatalog(bundle);` (with it as a standalone
class)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---