use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class DistributedProgramRunnerTxTimeoutTest method setup.
@BeforeClass
public static void setup() {
Application app = new AppWithAllProgramTypes();
DefaultAppConfigurer configurer = new DefaultAppConfigurer(Id.Namespace.DEFAULT, new Id.Artifact(Id.Namespace.DEFAULT, "artifact", new ArtifactVersion("0.1")), app);
app.configure(configurer, new ApplicationContext() {
@Override
public Config getConfig() {
return null;
}
});
appSpec = configurer.createSpecification("app", "1.0");
// System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(appSpec));
cConf.setInt(TxConstants.Manager.CFG_TX_MAX_TIMEOUT, 60);
flowRunner = new DistributedFlowProgramRunner(null, yConf, cConf, null, null, null, null, null);
serviceRunner = new DistributedServiceProgramRunner(null, yConf, cConf, null, null);
workerRunner = new DistributedWorkerProgramRunner(null, yConf, cConf, null, null);
mapreduceRunner = new DistributedMapReduceProgramRunner(null, yConf, cConf, null, null);
sparkRunner = new DistributedSparkProgramRunner(SparkCompat.SPARK1_2_10, null, yConf, cConf, null, null, null);
workflowRunner = new DistributedWorkflowProgramRunner(null, yConf, cConf, null, null, null);
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactStore method addArtifactsToList.
private void addArtifactsToList(List<ArtifactDetail> artifactDetails, Row row, int limit, @Nullable ArtifactRange range) throws IOException {
ArtifactKey artifactKey = ArtifactKey.parse(row.getRow());
for (Map.Entry<byte[], byte[]> columnVal : row.getColumns().entrySet()) {
if (limit != Integer.MAX_VALUE && artifactDetails.size() == limit) {
break;
}
String version = Bytes.toString(columnVal.getKey());
if (range != null && !range.versionIsInRange(new ArtifactVersion(version))) {
continue;
}
ArtifactData data = GSON.fromJson(Bytes.toString(columnVal.getValue()), ArtifactData.class);
Id.Artifact artifactId = new NamespaceId(artifactKey.namespace).artifact(artifactKey.name, version).toId();
artifactDetails.add(new ArtifactDetail(new ArtifactDescriptor(artifactId.toArtifactId(), Locations.getLocationFromAbsolutePath(locationFactory, data.getLocationPath())), data.meta));
}
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactStore method addAndSortArtifacts.
private void addAndSortArtifacts(List<ArtifactDetail> artifacts, Row row, int limit, final ArtifactSortOrder order, @Nullable ArtifactRange range) {
ArtifactKey artifactKey = ArtifactKey.parse(row.getRow());
PriorityQueue<ArtifactDetail> queue = getPriorityQueue(limit, order);
for (Map.Entry<byte[], byte[]> columnEntry : row.getColumns().entrySet()) {
String version = Bytes.toString(columnEntry.getKey());
if (range != null && !range.versionIsInRange(new ArtifactVersion(version))) {
continue;
}
ArtifactData data = GSON.fromJson(Bytes.toString(columnEntry.getValue()), ArtifactData.class);
ArtifactId artifactId = new ArtifactId(artifactKey.name, new ArtifactVersion(version), artifactKey.namespace.equals(NamespaceId.SYSTEM.getNamespace()) ? ArtifactScope.SYSTEM : ArtifactScope.USER);
queue.add(new ArtifactDetail(new ArtifactDescriptor(artifactId, Locations.getLocationFromAbsolutePath(locationFactory, data.getLocationPath())), data.meta));
if (limit != Integer.MAX_VALUE && queue.size() > limit) {
queue.poll();
}
}
while (!queue.isEmpty()) {
artifacts.add(queue.poll());
}
Collections.reverse(artifacts.subList(0, artifacts.size()));
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactHttpHandlerTest method testGetPlugins.
@Test
public void testGetPlugins() throws Exception {
// add an app for plugins to extend
Id.Artifact wordCount1Id = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "1.0.0");
Assert.assertEquals(HttpResponseStatus.OK.getCode(), addAppArtifact(wordCount1Id, WordCountApp.class).getStatusLine().getStatusCode());
Id.Artifact wordCount2Id = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "2.0.0");
Assert.assertEquals(HttpResponseStatus.OK.getCode(), addAppArtifact(wordCount2Id, WordCountApp.class).getStatusLine().getStatusCode());
// add some plugins.
// plugins-1.0.0 extends wordcount[1.0.0,2.0.0)
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
Id.Artifact pluginsId1 = Id.Artifact.from(Id.Namespace.DEFAULT, "plugins", "1.0.0");
Set<ArtifactRange> plugins1Parents = Sets.newHashSet(new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "wordcount", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
Assert.assertEquals(HttpResponseStatus.OK.getCode(), addPluginArtifact(pluginsId1, Plugin1.class, manifest, plugins1Parents).getStatusLine().getStatusCode());
// plugin-2.0.0 extends wordcount[1.0.0,3.0.0)
Id.Artifact pluginsId2 = Id.Artifact.from(Id.Namespace.DEFAULT, "plugins", "2.0.0");
Set<ArtifactRange> plugins2Parents = Sets.newHashSet(new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "wordcount", new ArtifactVersion("1.0.0"), new ArtifactVersion("3.0.0")));
Assert.assertEquals(HttpResponseStatus.OK.getCode(), addPluginArtifact(pluginsId2, Plugin1.class, manifest, plugins2Parents).getStatusLine().getStatusCode());
ArtifactSummary plugins1Artifact = new ArtifactSummary("plugins", "1.0.0");
ArtifactSummary plugins2Artifact = new ArtifactSummary("plugins", "2.0.0");
// get plugin types, should be the same for both
Set<String> expectedTypes = Sets.newHashSet("dummy", "callable");
Set<String> actualTypes = getPluginTypes(wordCount1Id);
Assert.assertEquals(expectedTypes, actualTypes);
actualTypes = getPluginTypes(wordCount2Id);
Assert.assertEquals(expectedTypes, actualTypes);
// get plugin summaries. wordcount1 should see plugins from both plugin artifacts
Set<PluginSummary> expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins1Artifact), new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact));
Set<PluginSummary> actualSummaries = getPluginSummaries(wordCount1Id, "dummy");
Assert.assertEquals(expectedSummaries, actualSummaries);
expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins1Artifact), new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact));
actualSummaries = getPluginSummaries(wordCount1Id, "callable");
Assert.assertEquals(expectedSummaries, actualSummaries);
// wordcount2 should only see plugins from plugins2 artifact
expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact));
actualSummaries = getPluginSummaries(wordCount2Id, "dummy");
Assert.assertEquals(expectedSummaries, actualSummaries);
expectedSummaries = Sets.newHashSet(new PluginSummary("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact));
actualSummaries = getPluginSummaries(wordCount2Id, "callable");
Assert.assertEquals(expectedSummaries, actualSummaries);
// get plugin info. Again, wordcount1 should see plugins from both artifacts
Map<String, PluginPropertyField> p1Properties = ImmutableMap.of("x", new PluginPropertyField("x", "", "int", true, false), "stuff", new PluginPropertyField("stuff", "", "string", true, true));
Map<String, PluginPropertyField> p2Properties = ImmutableMap.of("v", new PluginPropertyField("v", "value to return when called", "int", true, false));
Set<PluginInfo> expectedInfos = Sets.newHashSet(new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins1Artifact, p1Properties, new HashSet<String>()), new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact, p1Properties, new HashSet<String>()));
Assert.assertEquals(expectedInfos, getPluginInfos(wordCount1Id, "dummy", "Plugin1"));
expectedInfos = Sets.newHashSet(new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins1Artifact, p2Properties, new HashSet<String>()), new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact, p2Properties, new HashSet<String>()));
Assert.assertEquals(expectedInfos, getPluginInfos(wordCount1Id, "callable", "Plugin2"));
// while wordcount2 should only see plugins from plugins2 artifact
expectedInfos = Sets.newHashSet(new PluginInfo("Plugin1", "dummy", "This is plugin1", Plugin1.class.getName(), plugins2Artifact, p1Properties, new HashSet<String>()));
Assert.assertEquals(expectedInfos, getPluginInfos(wordCount2Id, "dummy", "Plugin1"));
expectedInfos = Sets.newHashSet(new PluginInfo("Plugin2", "callable", "Just returns the configured integer", Plugin2.class.getName(), plugins2Artifact, p2Properties, new HashSet<String>()));
Assert.assertEquals(expectedInfos, getPluginInfos(wordCount2Id, "callable", "Plugin2"));
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ApplicationLifecycleService method updateApp.
/**
* Update an existing application. An application's configuration and artifact version can be updated.
*
* @param appId the id of the application to update
* @param appRequest the request to update the application, including new config and artifact
* @param programTerminator a program terminator that will stop programs that are removed when updating an app.
* For example, if an update removes a flow, the terminator defines how to stop that flow.
* @return information about the deployed application
* @throws ApplicationNotFoundException if the specified application does not exist
* @throws ArtifactNotFoundException if the requested artifact does not exist
* @throws InvalidArtifactException if the specified artifact is invalid. For example, if the artifact name changed,
* if the version is an invalid version, or the artifact contains no app classes
* @throws Exception if there was an exception during the deployment pipeline. This exception will often wrap
* the actual exception
*/
public ApplicationWithPrograms updateApp(ApplicationId appId, AppRequest appRequest, ProgramTerminator programTerminator) throws Exception {
// check that app exists
ApplicationSpecification currentSpec = store.getApplication(appId);
if (currentSpec == null) {
throw new ApplicationNotFoundException(appId);
}
// App exists. Check if the current user has admin privileges on it before updating. The user's write privileges on
// the namespace will get enforced in the deployApp method.
authorizationEnforcer.enforce(appId, authenticationContext.getPrincipal(), Action.ADMIN);
ArtifactId currentArtifact = currentSpec.getArtifactId();
// if no artifact is given, use the current one.
ArtifactId newArtifactId = currentArtifact;
// otherwise, check requested artifact is valid and use it
ArtifactSummary requestedArtifact = appRequest.getArtifact();
if (requestedArtifact != null) {
// cannot change artifact name, only artifact version.
if (!currentArtifact.getName().equals(requestedArtifact.getName())) {
throw new InvalidArtifactException(String.format(" Only artifact version updates are allowed. Cannot change from artifact '%s' to '%s'.", currentArtifact.getName(), requestedArtifact.getName()));
}
if (!currentArtifact.getScope().equals(requestedArtifact.getScope())) {
throw new InvalidArtifactException("Only artifact version updates are allowed. " + "Cannot change from a non-system artifact to a system artifact or vice versa.");
}
// check requested artifact version is valid
ArtifactVersion requestedVersion = new ArtifactVersion(requestedArtifact.getVersion());
if (requestedVersion.getVersion() == null) {
throw new InvalidArtifactException(String.format("Requested artifact version '%s' is invalid", requestedArtifact.getVersion()));
}
newArtifactId = new ArtifactId(currentArtifact.getName(), requestedVersion, currentArtifact.getScope());
}
// ownerAdmin.getImpersonationPrincipal will give the owner which will be impersonated for the application
// irrespective of the version
SecurityUtil.verifyOwnerPrincipal(appId, appRequest.getOwnerPrincipal(), ownerAdmin);
Object requestedConfigObj = appRequest.getConfig();
// if config is null, use the previous config. Shouldn't use a static GSON since the request Config object can
// be a user class, otherwise there will be ClassLoader leakage.
String requestedConfigStr = requestedConfigObj == null ? currentSpec.getConfiguration() : new Gson().toJson(requestedConfigObj);
Id.Artifact artifactId = Artifacts.toArtifactId(appId.getParent(), newArtifactId).toId();
return deployApp(appId.getParent(), appId.getApplication(), null, artifactId, requestedConfigStr, programTerminator, ownerAdmin.getOwner(appId), appRequest.canUpdateSchedules());
}
Aggregations