use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.
the class InMemoryDatasetFramework method deleteAllInstances.
@Override
public void deleteAllInstances(NamespaceId namespaceId) throws DatasetManagementException, IOException {
writeLock.lock();
try {
for (DatasetSpecification spec : instances.row(namespaceId).values()) {
DatasetDefinition def = getDefinitionForType(namespaceId, spec.getType());
if (def == null) {
throw new DatasetManagementException(String.format("Dataset type '%s' is neither registered in the '%s' namespace nor in the system namespace", spec.getType(), namespaceId));
}
def.getAdmin(DatasetContext.from(namespaceId.getEntityName()), spec, null).drop();
publishAudit(namespaceId.dataset(spec.getName()), AuditType.DELETE);
}
instances.row(namespaceId).clear();
} finally {
writeLock.unlock();
}
}
use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.
the class InMemoryDatasetFrameworkTest method getFramework.
@Override
protected DatasetFramework getFramework() throws DatasetManagementException {
InMemoryDatasetFramework framework = new InMemoryDatasetFramework(registryFactory, DEFAULT_MODULES);
framework.setAuditPublisher(inMemoryAuditPublisher);
try {
namespacedLocationFactory.get(NAMESPACE_ID).mkdirs();
} catch (IOException e) {
throw new DatasetManagementException(e.getMessage());
}
return framework;
}
use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.
the class ExternalDatasets method makeTrackable.
/**
* If the output is an external sink then an external dataset is created for tracking purpose and returned.
* If the output is a regular dataset then it is already trackable, hence same output is returned.
*
* @param admin {@link Admin} used to create external dataset
* @param output output to be tracked
* @return an external dataset if output is an external sink, otherwise the same output is returned
*/
public static Output makeTrackable(Admin admin, Output output) {
// If output is not an external sink, return the same output as it can be tracked by itself.
if (!(output instanceof Output.OutputFormatProviderOutput)) {
return output;
}
// Output is an external sink, create an external dataset so that it can be tracked.
String outputName = output.getName();
OutputFormatProvider outputFormatProvider = ((Output.OutputFormatProviderOutput) output).getOutputFormatProvider();
Map<String, String> outputFormatConfiguration = outputFormatProvider.getOutputFormatConfiguration();
// this can be tracked by itself without creating an external dataset
if (outputFormatProvider instanceof Dataset) {
return output;
}
// Output is an external sink, create an external dataset so that it can be tracked.
try {
// Create an external dataset for the output format for lineage tracking
Map<String, String> arguments = new HashMap<>();
arguments.put("output.format.class", outputFormatProvider.getOutputFormatClassName());
arguments.putAll(outputFormatConfiguration);
if (!admin.datasetExists(outputName)) {
// Note: the dataset properties are the same as the arguments since we cannot identify them separately
// since they are mixed up in a single configuration object (CDAP-5674)
// Also, the properties of the external dataset created will contain runtime arguments for the same reason.
admin.createDataset(outputName, EXTERNAL_DATASET_TYPE, DatasetProperties.of(arguments));
} else {
// Check if the external dataset name clashes with an existing CDAP Dataset
String datasetType = admin.getDatasetType(outputName);
if (!EXTERNAL_DATASET_TYPE.equals(datasetType)) {
throw new IllegalArgumentException("An external sink cannot have the same name as an existing CDAP Dataset instance " + outputName);
}
}
return Output.ofDataset(outputName, Collections.unmodifiableMap(arguments)).alias(output.getAlias());
} catch (DatasetManagementException e) {
throw Throwables.propagate(e);
}
}
use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.
the class DatasetServiceClient method addUserIdHeader.
private HttpRequest.Builder addUserIdHeader(HttpRequest.Builder builder) throws DatasetManagementException {
if (!securityEnabled || !authorizationEnabled) {
return builder;
}
String currUserShortName;
try {
currUserShortName = UserGroupInformation.getCurrentUser().getShortUserName();
} catch (IOException e) {
throw new DatasetManagementException("Unable to get the current user", e);
}
// If the request originated from the router and was forwarded to any service other than dataset service, before
// going to dataset service via dataset service client, the userId could be set in the SecurityRequestContext.
// e.g. deploying an app that contains a dataset.
// For user datasets, if a dataset call originates from a program runtime, then find the userId from
// UserGroupInformation#getCurrentUser()
String userId = authenticationContext.getPrincipal().getName();
if (NamespaceId.SYSTEM.equals(namespaceId)) {
// configured principal
if (!kerberosEnabled || currUserShortName.equals(masterShortUserName)) {
LOG.trace("Accessing dataset in system namespace using the system principal because the current user " + "{} is the same as the CDAP master user {}.", currUserShortName, masterShortUserName);
userId = currUserShortName;
}
}
return builder.addHeader(Constants.Security.Headers.USER_ID, userId);
}
use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.
the class DatasetServiceClient method getInstance.
@Nullable
public DatasetMeta getInstance(String instanceName, @Nullable Iterable<? extends EntityId> owners) throws DatasetManagementException {
String query = "";
if (owners != null) {
Set<String> ownerParams = Sets.newHashSet();
for (EntityId owner : owners) {
ownerParams.add("owner=" + owner.toString());
}
query = ownerParams.isEmpty() ? "" : "?" + Joiner.on("&").join(ownerParams);
}
HttpResponse response = doGet("datasets/" + instanceName + query);
if (HttpResponseStatus.NOT_FOUND.getCode() == response.getResponseCode()) {
return null;
}
if (HttpResponseStatus.OK.getCode() != response.getResponseCode()) {
throw new DatasetManagementException(String.format("Cannot retrieve dataset instance %s info, details: %s", instanceName, response));
}
return GSON.fromJson(response.getResponseBodyAsString(), DatasetMeta.class);
}
Aggregations