Search in sources :

Example 16 with ArkRuntimeException

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

the class TestClassLoader 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)

Example 17 with ArkRuntimeException

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

the class DefaultBizDeployer method unDeploy.

@Override
public void unDeploy() {
    for (Biz biz : bizManagerService.getBizInOrder()) {
        try {
            LOGGER.info(String.format("Begin to stop biz: %s", biz.getBizName()));
            biz.stop();
            LOGGER.info(String.format("Finish to stop biz: %s", biz.getBizName()));
        } catch (Throwable e) {
            LOGGER.error(String.format("stop biz: %s meet error", biz.getBizName()), e);
            throw new ArkRuntimeException(e);
        }
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 18 with ArkRuntimeException

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

the class DefaultBizDeployer method deploy.

@Override
public void deploy() {
    for (Biz biz : bizManagerService.getBizInOrder()) {
        try {
            LOGGER.info(String.format("Begin to start biz: %s", biz.getBizName()));
            biz.start(arguments);
            LOGGER.info(String.format("Finish to start biz: %s", biz.getBizName()));
        } catch (Throwable e) {
            LOGGER.error(String.format("Start biz: %s meet error", biz.getBizName()), e);
            throw new ArkRuntimeException(e);
        }
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 19 with ArkRuntimeException

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

the class ExtensionLoaderServiceImpl method loadExtension.

private <I, L> Set<ExtensionClass<I, L>> loadExtension(Class<I> interfaceType, String extensionName, L location, ClassLoader resourceLoader) throws Throwable {
    BufferedReader reader = null;
    try {
        Set<ExtensionClass<I, L>> extensionClassSet = new HashSet<>();
        Extensible extensible = interfaceType.getAnnotation(Extensible.class);
        if (extensible == null) {
            throw new ArkRuntimeException(String.format("Extensible class %s is not annotated by %s.", interfaceType, Extensible.class));
        }
        String fileName = interfaceType.getCanonicalName();
        if (!StringUtils.isEmpty(extensible.file())) {
            fileName = extensible.file();
        }
        Enumeration<URL> enumeration = resourceLoader.getResources(EXTENSION_FILE_DIR + fileName);
        while (enumeration.hasMoreElements()) {
            URL url = enumeration.nextElement();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Loading extension of extensible: {} from location: {} and file: {}", interfaceType, location, url);
            }
            reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                ExtensionClass<I, L> extensionClass = new ExtensionClass<>();
                extensionClass.setDefinedLocation(location);
                extensionClass.setExtensible(extensible);
                extensionClass.setInterfaceClass(interfaceType);
                Class<?> implementClass = null;
                String clazzName = line.trim();
                try {
                    implementClass = resourceLoader.loadClass(clazzName);
                } catch (Exception e) {
                    if (ArkConfigs.isEmbedEnable() && resourceLoader != ArkClient.getMasterBiz().getBizClassLoader()) {
                        implementClass = ArkClient.getMasterBiz().getBizClassLoader().loadClass(clazzName);
                    } else {
                        throw e;
                    }
                }
                if (!interfaceType.isAssignableFrom(implementClass)) {
                    throw new ArkRuntimeException(String.format("Extension implementation class %s is not type of %s.", implementClass.getCanonicalName(), interfaceType.getCanonicalName()));
                }
                Extension extension = implementClass.getAnnotation(Extension.class);
                if (extension == null) {
                    throw new ArkRuntimeException(String.format("Extension implementation class %s is not annotated by %s.", implementClass, Extension.class));
                }
                if (!extensionName.equals(extension.value())) {
                    continue;
                }
                extensionClass.setExtension(extension);
                extensionClass.setImplementClass((Class<I>) implementClass);
                extensionClassSet.add(extensionClass);
            }
        }
        return extensionClassSet;
    } catch (Throwable throwable) {
        LOGGER.error("Loading extension files from {} occurs an error {}.", location, throwable);
        throw throwable;
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
Also used : Extensible(com.alipay.sofa.ark.spi.service.extension.Extensible) InputStreamReader(java.io.InputStreamReader) ExtensionClass(com.alipay.sofa.ark.spi.service.extension.ExtensionClass) URL(java.net.URL) URL(java.net.URL) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) Extension(com.alipay.sofa.ark.spi.service.extension.Extension) BufferedReader(java.io.BufferedReader) HashSet(java.util.HashSet)

Example 20 with ArkRuntimeException

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

the class ArkContainer method main.

public static Object main(String[] args) throws ArkRuntimeException {
    if (args.length < MINIMUM_ARGS_SIZE) {
        throw new ArkRuntimeException("Please provide suitable arguments to continue !");
    }
    try {
        LaunchCommand launchCommand = LaunchCommand.parse(args);
        if (launchCommand.isExecutedByCommandLine()) {
            ExecutableArkBizJar executableArchive;
            File rootFile = new File(URLDecoder.decode(launchCommand.getExecutableArkBizJar().getFile()));
            if (rootFile.isDirectory()) {
                executableArchive = new ExecutableArkBizJar(new ExplodedArchive(rootFile));
            } else {
                executableArchive = new ExecutableArkBizJar(new JarFileArchive(rootFile, launchCommand.getExecutableArkBizJar()));
            }
            return new ArkContainer(executableArchive, launchCommand).start();
        } else {
            ClassPathArchive classPathArchive;
            if (ArkConfigs.isEmbedEnable()) {
                classPathArchive = new EmbedClassPathArchive(launchCommand.getEntryClassName(), launchCommand.getEntryMethodName(), launchCommand.getClasspath());
            } else {
                classPathArchive = new ClassPathArchive(launchCommand.getEntryClassName(), launchCommand.getEntryMethodName(), launchCommand.getClasspath());
            }
            return new ArkContainer(classPathArchive, launchCommand).start();
        }
    } catch (IOException e) {
        throw new ArkRuntimeException(String.format("SOFAArk startup failed, commandline=%s", LaunchCommand.toString(args)), e);
    }
}
Also used : ExplodedArchive(com.alipay.sofa.ark.loader.archive.ExplodedArchive) LaunchCommand(com.alipay.sofa.ark.spi.argument.LaunchCommand) EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive) ExecutableArkBizJar(com.alipay.sofa.ark.loader.ExecutableArkBizJar) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) IOException(java.io.IOException) File(java.io.File) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ClassPathArchive(com.alipay.sofa.ark.bootstrap.ClasspathLauncher.ClassPathArchive) EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive)

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