Search in sources :

Example 31 with Plugin

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

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 32 with Plugin

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

the class ClassLoaderServiceTest method testIsClassImport.

@Test
public void testIsClassImport() {
    Plugin plugin = new PluginModel().setPluginName("mockPlugin").setImportClasses(null).setImportPackages("a.c,a.b.c.*,a.b.c");
    pluginManagerService.registerPlugin(plugin);
    Assert.assertTrue(classloaderService.isClassInImport("mockPlugin", "a.c.e"));
    Assert.assertFalse(classloaderService.isClassInImport("mockPlugin", "a.c"));
    Assert.assertFalse(classloaderService.isClassInImport("mockPlugin", "a.c.e.f"));
    Assert.assertFalse(classloaderService.isClassInImport("mockPlugin", "a.b.c"));
    Assert.assertTrue(classloaderService.isClassInImport("mockPlugin", "a.b.c.e"));
    Assert.assertTrue(classloaderService.isClassInImport("mockPlugin", "a.b.c.e.f"));
}
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 33 with Plugin

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

the class PluginManagerServiceImpl method getPluginsInOrder.

@Override
public List<Plugin> getPluginsInOrder() {
    List<Plugin> pluginList = new ArrayList<>(plugins.values());
    Collections.sort(pluginList, new OrderComparator());
    return pluginList;
}
Also used : ArrayList(java.util.ArrayList) OrderComparator(com.alipay.sofa.ark.common.util.OrderComparator) Plugin(com.alipay.sofa.ark.spi.model.Plugin)

Example 34 with Plugin

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

the class EventTest 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.get(0).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START));
    eventAdminService.sendEvent(new BeforeBizStartupEvent(biz));
    Assert.assertTrue(result.get(1).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_START));
    eventAdminService.sendEvent(new BeforeBizStopEvent(biz));
    Assert.assertTrue(result.get(2).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_STOP));
    eventAdminService.sendEvent(new AfterBizStopEvent(biz));
    Assert.assertTrue(result.get(3).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP));
    eventAdminService.sendEvent(new BeforeBizSwitchEvent(biz));
    Assert.assertTrue(result.get(4).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_SWITCH));
    eventAdminService.sendEvent(new AfterBizSwitchEvent(biz));
    Assert.assertTrue(result.get(5).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_SWITCH));
    eventAdminService.sendEvent(new AfterPluginStartupEvent(plugin));
    Assert.assertTrue(result.get(6).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_START));
    eventAdminService.sendEvent(new AfterPluginStopEvent(plugin));
    Assert.assertTrue(result.get(7).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_STOP));
    eventAdminService.sendEvent(new BeforePluginStartupEvent(plugin));
    Assert.assertTrue(result.get(8).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_START));
    eventAdminService.sendEvent(new BeforePluginStopEvent(plugin));
    Assert.assertTrue(result.get(9).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_STOP));
    eventAdminService.sendEvent(new AfterFinishDeployEvent());
    Assert.assertTrue(result.get(10).equalsIgnoreCase(Constants.ARK_EVENT_TOPIC_AFTER_FINISH_DEPLOY_STAGE));
    eventAdminService.sendEvent(new AfterFinishStartupEvent());
    Assert.assertTrue(result.get(11).equalsIgnoreCase(Constants.ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE));
    eventAdminService.sendEvent(new TestArkEvent(""));
    Assert.assertTrue(result.get(12).equalsIgnoreCase("test-ark"));
    eventAdminService.sendEvent(new BeforeBizRecycleEvent(biz));
    Assert.assertTrue(result.get(13).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_RECYCLE_BIZ));
}
Also used : BeforePluginStopEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStopEvent) AfterPluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.AfterPluginStartupEvent) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) AfterFinishStartupEvent(com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent) BeforeBizSwitchEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizSwitchEvent) BizModel(com.alipay.sofa.ark.container.model.BizModel) AfterBizStopEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent) BeforeBizRecycleEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent) 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) BeforeBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent) AfterFinishDeployEvent(com.alipay.sofa.ark.spi.event.AfterFinishDeployEvent) AfterBizSwitchEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizSwitchEvent) BeforeBizStopEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent) Plugin(com.alipay.sofa.ark.spi.model.Plugin) AfterPluginStopEvent(com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 35 with Plugin

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

the class HandleArchiveStage method processEmbed.

protected void processEmbed(PipelineContext pipelineContext) throws Exception {
    ClassLoader masterBizClassLoader = pipelineContext.getClass().getClassLoader();
    Biz masterBiz = bizFactoryService.createEmbedMasterBiz(masterBizClassLoader);
    bizManagerService.registerBiz(masterBiz);
    ArkClient.setMasterBiz(masterBiz);
    ArkConfigs.putStringValue(Constants.MASTER_BIZ, masterBiz.getBizName());
    ExecutableArchive executableArchive = pipelineContext.getExecutableArchive();
    List<PluginArchive> pluginArchives = executableArchive.getPluginArchives();
    for (PluginArchive pluginArchive : pluginArchives) {
        Plugin plugin = pluginFactoryService.createEmbedPlugin(pluginArchive, masterBizClassLoader);
        if (!isPluginExcluded(plugin)) {
            pluginManagerService.registerPlugin(plugin);
        } else {
            LOGGER.warn(String.format("The plugin of %s is excluded.", plugin.getPluginName()));
        }
    }
    return;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ExecutableArchive(com.alipay.sofa.ark.spi.archive.ExecutableArchive) PluginArchive(com.alipay.sofa.ark.spi.archive.PluginArchive) 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