Package co.cask.cdap.proto

Examples of co.cask.cdap.proto.DatasetInstanceConfiguration


   */
  @PUT
  @Path("/data/datasets/{name}")
  public void create(HttpRequest request, final HttpResponder responder,
                  @PathParam("name") String name) {
    DatasetInstanceConfiguration creationProperties = getInstanceConfiguration(request);

    LOG.info("Creating dataset {}, type name: {}, typeAndProps: {}",
             name, creationProperties.getTypeName(), creationProperties.getProperties());

    DatasetSpecification existing = instanceManager.get(name);
    if (existing != null) {
      String message = String.format("Cannot create dataset %s: instance with same name already exists %s",
                                     name, existing);
      LOG.warn(message);
      responder.sendError(HttpResponseStatus.CONFLICT, message);
      return;
    }

    if (!createDatasetInstance(creationProperties, name, responder, "create")) {
      return;
    }

    // Enable ad-hoc exploration of dataset
    // Note: today explore enable is not transactional with dataset create - CDAP-8
    try {
      datasetExploreFacade.enableExplore(name);
    } catch (Exception e) {
      String msg = String.format("Cannot enable exploration of dataset instance %s of type %s: %s",
                                 name, creationProperties.getProperties(), e.getMessage());
      LOG.error(msg, e);
      // TODO: at this time we want to still allow using dataset even if it cannot be used for exploration
      //responder.sendError(HttpResponseStatus.INTERNAL_SERVER_ERROR, msg);
      //return;
    }
View Full Code Here


   */
  @PUT
  @Path("/data/datasets/{name}/properties")
  public void update(HttpRequest request, final HttpResponder responder,
                     @PathParam("name") String name) {
    DatasetInstanceConfiguration creationProperties = getInstanceConfiguration(request);

    LOG.info("Update dataset {}, type name: {}, typeAndProps: {}",
             name, creationProperties.getTypeName(), creationProperties.getProperties());
    DatasetSpecification existing = instanceManager.get(name);

    if (existing == null) {
      // update is true , but dataset instance does not exist, return 404.
      responder.sendError(HttpResponseStatus.NOT_FOUND,
                          String.format("Dataset Instance %s does not exist to update", name));
      return;
    }

    if (!existing.getType().equals(creationProperties.getTypeName())) {
      String  message = String.format("Cannot update dataset %s instance with a different type, existing type is %s",
                                      name, existing.getType());
      LOG.warn(message);
      responder.sendError(HttpResponseStatus.CONFLICT, message);
      return;
    }

    if (!createDatasetInstance(creationProperties, name, responder, "update")) {
      return;
    }
    // Enable ad-hoc exploration of dataset
    // Note: today explore enable is not transactional with dataset create - CDAP-8

    try {
      datasetExploreFacade.disableExplore(name);
      datasetExploreFacade.enableExplore(name);
    } catch (Exception e) {
      String msg = String.format("Cannot enable exploration of dataset instance %s of type %s: %s",
                                 name, creationProperties.getProperties(), e.getMessage());
      LOG.error(msg, e);
      // TODO: at this time we want to still allow using dataset even if it cannot be used for exploration
      //responder.sendError(HttpResponseStatus.INTERNAL_SERVER_ERROR, msg);
      //return;
    }
View Full Code Here

    executeAdmin(request, responder, name, "upgrade");
  }

  private DatasetInstanceConfiguration getInstanceConfiguration(HttpRequest request) {
    Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()));
    DatasetInstanceConfiguration creationProperties = GSON.fromJson(reader, DatasetInstanceConfiguration.class);
    if (creationProperties.getProperties().containsKey(OrderedTable.PROPERTY_TTL)) {
      long ttl = TimeUnit.SECONDS.toMillis(Long.parseLong
        (creationProperties.getProperties().get(OrderedTable.PROPERTY_TTL)));
      creationProperties.getProperties().put(OrderedTable.PROPERTY_TTL, String.valueOf(ttl));
    }
    return  creationProperties;
  }
View Full Code Here

    return GSON.fromJson(new String(response.getResponseBody(), Charsets.UTF_8), DatasetTypeMeta.class);
  }

  public void addInstance(String datasetInstanceName, String datasetType, DatasetProperties props)
    throws DatasetManagementException {
    DatasetInstanceConfiguration creationProperties = new DatasetInstanceConfiguration(datasetType,
                                                                                       props.getProperties());

    HttpResponse response = doPut("datasets/" + datasetInstanceName, GSON.toJson(creationProperties));

    if (HttpResponseStatus.CONFLICT.getCode() == response.getResponseCode()) {
View Full Code Here

  }

  public void updateInstance(String datasetInstanceName, DatasetProperties props)
    throws DatasetManagementException {
    DatasetMeta meta = getInstance(datasetInstanceName);
    DatasetInstanceConfiguration creationProperties =
      new DatasetInstanceConfiguration(meta.getSpec().getType(), props.getProperties());

    HttpResponse response = doPut("datasets/" + datasetInstanceName + "/properties", GSON.toJson(creationProperties));

    if (HttpResponseStatus.CONFLICT.getCode() == response.getResponseCode()) {
      throw new InstanceConflictException(String.format("Failed to add instance %s due to conflict, details: %s",
View Full Code Here

   * @throws IOException if a network error occurred
   * @throws UnAuthorizedAccessTokenException if the request is not authorized successfully in the gateway server
   */
  public void create(String datasetName, String typeName)
    throws DatasetTypeNotFoundException, DatasetAlreadyExistsException, IOException, UnAuthorizedAccessTokenException {
    create(datasetName, new DatasetInstanceConfiguration(typeName, ImmutableMap.<String, String>of()));
  }
View Full Code Here

TOP

Related Classes of co.cask.cdap.proto.DatasetInstanceConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.