use of org.apache.twill.filesystem.Location in project cdap by caskdata.
the class ArtifactStore method getArtifact.
/**
* Get information about the given artifact.
*
* @param artifactId the artifact to get
* @return information about the artifact
* @throws ArtifactNotFoundException if the given artifact does not exist
* @throws IOException if there was an exception reading the artifact information from the metastore
*/
public ArtifactDetail getArtifact(final Id.Artifact artifactId) throws ArtifactNotFoundException, IOException {
try {
final ArtifactData artifactData = Transactions.execute(transactional, new TxCallable<ArtifactData>() {
@Override
public ArtifactData call(DatasetContext context) throws Exception {
ArtifactCell artifactCell = new ArtifactCell(artifactId);
byte[] value = getMetaTable(context).get(artifactCell.rowkey, artifactCell.column);
if (value == null) {
throw new ArtifactNotFoundException(artifactId.toEntityId());
}
return GSON.fromJson(Bytes.toString(value), ArtifactData.class);
}
});
Location artifactLocation = impersonator.doAs(artifactId.getNamespace().toEntityId(), new Callable<Location>() {
@Override
public Location call() throws Exception {
return Locations.getLocationFromAbsolutePath(locationFactory, artifactData.getLocationPath());
}
});
return new ArtifactDetail(new ArtifactDescriptor(artifactId.toArtifactId(), artifactLocation), artifactData.meta);
} catch (TransactionFailureException e) {
throw Transactions.propagate(e, IOException.class, ArtifactNotFoundException.class);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.apache.twill.filesystem.Location in project cdap by caskdata.
the class ArtifactStore method writeMeta.
// write a new artifact snapshot and clean up the old snapshot data
private void writeMeta(Table table, Id.Artifact artifactId, ArtifactData data) throws IOException {
ArtifactCell artifactCell = new ArtifactCell(artifactId);
table.put(artifactCell.rowkey, artifactCell.column, Bytes.toBytes(GSON.toJson(data)));
// column for plugin meta and app meta. {artifact-name}:{artifact-version}
// does not need to contain namespace because namespace is in the rowkey
byte[] artifactColumn = new ArtifactColumn(artifactId).getColumn();
ArtifactClasses classes = data.meta.getClasses();
Location artifactLocation = Locations.getLocationFromAbsolutePath(locationFactory, data.getLocationPath());
// write pluginClass metadata
for (PluginClass pluginClass : classes.getPlugins()) {
// write metadata for each artifact this plugin extends
for (ArtifactRange artifactRange : data.meta.getUsableBy()) {
// p:{namespace}:{type}:{name}
PluginKey pluginKey = new PluginKey(artifactRange.getNamespace(), artifactRange.getName(), pluginClass.getType(), pluginClass.getName());
byte[] pluginDataBytes = Bytes.toBytes(GSON.toJson(new PluginData(pluginClass, artifactRange, artifactLocation)));
table.put(pluginKey.getRowKey(), artifactColumn, pluginDataBytes);
}
}
// write appClass metadata
for (ApplicationClass appClass : classes.getApps()) {
// a:{namespace}:{classname}
AppClassKey appClassKey = new AppClassKey(artifactId.getNamespace().toEntityId(), appClass.getClassName());
byte[] appDataBytes = Bytes.toBytes(GSON.toJson(new AppData(appClass, artifactLocation)));
table.put(appClassKey.getRowKey(), artifactColumn, appDataBytes);
}
}
use of org.apache.twill.filesystem.Location in project cdap by caskdata.
the class MapReduceRuntimeService method copyProgramJar.
/**
* Creates a temp copy of the program jar.
*
* @return a new {@link Location} which contains the same content as the program jar
*/
private Location copyProgramJar(Location targetDir) throws IOException {
Location programJarCopy = targetDir.append("program.jar");
ByteStreams.copy(Locations.newInputSupplier(programJarLocation), Locations.newOutputSupplier(programJarCopy));
LOG.debug("Copied Program Jar to {}, source: {}", programJarCopy, programJarLocation);
return programJarCopy;
}
use of org.apache.twill.filesystem.Location in project cdap by caskdata.
the class DefaultSecureStoreServiceTest method createCConf.
private static CConfiguration createCConf() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMPORARY_FOLDER.newFolder().getAbsolutePath());
cConf.setBoolean(Constants.Security.ENABLED, true);
cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
// we only want to test authorization, but we don't specify principal/keytab, so disable kerberos
cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
cConf.setInt(Constants.Security.Authorization.CACHE_MAX_ENTRIES, 0);
LocationFactory locationFactory = new LocalLocationFactory(TEMPORARY_FOLDER.newFolder());
Location authorizerJar = AppJarHelper.createDeploymentJar(locationFactory, InMemoryAuthorizer.class);
cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, authorizerJar.toURI().getPath());
// set secure store provider
cConf.set(Constants.Security.Store.PROVIDER, "file");
return cConf;
}
use of org.apache.twill.filesystem.Location in project cdap by caskdata.
the class ProgramLifecycleServiceAuthorizationTest method createCConf.
private static CConfiguration createCConf() throws IOException {
CConfiguration cConf = CConfiguration.create();
cConf.setBoolean(Constants.Security.ENABLED, true);
cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
// we only want to test authorization, but we don't specify principal/keytab, so disable kerberos
cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
cConf.setInt(Constants.Security.Authorization.CACHE_MAX_ENTRIES, 0);
LocationFactory locationFactory = new LocalLocationFactory(new File(TEMPORARY_FOLDER.newFolder().toURI()));
Location authorizerJar = AppJarHelper.createDeploymentJar(locationFactory, InMemoryAuthorizer.class);
cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, authorizerJar.toURI().getPath());
return cConf;
}
Aggregations