Search in sources :

Example 6 with DatasetTypeMeta

use of io.cdap.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetAdminOpHTTPHandler method update.

@POST
@Path("/data/datasets/{name}/admin/update")
public void update(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
    propagateUserId(request);
    InternalDatasetUpdateParams params = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), InternalDatasetUpdateParams.class);
    Preconditions.checkArgument(params.getProperties() != null, "Missing required 'instanceProps' parameter.");
    Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
    Preconditions.checkArgument(params.getExistingSpec() != null, "Missing required 'existingSpec' parameter.");
    DatasetProperties props = params.getProperties();
    DatasetSpecification existing = params.getExistingSpec();
    DatasetTypeMeta typeMeta = params.getTypeMeta();
    try {
        DatasetId instanceId = new DatasetId(namespaceId, name);
        DatasetCreationResponse response = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
        responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response));
    } catch (IncompatibleUpdateException e) {
        throw new ConflictException(e.getMessage());
    }
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 7 with DatasetTypeMeta

use of io.cdap.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetAdminOpHTTPHandler method drop.

@POST
@Path("/data/datasets/{name}/admin/drop")
public void drop(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) throws Exception {
    propagateUserId(request);
    InternalDatasetDropParams params = GSON.fromJson(request.content().toString(StandardCharsets.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();
    datasetAdminService.drop(new DatasetId(namespaceId, instanceName), typeMeta, spec);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(spec));
}
Also used : DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 8 with DatasetTypeMeta

use of io.cdap.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetTypeTable method getTypes.

public Collection<DatasetTypeMeta> getTypes(NamespaceId namespaceId) throws IOException {
    List<DatasetTypeMeta> types = Lists.newArrayList();
    try (CloseableIterator<StructuredRow> iterator = getTypeTable().scan(Range.singleton(getModulePrefix(namespaceId.getEntityName())), Integer.MAX_VALUE)) {
        while (iterator.hasNext()) {
            StructuredRow row = iterator.next();
            String typeName = row.getString(StoreDefinition.DatasetTypeStore.TYPE_NAME_FIELD);
            DatasetModuleId moduleId = GSON.fromJson(row.getString(StoreDefinition.DatasetTypeStore.DATASET_METADATA_FIELD), DatasetModuleId.class);
            types.add(getTypeMeta(namespaceId, typeName, moduleId));
        }
    }
    return types;
}
Also used : DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) StructuredRow(io.cdap.cdap.spi.data.StructuredRow)

Example 9 with DatasetTypeMeta

use of io.cdap.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(io.cdap.cdap.proto.DatasetTypeMeta) HttpResponse(io.cdap.common.http.HttpResponse) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) URL(java.net.URL)

Example 10 with DatasetTypeMeta

use of io.cdap.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class GenerateClientUsageExample method datasetTypeClient.

public void datasetTypeClient() throws Exception {
    // Construct the client used to interact with CDAP
    DatasetTypeClient datasetTypeClient = new DatasetTypeClient(clientConfig);
    // Fetch the dataset type information using the type name
    DatasetTypeMeta datasetTypeMeta = datasetTypeClient.get(NamespaceId.DEFAULT.datasetType("someDatasetType"));
    // Fetch the dataset type information using the classname
    datasetTypeClient.get(NamespaceId.DEFAULT.datasetType(SomeDataset.class.getName()));
}
Also used : DatasetTypeClient(io.cdap.cdap.client.DatasetTypeClient) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta)

Aggregations

DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)21 DatasetTypeNotFoundException (io.cdap.cdap.common.DatasetTypeNotFoundException)8 DatasetTypeId (io.cdap.cdap.proto.id.DatasetTypeId)7 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)5 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)5 DatasetId (io.cdap.cdap.proto.id.DatasetId)5 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)4 DatasetNotFoundException (io.cdap.cdap.common.DatasetNotFoundException)4 DatasetModuleId (io.cdap.cdap.proto.id.DatasetModuleId)3 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)3 HttpResponse (io.cdap.common.http.HttpResponse)3 RowMaker (io.cdap.cdap.cli.util.RowMaker)2 Table (io.cdap.cdap.cli.util.table.Table)2 DatasetTypeClient (io.cdap.cdap.client.DatasetTypeClient)2 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)2 NotFoundException (io.cdap.cdap.common.NotFoundException)2 DatasetCreationResponse (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetCreationResponse)2 DatasetInstanceConfiguration (io.cdap.cdap.proto.DatasetInstanceConfiguration)2 DatasetMeta (io.cdap.cdap.proto.DatasetMeta)2 Principal (io.cdap.cdap.proto.security.Principal)2