use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class DefaultPluginContext method getPlugin.
private Plugin getPlugin(String pluginId) {
Plugin plugin = plugins.get(pluginId);
Preconditions.checkArgument(plugin != null, "Plugin with id %s does not exist in program %s of application %s.", pluginId, programId.getProgram(), programId.getApplication());
return plugin;
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class ConfiguratorTask method run.
@Override
public void run(RunnableTaskContext context) throws Exception {
AppDeploymentInfo deploymentInfo = GSON.fromJson(context.getParam(), AppDeploymentInfo.class);
Injector injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getDefaultModule(), new LocalLocationModule(), new ConfiguratorTaskModule(), new AuthenticationContextModules().getMasterWorkerModule());
ConfigResponse result = injector.getInstance(ConfiguratorTaskRunner.class).configure(deploymentInfo);
AppSpecInfo appSpecInfo = result.getAppSpecInfo();
// If configuration succeeded and if only system artifacts are involved, no need to restart the task
if (result.getExitCode() == 0 && appSpecInfo != null && NamespaceId.SYSTEM.equals(deploymentInfo.getArtifactId().getNamespaceId())) {
boolean hasUserPlugins = appSpecInfo.getAppSpec().getPlugins().values().stream().map(Plugin::getArtifactId).map(ArtifactId::getScope).anyMatch(ArtifactScope.USER::equals);
context.setTerminateOnComplete(hasUserPlugins);
}
context.writeResult(GSON.toJson(result).getBytes(StandardCharsets.UTF_8));
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class DefaultPluginConfigurer method addPlugin.
protected Plugin addPlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) throws PluginNotExistsException {
validateExistingPlugin(pluginId);
final Class[] callerClasses = CallerClassSecurityManager.getCallerClasses();
if (callerClasses.length < 3) {
// This shouldn't happen as there should be someone calling this method.
throw new IllegalStateException("Invalid call stack.");
}
Set<ArtifactId> parents = new LinkedHashSet<>();
// 0 is the CallerClassSecurityManager, 1 is this class, hence 2 is the actual caller
for (int i = 2; i < callerClasses.length; i++) {
ClassLoader classloader = callerClasses[i].getClassLoader();
if (classloader instanceof PluginClassLoader) {
// if this is the first time we've seen this plugin artifact, it must be a new plugin parent.
io.cdap.cdap.api.artifact.ArtifactId pluginCallerArtifactId = ((PluginClassLoader) classloader).getArtifactId();
parents.add((pluginCallerArtifactId.getScope() == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : pluginNamespaceId).artifact(pluginCallerArtifactId.getName(), pluginCallerArtifactId.getVersion().getVersion()));
}
}
PluginNotExistsException exception = null;
for (ArtifactId parentId : Iterables.concat(parents, Collections.singleton(artifactId))) {
try {
Map.Entry<ArtifactDescriptor, PluginClass> pluginEntry = pluginFinder.findPlugin(pluginNamespaceId, parentId, pluginType, pluginName, selector);
Plugin plugin = FindPluginHelper.getPlugin(Iterables.transform(parents, ArtifactId::toApiArtifactId), pluginEntry, properties, pluginInstantiator);
plugins.put(pluginId, new PluginWithLocation(plugin, pluginEntry.getKey().getLocation()));
return plugin;
} catch (PluginNotExistsException e) {
// ignore this in case the plugin extends something higher up in the call stack.
// For example, suppose the app uses pluginA, which uses pluginB. However, pluginB is a plugin that
// has the app as its parent and not pluginA as its parent. In this case, we want to keep going up the call
// stack until we get to the app as the parent, which would be able to find plugin B.
exception = e;
}
}
throw exception == null ? new PluginNotExistsException(pluginNamespaceId, pluginType, pluginName) : exception;
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class DefaultServicePluginConfigurer method createClassLoader.
@Override
public ClassLoader createClassLoader() {
Map<String, Plugin> plugins = getPlugins().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().getPlugin()));
ClassLoader pluginsClassLoader = PluginClassLoaders.createFilteredPluginsClassLoader(plugins, getPluginInstantiator());
return new CombineClassLoader(null, programClassLoader, pluginsClassLoader, getClass().getClassLoader());
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class RemotePluginConfigurer method addPlugin.
@Override
protected Plugin addPlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) throws PluginNotExistsException {
validateExistingPlugin(pluginId);
// plugin
if (!localPlugins.containsKey(pluginId)) {
return super.addPlugin(pluginType, pluginName, pluginId, properties, selector);
}
Plugin existingPlugin = localPlugins.get(pluginId);
File existingPluginLocation = new File(localPluginDir, Artifacts.getFileName(existingPlugin.getArtifactId()));
// need to regenerate this plugin to ensure the plugin has updated properties with macro resolved, also
// register it to plugin instantiator
io.cdap.cdap.api.artifact.ArtifactId artifactId = existingPlugin.getArtifactId();
String namespace = artifactId.getScope().equals(ArtifactScope.SYSTEM) ? NamespaceId.SYSTEM.getNamespace() : pluginNamespaceId.getNamespace();
Location pluginLocation = Locations.toLocation(existingPluginLocation);
SortedMap<io.cdap.cdap.api.artifact.ArtifactId, PluginClass> selectedPlugin = new TreeMap<>();
selectedPlugin.put(artifactId, existingPlugin.getPluginClass());
selector.select(selectedPlugin);
Plugin plugin = FindPluginHelper.getPlugin(existingPlugin.getParents(), Maps.immutableEntry(new ArtifactDescriptor(namespace, artifactId, pluginLocation), existingPlugin.getPluginClass()), properties, pluginInstantiator);
plugins.put(pluginId, new PluginWithLocation(plugin, pluginLocation));
return plugin;
}
Aggregations