Search in sources :

Example 31 with DatasetId

use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.

the class UsageHandler method getDatasetAppUsage.

@GET
@Path("/namespaces/{namespace-id}/data/datasets/{dataset-id}/programs")
public void getDatasetAppUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("dataset-id") String datasetId) {
    final DatasetId id = new DatasetId(namespaceId, datasetId);
    Set<ProgramId> ids = registry.getPrograms(id);
    responder.sendJson(HttpResponseStatus.OK, BackwardCompatibility.IdProgram.transform(ids));
}
Also used : ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 32 with DatasetId

use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.

the class WorkflowHttpHandler method deleteWorkflowLocalDatasets.

@DELETE
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/localdatasets")
public void deleteWorkflowLocalDatasets(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException {
    WorkflowSpecification workflowSpec = getWorkflowSpecForValidRun(namespaceId, applicationId, workflowId, runId);
    Set<String> errorOnDelete = new HashSet<>();
    for (Map.Entry<String, DatasetCreationSpec> localDatasetEntry : workflowSpec.getLocalDatasetSpecs().entrySet()) {
        String mappedDatasetName = localDatasetEntry.getKey() + "." + runId;
        // try best to delete the local datasets.
        try {
            datasetFramework.deleteInstance(new DatasetId(namespaceId, mappedDatasetName));
        } catch (InstanceNotFoundException e) {
        // Dataset instance is already deleted. so its no-op.
        } catch (Throwable t) {
            errorOnDelete.add(mappedDatasetName);
            LOG.error("Failed to delete the Workflow local dataset {}. Reason - {}", mappedDatasetName, t.getMessage());
        }
    }
    if (errorOnDelete.isEmpty()) {
        responder.sendStatus(HttpResponseStatus.OK);
        return;
    }
    String errorMessage = "Failed to delete Workflow local datasets - " + Joiner.on(",").join(errorOnDelete);
    throw new RuntimeException(errorMessage);
}
Also used : InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 33 with DatasetId

use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.

the class RemoteLineageWriterHandler method addDatasetAccess.

@POST
@Path("/addDatasetAccess")
public void addDatasetAccess(HttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    ProgramRunId run = deserializeNext(arguments);
    DatasetId datasetInstance = deserializeNext(arguments);
    AccessType accessType = deserializeNext(arguments);
    NamespacedEntityId component = deserializeNext(arguments);
    lineageWriter.addAccess(run, datasetInstance, accessType, component);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) MethodArgument(co.cask.cdap.common.internal.remote.MethodArgument) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) AccessType(co.cask.cdap.data2.metadata.lineage.AccessType) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 34 with DatasetId

use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.

the class RemoteUsageRegistryHandler method registerDataset.

@POST
@Path("/registerDataset")
public void registerDataset(HttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    ProgramId programId = deserializeNext(arguments);
    DatasetId datasetInstance = deserializeNext(arguments);
    usageRegistry.register(programId, datasetInstance);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : MethodArgument(co.cask.cdap.common.internal.remote.MethodArgument) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 35 with DatasetId

use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.

the class WorkflowDriver method createLocalDatasets.

private void createLocalDatasets() throws IOException, DatasetManagementException {
    String principal = programOptions.getArguments().getOption(ProgramOptionConstants.PRINCIPAL);
    final KerberosPrincipalId principalId = principal == null ? null : new KerberosPrincipalId(principal);
    for (final Map.Entry<String, String> entry : datasetFramework.getDatasetNameMapping().entrySet()) {
        final String localInstanceName = entry.getValue();
        final DatasetId instanceId = new DatasetId(workflowRunId.getNamespace(), localInstanceName);
        final DatasetCreationSpec instanceSpec = workflowSpec.getLocalDatasetSpecs().get(entry.getKey());
        LOG.debug("Adding Workflow local dataset instance: {}", localInstanceName);
        try {
            Retries.callWithRetries(new Retries.Callable<Void, Exception>() {

                @Override
                public Void call() throws Exception {
                    datasetFramework.addInstance(instanceSpec.getTypeName(), instanceId, addLocalDatasetProperty(instanceSpec.getProperties()), principalId);
                    return null;
                }
            }, RetryStrategies.fixDelay(Constants.Retry.LOCAL_DATASET_OPERATION_RETRY_DELAY_SECONDS, TimeUnit.SECONDS));
        } catch (IOException | DatasetManagementException e) {
            throw e;
        } catch (Exception e) {
            // this should never happen
            throw new IllegalStateException(e);
        }
    }
}
Also used : IOException(java.io.IOException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DatasetId(co.cask.cdap.proto.id.DatasetId) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) Retries(co.cask.cdap.common.service.Retries) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) KerberosPrincipalId(co.cask.cdap.proto.id.KerberosPrincipalId) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

DatasetId (co.cask.cdap.proto.id.DatasetId)180 Test (org.junit.Test)96 ProgramId (co.cask.cdap.proto.id.ProgramId)34 StreamId (co.cask.cdap.proto.id.StreamId)34 Path (javax.ws.rs.Path)34 TransactionExecutor (org.apache.tephra.TransactionExecutor)31 NamespaceId (co.cask.cdap.proto.id.NamespaceId)25 ApplicationId (co.cask.cdap.proto.id.ApplicationId)23 IOException (java.io.IOException)19 POST (javax.ws.rs.POST)17 TransactionFailureException (org.apache.tephra.TransactionFailureException)17 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)16 QueryResult (co.cask.cdap.proto.QueryResult)16 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)15 ColumnDesc (co.cask.cdap.proto.ColumnDesc)14 Map (java.util.Map)13 NoSuchElementException (java.util.NoSuchElementException)13 Table (co.cask.cdap.api.dataset.table.Table)12 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)11 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11