Search in sources :

Example 6 with DatasetTypeNotFoundException

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());
    }
}
Also used : HandlerException(co.cask.cdap.common.HandlerException) DatasetAlreadyExistsException(co.cask.cdap.common.DatasetAlreadyExistsException) DatasetInstanceConfiguration(co.cask.cdap.proto.DatasetInstanceConfiguration) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 7 with DatasetTypeNotFoundException

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);
}
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 8 with DatasetTypeNotFoundException

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

Aggregations

DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)8 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)6 DatasetAlreadyExistsException (co.cask.cdap.common.DatasetAlreadyExistsException)3 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)2 DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)2 HandlerException (co.cask.cdap.common.HandlerException)2 DatasetInstanceConfiguration (co.cask.cdap.proto.DatasetInstanceConfiguration)2 DatasetId (co.cask.cdap.proto.id.DatasetId)2 DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 Principal (co.cask.cdap.proto.security.Principal)2 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)2 HttpResponse (co.cask.common.http.HttpResponse)2 URL (java.net.URL)2 Test (org.junit.Test)2 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1 DatasetTypeClient (co.cask.cdap.client.DatasetTypeClient)1 NamespaceClient (co.cask.cdap.client.NamespaceClient)1 FakeDataset (co.cask.cdap.client.app.FakeDataset)1 StandaloneDataset (co.cask.cdap.client.app.StandaloneDataset)1