You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2016/07/07 11:36:23 UTC

[GitHub] brooklyn-server pull request #237: Misc osgi [Work In Progress]

GitHub user aledsage opened a pull request:

    https://github.com/apache/brooklyn-server/pull/237

    Misc osgi [Work In Progress]

    For review only at this point.
    
    Please first merge https://github.com/apache/brooklyn-server/pull/236, then I'll rebase this.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/aledsage/brooklyn-server misc-osgi-aledsage

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/237.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #237
    
----
commit aaec0747245c509f795a3669063152b85217c382
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date:   2016-07-06T14:37:19Z

    Persistence hacks

commit 7fc10330239e0226c47ddcbb9432a371b22d6707
Author: Aled Sage <al...@gmail.com>
Date:   2016-07-06T23:07:25Z

    $brooklyn:object: handle osgi classes
    
    If can\u2019t load immediately, then defer until we know the entity thus
    the catalog (and libraries).

commit f35f835a09c5c65b3a71f826d23d534a74ad4938
Author: Aled Sage <al...@gmail.com>
Date:   2016-07-06T23:12:30Z

    OSGi classloading for persistence
    
    * classnames are written out with the OSGi bundle\u2019s symbolic name
      as a prefix in persisted state (unless from a white-listed brooklyn
      bundle)
    * stream custom classloading to handle the bundle-name prefix
    * adds SimpleObject to osgi jar (and adds config keys to entity)
    * adds tests for rebind with OSGi

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #237: Misc osgi classloading

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/237


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #237: Misc osgi [Work In Progress]

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/237#discussion_r69899091
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java ---
    @@ -0,0 +1,398 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.camp.brooklyn;
    +
    +import static org.testng.Assert.assertEquals;
    +import static org.testng.Assert.assertFalse;
    +import static org.testng.Assert.assertNotNull;
    +import static org.testng.Assert.assertNull;
    +
    +import java.io.File;
    +import java.util.List;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.api.policy.Policy;
    +import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
    +import org.apache.brooklyn.core.config.ConfigKeys;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.StartableApplication;
    +import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
    +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
    +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
    +import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
    +import org.apache.brooklyn.core.sensor.Sensors;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.apache.brooklyn.util.core.osgi.Osgis;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +import org.apache.brooklyn.util.guava.Maybe;
    +import org.apache.brooklyn.util.javalang.Reflections;
    +import org.apache.brooklyn.util.osgi.OsgiTestResources;
    +import org.jclouds.compute.domain.OsFamily;
    +import org.osgi.framework.Bundle;
    +import org.osgi.framework.launch.Framework;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.DataProvider;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.base.Joiner;
    +import com.google.common.base.Predicates;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.Iterables;
    +import com.google.common.collect.Lists;
    +
    +public class RebindOsgiTest extends AbstractYamlRebindTest {
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(RebindOsgiTest.class);
    +
    +    private static final String OSGI_BUNDLE_URL = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
    +    private static final String OSGI_BUNDLE_SYMBOLIC_NAME = "org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities";
    +    private static final String OSGI_ENTITY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
    +    private static final String OSGI_POLICY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_POLICY;
    +    private static final String OSGI_OBJECT_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_OBJECT;
    +    private static final String OSGI_ENTITY_CONFIG_NAME = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY_CONFIG_NAME;
    +    private static final String OSGI_ENTITY_SENSOR_NAME = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY_SENSOR_NAME;
    +
    +    private List<String> bundleUrlsToInstallOnRebind;
    +    
    +    @BeforeMethod(alwaysRun = true)
    +    @Override
    +    public void setUp() throws Exception {
    +        bundleUrlsToInstallOnRebind = Lists.newArrayList();
    +        super.setUp();
    +    }
    +
    +    @Override
    +    protected boolean useOsgi() {
    +        return true;
    +    }
    +    
    +    @Override
    +    protected LocalManagementContext createNewManagementContext(File mementoDir) {
    +        LocalManagementContext result = super.createNewManagementContext(mementoDir);
    +        for (String bundleUrl : bundleUrlsToInstallOnRebind) {
    +            try {
    +                installBundle(result, bundleUrl);
    +            } catch (Exception e) {
    +                throw Exceptions.propagate(e);
    +            }
    +        }
    +        return result;
    +    }
    +    
    +    @DataProvider(name = "valInEntityDataProvider")
    +    public Object[][] valInEntityDataProvider() {
    +        return new Object[][] {
    +            {Predicates.alwaysTrue(), false},
    +            {Predicates.alwaysTrue(), true},
    +            {OsFamily.CENTOS, false},
    +            {OsFamily.CENTOS, true},
    +        };
    +    }
    + 
    +    @Test(dataProvider = "valInEntityDataProvider")
    +    public void testValInEntity(Object val, boolean useOsgi) throws Exception {
    +        String appSymbolicName = "my.catalog.app.id.load";
    +        String appVersion = "0.1.0";
    +        String appCatalogFormat;
    +        if (useOsgi) {
    --- End diff --
    
    Throw if `OSGI_BUNDLE_URL` missing.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #237: Misc osgi [Work In Progress]

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/237#discussion_r69901713
  
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java ---
    @@ -67,21 +71,33 @@ public ClassLoaderUtils(Object callingObj, @Nullable ManagementContext mgmt) {
         }
     
         public ClassLoaderUtils(Class<?> callingClass) {
    -        this.callingClass = callingClass;
    +        this.classLoader = checkNotNull(callingClass, "callingClass").getClassLoader();
    +        this.entity = null;
    +        this.mgmt = null;
    +    }
    +
    +    public ClassLoaderUtils(ClassLoader cl) {
    +        this.classLoader = checkNotNull(cl, "classLoader");
             this.entity = null;
             this.mgmt = null;
         }
     
    +    public ClassLoaderUtils(ClassLoader cl, @Nullable ManagementContext mgmt) {
    +        this.classLoader = checkNotNull(cl, "classLoader");
    +        this.entity = null;
    +        this.mgmt = checkNotNull(mgmt, "mgmt");
    +    }
    +
         public ClassLoaderUtils(Class<?> callingClass, Entity entity) {
    -        this.callingClass = callingClass;
    -        this.entity = entity;
    +        this.classLoader = checkNotNull(callingClass, "callingClass").getClassLoader();
    +        this.entity = checkNotNull(entity, "entity");
             this.mgmt = ((EntityInternal)entity).getManagementContext();
         }
     
         public ClassLoaderUtils(Class<?> callingClass, @Nullable ManagementContext mgmt) {
    -        this.callingClass = callingClass;
    +        this.classLoader = checkNotNull(callingClass, "callingClass").getClassLoader();
    --- End diff --
    
    `getClassLoader` returns `null` for classes on the bootstrap class path.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #237: Misc osgi [Work In Progress]

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/237#discussion_r69907640
  
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java ---
    @@ -129,9 +185,16 @@ public ClassLoaderUtils(Class<?> callingClass, @Nullable ManagementContext mgmt)
                 }
             }
     
    +        Class<?> cls = tryLoadFromBundleWhiteList(name);
    --- End diff --
    
    Should be `className`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---