use of co.cask.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.
the class DatasetInstanceHandler method create.
/**
* Creates a new dataset instance.
*
* @param namespaceId namespace of the new dataset instance
* @param name name of the new dataset instance
*/
@PUT
@Path("/data/datasets/{name}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void create(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
DatasetInstanceConfiguration creationProperties = ConversionHelpers.getInstanceConfiguration(request);
try {
instanceService.create(namespaceId, name, creationProperties);
responder.sendStatus(HttpResponseStatus.OK);
} catch (DatasetAlreadyExistsException e) {
responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage());
} catch (DatasetTypeNotFoundException e) {
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
} catch (HandlerException e) {
responder.sendString(e.getFailureStatus(), e.getMessage());
}
}
use of co.cask.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 Action#ADMIN} privilege on the #instance
*/
void update(DatasetId instance, Map<String, String> properties) throws Exception {
ensureNamespaceExists(instance.getParent());
DatasetSpecification existing = instanceManager.get(instance);
if (existing == null) {
throw new DatasetNotFoundException(instance);
}
LOG.info("Update dataset {}, properties: {}", instance.getEntityName(), ConversionHelpers.toJson(properties));
authorizationEnforcer.enforce(instance, authenticationContext.getPrincipal(), Action.ADMIN);
DatasetTypeMeta typeMeta = getTypeInfo(instance.getParent(), existing.getType());
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);
DatasetSpecification spec = opExecutorClient.update(instance, typeMeta, datasetProperties, existing);
instanceManager.add(instance.getParent(), spec);
metaCache.invalidate(instance);
updateExplore(instance, datasetProperties, existing, spec);
publishAudit(instance, AuditType.UPDATE);
}
use of co.cask.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();
}
Aggregations