Search in sources :

Example 6 with Plugin

use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.

the class GlobalEventHandlerTest method testEvent.

@Test
public void testEvent() {
    Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
    Plugin plugin = new PluginModel().setPluginName("test-plugin").setVersion("1.0.0");
    eventAdminService.sendEvent(new AfterBizStartupEvent(biz));
    Assert.assertTrue(result.size() == 3);
    Assert.assertTrue(result.contains("AbstractArkEvent->AfterBizStartupEvent"));
    eventAdminService.sendEvent(new BeforePluginStartupEvent(plugin));
    Assert.assertTrue(result.size() == 5);
    // test for ArkEvent.class.isAssignableFrom(event.getClass()
    eventAdminService.sendEvent(new ArkEvent() {

        @Override
        public String getTopic() {
            return "ark-event";
        }
    });
    Assert.assertTrue(result.size() == 7);
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BeforePluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent) Biz(com.alipay.sofa.ark.spi.model.Biz) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) BizModel(com.alipay.sofa.ark.container.model.BizModel) ArkEvent(com.alipay.sofa.ark.spi.event.ArkEvent) AbstractArkEvent(com.alipay.sofa.ark.spi.event.AbstractArkEvent) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 7 with Plugin

use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.

the class ClassLoaderServiceTest method testFindExportResources.

@Test
public void testFindExportResources() {
    PluginClassLoader pluginClassLoader = new PluginClassLoader("mockPlugin", new URL[] {});
    String exportResources = "spring-beans.xsd,*.xsd,com/alipay/sofa/*,xml-test.xml";
    Plugin plugin = new PluginModel().setPluginName("mockPlugin").setExportPackages("").setExportClasses("").setPluginClassLoader(pluginClassLoader).setExportResources(exportResources);
    pluginManagerService.registerPlugin(plugin);
    classloaderService.prepareExportClassAndResourceCache();
    Set<String> exportPrefixResourceStems = plugin.getExportPrefixResourceStems();
    Assert.assertTrue(exportPrefixResourceStems.contains("com/alipay/sofa/"));
    Set<String> exportSuffixResourceStems = plugin.getExportSuffixResourceStems();
    Assert.assertTrue(exportSuffixResourceStems.contains(".xsd"));
    Set<String> resources = plugin.getExportResources();
    Assert.assertTrue(resources.contains("xml-test.xml"));
    Assert.assertTrue(resources.contains("spring-beans.xsd"));
    plugin.getExportPrefixResourceStems().clear();
    plugin.getExportSuffixResourceStems().clear();
    plugin.getExportResources().clear();
    pluginManagerService.getPluginsInOrder().remove(plugin);
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 8 with Plugin

use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.

the class PluginDeployServiceImpl method unDeploy.

@Override
public void unDeploy() throws ArkRuntimeException {
    List<Plugin> pluginsInOrder = pluginManagerService.getPluginsInOrder();
    Collections.reverse(pluginsInOrder);
    for (Plugin plugin : pluginsInOrder) {
        try {
            unDeployPlugin(plugin);
        } catch (ArkRuntimeException e) {
            LOGGER.error(String.format("UnDeploy plugin: %s meet error", plugin.getPluginName()), e);
            throw e;
        }
    }
}
Also used : Plugin(com.alipay.sofa.ark.spi.model.Plugin) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 9 with Plugin

use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.

the class BizFactoryServiceTest method testPackageInfo.

@Test
public void testPackageInfo() throws Throwable {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL samplePlugin = cl.getResource("sample-ark-plugin.jar");
    Plugin plugin = pluginFactoryService.createPlugin(new File(samplePlugin.getFile()));
    ClassLoader pluginClassLoader = plugin.getPluginClassLoader();
    pluginManagerService.registerPlugin(plugin);
    Class mdc = pluginClassLoader.loadClass("org.slf4j.MDC");
    Assert.assertTrue(mdc.getClassLoader().equals(pluginClassLoader));
    Assert.assertNotNull(mdc.getPackage().getImplementationVersion());
}
Also used : File(java.io.File) URL(java.net.URL) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 10 with Plugin

use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.

the class ClassLoaderServiceImpl method isResourceInImport.

@Override
public boolean isResourceInImport(String pluginName, String resourceName) {
    Plugin plugin = pluginManagerService.getPluginByName(pluginName);
    AssertUtils.assertNotNull(plugin, "plugin: " + pluginName + " is null");
    for (String importResource : plugin.getImportResources()) {
        if (importResource.equals(resourceName)) {
            return true;
        }
    }
    for (String importResource : plugin.getImportPrefixResourceStems()) {
        if (resourceName.startsWith(importResource)) {
            return true;
        }
    }
    for (String importResource : plugin.getImportSuffixResourceStems()) {
        if (resourceName.endsWith(importResource)) {
            return true;
        }
    }
    return false;
}
Also used : Plugin(com.alipay.sofa.ark.spi.model.Plugin)

Aggregations

Plugin (com.alipay.sofa.ark.spi.model.Plugin)42 Test (org.junit.Test)22 BaseTest (com.alipay.sofa.ark.container.BaseTest)20 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)14 URL (java.net.URL)14 Biz (com.alipay.sofa.ark.spi.model.Biz)10 File (java.io.File)10 JarFile (com.alipay.sofa.ark.loader.jar.JarFile)6 PluginArchive (com.alipay.sofa.ark.spi.archive.PluginArchive)6 HashSet (java.util.HashSet)6 BizModel (com.alipay.sofa.ark.container.model.BizModel)4 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)4 JarPluginArchive (com.alipay.sofa.ark.loader.JarPluginArchive)4 JarFileArchive (com.alipay.sofa.ark.loader.archive.JarFileArchive)4 ExecutableArchive (com.alipay.sofa.ark.spi.archive.ExecutableArchive)4 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)4 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)4 OrderComparator (com.alipay.sofa.ark.common.util.OrderComparator)2 DirectoryBizArchive (com.alipay.sofa.ark.loader.DirectoryBizArchive)2 JarBizArchive (com.alipay.sofa.ark.loader.JarBizArchive)2