use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class WorkflowClient method getWorkflowNodeStates.
/**
* Get node states associated with the Workflow run.
* @param workflowRunId run id for the Workflow
* @return the map of node id to the {@link WorkflowNodeStateDetail}
* @throws IOException if the error occurred during executing the http request
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NotFoundException if the workflow with given runid not found
*/
public Map<String, WorkflowNodeStateDetail> getWorkflowNodeStates(ProgramRunId workflowRunId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/workflows/%s/runs/%s/nodes/state", workflowRunId.getApplication(), workflowRunId.getProgram(), workflowRunId.getRun());
NamespaceId namespaceId = workflowRunId.getNamespaceId();
URL urlPath = config.resolveNamespacedURLV3(namespaceId, path);
HttpResponse response = restClient.execute(HttpMethod.GET, urlPath, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(workflowRunId);
}
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, WorkflowNodeStateDetail>>() {
}).getResponseObject();
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class WorkflowClient method getWorkflowLocalDatasetURL.
private URL getWorkflowLocalDatasetURL(ProgramRunId workflowRunId) throws MalformedURLException {
String path = String.format("apps/%s/workflows/%s/runs/%s/localdatasets", workflowRunId.getApplication(), workflowRunId.getProgram(), workflowRunId.getRun());
NamespaceId namespaceId = workflowRunId.getNamespaceId();
return config.resolveNamespacedURLV3(namespaceId, path);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DatasetInstanceService method create.
/**
* Creates a dataset instance.
*
* @param namespaceId the namespace to create the dataset instance in
* @param name the name of the new dataset instance
* @param props the properties for the new dataset instance
* @throws NamespaceNotFoundException if the specified namespace was not found
* @throws DatasetAlreadyExistsException if a dataset with the same name already exists
* @throws DatasetTypeNotFoundException if the dataset type was not found
* @throws UnauthorizedException if perimeter security and authorization are enabled, and the current user does not
* have {@link Action#WRITE} privilege on the #instance's namespace
*/
void create(String namespaceId, String name, DatasetInstanceConfiguration props) throws Exception {
NamespaceId namespace = ConversionHelpers.toNamespaceId(namespaceId);
Principal principal = authenticationContext.getPrincipal();
authorizationEnforcer.enforce(namespace, principal, Action.WRITE);
ensureNamespaceExists(namespace);
DatasetId datasetId = ConversionHelpers.toDatasetInstanceId(namespaceId, name);
DatasetSpecification existing = instanceManager.get(datasetId);
if (existing != null) {
throw new DatasetAlreadyExistsException(datasetId);
}
DatasetTypeMeta typeMeta = getTypeInfo(namespace, props.getTypeName());
if (typeMeta == null) {
// Type not found in the instance's namespace and the system namespace. Bail out.
throw new DatasetTypeNotFoundException(ConversionHelpers.toDatasetTypeId(namespace, props.getTypeName()));
}
// It is now determined that a new dataset will be created. First grant privileges, then create the dataset.
// If creation fails, revoke the granted privileges. This ensures that just like delete, there may be orphaned
// privileges in rare scenarios, but there can never be orphaned datasets.
// If the dataset previously existed and was deleted, but revoking privileges somehow failed, there may be orphaned
// privileges for the dataset. Revoke them first, so no users unintentionally get privileges on the dataset.
privilegesManager.revoke(datasetId);
// grant all privileges on the dataset to be created
privilegesManager.grant(datasetId, principal, EnumSet.allOf(Action.class));
LOG.info("Creating dataset {}.{}, type name: {}, properties: {}", namespaceId, name, props.getTypeName(), props.getProperties());
// Note how we execute configure() via opExecutorClient (outside of ds service) to isolate running user code
try {
String ownerPrincipal = props.getOwnerPrincipal();
// exists or not
if (ownerPrincipal != null) {
KerberosPrincipalId owner = new KerberosPrincipalId(ownerPrincipal);
ownerAdmin.add(datasetId, owner);
}
try {
DatasetSpecification spec = opExecutorClient.create(datasetId, typeMeta, DatasetProperties.builder().addAll(props.getProperties()).setDescription(props.getDescription()).build());
instanceManager.add(namespace, spec);
metaCache.invalidate(datasetId);
publishAudit(datasetId, AuditType.CREATE);
// Enable explore
enableExplore(datasetId, spec, props);
} catch (Exception e) {
// there was a problem in creating the dataset instance so delete the owner if it got added earlier
// safe to call for entities which does not have an owner too
ownerAdmin.delete(datasetId);
throw e;
}
} catch (Exception e) {
// there was a problem in creating the dataset instance so revoke the privileges
privilegesManager.revoke(datasetId);
throw e;
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DatasetAdminOpHTTPHandler method exists.
@POST
@Path("/data/datasets/{name}/admin/exists")
public void exists(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) {
propagateUserId(request);
NamespaceId namespace = new NamespaceId(namespaceId);
try {
DatasetId instanceId = namespace.dataset(instanceName);
responder.sendJson(HttpResponseStatus.OK, new DatasetAdminOpResponse(datasetAdminService.exists(instanceId), null));
} catch (NotFoundException e) {
LOG.debug("Got handler exception", e);
responder.sendString(HttpResponseStatus.NOT_FOUND, StringUtils.defaultIfEmpty(e.getMessage(), ""));
} catch (Exception e) {
LOG.error(getAdminOpErrorMessage("exists", instanceName), e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, getAdminOpErrorMessage("exists", instanceName));
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LevelDBDatasetMetricsReporter method report.
private void report(Map<TableId, LevelDBTableService.TableStats> datasetStat) throws DatasetManagementException {
for (Map.Entry<TableId, LevelDBTableService.TableStats> statEntry : datasetStat.entrySet()) {
String namespace = statEntry.getKey().getNamespace();
// emit metrics for only user datasets, tables in system namespace are ignored
if (NamespaceId.SYSTEM.getNamespace().equals(namespace)) {
continue;
}
String tableName = statEntry.getKey().getTableName();
Collection<DatasetSpecificationSummary> instances = dsFramework.getInstances(new NamespaceId(namespace));
for (DatasetSpecificationSummary spec : instances) {
DatasetSpecification specification = dsFramework.getDatasetSpec(new DatasetId(namespace, spec.getName()));
if (specification.isParent(tableName)) {
MetricsContext collector = metricsService.getContext(ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, namespace, Constants.Metrics.Tag.DATASET, spec.getName()));
int sizeInMb = (int) (statEntry.getValue().getDiskSizeBytes() / BYTES_IN_MB);
collector.gauge("dataset.size.mb", sizeInMb);
break;
}
}
}
}
Aggregations