use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.
the class DatasetInstanceService method getTypeInfo.
/**
* Finds the {@link DatasetTypeMeta} for the specified dataset type name.
* Search order - first in the specified namespace, then in the 'system' namespace from defaultModules
*
* @param namespaceId {@link NamespaceId} for the specified namespace
* @param typeName the name of the dataset type to search
* @param byPassCheck a flag which determines whether to check privilege for the dataset type
* @return {@link DatasetTypeMeta} for the type if found in either the specified namespace or in the system namespace,
* null otherwise.
* TODO: This may need to move to a util class eventually
*/
@Nullable
private DatasetTypeMeta getTypeInfo(NamespaceId namespaceId, String typeName, boolean byPassCheck) throws Exception {
DatasetTypeId datasetTypeId = ConversionHelpers.toDatasetTypeId(namespaceId, typeName);
try {
LOG.trace("Retrieving metadata from mds for dataset type {} with authorization: {}", typeName, byPassCheck);
DatasetTypeMeta meta = byPassCheck ? noAuthDatasetTypeService.getType(datasetTypeId) : authorizationDatasetTypeService.getType(datasetTypeId);
LOG.trace("Retrieved metadata from mds for dataset type {}", typeName);
return meta;
} catch (DatasetTypeNotFoundException | UnauthorizedException e) {
try {
// Type not found in the instance's namespace. Now try finding it in the system namespace
LOG.trace("Retrieving metadata from mds for system dataset type {}", typeName);
DatasetTypeId systemDatasetTypeId = ConversionHelpers.toDatasetTypeId(NamespaceId.SYSTEM, typeName);
LOG.trace("Retrieved metadata from mds for system dataset type {}", typeName);
return noAuthDatasetTypeService.getType(systemDatasetTypeId);
} catch (DatasetTypeNotFoundException exnWithSystemNS) {
// if it's not found in system namespace, throw the original exception with the correct namespace
throw e;
}
}
}
use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.
the class DefaultDatasetTypeService method getType.
/**
* Returns details of the specified {@link DatasetTypeId dataset type}.
*/
@Override
public DatasetTypeMeta getType(DatasetTypeId datasetTypeId) throws Exception {
ensureNamespaceExists(datasetTypeId.getParent());
DatasetTypeMeta typeMeta = typeManager.getTypeInfo(datasetTypeId);
if (typeMeta == null) {
throw new DatasetTypeNotFoundException(datasetTypeId);
}
return typeMeta;
}
use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.
the class DatasetClient method create.
/**
* Creates a dataset.
*
* @param instance ID of the dataset instance
* @param properties properties of the dataset to create
* @throws DatasetTypeNotFoundException if the desired dataset type was not found
* @throws DatasetAlreadyExistsException if a dataset by the same name already exists
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void create(DatasetId instance, DatasetInstanceConfiguration properties) throws DatasetTypeNotFoundException, DatasetAlreadyExistsException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s", instance.getDataset()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new DatasetTypeNotFoundException(instance.getParent().datasetType(properties.getTypeName()));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new DatasetAlreadyExistsException(instance);
}
}
use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.
the class DatasetTypeClient method get.
/**
* Gets information about a dataset type.
*
* @param type the dataset type
* @return {@link DatasetTypeMeta} of the dataset type
* @throws DatasetTypeNotFoundException if the dataset type could not be found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public DatasetTypeMeta get(DatasetTypeId type) throws DatasetTypeNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(type.getParent(), String.format("data/types/%s", type.getType()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new DatasetTypeNotFoundException(type);
}
return ObjectResponse.fromJsonBody(response, DatasetTypeMeta.class).getResponseObject();
}
use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.
the class DatasetInstanceService method update.
/**
* Updates an existing Dataset specification properties.
* {@link DatasetInstanceConfiguration} is constructed based on request and the Dataset instance is updated.
*
* @param instance the dataset instance
* @param properties the dataset properties to be used
* @throws NamespaceNotFoundException if the specified namespace was not found
* @throws DatasetNotFoundException if the dataset was not found
* @throws DatasetTypeNotFoundException if the type of the existing dataset was not found
* @throws UnauthorizedException if perimeter security and authorization are enabled, and the current user does not
* have {@link StandardPermission#UPDATE} privilege on the #instance
*/
void update(DatasetId instance, Map<String, String> properties) throws Exception {
ensureNamespaceExists(instance.getParent());
Principal requestingUser = authenticationContext.getPrincipal();
if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
accessEnforcer.enforce(instance, requestingUser, StandardPermission.UPDATE);
}
DatasetSpecification existing = instanceManager.get(instance);
if (existing == null) {
throw new DatasetNotFoundException(instance);
}
LOG.info("Update dataset {}, properties: {}", instance.getEntityName(), ConversionHelpers.toJson(properties));
// by pass the auth check for dataset type when the operation is not creation
DatasetTypeMeta typeMeta = getTypeInfo(instance.getParent(), existing.getType(), true);
if (typeMeta == null) {
// Type not found in the instance's namespace and the system namespace. Bail out.
throw new DatasetTypeNotFoundException(ConversionHelpers.toDatasetTypeId(instance.getParent(), existing.getType()));
}
// Note how we execute configure() via opExecutorClient (outside of ds service) to isolate running user code
DatasetProperties datasetProperties = DatasetProperties.of(properties);
DatasetCreationResponse response = opExecutorClient.update(instance, typeMeta, datasetProperties, existing);
DatasetSpecification spec = response.getSpec();
instanceManager.add(instance.getParent(), spec);
metaCache.invalidate(instance);
updateExplore(instance, datasetProperties, existing, spec);
publishAudit(instance, AuditType.UPDATE);
publishMetadata(instance, response.getMetadata());
}
Aggregations