Search in sources :

Example 21 with Plugin

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

the class ExtensionLoaderServiceImpl method getExtensionContributorFromArkPlugin.

@Override
public <T> T getExtensionContributorFromArkPlugin(Class<T> interfaceType, String extensionName, String pluginName) {
    AssertUtils.assertNotNull(interfaceType, "interfaceType can't be null.");
    AssertUtils.assertNotNull(extensionName, "extensionName can't be null.");
    AssertUtils.assertNotNull(pluginName, "pluginName can't be null.");
    Plugin plugin = pluginManagerService.getPluginByName(pluginName);
    AssertUtils.assertNotNull(plugin, "plugin: " + pluginName + " is null");
    return getExtensionContributor(interfaceType, extensionName, plugin, plugin.getPluginClassLoader());
}
Also used : Plugin(com.alipay.sofa.ark.spi.model.Plugin)

Example 22 with Plugin

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

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

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

the class PluginCommandProviderTest method testPluginCommandProcess.

@Test
public void testPluginCommandProcess(@Mocked final PluginManagerService pluginManagerService) {
    URL[] urls = ((URLClassLoader) this.getClass().getClassLoader()).getURLs();
    final Plugin pluginA = new PluginModel().setPluginName("pluginA").setImportClasses("com.google.common.io.AppendableWriter").setImportPackages(" com.google.common.cache, com.google.common.base ").setImportResources(" import_resource1").setExportPackages("com.alipay.sofa.*").setExportResources(" export_resource1, export_resource2").setPluginActivator("com.alipay.sofa.pluginA.Activator").setClassPath(urls).setGroupId("com.alipay.sofa").setArtifactId("ark-mock-pluginA").setVersion("1.0.0");
    final Plugin pluginB = new PluginModel().setPluginName("pluginB").setImportClasses("com.google.common.io.AppendableWriter").setImportPackages(" com.google.common.cache, com.google.common.base ").setImportResources(" import_resource1").setExportPackages("com.alipay.sofa.*").setExportResources(" export_resource1, export_resource2").setPluginActivator("com.alipay.sofa.pluginA.Activator").setClassPath(urls).setGroupId("com.alipay.sofa").setArtifactId("ark-mock-pluginB").setVersion("1.0.0");
    final Set<String> set = new HashSet<>();
    set.add("pluginA");
    set.add("pluginB");
    new Expectations() {

        {
            pluginManagerService.getAllPluginNames();
            result = set;
            minTimes = 0;
            pluginManagerService.getPluginByName("pluginA");
            result = pluginA;
            minTimes = 0;
            pluginManagerService.getPluginByName("pluginB");
            result = pluginB;
            minTimes = 0;
        }
    };
    PluginCommandProvider pluginCommandProvider = new PluginCommandProvider();
    try {
        Field field = PluginCommandProvider.class.getDeclaredField("pluginManagerService");
        field.setAccessible(true);
        field.set(pluginCommandProvider, pluginManagerService);
    } catch (Throwable throwable) {
    // ignore
    }
    String errorMessage = "Error command format. Pls type 'plugin -h' to get help message\n";
    Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plu")));
    Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plugin -h pluginA")));
    Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plugin -b pluginA")));
    Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plu")));
    Assert.assertTrue(pluginCommandProvider.getHelp().equals(pluginCommandProvider.handleCommand("plugin -h")));
    Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plugin ")));
    String details = pluginCommandProvider.handleCommand("plugin -m -d -s pluginA");
    Assert.assertTrue(details.contains("Activator"));
    Assert.assertTrue(details.contains("GroupId"));
    details = pluginCommandProvider.handleCommand("plugin -d pluginB");
    Assert.assertTrue(details.contains("GroupId"));
    Assert.assertFalse(details.contains("Activator"));
    details = pluginCommandProvider.handleCommand("plugin -m plugin.");
    Assert.assertTrue(details.contains("pluginA"));
    Assert.assertTrue(details.contains("pluginB"));
    details = pluginCommandProvider.handleCommand("plugin -m pluginC");
    Assert.assertTrue(details.contains("no matched plugin candidates."));
}
Also used : Expectations(mockit.Expectations) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) Field(java.lang.reflect.Field) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Plugin(com.alipay.sofa.ark.spi.model.Plugin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with Plugin

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

the class PluginFactoryServiceTest method testCreateEmbedPlugin.

@Test
public void testCreateEmbedPlugin() throws IOException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL samplePlugin = cl.getResource("sample-plugin.jar");
    PluginArchive archive = new JarPluginArchive(new JarFileArchive(new File(samplePlugin.getFile())));
    Plugin plugin = pluginFactoryService.createEmbedPlugin(archive, this.getClass().getClassLoader());
    Assert.assertNotNull(plugin);
}
Also used : JarPluginArchive(com.alipay.sofa.ark.loader.JarPluginArchive) PluginArchive(com.alipay.sofa.ark.spi.archive.PluginArchive) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) File(java.io.File) URL(java.net.URL) JarPluginArchive(com.alipay.sofa.ark.loader.JarPluginArchive) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 25 with Plugin

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

the class PluginFactoryServiceTest method test.

@Test
public void test() throws Throwable {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL samplePlugin = cl.getResource("sample-plugin.jar");
    Plugin plugin = pluginFactoryService.createPlugin(new File(samplePlugin.getFile()));
    Assert.assertNotNull(plugin);
}
Also used : JarFile(com.alipay.sofa.ark.loader.jar.JarFile) 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)

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