use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class ApplicationLifecycleService method getApps.
/**
* Get all applications in the specified namespace that satisfy the specified predicate.
*
* @param namespace the namespace to get apps from
* @param predicate the predicate that must be satisfied in order to be returned
* @return list of all applications in the namespace that satisfy the specified predicate
*/
public List<ApplicationRecord> getApps(final NamespaceId namespace, com.google.common.base.Predicate<ApplicationRecord> predicate) throws Exception {
List<ApplicationRecord> appRecords = new ArrayList<>();
Map<ApplicationId, ApplicationSpecification> appSpecs = new HashMap<>();
for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
appSpecs.put(namespace.app(appSpec.getName(), appSpec.getAppVersion()), appSpec);
}
appSpecs.keySet().retainAll(authorizationEnforcer.isVisible(appSpecs.keySet(), authenticationContext.getPrincipal()));
for (ApplicationId appId : appSpecs.keySet()) {
ApplicationSpecification appSpec = appSpecs.get(appId);
if (appSpec == null) {
continue;
}
// possible if this particular app was deploy prior to v3.2 and upgrade failed for some reason.
ArtifactId artifactId = appSpec.getArtifactId();
ArtifactSummary artifactSummary = artifactId == null ? new ArtifactSummary(appSpec.getName(), null) : ArtifactSummary.from(artifactId);
ApplicationRecord record = new ApplicationRecord(artifactSummary, appId, appSpec.getDescription(), ownerAdmin.getOwnerPrincipal(appId));
if (predicate.apply(record)) {
appRecords.add(record);
}
}
return appRecords;
}
use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class AppFabricTestHelper method deployApplicationWithManager.
public static ApplicationWithPrograms deployApplicationWithManager(Id.Namespace namespace, Class<?> appClass, Supplier<File> folderSupplier, Config config) throws Exception {
ensureNamespaceExists(namespace.toEntityId());
Location deployedJar = createAppJar(appClass, folderSupplier);
ArtifactVersion artifactVersion = new ArtifactVersion(String.format("1.0.%d", System.currentTimeMillis()));
ArtifactId artifactId = new ArtifactId(appClass.getSimpleName(), artifactVersion, ArtifactScope.USER);
ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
ArtifactRepository artifactRepository = getInjector().getInstance(ArtifactRepository.class);
artifactRepository.addArtifact(Id.Artifact.fromEntityId(Artifacts.toArtifactId(namespace.toEntityId(), artifactId)), new File(deployedJar.toURI()));
AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, namespace.toEntityId(), appClass.getName(), null, null, config == null ? null : new Gson().toJson(config));
return getLocalManager().deploy(info).get();
}
use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.
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<ArtifactId>(), 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", plugin.call());
}
}
}
}
use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class ArtifactRepositoryTest method testPluginConfigWithNoStringValues.
@Test
public void testPluginConfigWithNoStringValues() throws Exception {
File pluginDir = TMP_FOLDER.newFolder();
addPluginArtifact();
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = getPlugins();
copyArtifacts(pluginDir, plugins);
String numericValue = "42";
// 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<ArtifactId>(), entry.getKey().getArtifactId(), pluginClass, PluginProperties.builder().add("class.name", TEST_EMPTY_CLASS).add("nullableLongFlag", numericValue).add("host", "example.com").add("aBoolean", "${aBoolean}").add("aByte", numericValue).add("aChar", "${aChar}").add("aDouble", "${aDouble}").add("anInt", numericValue).add("aFloat", "${aFloat}").add("aLong", numericValue).add("aShort", numericValue).build());
// first test with quotes ("42")
String jsonPluginStr = GSON.toJson(pluginInfo);
pluginInfo = GSON.fromJson(jsonPluginStr, Plugin.class);
instantiator.newInstance(pluginInfo);
// test without quotes (42)
pluginInfo = GSON.fromJson(jsonPluginStr.replaceAll("\"" + numericValue + "\"", numericValue), Plugin.class);
instantiator.newInstance(pluginInfo);
// test with quotes and dot ("42.0")
pluginInfo = GSON.fromJson(jsonPluginStr.replaceAll(numericValue, numericValue + ".0"), Plugin.class);
instantiator.newInstance(pluginInfo);
// test with dot (42.0)
pluginInfo = GSON.fromJson(jsonPluginStr.replaceAll("\"" + numericValue + "\"", numericValue + ".0"), Plugin.class);
instantiator.newInstance(pluginInfo);
// test with some actual double number 42.5
pluginInfo = GSON.fromJson(jsonPluginStr.replaceAll("\"" + numericValue + "\"", numericValue + ".5"), Plugin.class);
try {
instantiator.newInstance(pluginInfo);
Assert.fail("Plugin instantiation should fail with value '42.5'");
} catch (InvalidPluginConfigException e) {
// expected
}
}
}
}
}
use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class ArtifactRepositoryTest method addPluginArtifact.
private static void addPluginArtifact(Set<ArtifactRange> parents) throws Exception {
// Create the plugin jar. There should be two plugins there (TestPlugin and TestPlugin2).
Manifest manifest = createManifest(ManifestFields.EXPORT_PACKAGE, TestPlugin.class.getPackage().getName());
File jarFile = createPluginJar(TestPlugin.class, new File(tmpDir, "myPlugin-1.0.jar"), manifest);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "myPlugin", "1.0");
artifactRepository.addArtifact(artifactId, jarFile, parents, null);
}
Aggregations