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()));
}
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));
}
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)));
}
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"));
}
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()));
}
Aggregations