use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class SparkContainerDriverLauncher method localizeArtifactsFromAppfabric.
private static void localizeArtifactsFromAppfabric(CConfiguration cConf, Configuration hConf) throws Exception {
ArtifactLocalizerClient fetchArtifacts = createArtifactLocalizerClient(cConf, hConf);
ApplicationSpecification spec = GSON.fromJson(hConf.getRaw(CDAP_APP_SPEC_KEY), ApplicationSpecification.class);
ProgramId programId = GSON.fromJson(hConf.getRaw(PROGRAM_ID_KEY), ProgramId.class);
// Create plugin location for storing plugin jars
Path pluginsLocation = new File(WORKING_DIRECTORY).getAbsoluteFile().toPath().resolve(SparkRuntimeContextProvider.ARTIFACTS_DIRECTORY_NAME).toAbsolutePath();
Files.createDirectories(pluginsLocation);
// Fetching plugin artifacts from app-fabric
Set<String> localizedPlugins = new HashSet<>();
for (Plugin plugin : spec.getPlugins().values()) {
String pluginName = String.format("%s-%s-%s.jar", plugin.getArtifactId().getScope().toString(), plugin.getArtifactId().getName(), plugin.getArtifactId().getVersion().toString());
if (localizedPlugins.contains(pluginName)) {
// skip localizing existing artifacts
continue;
}
File tempLocation = fetchArtifacts.localizeArtifact(plugin.getArtifactId(), programId.getNamespace());
BundleJarUtil.unJar(tempLocation, pluginsLocation.resolve(pluginName).toFile());
localizedPlugins.add(pluginName);
}
// Fetching program.jar from app-fabric and expand it
Path programJarLocation = new File(WORKING_DIRECTORY).getAbsoluteFile().toPath();
File tempLocation = fetchArtifacts.localizeArtifact(spec.getArtifactId(), programId.getNamespace());
BundleJarUtil.unJar(tempLocation, programJarLocation.resolve(PROGRAM_JAR_EXPANDED_NAME).toFile());
Files.copy(tempLocation.toPath(), programJarLocation.resolve(PROGRAM_JAR_NAME));
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by caskdata.
the class ApplicationDetail method fromSpec.
public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
List<ProgramRecord> programs = new ArrayList<>();
for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getServices().values()) {
programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getSpark().values()) {
programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkers().values()) {
programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
List<DatasetDetail> datasets = new ArrayList<>();
for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
}
List<PluginDetail> plugins = new ArrayList<>();
for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
}
// this is only required if there are old apps lying around that failed to get upgrading during
// the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
// in the meantime, we don't want this api call to null pointer exception.
ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), datasets, programs, plugins, summary, ownerPrincipal);
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.
the class ArtifactRepositoryTest method testPlugin.
@Test
public void testPlugin() throws Exception {
File pluginDir = TMP_FOLDER.newFolder();
addPluginArtifact();
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = getPlugins();
copyArtifacts(pluginDir, plugins);
// Instantiate the plugins and execute them
try (PluginInstantiator instantiator = new PluginInstantiator(cConf, appClassLoader, pluginDir)) {
for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> entry : plugins.entrySet()) {
for (PluginClass pluginClass : entry.getValue()) {
Plugin pluginInfo = new Plugin(new ArrayList<>(), entry.getKey().getArtifactId(), pluginClass, PluginProperties.builder().add("class.name", TEST_EMPTY_CLASS).add("nullableLongFlag", "10").add("host", "example.com").add("aBoolean", "${aBoolean}").add("aByte", "${aByte}").add("aChar", "${aChar}").add("aDouble", "${aDouble}").add("anInt", "${anInt}").add("aFloat", "${aFloat}").add("aLong", "${aLong}").add("aShort", "${aShort}").build());
Callable<String> plugin = instantiator.newInstance(pluginInfo);
Assert.assertEquals("example.com,false,0,\u0000,0.0,0.0,0,0,0,null", plugin.call());
}
}
}
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.
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;
}
use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.
the class ServiceSpecificationCodec method deserialize.
@Override
public ServiceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = (JsonObject) json;
if (isOldSpec(jsonObj)) {
return decodeOldSpec(jsonObj);
}
String className = jsonObj.get("className").getAsString();
String name = jsonObj.get("name").getAsString();
String description = jsonObj.get("description").getAsString();
Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);
Map<String, HttpServiceHandlerSpecification> handlers = deserializeMap(jsonObj.get("handlers"), context, HttpServiceHandlerSpecification.class);
Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class);
int instances = jsonObj.get("instances").getAsInt();
Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
return new ServiceSpecification(className, name, description, handlers, resources, instances, plugins, properties);
}
Aggregations