Search in sources :

Example 1 with PluginNotExistException

use of com.alibaba.alink.common.exceptions.PluginNotExistException in project Alink by alibaba.

the class ResourcePluginFactory method getResourcePluginPath.

public static FilePath getResourcePluginPath(RegisterKey registerKey, RegisterKey... candidates) throws IOException {
    PluginDownloader pluginDownloader = new PluginDownloader();
    if (pluginDownloader.checkPluginExistRoughly(registerKey.getName(), registerKey.getVersion())) {
        return new FilePath(pluginDownloader.localResourcePluginPath(registerKey.getName(), registerKey.getVersion()), new LocalFileSystem());
    }
    for (RegisterKey candidate : candidates) {
        if (pluginDownloader.checkPluginExistRoughly(candidate.getName(), candidate.getVersion())) {
            return new FilePath(pluginDownloader.localResourcePluginPath(candidate.getName(), candidate.getVersion()), new LocalFileSystem());
        }
    }
    DistributeCache distributeCache = PluginDistributeCache.createDistributeCache(registerKey.getName(), registerKey.getVersion());
    distributeCache.distributeAsLocalFile();
    ResourcesPluginManager manager = PluginUtils.createResourcesPluginManagerFromRootFolder(PluginUtils.readPluginConf(distributeCache.context()));
    Iterator<ResourcesPluginDescriptor> iterator = manager.iterator(registerKey.getName(), registerKey.getVersion());
    if (iterator.hasNext()) {
        return iterator.next().getRootFolder();
    } else {
        throw new PluginNotExistException(String.format("Could not find the appropriate resource plugin. name: %s, version: %s", registerKey.getName(), registerKey.getVersion()));
    }
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) LocalFileSystem(com.alibaba.alink.common.io.filesystem.LocalFileSystem) PluginNotExistException(com.alibaba.alink.common.exceptions.PluginNotExistException)

Aggregations

PluginNotExistException (com.alibaba.alink.common.exceptions.PluginNotExistException)1 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)1 LocalFileSystem (com.alibaba.alink.common.io.filesystem.LocalFileSystem)1