Search in sources :

Example 16 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class HandleArchiveStage method transformBizArchives.

private Biz transformBizArchives(BizArchive bizArchive) throws Exception {
    BizModel bizModel = new BizModel();
    Attributes manifestMainAttributes = bizArchive.getManifest().getMainAttributes();
    return bizModel.setBizName(manifestMainAttributes.getValue(ARK_BIZ_NAME)).setMainClass(manifestMainAttributes.getValue(MAIN_CLASS_ATTRIBUTE)).setPriority(manifestMainAttributes.getValue(PRIORITY_ATTRIBUTE)).setClassPath(bizArchive.getUrls()).setClassLoader(new BizClassLoader(bizModel.getBizName(), bizModel.getClassPath()));
}
Also used : Attributes(java.util.jar.Attributes) BizModel(com.alipay.sofa.ark.container.model.BizModel) BizClassLoader(com.alipay.sofa.ark.container.service.classloader.BizClassLoader)

Example 17 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel 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 18 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class BizClassLoaderTest method testGetJdkResource.

@Test
public void testGetJdkResource() throws IOException {
    BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
    bizModel.setBizName("biz A").setBizVersion("1.0.0").setClassPath(new URL[] {}).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
    bizManagerService.registerBiz(bizModel);
    ClassLoader cl = bizModel.getBizClassLoader();
    String name = "META-INF/services/javax.script.ScriptEngineFactory";
    URL res1 = cl.getResource(name);
    Assert.assertNotNull(res1);
    URL res2 = ClassLoader.getSystemClassLoader().getResource(name);
    Assert.assertEquals(res2, res1);
    Enumeration<URL> enu1 = cl.getResources(name);
    Assert.assertTrue(enu1.hasMoreElements());
    Enumeration<URL> enu2 = ClassLoader.getSystemClassLoader().getResources(name);
    Assert.assertEquals(Sets.newHashSet(Collections.list(enu2)), Sets.newHashSet(Collections.list(enu1)));
}
Also used : URLClassLoader(java.net.URLClassLoader) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 19 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class BizClassLoaderTest method testAgentClass.

@Test
public void testAgentClass() throws ClassNotFoundException {
    BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
    bizModel.setBizName("biz A").setBizVersion("1.0.0").setClassPath(new URL[] {}).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath())).setDenyImportResources("").setDenyImportClasses("");
    bizManagerService.registerBiz(bizModel);
    Class clazz = bizModel.getBizClassLoader().loadClass("SampleClass");
    Assert.assertFalse(clazz.getClassLoader() instanceof AgentClassLoader);
    Assert.assertTrue(clazz.getClassLoader().getClass().getCanonicalName().contains("Launcher.AppClassLoader"));
}
Also used : BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 20 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class BizClassLoaderTest method testImport.

@Test
public void testImport() throws Exception {
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportClasses("").setExportPackages(ClassUtils.getPackageName(ITest.class.getName())).setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
    pluginManagerService.registerPlugin(pluginA);
    pluginDeployService.deploy();
    classloaderService.prepareExportClassAndResourceCache();
    BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
    bizModel.setBizName("biz A").setBizVersion("1.0.0").setClassPath(new URL[] { classPathURL }).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
    bizModel.setDenyImportResources(StringUtils.EMPTY_STRING);
    bizModel.setDenyImportClasses(StringUtils.EMPTY_STRING);
    bizModel.setDenyImportPackages(StringUtils.EMPTY_STRING);
    bizManagerService.registerBiz(bizModel);
    Assert.assertEquals(pluginA.getPluginClassLoader().loadClass(ITest.class.getName()), bizModel.getBizClassLoader().loadClass(ITest.class.getName()));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ITest(com.alipay.sofa.ark.container.testdata.ITest) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Aggregations

BizModel (com.alipay.sofa.ark.container.model.BizModel)31 Test (org.junit.Test)22 BaseTest (com.alipay.sofa.ark.container.BaseTest)18 Biz (com.alipay.sofa.ark.spi.model.Biz)12 ITest (com.alipay.sofa.ark.container.testdata.ITest)11 URL (java.net.URL)11 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)8 HandleArchiveStage (com.alipay.sofa.ark.container.pipeline.HandleArchiveStage)4 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)3 URLClassLoader (java.net.URLClassLoader)3 HashSet (java.util.HashSet)3 BizClassLoader (com.alipay.sofa.ark.container.service.classloader.BizClassLoader)2 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)2 ExplodedBizArchive (com.alipay.sofa.ark.loader.ExplodedBizArchive)2 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)2 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)2 Plugin (com.alipay.sofa.ark.spi.model.Plugin)2 Attributes (java.util.jar.Attributes)2 ArkClient (com.alipay.sofa.ark.api.ArkClient)1 JarBizArchive (com.alipay.sofa.ark.loader.JarBizArchive)1