use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.
the class TagV1Resource method removeTableTags.
/**
* {@inheritDoc}
*/
@Override
public void removeTableTags(final String catalogName, final String databaseName, final String tableName, final Boolean deleteAll, final Set<String> tags) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
if (!tableService.exists(name)) {
// Delete tags if exists
tagService.delete(name, false);
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
tagService.removeTableTags(name, deleteAll, tags, true);
final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return null;
});
}
use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.
the class TagV1Resource method setTableTags.
/**
* {@inheritDoc}
*/
@Override
public Set<String> setTableTags(final String catalogName, final String databaseName, final String tableName, final Set<String> tags) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
return requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
if (!tableService.exists(name)) {
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
final Set<String> result = tagService.setTableTags(name, tags, true);
final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return result;
});
}
use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.
the class TagController method removeResourceTags.
private void removeResourceTags(final TagRemoveRequestDto tagRemoveRequestDto) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = tagRemoveRequestDto.getName();
switch(name.getType()) {
case CATALOG:
// catalog service will throw exception if not found
this.catalogService.get(name, GetCatalogServiceParameters.builder().includeDatabaseNames(false).includeUserMetadata(false).build());
this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), true);
break;
case DATABASE:
if (!this.databaseService.exists(name)) {
throw new DatabaseNotFoundException(name);
}
this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), true);
this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
break;
case TABLE:
if (!this.tableService.exists(name)) {
this.tagService.delete(name, false);
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), true);
final TableDto currentTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
break;
case MVIEW:
if (!this.mViewService.exists(name)) {
throw new MetacatNotFoundException(name.toString());
}
final Optional<TableDto> oldView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
if (oldView.isPresent()) {
this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), true);
final Optional<TableDto> currentView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
currentView.ifPresent(p -> this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldView.get(), currentView.get())));
}
break;
default:
throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);
}
}
use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.
the class TagController method setTableTags.
/**
* Sets the tags on the given table.
* TODO: remove after setTags api is adopted
*
* @param catalogName catalog name
* @param databaseName database name
* @param tableName table name
* @param tags set of tags
* @return set of tags
*/
@RequestMapping(method = RequestMethod.POST, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "Sets the tags on the given table", notes = "Sets the tags on the given table")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "The tags were successfully created on the table"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located") })
public Set<String> setTableTags(@ApiParam(value = "The name of the catalog", required = true) @PathVariable("catalog-name") final String catalogName, @ApiParam(value = "The name of the database", required = true) @PathVariable("database-name") final String databaseName, @ApiParam(value = "The name of the table", required = true) @PathVariable("table-name") final String tableName, @ApiParam(value = "Set of tags", required = true) @RequestBody final Set<String> tags) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
return this.requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
// TODO: shouldn't this be in the tag service?
if (!this.tableService.exists(name)) {
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
final Set<String> result = this.tagService.setTags(name, tags, true);
final TableDto currentTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return result;
});
}
use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.
the class IcebergTableEventHandler method metacatUpdateTableEventHandler.
/**
* The update table event handler.
*
* @param event The event.
*/
@EventListener
public void metacatUpdateTableEventHandler(final MetacatUpdateIcebergTablePostEvent event) {
final QualifiedName name = event.getName();
final TableDto tableDto = event.getRequestTable();
TableDto updatedDto = tableDto;
try {
updatedDto = tableService.get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElse(tableDto);
} catch (Exception ex) {
handleException(name, "getTable", ex);
}
try {
eventBus.post(new MetacatUpdateTablePostEvent(event.getName(), event.getRequestContext(), this, event.getOldTable(), updatedDto, updatedDto != tableDto));
} catch (Exception ex) {
handleException(name, "postEvent", ex);
}
}
Aggregations