use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.
the class DatasetAdminOpHTTPHandler method drop.
@POST
@Path("/data/datasets/{name}/admin/drop")
public void drop(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) throws Exception {
propagateUserId(request);
InternalDatasetDropParams params = GSON.fromJson(request.getContent().toString(Charsets.UTF_8), InternalDatasetDropParams.class);
Preconditions.checkArgument(params.getInstanceSpec() != null, "Missing required 'instanceSpec' parameter.");
Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
DatasetSpecification spec = params.getInstanceSpec();
DatasetTypeMeta typeMeta = params.getTypeMeta();
try {
datasetAdminService.drop(new DatasetId(namespaceId, instanceName), typeMeta, spec);
responder.sendJson(HttpResponseStatus.OK, spec);
} catch (BadRequestException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
}
}
use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.
the class DatasetTypeHandlerTest method verifyAll.
private void verifyAll(Set<DatasetModuleMeta> expectedModules, Map<String, List<String>> typeDependencies) throws IOException {
Set<DatasetModuleMeta> actualModules = new HashSet<>(getModules().getResponseObject());
Assert.assertEquals(expectedModules, actualModules);
for (DatasetModuleMeta expectedModule : expectedModules) {
ObjectResponse<DatasetModuleMeta> response = getModule(expectedModule.getName());
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals(expectedModule, response.getResponseObject());
for (String type : expectedModule.getTypes()) {
ObjectResponse<DatasetTypeMeta> typeResponse = getType(type);
Assert.assertEquals(HttpStatus.SC_OK, typeResponse.getResponseCode());
verify(typeResponse.getResponseObject(), type, typeDependencies.get(type));
}
}
List<DatasetTypeMeta> actualTypes = getTypes().getResponseObject();
Assert.assertEquals(actualTypes.size(), typeDependencies.size());
Assert.assertTrue(Iterables.elementsEqual(typeDependencies.keySet(), Iterables.transform(actualTypes, new Function<DatasetTypeMeta, String>() {
@Nullable
@Override
public String apply(@Nullable DatasetTypeMeta input) {
return input == null ? null : input.getName();
}
})));
for (DatasetTypeMeta typeMeta : actualTypes) {
verify(typeMeta, typeMeta.getName(), typeDependencies.get(typeMeta.getName()));
}
}
use of co.cask.cdap.proto.DatasetTypeMeta 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.proto.DatasetTypeMeta 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 co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.
the class DatasetTypeClient method list.
/**
* Lists all dataset types.
*
* @return list of {@link DatasetTypeMeta}s.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<DatasetTypeMeta> list(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "data/types");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<DatasetTypeMeta>>() {
}).getResponseObject();
}
Aggregations