use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class CreateDatasetInstancesStage method process.
/**
* Receives an input containing application specification and location
* and verifies both.
*
* @param input An instance of {@link ApplicationDeployable}
*/
@Override
public void process(ApplicationDeployable input) throws Exception {
// create dataset instances
ApplicationSpecification specification = input.getSpecification();
NamespaceId namespaceId = input.getApplicationId().getParent();
KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal();
// get the authorizing user
String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal);
datasetInstanceCreator.createInstances(namespaceId, specification.getDatasets(), ownerPrincipal, authorizingUser);
// Emit the input to next stage.
emit(input);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AbstractStorageProviderNamespaceAdmin method createLocation.
private void createLocation(NamespaceMeta namespaceMeta) throws IOException {
NamespaceId namespaceId = namespaceMeta.getNamespaceId();
boolean createdHome = false;
Location namespaceHome;
if (hasCustomLocation(namespaceMeta)) {
namespaceHome = validateCustomLocation(namespaceMeta);
} else {
// no namespace custom location was provided one must be created by cdap
namespaceHome = namespacePathLocator.get(namespaceMeta);
if (namespaceHome.exists()) {
throw new FileAlreadyExistsException(null, null, String.format("Directory '%s' for '%s' already exists.", namespaceHome, namespaceId));
}
createdHome = createNamespaceDir(namespaceHome, "home", namespaceId);
}
// data/
Location dataLoc = namespaceHome.append(Constants.Dataset.DEFAULT_DATA_DIR);
// tmp/
Location tempLoc = namespaceHome.append(cConf.get(Constants.AppFabric.TEMP_DIR));
String configuredGroupName = namespaceMeta.getConfig().getGroupName();
boolean createdData = false;
boolean createdTemp = false;
try {
if (createdHome && SecurityUtil.isKerberosEnabled(cConf)) {
// set the group id of the namespace home if configured, or the current user's primary group
String groupToSet = configuredGroupName;
if (groupToSet == null) {
// attempt to determine the current user's primary group. Note that we cannot use ugi.getPrimaryGroup()
// because that is not implemented at least in Hadoop 2.0 and 2.2, possibly other versions. Also note
// that there is no guarantee that getGroupNames() returns anything.
String[] groups = UserGroupInformation.getCurrentUser().getGroupNames();
if (groups != null && groups.length > 0) {
groupToSet = groups[0];
}
}
// if this is still null at this point, then the directory will have whatever HDFS assigned at creation
if (groupToSet != null) {
try {
namespaceHome.setGroup(groupToSet);
} catch (Exception e) {
// the exception from the file system typically does not include the group and user, so add that here
throw new IOException(String.format("Failed to set group '%s' for %s with current user '%s'", groupToSet, namespaceHome, UserGroupInformation.getCurrentUser().getUserName()), e);
}
}
}
// create all the directories with default permissions
createdData = createNamespaceDir(dataLoc, "data", namespaceId);
createdTemp = createNamespaceDir(tempLoc, "temp", namespaceId);
// set all these directories to be owned and group writable by the configured group.
if (SecurityUtil.isKerberosEnabled(cConf) && configuredGroupName != null) {
for (Location loc : new Location[] { dataLoc, tempLoc }) {
loc.setGroup(configuredGroupName);
// set the permissions to rwx for group
String permissions = loc.getPermissions();
loc.setPermissions(permissions.substring(0, 3) + "rwx" + permissions.substring(6));
}
}
} catch (Throwable t) {
if (createdHome) {
deleteDirSilently(namespaceHome, t, "home", namespaceMeta.getNamespaceId());
} else {
if (createdData) {
deleteDirSilently(dataLoc, t, "data", namespaceMeta.getNamespaceId());
}
if (createdTemp) {
deleteDirSilently(tempLoc, t, "temp", namespaceMeta.getNamespaceId());
}
}
throw t;
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MapReduceProgramRunnerTest method testMapreduceWithObjectStore.
@Test
public void testMapreduceWithObjectStore() throws Exception {
// Deploy apps to another namespace and test cross-namespace access meanwhile
final ApplicationWithPrograms app = deployApp(Id.Namespace.fromEntityId(new NamespaceId("someOtherNameSpace")), AppWithMapReduceUsingObjectStore.class);
final ObjectStore<String> input = datasetCache.getDataset("someOtherNameSpace", "keys");
// Get dataset from a non existing namespace
try {
datasetCache.getDataset("nonExistingNameSpace", "keys");
Assert.fail("getDataset() should throw an exception when accessing dataset from a non-existing namespace.");
} catch (DatasetInstantiationException e) {
// expected
}
final String testString = "persisted data";
// Populate some input
Transactions.createTransactionExecutor(txExecutorFactory, (TransactionAware) input).execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() {
input.write(Bytes.toBytes(testString), testString);
input.write(Bytes.toBytes("distributed systems"), "distributed systems");
}
});
runProgram(app, AppWithMapReduceUsingObjectStore.ComputeCounts.class, false, true);
final KeyValueTable output = datasetCache.getDataset("someOtherNameSpace", "count");
// read output and verify result
Transactions.createTransactionExecutor(txExecutorFactory, output).execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() {
byte[] val = output.read(Bytes.toBytes(testString));
Assert.assertTrue(val != null);
Assert.assertEquals(Bytes.toString(val), Integer.toString(testString.length()));
val = output.read(Bytes.toBytes("distributed systems"));
Assert.assertTrue(val != null);
Assert.assertEquals(Bytes.toString(val), "19");
}
});
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class UpdateTimeScheduleCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
String scheduleName = arguments.get(ArgumentName.SCHEDULE_NAME.toString());
String[] programIdParts = arguments.get(ArgumentName.PROGRAM.toString()).split("\\.");
String version = arguments.getOptional(ArgumentName.APP_VERSION.toString());
String scheduleDescription = arguments.getOptional(ArgumentName.DESCRIPTION.toString(), "");
String cronExpression = arguments.get(ArgumentName.CRON_EXPRESSION.toString());
String schedulePropertiesString = arguments.getOptional(ArgumentName.SCHEDULE_PROPERTIES.toString(), "");
String scheduleRunConcurrencyString = arguments.getOptional(ArgumentName.CONCURRENCY.toString(), null);
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
String appId = programIdParts[0];
NamespaceId namespaceId = cliConfig.getCurrentNamespace();
ApplicationId applicationId = (version == null) ? namespaceId.app(appId) : namespaceId.app(appId, version);
ScheduleId scheduleId = applicationId.schedule(scheduleName);
String description = scheduleDescription == null ? null : scheduleDescription;
ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, programIdParts[1]);
List<Constraint> constraints = scheduleRunConcurrencyString == null ? ImmutableList.of() : ImmutableList.of(new ProtoConstraint.ConcurrencyConstraint(Integer.valueOf(scheduleRunConcurrencyString)));
Map<String, String> propertiesMap = ArgumentParser.parseMap(schedulePropertiesString, ArgumentName.SCHEDULE_PROPERTIES.toString());
ScheduleDetail scheduleDetail = new ScheduleDetail(scheduleName, description, programInfo, propertiesMap, new ProtoTrigger.TimeTrigger(cronExpression), constraints, null);
scheduleClient.update(scheduleId, scheduleDetail);
printStream.printf("Successfully updated schedule '%s' in app '%s'\n", scheduleName, appId);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class InstanceURIParser method parseInstanceURI.
public CLIConnectionConfig parseInstanceURI(String uriString, String namespaceString) {
uriString = addScheme(uriString);
// Having '/' at the end of the path helps java.net.URI to recognise this as a valid URI path
if (uriString.length() > 0 && !uriString.endsWith("/")) {
uriString = String.format("%s/", uriString);
}
URI uri = URI.create(uriString);
NamespaceId namespace = (namespaceString == null || namespaceString.isEmpty()) ? NamespaceId.DEFAULT : new NamespaceId(namespaceString);
String apiPath = uri.getPath();
if (apiPath != null && apiPath.startsWith("/")) {
apiPath = apiPath.substring(1);
}
ConnectionConfig config = ConnectionConfig.builder().setHostname(uri.getHost()).setPort(uri.getPort() == -1 ? null : uri.getPort()).setSSLEnabled("https".equals(uri.getScheme())).setApiPath(apiPath).build();
return new CLIConnectionConfig(config, namespace, null);
}
Aggregations