Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/746#discussion_r128024759
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
 ---
    @@ -1060,28 +1336,87 @@ private String makeAsIndentedObject(String yaml) {
     
         @Override
         public List<? extends CatalogItem<?,?>> addItems(String yaml) {
    -        return addItems(yaml, null);
    +        return addItems(yaml, false);
         }
         
         @Override
    -    public List<? extends CatalogItem<?, ?>> addItems(String yaml, 
ManagedBundle bundle) {
    -        return addItems(yaml, bundle, false);
    -    }
    -
    -    @Override
         public CatalogItem<?,?> addItem(String yaml, boolean forceUpdate) {
             return Iterables.getOnlyElement(addItems(yaml, forceUpdate));
         }
         
         @Override
         public List<? extends CatalogItem<?,?>> addItems(String yaml, boolean 
forceUpdate) {
    +        Maybe<OsgiManager> osgiManager = 
((ManagementContextInternal)mgmt).getOsgiManager();
    +        if (osgiManager.isPresent() && AUTO_WRAP_CATALOG_YAML_AS_BUNDLE) {
    +            // wrap in a bundle to be managed; need to get bundle and 
version from yaml
    +            Map<?, ?> cm = BasicBrooklynCatalog.getCatalogMetadata(yaml);
    +            VersionedName vn = BasicBrooklynCatalog.getVersionedName( cm, 
false );
    +            if (vn==null) {
    +                // for better legacy compatibiity, if id specified at root 
use that
    +                String id = (String) cm.get("id");
    +                if (Strings.isNonBlank(id)) {
    +                    vn = VersionedName.fromString(id);
    +                }
    +                vn = new VersionedName(vn!=null && 
Strings.isNonBlank(vn.getSymbolicName()) ? vn.getSymbolicName() : 
"brooklyn-catalog-bom-"+Identifiers.makeRandomId(8), 
    +                    vn!=null && vn.getVersionString()!=null ? 
vn.getVersionString() : getFirstAs(cm, String.class, "version").or(NO_VERSION));
    +            }
    +            log.debug("Wrapping supplied BOM as "+vn);
    +            Manifest mf = new Manifest();
    +            mf.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, 
vn.getSymbolicName());
    +            mf.getMainAttributes().putValue(Constants.BUNDLE_VERSION, 
vn.getOsgiVersionString() );
    +            
mf.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), 
OSGI_MANIFEST_VERSION_VALUE);
    +            mf.getMainAttributes().putValue(BROOKLYN_WRAPPED_BOM_BUNDLE, 
Boolean.TRUE.toString());
    +            
    +            BundleMaker bm = new BundleMaker(mgmt);
    +            File bf = bm.createTempBundle(vn.getSymbolicName(), mf, 
MutableMap.of(
    +                new ZipEntry(CATALOG_BOM), (InputStream) new 
ByteArrayInputStream(yaml.getBytes())) );
    +
    +            OsgiBundleInstallationResult result = null;
    +            try {
    +                result = osgiManager.get().install(null, new 
FileInputStream(bf), true, true, forceUpdate).get();
    +            } catch (FileNotFoundException e) {
    +                throw Exceptions.propagate(e);
    +            }
    +            bf.delete();
    --- End diff --
    
    put into a `finally`


---
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.
---

Reply via email to