Search in sources :

Example 16 with DatasetTypeMeta

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());
    }
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 17 with DatasetTypeMeta

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()));
    }
}
Also used : DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

Example 18 with DatasetTypeMeta

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);
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException)

Example 19 with DatasetTypeMeta

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();
}
Also used : DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) HttpResponse(co.cask.common.http.HttpResponse) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) URL(java.net.URL)

Example 20 with DatasetTypeMeta

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();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Aggregations

DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)20 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)7 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)6 DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)6 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)5 DatasetId (co.cask.cdap.proto.id.DatasetId)5 DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)4 NotFoundException (co.cask.cdap.common.NotFoundException)4 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)3 BadRequestException (co.cask.cdap.common.BadRequestException)3 Principal (co.cask.cdap.proto.security.Principal)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)2 RowMaker (co.cask.cdap.cli.util.RowMaker)2 Table (co.cask.cdap.cli.util.table.Table)2 DatasetTypeClient (co.cask.cdap.client.DatasetTypeClient)2 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 DatasetMeta (co.cask.cdap.proto.DatasetMeta)2 EntityId (co.cask.cdap.proto.id.EntityId)2