Search in sources :

Example 11 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class ExtensionServiceTest method testNoExtensionAnnotation.

@Test
public void testNoExtensionAnnotation() {
    PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
    PluginModel pluginModel = new PluginModel().setPluginClassLoader(this.getClass().getClassLoader()).setPluginName("mock-plugin");
    pluginManagerService.registerPlugin(pluginModel);
    try {
        ArkServiceLoader.loadExtensionFromArkPlugin(ServiceD.class, "", "mock-plugin");
    } catch (ArkRuntimeException ex) {
        Assert.assertTrue(ex.getMessage().contains(String.format("is not annotated by %s.", Extension.class)));
    }
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) Extension(com.alipay.sofa.ark.spi.service.extension.Extension) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ArkContainerTest(com.alipay.sofa.ark.container.ArkContainerTest) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 12 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class ZookeeperConfigActivator method subscribeIpConfig.

protected void subscribeIpConfig() {
    ipNodeCache = new NodeCache(zkClient, ipResourcePath);
    ipNodeCache.getListenable().addListener(new NodeCacheListener() {

        private int version = -1;

        @Override
        public void nodeChanged() throws Exception {
            if (ipNodeCache.getCurrentData() != null && ipNodeCache.getCurrentData().getStat().getVersion() > version) {
                version = ipNodeCache.getCurrentData().getStat().getVersion();
                String configData = new String(ipNodeCache.getCurrentData().getData());
                ipConfigDeque.add(configData);
                LOGGER.info("Receive ip config data: {}, version is {}.", configData, version);
            }
        }
    });
    try {
        LOGGER.info("Subscribe ip config: {}.", ipResourcePath);
        ipNodeCache.start(true);
    } catch (Exception e) {
        throw new ArkRuntimeException("Failed to subscribe ip resource path.", e);
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 13 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class ZookeeperConfigActivator method subscribeBizConfig.

protected void subscribeBizConfig() {
    bizNodeCache = new NodeCache(zkClient, bizResourcePath);
    bizNodeCache.getListenable().addListener(new NodeCacheListener() {

        private int version = -1;

        @Override
        public void nodeChanged() throws Exception {
            if (bizNodeCache.getCurrentData() != null && bizNodeCache.getCurrentData().getStat().getVersion() > version) {
                version = bizNodeCache.getCurrentData().getStat().getVersion();
                String configData = new String(bizNodeCache.getCurrentData().getData());
                bizConfigDeque.add(configData);
                LOGGER.info("Receive app config data: {}, version is {}.", configData, version);
            }
        }
    });
    try {
        bizNodeCache.start(true);
    } catch (Exception e) {
        throw new ArkRuntimeException("Failed to subscribe resource path.", e);
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 14 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class ExtensionServiceTest method testNotExtensibleService.

@Test
public void testNotExtensibleService() {
    PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
    PluginModel pluginModel = new PluginModel().setPluginClassLoader(this.getClass().getClassLoader()).setPluginName("mock-plugin");
    pluginManagerService.registerPlugin(pluginModel);
    try {
        ArkServiceLoader.loadExtensionFromArkPlugin(ServiceC.class, "", "mock-plugin");
    } catch (ArkRuntimeException ex) {
        Assert.assertTrue(ex.getMessage().contains(String.format("is not annotated by %s.", Extensible.class)));
    }
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) Extensible(com.alipay.sofa.ark.spi.service.extension.Extensible) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ArkContainerTest(com.alipay.sofa.ark.container.ArkContainerTest) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 15 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class NoneDelegateTestClassLoader method createTestBiz.

private Biz createTestBiz(String bizIdentity) {
    String[] bizNameAndVersion = bizIdentity.split(":");
    if (bizNameAndVersion.length != 2) {
        throw new ArkRuntimeException("error bizIdentity format.");
    }
    BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
    Biz testBiz = new BizModel().setBizName(bizNameAndVersion[0]).setBizVersion(bizNameAndVersion[1]).setClassLoader(this).setDenyImportPackages("").setDenyImportClasses("").setDenyImportResources("").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(testBiz);
    return testBiz;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Aggregations

ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)23 Biz (com.alipay.sofa.ark.spi.model.Biz)6 URL (java.net.URL)4 ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)3 BaseTest (com.alipay.sofa.ark.container.BaseTest)3 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)3 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)3 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)3 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)3 File (java.io.File)3 KeeperException (org.apache.zookeeper.KeeperException)3 Test (org.junit.Test)3 BizModel (com.alipay.sofa.ark.container.model.BizModel)2 Plugin (com.alipay.sofa.ark.spi.model.Plugin)2 Extensible (com.alipay.sofa.ark.spi.service.extension.Extensible)2 Extension (com.alipay.sofa.ark.spi.service.extension.Extension)2 HashSet (java.util.HashSet)2 NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)2 NodeCacheListener (org.apache.curator.framework.recipes.cache.NodeCacheListener)2 ClassPathArchive (com.alipay.sofa.ark.bootstrap.ClasspathLauncher.ClassPathArchive)1